Skip to content

Commit 704f949

Browse files
committed
Print the SHA1 of the cert
1 parent 69d2213 commit 704f949

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

examples/Tools/ECCX08SelfSignedCert/ECCX08SelfSignedCert.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ void setup() {
100100
Serial.println("Here's your self signed cert, enjoy!");
101101
Serial.println();
102102
Serial.println(cert);
103+
Serial.println();
104+
105+
Serial.print("SHA1: ");
106+
Serial.println(ECCX08SelfSignedCert.sha1());
103107
}
104108

105109
void loop() {

src/utility/ECCX08SelfSignedCert.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
#include "ArduinoECCX08.h"
2121

22+
extern "C" {
23+
#include "sha1.h"
24+
}
2225
#include "ASN1Utils.h"
2326
#include "PEMUtils.h"
2427

@@ -122,6 +125,28 @@ int ECCX08SelfSignedCertClass::length()
122125
return _length;
123126
}
124127

128+
String ECCX08SelfSignedCertClass::sha1()
129+
{
130+
char result[20 + 1];
131+
132+
SHA1(result, (const char*)_bytes, _length);
133+
134+
String sha1Str;
135+
136+
sha1Str.reserve(40);
137+
138+
for (int i = 0; i < 20; i++) {
139+
uint8_t b = result[i];
140+
141+
if (b < 16) {
142+
sha1Str += '0';
143+
}
144+
sha1Str += String(b, HEX);
145+
}
146+
147+
return sha1Str;
148+
}
149+
125150
void ECCX08SelfSignedCertClass::setIssueYear(int issueYear)
126151
{
127152
struct CompressedCert* compressedCert = (struct CompressedCert*)_temp;

src/utility/ECCX08SelfSignedCert.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ECCX08SelfSignedCertClass {
3636
uint8_t* bytes();
3737
int length();
3838

39+
String sha1();
40+
3941
void setIssueYear(int issueYear);
4042
void setIssueMonth(int issueMonth);
4143
void setIssueDay(int issueDay);

0 commit comments

Comments
 (0)