SOPC_SerializedAsymmetricKey should always be in DER format
As it was done in !1133 (merged) for SerializedCertificate, SOPC_SerializedAsymmetricKey should always be in DER format and documented in consequence.
It means SOPC_KeyManager_SerializedAsymmetricKey_CreateFromFile_WithPwd
shall always parse the key (PEM or DER) with crypto library and then deserialize it (DER) to provide a normalized DER format key.
The following modification should be sufficient but should be tested with a non encrypted key:
--- a/src/Common/crypto/sopc_key_manager.c
+++ b/src/Common/crypto/sopc_key_manager.c
@@ -110,17 +110,8 @@ SOPC_ReturnStatus SOPC_KeyManager_SerializedAsymmetricKey_CreateFromFile_WithPwd
return SOPC_STATUS_INVALID_PARAMETERS;
}
- SOPC_ReturnStatus status = SOPC_STATUS_OK;
-
- if (NULL == password)
- {
- // The key is not encrypt
- status = SOPC_KeyManager_SerializedAsymmetricKey_CreateFromFile(keyPath, key);
- return status;
- }
-
SOPC_AsymmetricKey* pKey = NULL;
- status = SOPC_KeyManager_AsymmetricKey_CreateFromFile(keyPath, &pKey, password, lenPassword);
+ SOPC_ReturnStatus status = SOPC_KeyManager_AsymmetricKey_CreateFromFile(keyPath, &pKey, password, lenPassword);
SOPC_KeyManager_SerializedAsymmetricKey_CreateFromFile
is already marked as deprecated and shall not be used anymore to guarantee serialized format.
Edited by Vincent Monfort