1 // 2 // Copyright (C) 2015 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef TRUNKS_HMAC_SESSION_H_ 18 #define TRUNKS_HMAC_SESSION_H_ 19 20 #include <string> 21 22 #include <base/macros.h> 23 24 #include "trunks/tpm_generated.h" 25 26 namespace trunks { 27 28 class AuthorizationDelegate; 29 30 // HmacSession is an interface for managing hmac backed sessions for 31 // authorization and parameter encryption. 32 class HmacSession { 33 public: HmacSession()34 HmacSession() {} ~HmacSession()35 virtual ~HmacSession() {} 36 37 // Returns an authorization delegate for this session. Ownership of the 38 // delegate pointer is retained by the session. 39 virtual AuthorizationDelegate* GetDelegate() = 0; 40 41 // Starts a salted session which is bound to |bind_entity| with 42 // |bind_authorization_value|. Encryption is enabled if |enable_encryption| is 43 // true. The session remains active until this object is destroyed or another 44 // session is started with a call to Start*Session. 45 virtual TPM_RC StartBoundSession( 46 TPMI_DH_ENTITY bind_entity, 47 const std::string& bind_authorization_value, 48 bool enable_encryption) = 0; 49 50 // Starts a salted, unbound session. Encryption is enabled if 51 // |enable_encryption| is true. The session remains active until this object 52 // is destroyed or another session is started with a call to Start*Session. 53 virtual TPM_RC StartUnboundSession(bool enable_encryption) = 0; 54 55 // Sets the current entity authorization value. This can be safely called 56 // while the session is active and subsequent commands will use the value. 57 virtual void SetEntityAuthorizationValue(const std::string& value) = 0; 58 59 // Sets the future_authorization_value field in the HmacDelegate. This 60 // is used in response validation for the TPM2_HierarchyChangeAuth command. 61 // We need to perform this because the HMAC value returned from 62 // HierarchyChangeAuth uses the new auth_value. 63 virtual void SetFutureAuthorizationValue(const std::string& value) = 0; 64 65 private: 66 DISALLOW_COPY_AND_ASSIGN(HmacSession); 67 }; 68 69 } // namespace trunks 70 71 #endif // TRUNKS_HMAC_SESSION_H_ 72