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