Implement public key extraction in TZ backend
[platform/core/security/key-manager.git] / src / manager / crypto / tz-backend / store.cpp
index 302fd2a..ff06b77 100644 (file)
@@ -68,19 +68,23 @@ GObjUPtr Store::getObject(const Token &token, const Password &pass)
        RawBuffer tag;
        unpack(token.data, pass, scheme, id, iv, tag);
 
-       if (token.dataType.isKeyPrivate() || token.dataType.isKeyPublic())
+       if (token.dataType.isKeyPrivate())
                return make<AKey>(scheme, std::move(id), Pwd(pass, iv, tag), token.dataType);
 
        if (token.dataType.isSymmetricKey())
-               return make<SKey>(scheme, std::move(id), Pwd(pass, iv, tag), token.dataType);
+               return make<SKey>(scheme, std::move(id), Pwd(pass, iv, tag));
 
        if (token.dataType.isCertificate() || token.dataType.isChainCert())
                return make<Cert>(scheme, std::move(id), Pwd(pass, iv, tag), token.dataType);
 
-       if (token.dataType.isBinaryData()) {
-               RawBuffer exported_data = Internals::getData(std::move(id), Pwd(pass, iv, tag));
-               return make<BData>(std::move(exported_data));
-       }
+       auto pwd = Pwd(pass, iv, tag);
+       RawBuffer raw = Internals::getData(id, pwd);
+
+       if (token.dataType.isKeyPublic())
+               return make<AKey>(scheme, std::move(id), std::move(pwd), token.dataType, std::move(raw));
+
+       if (token.dataType.isBinaryData())
+               return make<BData>(scheme, std::move(id), std::move(pwd), std::move(raw));
 
        ThrowErr(Exc::Crypto::DataTypeNotSupported,
                         "This type of data is not supported by trustzone backend: ", token.dataType);
@@ -198,7 +202,7 @@ void Store::unpack(const RawBuffer &packed,
                buffer.Deserialize(data);
        }
 
-       if (scheme & EncryptionScheme::PASSWORD && password.empty()) {
+       if ((scheme & EncryptionScheme::PASSWORD) && password.empty()) {
                ThrowErr(Exc::Crypto::AuthenticationFailed,
                                 "This token is protected with password and none passed");
        } else if (!(scheme & EncryptionScheme::PASSWORD) && !password.empty()) {