Fix close entited key session in oemcrypto adaptor
[ Merge of http://go/wvgerrit/153290 ] Currently OEMCrypto_Close will be called for entitled key sessions as well upon destroying, while only OEMCrypto sessions should be called. This CL adds a session type to the oemcrypto adaptor. Bug: 232225911 Bug: 236317198 Test: request_license_test Change-Id: I323fff80139ce949f801cf0df5aa2bd3171dfb51
This commit is contained in:
@@ -806,13 +806,24 @@ OEMCryptoResult SetAllowTestKeybox(bool allow) {
|
|||||||
return OEMCrypto_SUCCESS;
|
return OEMCrypto_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef enum OEMCryptoSessionType {
|
||||||
|
SESSION_TYPE_OEMCRYPTO = 0,
|
||||||
|
SESSION_TYPE_ENTITLED_KEY = 1,
|
||||||
|
SESSION_TYPE_UNKNOWN = 2,
|
||||||
|
} OEMCryptoSessionType;
|
||||||
|
|
||||||
struct LevelSession {
|
struct LevelSession {
|
||||||
FunctionPointers* fcn;
|
FunctionPointers* fcn;
|
||||||
OEMCrypto_SESSION session;
|
OEMCrypto_SESSION session;
|
||||||
|
OEMCryptoSessionType session_type;
|
||||||
// For backwards compatibility, we need to remember the session's nonce
|
// For backwards compatibility, we need to remember the session's nonce
|
||||||
// so that we can pass it to the ODK library.
|
// so that we can pass it to the ODK library.
|
||||||
uint32_t nonce;
|
uint32_t nonce;
|
||||||
LevelSession() : fcn(nullptr), session(0), nonce(0) {}
|
LevelSession()
|
||||||
|
: fcn(nullptr),
|
||||||
|
session(0),
|
||||||
|
session_type(SESSION_TYPE_OEMCRYPTO),
|
||||||
|
nonce(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define QUOTE_DEFINE(A) #A
|
#define QUOTE_DEFINE(A) #A
|
||||||
@@ -1257,7 +1268,9 @@ class Adapter {
|
|||||||
|
|
||||||
OEMCryptoResult Terminate() {
|
OEMCryptoResult Terminate() {
|
||||||
for (map_iterator i = session_map_.begin(); i != session_map_.end(); ++i) {
|
for (map_iterator i = session_map_.begin(); i != session_map_.end(); ++i) {
|
||||||
if (i->second.fcn) i->second.fcn->CloseSession(i->second.session);
|
if (i->second.fcn && i->second.session_type == SESSION_TYPE_OEMCRYPTO) {
|
||||||
|
i->second.fcn->CloseSession(i->second.session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
session_map_.clear();
|
session_map_.clear();
|
||||||
OEMCryptoResult result = Level3_Terminate();
|
OEMCryptoResult result = Level3_Terminate();
|
||||||
@@ -1285,6 +1298,7 @@ class Adapter {
|
|||||||
OEMCryptoResult OpenSession(OEMCrypto_SESSION* session,
|
OEMCryptoResult OpenSession(OEMCrypto_SESSION* session,
|
||||||
wvcdm::RequestedSecurityLevel level) {
|
wvcdm::RequestedSecurityLevel level) {
|
||||||
LevelSession new_session;
|
LevelSession new_session;
|
||||||
|
new_session.session_type = SESSION_TYPE_OEMCRYPTO;
|
||||||
OEMCryptoResult result;
|
OEMCryptoResult result;
|
||||||
if (level == kLevelDefault && level1_valid_) {
|
if (level == kLevelDefault && level1_valid_) {
|
||||||
new_session.fcn = &level1_;
|
new_session.fcn = &level1_;
|
||||||
@@ -1335,6 +1349,7 @@ class Adapter {
|
|||||||
new_session.fcn = pair.fcn;
|
new_session.fcn = pair.fcn;
|
||||||
new_session.nonce = pair.nonce;
|
new_session.nonce = pair.nonce;
|
||||||
new_session.session = *key_session;
|
new_session.session = *key_session;
|
||||||
|
new_session.session_type = SESSION_TYPE_ENTITLED_KEY;
|
||||||
std::unique_lock<std::mutex> auto_lock(session_map_lock_);
|
std::unique_lock<std::mutex> auto_lock(session_map_lock_);
|
||||||
// Make sure session is not already in my list of sessions.
|
// Make sure session is not already in my list of sessions.
|
||||||
while (session_map_.find(*key_session) != session_map_.end()) {
|
while (session_map_.find(*key_session) != session_map_.end()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user