Skip to content

SSLClient SE050: fix KeySlot and signature algo configuration #220

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

Closed
wants to merge 2 commits into from
Closed
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
29 changes: 28 additions & 1 deletion extras/tls/mbedtls_alt/ecdsa_se05x.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,36 @@ int mbedtls_ecdsa_sign(mbedtls_ecp_group *grp,
return -1;
}

SE05x_ECSignatureAlgo_t signatureAlgo = kSE05x_ECSignatureAlgo_NA;

switch (blen) {
case 20:
signatureAlgo = kSE05x_ECSignatureAlgo_SHA;
break;
case 28:
signatureAlgo = kSE05x_ECSignatureAlgo_SHA_224;
break;
case 32:
signatureAlgo = kSE05x_ECSignatureAlgo_SHA_256;
break;
case 48:
signatureAlgo = kSE05x_ECSignatureAlgo_SHA_384;
break;
case 64:
signatureAlgo = kSE05x_ECSignatureAlgo_SHA_512;
break;
default:
break;
}

if (signatureAlgo == kSE05x_ECSignatureAlgo_NA) {
SMLOG_E("Unknown EC signature algo %d\r\n", blen);
return -1;
}

SMLOG_I("Using SE05x for ecdsa sign. blen: %d\r\n", blen);
status = Se05x_API_ECDSASign(
pSession, keyID, kSE05x_ECSignatureAlgo_SHA_384, (uint8_t *)buf, blen, signature, &signature_len);
pSession, keyID, signatureAlgo, (uint8_t *)buf, blen, signature, &signature_len);
if (status != SM_OK) {
SMLOG_E("Error in Se05x_API_ECDSASign\r\n");
return -1;
Expand Down
7 changes: 5 additions & 2 deletions libraries/SSLClient/src/SSLClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ bool SSLClient::loadPrivateKey(Stream& stream, size_t size) {
return ret;
}

void SSLClient::setEccSlot(int KeySlot, const byte cert[], int certLen) {
void SSLClient::setEccSlot(unsigned int KeySlot, const byte cert[], int certLen) {
unsigned char buf[1024];
size_t olen;
int ret;
Expand Down Expand Up @@ -377,7 +377,10 @@ void SSLClient::setEccSlot(int KeySlot, const byte cert[], int certLen) {
0x83, 0xA3, 0x5E, 0x5B, 0x64, 0x1D, 0x29, 0xED, 0x85
};

key[28] = KeySlot;
key[25] = (KeySlot >> 24) & 0xFF;
key[26] = (KeySlot >> 16) & 0xFF;
key[27] = (KeySlot >> 8) & 0xFF;
key[28] = KeySlot & 0xFF;

if ((ret = mbedtls_pem_write_buffer("-----BEGIN EC PRIVATE KEY-----\n",
"-----END EC PRIVATE KEY-----\n",
Expand Down
2 changes: 1 addition & 1 deletion libraries/SSLClient/src/SSLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SSLClient : public Client
bool loadCACert(Stream& stream, size_t size);
bool loadCertificate(Stream& stream, size_t size);
bool loadPrivateKey(Stream& stream, size_t size);
void setEccSlot(int KeySlot, const byte cert[], int certLen);
void setEccSlot(unsigned int KeySlot, const byte cert[], int certLen);
bool verify(const char* fingerprint, const char* domain_name);
void setHandshakeTimeout(unsigned long handshake_timeout);

Expand Down
Binary file modified libraries/SSLClient/src/cortex-m33/libmbedse05x.a
Binary file not shown.