Skip to content

SE050: Add serialNumber(byte sn[]) #977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions libraries/SE05X/src/SE05X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#define SE05X_EC_SIGNATURE_HEADER_LENGTH 6
#define SE05X_EC_SIGNATURE_DER_LENGTH SE05X_EC_SIGNATURE_HEADER_LENGTH + SE05X_EC_SIGNATURE_RAW_LENGTH
#define SE05X_SHA256_LENGTH 32
#define SE05X_SN_LENGTH 18
#define SE05X_DER_BUFFER_SIZE 256
#define SE05X_TEMP_OBJECT 9999

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

int SE05XClass::begin()
{
sss_status_t status;

memset(&_boot_ctx, 0, sizeof(ex_sss_boot_ctx_t));

se05x_ic_power_on();
Expand Down Expand Up @@ -158,17 +155,39 @@ int SE05XClass::readConfiguration(byte data[])
return 1;
}

int SE05XClass::serialNumber(byte sn[])
{
return serialNumber(sn, SE05X_SN_LENGTH);
}

int SE05XClass::serialNumber(byte sn[], size_t length)
{
size_t uidLen = SE05X_SN_LENGTH;
byte UID[SE05X_SN_LENGTH];

if(!sn) {
return 0;
}

sss_status_t status = sss_session_prop_get_au8(&_boot_ctx.session, kSSS_SessionProp_UID, UID, &uidLen);
if ((status != kStatus_SSS_Success)) {
SE05X_PRINT_ERROR("Error in Se05x_API_ReadObject \n");
return 0;
}
memcpy(sn, UID, length < SE05X_SN_LENGTH ? length : SE05X_SN_LENGTH);
return 1;
}

String SE05XClass::serialNumber()
{
String result = (char*)NULL;
byte UID[SE05X_SN_LENGTH];
size_t uidLen = 18;

sss_session_prop_get_au8(&_boot_ctx.session, kSSS_SessionProp_UID, UID, &uidLen);
serialNumber(UID, sizeof(UID));

result.reserve(uidLen*2);
result.reserve(SE05X_SN_LENGTH * 2);

for (int i = 0; i < uidLen; i++) {
for (size_t i = 0; i < SE05X_SN_LENGTH; i++) {
byte b = UID[i];

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

int SE05XClass::getObjectHandle(int objectId, sss_object_t * object)
{
sss_status_t status;

if(kStatus_SSS_Success != sss_key_object_init(object, &_boot_ctx.ks)) {
SE05X_PRINT_ERROR("sss_key_object_init Failed");
return 0;
Expand Down
8 changes: 6 additions & 2 deletions libraries/SE05X/src/SE05X.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
#include "se05x_APDU.h"

#if defined SE05X_PRINT_ERROR_ENABLE
#define SE05X_PRINT_ERROR Serial.println
#define SE05X_PRINT_ERROR(x) Serial.println(x)
#else
#define SE05X_PRINT_ERROR
#define SE05X_PRINT_ERROR(x)
#endif

#define SE05X_SN_LENGTH 18

class SE05XClass
{
public:
Expand All @@ -41,6 +43,8 @@ class SE05XClass
int begin();
void end();

int serialNumber(byte sn[]);
int serialNumber(byte sn[], size_t length);
String serialNumber();

long random(long max);
Expand Down