From 6d89f656f9404766bca442d670a1f5175932ea03 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 26 Sep 2024 14:54:28 +0200 Subject: [PATCH 1/5] Add JWS utility --- .github/workflows/compile-examples.yml | 6 ++ src/utility/SElementJWS.cpp | 126 +++++++++++++++++++++++++ src/utility/SElementJWS.h | 36 +++++++ 3 files changed, 168 insertions(+) create mode 100644 src/utility/SElementJWS.cpp create mode 100644 src/utility/SElementJWS.h diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 9b5d917..45677c2 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -102,6 +102,8 @@ jobs: platforms: | # Install Arduino mbed_nano Boards via Boards Manager - name: arduino:mbed_nicla + libraries: | + - name: ArduinoECCX08 - board: platform-name: arduino:mbed_opta platforms: | @@ -121,11 +123,15 @@ jobs: platforms: | # Install Arduino renesas_portenta Boards via Boards Manager - name: arduino:renesas_portenta + libraries: | + - name: ArduinoECCX08 - board: platform-name: arduino:renesas_uno platforms: | # Install Arduino renesas_uno Boards via Boards Manager - name: arduino:renesas_uno + libraries: | + - name: ArduinoECCX08 steps: - name: Checkout diff --git a/src/utility/SElementJWS.cpp b/src/utility/SElementJWS.cpp new file mode 100644 index 0000000..af88d80 --- /dev/null +++ b/src/utility/SElementJWS.cpp @@ -0,0 +1,126 @@ +/* + This file is part of the Arduino_SecureElement library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include +#include +#include +#include + +static String base64urlEncode(const byte in[], unsigned int length) +{ + static const char* CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="; + + int b; + String out; + + int reserveLength = 4 * ((length + 2) / 3); + out.reserve(reserveLength); + + for (unsigned int i = 0; i < length; i += 3) { + b = (in[i] & 0xFC) >> 2; + out += CODES[b]; + + b = (in[i] & 0x03) << 4; + if (i + 1 < length) { + b |= (in[i + 1] & 0xF0) >> 4; + out += CODES[b]; + b = (in[i + 1] & 0x0F) << 2; + if (i + 2 < length) { + b |= (in[i + 2] & 0xC0) >> 6; + out += CODES[b]; + b = in[i + 2] & 0x3F; + out += CODES[b]; + } else { + out += CODES[b]; + } + } else { + out += CODES[b]; + } + } + + while (out.lastIndexOf('=') != -1) { + out.remove(out.length() - 1); + } + + return out; +} + +String SElementJWS::publicKey(SecureElement & se, int slot, bool newPrivateKey) +{ + if (slot < 0 || slot > 8) { + return ""; + } + + byte publicKey[64]; + + if (newPrivateKey) { + if (!se.generatePrivateKey(slot, publicKey)) { + return ""; + } + } else { + if (!se.generatePublicKey(slot, publicKey)) { + return ""; + } + } + + int length = ASN1Utils.publicKeyLength(); + byte out[length]; + + ASN1Utils.appendPublicKey(publicKey, out); + + return PEMUtils.base64Encode(out, length, "-----BEGIN PUBLIC KEY-----\n", "\n-----END PUBLIC KEY-----\n"); +} + +String SElementJWS::sign(SecureElement & se, int slot, const char* header, const char* payload) +{ + if (slot < 0 || slot > 8) { + return ""; + } + + String encodedHeader = base64urlEncode((const byte*)header, strlen(header)); + String encodedPayload = base64urlEncode((const byte*)payload, strlen(payload)); + + String toSign; + toSign.reserve(encodedHeader.length() + 1 + encodedPayload.length()); + + toSign += encodedHeader; + toSign += '.'; + toSign += encodedPayload; + + + byte toSignSha256[32]; + byte signature[64]; + + se.SHA256((const uint8_t*)toSign.c_str(), toSign.length(), toSignSha256); + + if (!se.ecSign(slot, toSignSha256, signature)) { + return ""; + } + + String encodedSignature = base64urlEncode(signature, sizeof(signature)); + + String result; + result.reserve(toSign.length() + 1 + encodedSignature.length()); + + result += toSign; + result += '.'; + result += encodedSignature; + + return result; +} + +String SElementJWS::sign(SecureElement & se, int slot, const String& header, const String& payload) +{ + return sign(se, slot, header.c_str(), payload.c_str()); +} diff --git a/src/utility/SElementJWS.h b/src/utility/SElementJWS.h new file mode 100644 index 0000000..74400f7 --- /dev/null +++ b/src/utility/SElementJWS.h @@ -0,0 +1,36 @@ +/* + This file is part of the Arduino_SecureElement library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef SECURE_ELEMENT_JWS_H_ +#define SECURE_ELEMENT_JWS_H_ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include + + /****************************************************************************** + * CLASS DECLARATION + ******************************************************************************/ + +class SElementJWS +{ +public: + + String publicKey(SecureElement & se, int slot, bool newPrivateKey = true); + + String sign(SecureElement & se, int slot, const char* header, const char* payload); + String sign(SecureElement & se, int slot, const String& header, const String& payload); + +}; + + +#endif /* SECURE_ELEMENT_JWS_H_ */ From 72696f61876b60239166c1545c83f2354615da25 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Fri, 28 Mar 2025 18:03:09 +0100 Subject: [PATCH 2/5] add get ArduinoIoTCloud jwt --- src/utility/SElementArduinoCloudJWT.cpp | 23 +++++++++++++++++++++++ src/utility/SElementArduinoCloudJWT.h | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/utility/SElementArduinoCloudJWT.cpp create mode 100644 src/utility/SElementArduinoCloudJWT.h diff --git a/src/utility/SElementArduinoCloudJWT.cpp b/src/utility/SElementArduinoCloudJWT.cpp new file mode 100644 index 0000000..1853c8b --- /dev/null +++ b/src/utility/SElementArduinoCloudJWT.cpp @@ -0,0 +1,23 @@ +/* + This file is part of the Arduino_SecureElement library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ +#include "SElementArduinoCloudJWT.h" + +constexpr char JWT_HEADER[] = "{\"alg\":\"ES256\",\"typ\":\"JWT\"}"; +String getAIoTCloudJWT(SecureElement &se, String issuer, uint64_t iat, uint8_t slot) +{ + SElementJWS jws; + String jwtClaim = "{\"iat\":"; + jwtClaim += String((uint32_t)iat); + jwtClaim += ",\"iss\":\""; + jwtClaim += issuer; + jwtClaim += "\"}"; + String token = jws.sign(se, slot, JWT_HEADER, jwtClaim.c_str()); + return token; +} diff --git a/src/utility/SElementArduinoCloudJWT.h b/src/utility/SElementArduinoCloudJWT.h new file mode 100644 index 0000000..8658be4 --- /dev/null +++ b/src/utility/SElementArduinoCloudJWT.h @@ -0,0 +1,17 @@ +/* + This file is part of the Arduino_SecureElement library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef SECURE_ELEMENT_AIoTCloud_JWT_H_ +#define SECURE_ELEMENT_AIoTCloud_JWT_H_ +#include "SElementJWS.h" + +String getAIoTCloudJWT(SecureElement &se, String issuer, uint64_t iat, uint8_t slot = 1); + +#endif From 74410c100832da4817adea93b7d579a9d4ba4408 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 15 Apr 2025 14:31:17 +0200 Subject: [PATCH 3/5] Share SElement Base64 functions --- src/ECP256Certificate.cpp | 57 +------------------ src/utility/SElementBase64.cpp | 101 +++++++++++++++++++++++++++++++++ src/utility/SElementBase64.h | 20 +++++++ src/utility/SElementJWS.cpp | 49 ++-------------- 4 files changed, 129 insertions(+), 98 deletions(-) create mode 100644 src/utility/SElementBase64.cpp create mode 100644 src/utility/SElementBase64.h diff --git a/src/ECP256Certificate.cpp b/src/ECP256Certificate.cpp index e146a2f..4ba4a9b 100644 --- a/src/ECP256Certificate.cpp +++ b/src/ECP256Certificate.cpp @@ -15,6 +15,7 @@ /* This is needed for memmem */ #define _GNU_SOURCE #include +#include #include "ECP256Certificate.h" /****************************************************************************** @@ -29,58 +30,6 @@ #define ASN1_SEQUENCE 0x30 #define ASN1_SET 0x31 -/****************************************************************************** - * LOCAL MODULE FUNCTIONS - ******************************************************************************/ - -static String base64Encode(const byte in[], unsigned int length, const char* prefix, const char* suffix) { - static const char* CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - - int b; - String out; - - int reserveLength = 4 * ((length + 2) / 3) + ((length / 3 * 4) / 76) + strlen(prefix) + strlen(suffix); - out.reserve(reserveLength); - - if (prefix) { - out += prefix; - } - - for (unsigned int i = 0; i < length; i += 3) { - if (i > 0 && (i / 3 * 4) % 76 == 0) { - out += '\n'; - } - - b = (in[i] & 0xFC) >> 2; - out += CODES[b]; - - b = (in[i] & 0x03) << 4; - if (i + 1 < length) { - b |= (in[i + 1] & 0xF0) >> 4; - out += CODES[b]; - b = (in[i + 1] & 0x0F) << 2; - if (i + 2 < length) { - b |= (in[i + 2] & 0xC0) >> 6; - out += CODES[b]; - b = in[i + 2] & 0x3F; - out += CODES[b]; - } else { - out += CODES[b]; - out += '='; - } - } else { - out += CODES[b]; - out += "=="; - } - } - - if (suffix) { - out += suffix; - } - - return out; -} - /****************************************************************************** * CTOR/DTOR ******************************************************************************/ @@ -184,7 +133,7 @@ int ECP256Certificate::signCSR(byte * signature) String ECP256Certificate::getCSRPEM() { - return base64Encode(_certBuffer, _certBufferLen, "-----BEGIN CERTIFICATE REQUEST-----\n", "\n-----END CERTIFICATE REQUEST-----\n"); + return b64::encode(_certBuffer, _certBufferLen, "-----BEGIN CERTIFICATE REQUEST-----\n", "\n-----END CERTIFICATE REQUEST-----\n"); } int ECP256Certificate::buildCert() @@ -323,7 +272,7 @@ int ECP256Certificate::signCert() String ECP256Certificate::getCertPEM() { - return base64Encode(_certBuffer, _certBufferLen, "-----BEGIN CERTIFICATE-----\n", "\n-----END CERTIFICATE-----\n"); + return b64::encode(_certBuffer, _certBufferLen, "-----BEGIN CERTIFICATE-----\n", "\n-----END CERTIFICATE-----\n"); } void ECP256Certificate::getDateFromCompressedData(DateInfo& date) { diff --git a/src/utility/SElementBase64.cpp b/src/utility/SElementBase64.cpp new file mode 100644 index 0000000..a3b93ab --- /dev/null +++ b/src/utility/SElementBase64.cpp @@ -0,0 +1,101 @@ +/* + This file is part of the Arduino_SecureElement library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#include + +namespace arduino { namespace b64 { + +String urlEncode(const byte in[], unsigned int length) { + static const char* CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="; + + int b; + String out; + + int reserveLength = 4 * ((length + 2) / 3); + out.reserve(reserveLength); + + for (unsigned int i = 0; i < length; i += 3) { + b = (in[i] & 0xFC) >> 2; + out += CODES[b]; + + b = (in[i] & 0x03) << 4; + if (i + 1 < length) { + b |= (in[i + 1] & 0xF0) >> 4; + out += CODES[b]; + b = (in[i + 1] & 0x0F) << 2; + if (i + 2 < length) { + b |= (in[i + 2] & 0xC0) >> 6; + out += CODES[b]; + b = in[i + 2] & 0x3F; + out += CODES[b]; + } else { + out += CODES[b]; + } + } else { + out += CODES[b]; + } + } + + while (out.lastIndexOf('=') != -1) { + out.remove(out.length() - 1); + } + + return out; +} + +String encode(const byte in[], unsigned int length, const char* prefix, const char* suffix) { +static const char* CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + + int b; + String out; + + int reserveLength = 4 * ((length + 2) / 3) + ((length / 3 * 4) / 76) + strlen(prefix) + strlen(suffix); + out.reserve(reserveLength); + + if (prefix) { + out += prefix; + } + + for (unsigned int i = 0; i < length; i += 3) { + if (i > 0 && (i / 3 * 4) % 76 == 0) { + out += '\n'; + } + + b = (in[i] & 0xFC) >> 2; + out += CODES[b]; + + b = (in[i] & 0x03) << 4; + if (i + 1 < length) { + b |= (in[i + 1] & 0xF0) >> 4; + out += CODES[b]; + b = (in[i + 1] & 0x0F) << 2; + if (i + 2 < length) { + b |= (in[i + 2] & 0xC0) >> 6; + out += CODES[b]; + b = in[i + 2] & 0x3F; + out += CODES[b]; + } else { + out += CODES[b]; + out += '='; + } + } else { + out += CODES[b]; + out += "=="; + } + } + + if (suffix) { + out += suffix; + } + + return out; +} + +}} // arduino::b64 diff --git a/src/utility/SElementBase64.h b/src/utility/SElementBase64.h new file mode 100644 index 0000000..8519fe0 --- /dev/null +++ b/src/utility/SElementBase64.h @@ -0,0 +1,20 @@ +/* + This file is part of the Arduino_SecureElement library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#pragma once + +#include + +namespace arduino { namespace b64 { + + String urlEncode(const byte in[], unsigned int length); + String encode(const byte in[], unsigned int length, const char* prefix, const char* suffix); + +}} // arduino::b64 diff --git a/src/utility/SElementJWS.cpp b/src/utility/SElementJWS.cpp index af88d80..7e83642 100644 --- a/src/utility/SElementJWS.cpp +++ b/src/utility/SElementJWS.cpp @@ -13,48 +13,9 @@ ******************************************************************************/ #include +#include #include #include -#include - -static String base64urlEncode(const byte in[], unsigned int length) -{ - static const char* CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="; - - int b; - String out; - - int reserveLength = 4 * ((length + 2) / 3); - out.reserve(reserveLength); - - for (unsigned int i = 0; i < length; i += 3) { - b = (in[i] & 0xFC) >> 2; - out += CODES[b]; - - b = (in[i] & 0x03) << 4; - if (i + 1 < length) { - b |= (in[i + 1] & 0xF0) >> 4; - out += CODES[b]; - b = (in[i + 1] & 0x0F) << 2; - if (i + 2 < length) { - b |= (in[i + 2] & 0xC0) >> 6; - out += CODES[b]; - b = in[i + 2] & 0x3F; - out += CODES[b]; - } else { - out += CODES[b]; - } - } else { - out += CODES[b]; - } - } - - while (out.lastIndexOf('=') != -1) { - out.remove(out.length() - 1); - } - - return out; -} String SElementJWS::publicKey(SecureElement & se, int slot, bool newPrivateKey) { @@ -79,7 +40,7 @@ String SElementJWS::publicKey(SecureElement & se, int slot, bool newPrivateKey) ASN1Utils.appendPublicKey(publicKey, out); - return PEMUtils.base64Encode(out, length, "-----BEGIN PUBLIC KEY-----\n", "\n-----END PUBLIC KEY-----\n"); + return b64::encode(out, length, "-----BEGIN PUBLIC KEY-----\n", "\n-----END PUBLIC KEY-----\n"); } String SElementJWS::sign(SecureElement & se, int slot, const char* header, const char* payload) @@ -88,8 +49,8 @@ String SElementJWS::sign(SecureElement & se, int slot, const char* header, const return ""; } - String encodedHeader = base64urlEncode((const byte*)header, strlen(header)); - String encodedPayload = base64urlEncode((const byte*)payload, strlen(payload)); + String encodedHeader = b64::urlEncode((const byte*)header, strlen(header)); + String encodedPayload = b64::urlEncode((const byte*)payload, strlen(payload)); String toSign; toSign.reserve(encodedHeader.length() + 1 + encodedPayload.length()); @@ -108,7 +69,7 @@ String SElementJWS::sign(SecureElement & se, int slot, const char* header, const return ""; } - String encodedSignature = base64urlEncode(signature, sizeof(signature)); + String encodedSignature = b64::urlEncode(signature, sizeof(signature)); String result; result.reserve(toSign.length() + 1 + encodedSignature.length()); From 4900febf84435c1a06bb13451bced3bac6f16e76 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 15 Apr 2025 14:33:55 +0200 Subject: [PATCH 4/5] Remove dependency from ArduinoECCX08 --- .github/workflows/compile-examples.yml | 6 ------ src/ECP256Certificate.h | 7 +++++-- src/utility/SElementJWS.cpp | 6 ++---- src/utility/SElementJWS.h | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 45677c2..9b5d917 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -102,8 +102,6 @@ jobs: platforms: | # Install Arduino mbed_nano Boards via Boards Manager - name: arduino:mbed_nicla - libraries: | - - name: ArduinoECCX08 - board: platform-name: arduino:mbed_opta platforms: | @@ -123,15 +121,11 @@ jobs: platforms: | # Install Arduino renesas_portenta Boards via Boards Manager - name: arduino:renesas_portenta - libraries: | - - name: ArduinoECCX08 - board: platform-name: arduino:renesas_uno platforms: | # Install Arduino renesas_uno Boards via Boards Manager - name: arduino:renesas_uno - libraries: | - - name: ArduinoECCX08 steps: - name: Checkout diff --git a/src/ECP256Certificate.h b/src/ECP256Certificate.h index 2be7c5c..681f806 100644 --- a/src/ECP256Certificate.h +++ b/src/ECP256Certificate.h @@ -101,6 +101,11 @@ class ECP256Certificate { /* Import DER buffer into CertClass*/ int importCert(const byte certDER[], size_t derLen); +protected: + + int publicKeyLength(); + int appendPublicKey(const byte publicKey[], byte out[]); + private: struct CertInfo { @@ -154,7 +159,6 @@ class ECP256Certificate { int versionLength(); int issuerOrSubjectLength(const CertInfo& issuerOrSubjectData); int sequenceHeaderLength(int length); - int publicKeyLength(); int signatureLength(const byte signature[]); int serialNumberLength(const byte serialNumber[], int length); int authorityKeyIdLength(const byte authorityKeyId[], int length); @@ -171,7 +175,6 @@ class ECP256Certificate { int appendVersion(int version, byte out[]); int appendName(const String& name, int type, byte out[]); int appendIssuerOrSubject(const CertInfo& issuerOrSubjectData, byte out[]); - int appendPublicKey(const byte publicKey[], byte out[]); int appendSignature(const byte signature[], byte out[]); int appendSerialNumber(const byte serialNumber[], int length, byte out[]); int appendDate(int year, int month, int day, int hour, int minute, int second, byte out[]); diff --git a/src/utility/SElementJWS.cpp b/src/utility/SElementJWS.cpp index 7e83642..bd34ec4 100644 --- a/src/utility/SElementJWS.cpp +++ b/src/utility/SElementJWS.cpp @@ -14,8 +14,6 @@ #include #include -#include -#include String SElementJWS::publicKey(SecureElement & se, int slot, bool newPrivateKey) { @@ -35,10 +33,10 @@ String SElementJWS::publicKey(SecureElement & se, int slot, bool newPrivateKey) } } - int length = ASN1Utils.publicKeyLength(); + int length = publicKeyLength(); byte out[length]; - ASN1Utils.appendPublicKey(publicKey, out); + appendPublicKey(publicKey, out); return b64::encode(out, length, "-----BEGIN PUBLIC KEY-----\n", "\n-----END PUBLIC KEY-----\n"); } diff --git a/src/utility/SElementJWS.h b/src/utility/SElementJWS.h index 74400f7..82f392b 100644 --- a/src/utility/SElementJWS.h +++ b/src/utility/SElementJWS.h @@ -21,7 +21,7 @@ * CLASS DECLARATION ******************************************************************************/ -class SElementJWS +class SElementJWS : public ECP256Certificate { public: From 9ec6dc4a7e2a8643656d29db729dfe0e4d3512fc Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 28 Apr 2025 10:56:07 +0200 Subject: [PATCH 5/5] b64 rename encode in pemEncode --- src/ECP256Certificate.cpp | 4 ++-- src/utility/SElementBase64.cpp | 2 +- src/utility/SElementBase64.h | 2 +- src/utility/SElementJWS.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ECP256Certificate.cpp b/src/ECP256Certificate.cpp index 4ba4a9b..7bd4272 100644 --- a/src/ECP256Certificate.cpp +++ b/src/ECP256Certificate.cpp @@ -133,7 +133,7 @@ int ECP256Certificate::signCSR(byte * signature) String ECP256Certificate::getCSRPEM() { - return b64::encode(_certBuffer, _certBufferLen, "-----BEGIN CERTIFICATE REQUEST-----\n", "\n-----END CERTIFICATE REQUEST-----\n"); + return b64::pemEncode(_certBuffer, _certBufferLen, "-----BEGIN CERTIFICATE REQUEST-----\n", "\n-----END CERTIFICATE REQUEST-----\n"); } int ECP256Certificate::buildCert() @@ -272,7 +272,7 @@ int ECP256Certificate::signCert() String ECP256Certificate::getCertPEM() { - return b64::encode(_certBuffer, _certBufferLen, "-----BEGIN CERTIFICATE-----\n", "\n-----END CERTIFICATE-----\n"); + return b64::pemEncode(_certBuffer, _certBufferLen, "-----BEGIN CERTIFICATE-----\n", "\n-----END CERTIFICATE-----\n"); } void ECP256Certificate::getDateFromCompressedData(DateInfo& date) { diff --git a/src/utility/SElementBase64.cpp b/src/utility/SElementBase64.cpp index a3b93ab..97323f2 100644 --- a/src/utility/SElementBase64.cpp +++ b/src/utility/SElementBase64.cpp @@ -50,7 +50,7 @@ String urlEncode(const byte in[], unsigned int length) { return out; } -String encode(const byte in[], unsigned int length, const char* prefix, const char* suffix) { +String pemEncode(const byte in[], unsigned int length, const char* prefix, const char* suffix) { static const char* CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; int b; diff --git a/src/utility/SElementBase64.h b/src/utility/SElementBase64.h index 8519fe0..8446a02 100644 --- a/src/utility/SElementBase64.h +++ b/src/utility/SElementBase64.h @@ -15,6 +15,6 @@ namespace arduino { namespace b64 { String urlEncode(const byte in[], unsigned int length); - String encode(const byte in[], unsigned int length, const char* prefix, const char* suffix); + String pemEncode(const byte in[], unsigned int length, const char* prefix, const char* suffix); }} // arduino::b64 diff --git a/src/utility/SElementJWS.cpp b/src/utility/SElementJWS.cpp index bd34ec4..ac30bfe 100644 --- a/src/utility/SElementJWS.cpp +++ b/src/utility/SElementJWS.cpp @@ -38,7 +38,7 @@ String SElementJWS::publicKey(SecureElement & se, int slot, bool newPrivateKey) appendPublicKey(publicKey, out); - return b64::encode(out, length, "-----BEGIN PUBLIC KEY-----\n", "\n-----END PUBLIC KEY-----\n"); + return b64::pemEncode(out, length, "-----BEGIN PUBLIC KEY-----\n", "\n-----END PUBLIC KEY-----\n"); } String SElementJWS::sign(SecureElement & se, int slot, const char* header, const char* payload)