Skip to content

Commit aacd17c

Browse files
authored
Merge pull request #977 from pennam/se050-sn
SE050: Add serialNumber(byte sn[])
2 parents 103d4ab + 8bc3ab2 commit aacd17c

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

Diff for: libraries/SE05X/src/SE05X.cpp

+26-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#define SE05X_EC_SIGNATURE_HEADER_LENGTH 6
2727
#define SE05X_EC_SIGNATURE_DER_LENGTH SE05X_EC_SIGNATURE_HEADER_LENGTH + SE05X_EC_SIGNATURE_RAW_LENGTH
2828
#define SE05X_SHA256_LENGTH 32
29-
#define SE05X_SN_LENGTH 18
3029
#define SE05X_DER_BUFFER_SIZE 256
3130
#define SE05X_TEMP_OBJECT 9999
3231

@@ -111,8 +110,6 @@ static void setECSignatureRsValuesInDER(const byte* rawSignature, byte* signatur
111110

112111
int SE05XClass::begin()
113112
{
114-
sss_status_t status;
115-
116113
memset(&_boot_ctx, 0, sizeof(ex_sss_boot_ctx_t));
117114

118115
se05x_ic_power_on();
@@ -158,17 +155,39 @@ int SE05XClass::readConfiguration(byte data[])
158155
return 1;
159156
}
160157

158+
int SE05XClass::serialNumber(byte sn[])
159+
{
160+
return serialNumber(sn, SE05X_SN_LENGTH);
161+
}
162+
163+
int SE05XClass::serialNumber(byte sn[], size_t length)
164+
{
165+
size_t uidLen = SE05X_SN_LENGTH;
166+
byte UID[SE05X_SN_LENGTH];
167+
168+
if(!sn) {
169+
return 0;
170+
}
171+
172+
sss_status_t status = sss_session_prop_get_au8(&_boot_ctx.session, kSSS_SessionProp_UID, UID, &uidLen);
173+
if ((status != kStatus_SSS_Success)) {
174+
SE05X_PRINT_ERROR("Error in Se05x_API_ReadObject \n");
175+
return 0;
176+
}
177+
memcpy(sn, UID, length < SE05X_SN_LENGTH ? length : SE05X_SN_LENGTH);
178+
return 1;
179+
}
180+
161181
String SE05XClass::serialNumber()
162182
{
163183
String result = (char*)NULL;
164184
byte UID[SE05X_SN_LENGTH];
165-
size_t uidLen = 18;
166185

167-
sss_session_prop_get_au8(&_boot_ctx.session, kSSS_SessionProp_UID, UID, &uidLen);
186+
serialNumber(UID, sizeof(UID));
168187

169-
result.reserve(uidLen*2);
188+
result.reserve(SE05X_SN_LENGTH * 2);
170189

171-
for (int i = 0; i < uidLen; i++) {
190+
for (size_t i = 0; i < SE05X_SN_LENGTH; i++) {
172191
byte b = UID[i];
173192

174193
if (b < 16) {
@@ -591,8 +610,6 @@ int SE05XClass::deleteAllObjects(void)
591610

592611
int SE05XClass::getObjectHandle(int objectId, sss_object_t * object)
593612
{
594-
sss_status_t status;
595-
596613
if(kStatus_SSS_Success != sss_key_object_init(object, &_boot_ctx.ks)) {
597614
SE05X_PRINT_ERROR("sss_key_object_init Failed");
598615
return 0;

Diff for: libraries/SE05X/src/SE05X.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
#include "se05x_APDU.h"
2828

2929
#if defined SE05X_PRINT_ERROR_ENABLE
30-
#define SE05X_PRINT_ERROR Serial.println
30+
#define SE05X_PRINT_ERROR(x) Serial.println(x)
3131
#else
32-
#define SE05X_PRINT_ERROR
32+
#define SE05X_PRINT_ERROR(x)
3333
#endif
3434

35+
#define SE05X_SN_LENGTH 18
36+
3537
class SE05XClass
3638
{
3739
public:
@@ -41,6 +43,8 @@ class SE05XClass
4143
int begin();
4244
void end();
4345

46+
int serialNumber(byte sn[]);
47+
int serialNumber(byte sn[], size_t length);
4448
String serialNumber();
4549

4650
long random(long max);

0 commit comments

Comments
 (0)