• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SESSION_MANAGER_H_
18 #define TRUNKS_SESSION_MANAGER_H_
19 
20 #include <string>
21 
22 #include "trunks/hmac_authorization_delegate.h"
23 #include "trunks/tpm_generated.h"
24 #include "trunks/trunks_export.h"
25 #include "trunks/trunks_factory.h"
26 
27 namespace trunks {
28 
29 const trunks::TPM_HANDLE kUninitializedHandle = 0;
30 
31 // This class is used to keep track of a TPM session. Each instance of this
32 // class is used to account for one instance of a TPM session. Currently
33 // this class is used by AuthorizationSession instances to keep track of TPM
34 // sessions.
35 // Note: This class is not intended to be used independently. However clients
36 // who want to manually manage their sessions can use this class to Start and
37 // Close TPM backed Sessions. Example usage:
38 // trunks::TrunksFactoryImpl factory;
39 // scoped_ptr<SessionManager> session_manager = factory.GetSessionManager();
40 // session_manager->StartSession(...);
41 // TPM_HANDLE session_handle = session_manager->GetSessionHandle();
42 class TRUNKS_EXPORT SessionManager {
43  public:
SessionManager()44   SessionManager() {}
~SessionManager()45   virtual ~SessionManager() {}
46 
47   // This method is used get the handle to the AuthorizationSession managed by
48   // this instance.
49   virtual TPM_HANDLE GetSessionHandle() const = 0;
50 
51   // This method is used to flush all TPM context associated with the current
52   // session
53   virtual void CloseSession() = 0;
54 
55   // This method is used to start a new AuthorizationSession. Once started,
56   // GetSessionHandle() can be used to access the handle to the TPM session.
57   // Since the sessions are salted, we need to ensure that TPM ownership is
58   // taken and the salting key created before this method is called.
59   // Returns TPM_RC_SUCCESS and returns the nonces used to create the session
60   // on success.
61   virtual TPM_RC StartSession(TPM_SE session_type,
62                               TPMI_DH_ENTITY bind_entity,
63                               const std::string& bind_authorization_value,
64                               bool enable_encryption,
65                               HmacAuthorizationDelegate* delegate) = 0;
66 
67  private:
68   DISALLOW_COPY_AND_ASSIGN(SessionManager);
69 };
70 
71 }  // namespace trunks
72 
73 #endif  // TRUNKS_SESSION_MANAGER_H_
74