Skip to content

Commit 3dcdbf3

Browse files
committed
Add function to compare certificate signature
1 parent 5b742b6 commit 3dcdbf3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/utility/SElementArduinoCloudCertificate.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ int SElementArduinoCloudCertificate::read(SecureElement & se, ECP256Certificate
126126
return 1;
127127
}
128128

129+
int SElementArduinoCloudCertificate::signatureCompare(const byte * signatureA, const String & signatureB)
130+
{
131+
byte signatureBytes[ECP256_CERT_SIGNATURE_LENGTH];
132+
133+
if (signatureB.length() == 0 || signatureA == nullptr) {
134+
DEBUG_ERROR("SEACC::%s input params error.", __FUNCTION__);
135+
return -1;
136+
}
137+
138+
hexStringToBytes(signatureB, signatureBytes, sizeof(signatureBytes));
139+
140+
/* If authorityKeyId are matching there is no need to rebuild*/
141+
if (memcmp(signatureBytes, signatureA , sizeof(signatureBytes)) == 0) {
142+
DEBUG_VERBOSE("SEACC::%s signatures are equal", __FUNCTION__);
143+
return 0;
144+
}
145+
return 1;
146+
}
147+
129148
int SElementArduinoCloudCertificate::isAuthorityKeyIdDifferent(const ECP256Certificate & cert, const String & authorityKeyIdentifier)
130149
{
131150
byte authorityKeyIdentifierBytes[ECP256_CERT_AUTHORITY_KEY_ID_LENGTH];

src/utility/SElementArduinoCloudCertificate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class SElementArduinoCloudCertificate : public SElementCertificate
2929
static int write(SecureElement & se, ECP256Certificate & cert, const SElementArduinoCloudSlot certSlot);
3030
static int read(SecureElement & se, ECP256Certificate & cert, const SElementArduinoCloudSlot certSlot, const SElementArduinoCloudSlot keySlot = SElementArduinoCloudSlot::Key);
3131
static int isAuthorityKeyIdDifferent(const ECP256Certificate & cert, const String & authorityKeyIdentifier);
32+
static int signatureCompare(const byte * signatureA, const String & signatureB);
3233
static int rebuild(SecureElement & se, ECP256Certificate & cert, const String & deviceId,
3334
const String & notBefore, const String & notAfter, const String & serialNumber,
3435
const String & authorityKeyIdentifier, const String & signature,

0 commit comments

Comments
 (0)