Skip to content

Commit eb77a9f

Browse files
committed
SecureElement: fix read and write cert
1 parent 8419b3c commit eb77a9f

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/SecureElement.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ int SecureElement::writeCert(ECP256Certificate & cert, const int certSlot)
5555
if (!_secureElement.writeSlot(certSlot + 1, cert.compressedCertSerialAndAuthorityKeyIdBytes(), cert.compressedCertSerialAndAuthorityKeyIdLenght())) {
5656
return 0;
5757
}
58+
59+
if (!_secureElement.writeSlot(certSlot + 2, cert.subjectCommonNameBytes(), cert.subjectCommonNameLenght())) {
60+
return 0;
61+
}
5862
#endif
5963
return 1;
6064
}
6165

62-
int SecureElement::readCert(ECP256Certificate & cert, const int certSlot)
66+
int SecureElement::readCert(ECP256Certificate & cert, const int certSlot, const int keySlot)
6367
{
6468
#if defined(BOARD_HAS_SE050)
6569
byte derBuffer[SE_CERT_BUFFER_LENGTH];
@@ -72,16 +76,11 @@ int SecureElement::readCert(ECP256Certificate & cert, const int certSlot)
7276
return 0;
7377
}
7478
#else
75-
String deviceId;
79+
String deviceId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
7680
byte publicKey[ECP256_CERT_PUBLIC_KEY_LENGTH];
7781

7882
cert.begin();
7983

80-
/* To do certificate is splitted into multiple slots */
81-
//if (!readDeviceId(deviceId, 0)) {
82-
// return 0;
83-
//}
84-
8584
if (!_secureElement.readSlot(certSlot, cert.compressedCertSignatureAndDatesBytes(), cert.compressedCertSignatureAndDatesLength())) {
8685
return 0;
8786
}
@@ -90,8 +89,11 @@ int SecureElement::readCert(ECP256Certificate & cert, const int certSlot)
9089
return 0;
9190
}
9291

93-
/* TODO check key slot */
94-
if (!_secureElement.generatePublicKey(0, publicKey)) {
92+
if (!_secureElement.readSlot(certSlot + 2, (byte*)deviceId.begin(), deviceId.length())) {
93+
return 0;
94+
}
95+
96+
if (!_secureElement.generatePublicKey(keySlot, publicKey)) {
9597
return 0;
9698
}
9799

src/SecureElement.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class SecureElement
8282
#endif
8383

8484
int writeCert(ECP256Certificate & cert, const int certSlot);
85-
int readCert(ECP256Certificate & cert, const int certSlot);
85+
int readCert(ECP256Certificate & cert, const int certSlot, const int keySlot = 0);
8686

8787
private:
8888
#if defined(BOARD_HAS_SE050)

0 commit comments

Comments
 (0)