Retrieve TZ raw key data only when needed 79/295879/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 12 Jul 2023 08:59:31 +0000 (10:59 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 14 Jul 2023 12:43:30 +0000 (14:43 +0200)
Change-Id: Ia1ef537b9696e39c53c1f4972f96ead4cb0fb81a

src/manager/crypto/tz-backend/obj.cpp
src/manager/crypto/tz-backend/obj.h
src/manager/crypto/tz-backend/store.cpp

index 55a4164..8d85d1a 100644 (file)
@@ -177,6 +177,14 @@ GCtxShPtr AKey::initContext(const CryptoAlgorithm &, bool)
        ThrowErr(Exc::Crypto::OperationNotSupported);
 }
 
+RawBuffer AKey::getBinary() const
+{
+       if (m_type.isKeyPublic() && m_raw.empty())
+               m_raw = Internals::getData(getId(), getPassword());
+
+       return m_raw;
+}
+
 RawBuffer AKey::sign(
        const CryptoAlgorithm &alg,
        const RawBuffer &message)
index 2b0fff3..eec1e9f 100644 (file)
@@ -93,7 +93,7 @@ protected:
        int m_scheme;
        Pwd m_password;
        RawBuffer m_id;
-       RawBuffer m_raw;
+       mutable RawBuffer m_raw;
 };
 
 class Key : public BData {
@@ -127,13 +127,10 @@ public:
                 int scheme,
                 RawBuffer id,
                 Pwd pwd,
-                DataType dataType,
-                RawBuffer raw = RawBuffer()) :
-               Key(backendId, scheme, std::move(id), std::move(pwd)), m_type(dataType)
-       {
-               m_raw = std::move(raw);
-       }
+                DataType dataType) :
+               Key(backendId, scheme, std::move(id), std::move(pwd)), m_type(dataType) {}
 
+       RawBuffer getBinary() const override;
        RawBuffer sign(const CryptoAlgorithm &alg, const RawBuffer &message) override;
        int verify(const CryptoAlgorithm &alg, const RawBuffer &message,
                           const RawBuffer &sign) override;
index ff06b77..958da3a 100644 (file)
@@ -68,7 +68,7 @@ GObjUPtr Store::getObject(const Token &token, const Password &pass)
        RawBuffer tag;
        unpack(token.data, pass, scheme, id, iv, tag);
 
-       if (token.dataType.isKeyPrivate())
+       if (token.dataType.isKeyPrivate() || token.dataType.isKeyPublic())
                return make<AKey>(scheme, std::move(id), Pwd(pass, iv, tag), token.dataType);
 
        if (token.dataType.isSymmetricKey())
@@ -80,9 +80,6 @@ GObjUPtr Store::getObject(const Token &token, const Password &pass)
        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));