From 6c71b131263955ca3fa3b497cf96cfd8cf00f0ec Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Mon, 8 Jul 2019 09:29:59 +0200 Subject: [PATCH] Initial --- .gitignore | 7 + Ideas | 27 ++++ asn.bin | Bin 0 -> 71 bytes asnfinal.bin | Bin 0 -> 71 bytes convertCert.js | 127 ++++++++++++++++++ hash.bin | Bin 0 -> 32 bytes hello.dat | Bin 0 -> 32 bytes include/README | 39 ++++++ key64.pem | 3 + lib/README | 46 +++++++ localtry/LBs Sign Key.crt | 32 +++++ localtry/LBs Sign Key.key | 52 ++++++++ localtry/sign.txt | 1 + localtry/sign.txt.sha256 | Bin 0 -> 512 bytes message.txt | 1 + osslkey.pem | 4 + platformio.ini | 18 +++ press.txt | 1 + pub.crt | Bin 0 -> 448 bytes pubkey.der | 1 + pubreza.bin | Bin 0 -> 448 bytes reza.pem | 4 + sigasn.bin | Bin 0 -> 71 bytes sigdata64.sig | 1 + signormal.bin | Bin 0 -> 64 bytes src/fprint.h | 156 ++++++++++++++++++++++ src/main.cpp | 267 ++++++++++++++++++++++++++++++++++++++ staticdata.sig | Bin 0 -> 71 bytes staticdata2.bin | 1 + test/README | 11 ++ 30 files changed, 799 insertions(+) create mode 100644 .gitignore create mode 100644 Ideas create mode 100644 asn.bin create mode 100644 asnfinal.bin create mode 100644 convertCert.js create mode 100644 hash.bin create mode 100644 hello.dat create mode 100644 include/README create mode 100644 key64.pem create mode 100644 lib/README create mode 100644 localtry/LBs Sign Key.crt create mode 100644 localtry/LBs Sign Key.key create mode 100644 localtry/sign.txt create mode 100644 localtry/sign.txt.sha256 create mode 100644 message.txt create mode 100644 osslkey.pem create mode 100644 platformio.ini create mode 100644 press.txt create mode 100644 pub.crt create mode 100644 pubkey.der create mode 100644 pubreza.bin create mode 100644 reza.pem create mode 100644 sigasn.bin create mode 100644 sigdata64.sig create mode 100644 signormal.bin create mode 100644 src/fprint.h create mode 100644 src/main.cpp create mode 100644 staticdata.sig create mode 100644 staticdata2.bin create mode 100644 test/README diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dfb8d5b --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.pio +.pioenvs +.piolibdeps +.vscode +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json diff --git a/Ideas b/Ideas new file mode 100644 index 0000000..ee2d92c --- /dev/null +++ b/Ideas @@ -0,0 +1,27 @@ +Ideas: + +Use it on raspberrypi with the cli + +Build a tool to quickly provision chips... + +run the toolkit on the nanopi neo + +push a button to trigger a banner on a nodejs server thingy + +Change chip to proove that the certificate is the LBS Ca one and not the Infineon CA one =D + + +Steps: + +script that provisions chips with certs +-> Provision 2 chips with different certificates! (Maybe get another one tomorrow? or make this a live demo of the personalisation!) + +NodeMCU uses chip cert to make json object with data and signature to send its status + +Nodejs server that verifies messages and signature with openssl via tcp +-> Shows Cert Authority and state with a corner icon of eiter Yes or No + + + + + diff --git a/asn.bin b/asn.bin new file mode 100644 index 0000000000000000000000000000000000000000..3453c898cd7224101254dc061cfa8718cba208c6 GIT binary patch literal 71 zcmXqTWl~^LWVro!r^9k&|vqBuETob;WlA&0_mdH|gTUAjMDF3$J8Awi4`e)+Q a<(l8OZnHslMW=y5)wB1fxu>Z4{s91@7#o}b literal 0 HcmV?d00001 diff --git a/asnfinal.bin b/asnfinal.bin new file mode 100644 index 0000000000000000000000000000000000000000..dc3f8d7625315ee4f0da5afc63b77074e083be34 GIT binary patch literal 71 zcmV-N0J#4!MFJoKAOruxDSR%st@AI4LRkrL;$lu*qGv1(>8N|J;n(c~Appxa0w8t( d&37a(q}E$RN5%*g2&ysk8xI07sq-nkboGtePI9!Z2+K0N@J^XaE2J literal 0 HcmV?d00001 diff --git a/hello.dat b/hello.dat new file mode 100644 index 0000000000000000000000000000000000000000..7901fe1359b938048c7ee90470964f4836a0f531 GIT binary patch literal 32 LcmZQ&WWWmm0N(%y literal 0 HcmV?d00001 diff --git a/include/README b/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/key64.pem b/key64.pem new file mode 100644 index 0000000..83ace40 --- /dev/null +++ b/key64.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +BAcClNfW2eyy/2hT6MTd/ZZTIJOPczPdrIwuDk15XKQDS5sk9uxjzSrnoBTTS7wyIgW5TpCfiiFi8s4Vz9+hIBI= +-----END PUBLIC KEY----- \ No newline at end of file diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/localtry/LBs Sign Key.crt b/localtry/LBs Sign Key.crt new file mode 100644 index 0000000..d6fe3f1 --- /dev/null +++ b/localtry/LBs Sign Key.crt @@ -0,0 +1,32 @@ +-----BEGIN CERTIFICATE----- +MIIFdjCCA14CCQCH0F2k0CH8dTANBgkqhkiG9w0BAQsFADB9MQswCQYDVQQGEwJO +TDEVMBMGA1UECAwMWnVpZCBIb2xsYW5kMRIwEAYDVQQHDAlSb3R0ZXJkYW0xGjAY +BgNVBAoMEVNwYXJrbGluZyBOZXR3b3JrMRAwDgYDVQQLDAdJVCBEZXB0MRUwEwYD +VQQDDAxMQnMgU2lnbiBLZXkwHhcNMTkwNjI4MDk1NTE5WhcNMjAwNjI3MDk1NTE5 +WjB9MQswCQYDVQQGEwJOTDEVMBMGA1UECAwMWnVpZCBIb2xsYW5kMRIwEAYDVQQH +DAlSb3R0ZXJkYW0xGjAYBgNVBAoMEVNwYXJrbGluZyBOZXR3b3JrMRAwDgYDVQQL +DAdJVCBEZXB0MRUwEwYDVQQDDAxMQnMgU2lnbiBLZXkwggIiMA0GCSqGSIb3DQEB +AQUAA4ICDwAwggIKAoICAQDpUHMM+5VAkYHQ/fuQ6+j9sbB1B9gJ3r6FBzz/0E7e +KgKU967fa8NHUy14PE7t0EBJWIhPWRLgAZCHPdt4eCRVbjXpYo0F99tM5L5v77Pv +aZBYeMg1UWWHFD4v9IE7LEQEKPIllNlAjz5dM9nzSG9WDx5XtQhcBZ8+zIOcbcVQ +Mb39ZawVInvz/MnCESqoldqNxiILkb3Mf/PCW5eh9LrOh/jyBg27Brc8M+RnBj4d +fCDaNT/xbZFhgmZpEsNlkIKD9/wSiG//0Aa/XOOabBDuk3nYPCT5jr4OuNK5M8cO +Q5tGffkYCztNTR2hhrz+oq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YUAgUV/yBFLoh2j +YsXtCUTRC2HVvg== +-----END CERTIFICATE----- diff --git a/localtry/LBs Sign Key.key b/localtry/LBs Sign Key.key new file mode 100644 index 0000000..d96e53a --- /dev/null +++ b/localtry/LBs Sign Key.key @@ -0,0 +1,52 @@ +-----BEGIN PRIVATE KEY----- +MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDpUHMM+5VAkYHQ +/fuQ6+j9sbB1B9gJ3r6FBzz/0E7eKgKU967fa8NHUy14PE7t0EBJWIhPWRLgAZCH +Pdt4eCRVbjXpYo0F99tM5L5v77PvaZBYeMg1UWWHFD4v9IE7LEQEKPIllNlAjz5d +M9nzSG9WDx5XtQhcBZ8+zIOcbcVQMb39ZawVInvz/MnCESqoldqNxiILkb3Mf/PC +W5eh9LrOh/jyBg27Brc8M+RnBj4dfCDaNT/xbZFhgmZpEsNlkIKD9/wSiG//0Aa/ +XOOabBDuk3nYPCT5jr4OuNK5M8cOQ5tGffkYCztNTR2hhrz+oqjaTmjVGcnriQze +kIL390cW9Q0V5WwX95KNF0+eS+QdJRLDLS4vWIzKzo++74iiGSmrJoB170EY/yDn +BgA4Kg7Kjvt3oqjladLFWwk/cgGemVV3tSz3ctINT4j8/IUNWCySJmSa65JEzYkX +ze5Z+xSBtB9bU5H12w2xdESPbgF7mGEXoilbo9Mibgdxwr+ZjqmArdSMB/YeR1Pa +aPUjf/EsgN1XoPrVivEwqH5dNo2mxlMNu0nI9Utn4ot1X34MqulcZU3nW86ajRvZ +8U0VVcP+/vRrdH3pBFIGZXTMLjjjH9zDWCZ4DK+9f7mSuwD4q+0INk4t+nj1ww/+ +3YaBIafRbmOyvXaaCAgKoA/aKb/a4QIDAQABAoICAQCL0SRBQXsd6JTtE2dwX4+O +iK+AUqUKtStjOQU7IDBDPtWxRATN6xxpX9U92pZKOaRsz9tQAccn6ogcI9ukBAty +DsvMAr0UOIZ5PBNLrVAdRxuziR4hpZe8LUtfHZ1cQpi4DXmfP+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tEwO4narXTABTjML8hlEH4wpGrLvBGDNFGHBJHtn09ksOvuW/av1ABH +5sV4KavVjz6wciQK1zujvdUoZ7TF7dNnR8/9yV35dRcvGRJW7PUwv9qYVWN459EV +SykFgO0hP10e9Mw7Duf1u0UWfC0unA== +-----END PRIVATE KEY----- diff --git a/localtry/sign.txt b/localtry/sign.txt new file mode 100644 index 0000000..3fa0d4b --- /dev/null +++ b/localtry/sign.txt @@ -0,0 +1 @@ +Hello, World diff --git a/localtry/sign.txt.sha256 b/localtry/sign.txt.sha256 new file mode 100644 index 0000000000000000000000000000000000000000..a0813266d57037addbde47c5c94f28034d9a1c6b GIT binary patch literal 512 zcmV+b0{{J)Izr8(s0HY^GP<-|yUBRPkjue2%^P7oy#=df3$y#~Qx4mJ$(oUd=8*gk zDk+|}pf@aTLAw#A=A<#-ZcJPULr_VqymVZ}a`Zo8Q~$$Su}z|xqlHy7o2Q@LF)0GS zBsj-LM>)5VA!W6|%V=00NV()H$17?fp}z#VO=@!h1G^ft4W$V#?KZc1kEyku@ZKO? z^R9ZFr?eog4NP;l#2V~j+rP}OG$_2C79>+AA#X(4F~|ZguZCWys>uVUbX%yB|`*Y8iTa1LcZAp#Hw@Z?shE z87@|~v}G>t&_hz@_DIdqu1!B9bB_ttsX~$43QdA~Q=f8+ z2Nc{CgrFS6*&ElJAzQ(w)YDWX=~(JNYo+~X_gf#v2~Oqv0SkQ%R{AsUH9#3<{;T%& zlG%YNez@+YTu@r!Xg{oQi6nuBx9NNv_OQc&Rb{B8@$q21C@2gIQ*r>i zR(mHhlJzmvVyT|6|IS@>JBMncb3`A@ZYls-jr?wrH8eaHAO~f9?G?iibamnVEu@xk C*!f!k literal 0 HcmV?d00001 diff --git a/message.txt b/message.txt new file mode 100644 index 0000000..9ba7a0e --- /dev/null +++ b/message.txt @@ -0,0 +1 @@ +press diff --git a/osslkey.pem b/osslkey.pem new file mode 100644 index 0000000..ff3c889 --- /dev/null +++ b/osslkey.pem @@ -0,0 +1,4 @@ +-----BEGIN PUBLIC KEY----- +MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBwKU19bZ7LL/aFPoxN39llMgk49z +M92sjC4OTXlcpANLmyT27GPNKuegFNNLvDIiBblOkJ+KIWLyzhXP36EgEg== +-----END PUBLIC KEY----- diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..2147e44 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,18 @@ +;PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:m5stack-core-esp32] +framework = arduino +platform = espressif32 +board = m5stack-core-esp32 + +build_flags = -fpermissive +lib_deps = + OPTIGA Trust X@1.0.5 \ No newline at end of file diff --git a/press.txt b/press.txt new file mode 100644 index 0000000..9ba7a0e --- /dev/null +++ b/press.txt @@ -0,0 +1 @@ +press diff --git a/pub.crt b/pub.crt new file mode 100644 index 0000000000000000000000000000000000000000..1f5df1886a0b5d7ebe81d5cb67baa1a9587ee2db GIT binary patch literal 448 zcmXqLV%%fU#F(^znTe5!iN)Rc)>H#7HV&;ek8`#x%uEJFhTI06Y|No7Y{E<~u7-*R z@*oZukA!DlT4r8qex5=|YH~(ieolURW@@p5qr0K7fgnf;HxHM8K!~Tiqeh6YrlGch zCP3>G>iz9dcP779;++S>bcTJBTpKoQ%5@zq& zD&O8DpVfN4K;*Lb9wQ~zoqiMMcPS=)IwyMm{z3(z#SsQ!27Exb%JMTZ{$~LO0YifU z4~Q=e;xhp)7X|SYSojQhz#-Kn!r;Ov!Uzr+S!EUp1F;5?Q>@0<{g2dhdj7sGq%9W?{dt@i}iexQwdT~;8g5!Udo$gs?soy#mM;L?|@B!T_%g@O8p9L5M3=IZ6 zAigk&&jhqw6vR_t;WOX?hg6dYgA1bwBRF7Wm02VV#2Q3Su^M0ZKT^->`TMqz>iz4} z=Q_%XA_pt82ZMntlOn_6-HOZD_iX4Y{USQI?Bd@dtM{j(I<#IeuV6gDbR{ggl}SM< lrB1=eIC{mf^^v9l>FgZ7?L9?qC*0h1eA;tgz literal 0 HcmV?d00001 diff --git a/sigdata64.sig b/sigdata64.sig new file mode 100644 index 0000000..b4e619b --- /dev/null +++ b/sigdata64.sig @@ -0,0 +1 @@ +MEUCIAIgazJVRkrj7VBnBClMSeXETfw2XTuQsXT2wrWDnfJMAiEATjUCIQDA3H/RiapPfuLdrQuC3lkdmLrS46v20k5BSSU= \ No newline at end of file diff --git a/signormal.bin b/signormal.bin new file mode 100644 index 0000000000000000000000000000000000000000..f79394ce030f85c39e0d3a9c610498f226911103 GIT binary patch literal 64 zcmV-G0KfkNAOruxDSR%st@AI4LRkrL;$lu*qGv1(>8N|J;n(fUHv%Ab0L^zKFQnF6 WL`TL56bPy@^cxQXFys~>efwvKdK(J> literal 0 HcmV?d00001 diff --git a/src/fprint.h b/src/fprint.h new file mode 100644 index 0000000..46250a0 --- /dev/null +++ b/src/fprint.h @@ -0,0 +1,156 @@ +#ifndef FPRINT_H +#define FPRINT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "Arduino.h" + +#ifndef SUPPRESSCOLLORS +#define ANSI_COLOR_RED "\x1b[31m" +#define ANSI_COLOR_GREEN "\x1b[32m" +#define ANSI_COLOR_YELLOW "\x1b[33m" +#define ANSI_COLOR_BLUE "\x1b[34m" +#define ANSI_COLOR_MAGENTA "\x1b[35m" +#define ANSI_COLOR_CYAN "\x1b[36m" +#define ANSI_COLOR_RESET "\x1b[0m" +#else +#define ANSI_COLOR_RED "" +#define ANSI_COLOR_GREEN "" +#define ANSI_COLOR_YELLOW "" +#define ANSI_COLOR_BLUE "" +#define ANSI_COLOR_MAGENTA "" +#define ANSI_COLOR_CYAN "" +#define ANSI_COLOR_RESET "" +#endif + +#define MAXCMD_LEN 255 +#define HEXDUMP_COLS 16 + +#ifndef SUPPRESSHEXDUMP +#define SUPPRESSHEXDUMP 0 +#endif +#define HEXDUMP(a, b) (SUPPRESSHEXDUMP == 0) ? __hexdump__(a, b) : (void)0; +/** + * + * This function prints a given input in green + * color with a \r\n signs at the end + * + * @retval None + */ +inline void printlnGreen(const char c[]) { + char tmp[100]; + sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); + Serial.println(tmp); +} + +/** + * + * This function prints a given input in red + * color with a \r\n signs at the end + * + * @retval None + */ +inline void printlnRed(const char c[]) { + char tmp[100]; + sprintf(tmp, "%s%s%s", ANSI_COLOR_RED, c, ANSI_COLOR_RESET); + Serial.println(tmp); +} + +/** + * + * This function prints a given input in magenta + * color with a \r\n signs at the end + * + * @retval None + */ +inline void printlnMagenta(const char c[]) { + char tmp[100]; + sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); + Serial.println(tmp); +} + +/** + * + * This function prints a given input in magenta + * color without a \r\n signs at the end + * + * @retval None + */ +inline void printMagenta(const char c[]) { + char tmp[100]; + sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); + Serial.print(tmp); +} + +/** + * + * This function prints a given input in green + * color without a \r\n signs at the end + * + * @retval None + */ +inline void printGreen(const char c[]) { + char tmp[100]; + sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); + Serial.print(tmp); +} + +/** + * + * Printout data in a standard hex view + * + * @param[in] p_buf Pointer to data which should be printed out. + * @param[in] l_len Length of a data + * + * @retval None + * @example + 0x000000: 2e 2f 68 65 78 64 75 6d ./hexdum + 0x000008: 70 00 53 53 48 5f 41 47 p.SSH_AG + 0x000010: 45 4e 54 5f ENT_ + */ +inline void __hexdump__(const void *p_buf, uint32_t l_len) { + unsigned int i, j; + char str[MAXCMD_LEN]; + for (i = 0; i < l_len + ((l_len % HEXDUMP_COLS) ? (HEXDUMP_COLS - l_len % HEXDUMP_COLS) : 0); i++) { + /* print offset */ + if (i % HEXDUMP_COLS == 0) { + sprintf(str, "0x%06x: ", i); + Serial.print(str); + } + + /* print hex data */ + if (i < l_len) { + sprintf(str, "%02x ", 0xFF & ((char *)p_buf)[i]); + Serial.print(str); + } else /* end of block, just aligning for ASCII dump */ + { + sprintf(str, " "); + Serial.print(str); + } + + /* print ASCII dump */ + if (i % HEXDUMP_COLS == (HEXDUMP_COLS - 1)) { + for (j = i - (HEXDUMP_COLS - 1); j <= i; j++) { + if (j >= l_len) /* end of block, not really printing */ + { + Serial.print(' '); + } else if (isprint((int)((char *)p_buf)[j])) /* printable char */ + { + Serial.print(((char *)p_buf)[j]); + } else /* other char */ + { + Serial.print('.'); + } + } + Serial.print('\r'); + Serial.print('\n'); + } + } +} + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a1d7cc6 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,267 @@ +/** + * MIT License + * + * Copyright (c) 2018 Infineon Technologies AG + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE + * + * Demonstrates use of the + * Infineon Technologies AG OPTIGAâ„¢ Trust X Arduino library + */ + +#include "OPTIGATrustX.h" + +#define MAXCMD_LEN 255 +#define CERT_LENGTH 512 +#define RND_LENGTH 64 +#define HASH_LENGTH 32 +#define SIGN_LENGTH 80 +#define PUBKEY_LENGTH 70 +#define UID_LENGTH 27 + +#define SUPPRESSCOLLORS +#include "fprint.h" +#include + +bool oldButton = true; +#define button 18 + + +const char* ssid = "LBsPhone"; +const char* password = "simple"; + +const char* host = "192.168.0.111"; +const int port = 8234; + +#define ASSERT(err) if (ret) { printlnRed("Failed"); while (true); } + +/* + * Allocating buffers for further use in loop() + */ +uint8_t *cert = new uint8_t[CERT_LENGTH]; +uint16_t certLen = CERT_LENGTH; +uint8_t *rnd = new uint8_t[RND_LENGTH]; +uint16_t rndLen = RND_LENGTH; +uint8_t *hash = new uint8_t[HASH_LENGTH]; +uint16_t hashLen = HASH_LENGTH; +uint8_t *rawSign = new uint8_t[SIGN_LENGTH]; +uint8_t *formSign = new uint8_t[SIGN_LENGTH]; +uint16_t signLen = SIGN_LENGTH; +uint8_t *format = new uint8_t[SIGN_LENGTH]; +uint16_t formatLen = SIGN_LENGTH; +uint8_t *pubKey = new uint8_t[PUBKEY_LENGTH]; +uint16_t pubKeyLen = PUBKEY_LENGTH; +uint8_t *uid = new uint8_t[UID_LENGTH]; + + + + +static void output_result(char* tag, uint8_t* in, uint16_t in_len) +{ + printlnGreen("OK"); + printMagenta(tag); + printMagenta(" Length: "); + Serial.println(in_len); + printMagenta(tag); + printlnMagenta(":"); + HEXDUMP(in, in_len); +} + +void loop() +{ + uint32_t ret = 0; + uint8_t cntr = 10; + uint8_t ifxPublicKey[68]; + + /* + * Getting co-processor Unique ID + */ + printGreen("Get co-processor UID ... "); + uint16_t uidLength = UID_LENGTH; + ret = trustX.getUniqueID(uid, uidLength); + ASSERT(ret); + output_result("Co-processor UID", uid, uidLength); + + /* + * Getting primary certificate + */ + printGreen("Reading cert ... "); + ret = trustX.getCertificate(cert, certLen); + ASSERT(ret); + output_result("Certificate", cert, certLen); + + /* + * Generate a Keypair + */ + + /* + printGreen("Generate Key Pair ... "); + uint16_t ctx = 0; + ret = trustX.generateKeypair(pubKey, pubKeyLen, ctx); + ASSERT(ret); + output_result("Public key", pubKey, pubKeyLen); + */ + + /* + * Get random value of RND_LENGTH length + */ + /* + printGreen("Get random value ... "); + ret = trustX.getRandom(RND_LENGTH, rnd); + ASSERT(ret); + output_result("Random", rnd, RND_LENGTH); + */ + + /* + * Calculate SHA256 value + */ + + char cmd[6] = "press\n"; + + output_result("PRESS", cmd, 6); + + + printGreen("Calculate Hash ... "); + ret = trustX.sha256(cmd, 6, hash); + hashLen = 32; + ASSERT(ret); + output_result("SHA256", hash, hashLen); + + + /* + * Generate a signature NIST-P256 + */ + printGreen("Generate Signature ... "); + ret = trustX.calculateSignature(hash, hashLen, eFIRST_DEVICE_PRIKEY_1, formSign, signLen); + Serial.printf("Code: %u\n", ret); + ASSERT(ret); + output_result("Signature", formSign, signLen); + + printGreen("Format Signature ... "); + ret = trustX.formatSignature(formSign, signLen, format, formatLen); + ASSERT(ret); + output_result("Signature Formated", format, formatLen); + + /* + * Verify just geberated signature + */ + trustX.getPublicKey(ifxPublicKey); + + printGreen("Verify Signature ... "); + ret = trustX.verifySignature(hash, hashLen, formSign, signLen); + ASSERT(ret); + printlnGreen("OK"); + +// init wifi +// connect to server and send + + /* + * Count down 10 seconds and restart the application + */ + while(cntr) { + Serial.print(cntr); + Serial.println(" seconds untill restart."); + delay(1000); + cntr--; + } +} + +void initWifi(){ + Serial.print("Connecting to "); + Serial.println(ssid); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.println("WiFi connected with IP address: "); + Serial.println(WiFi.localIP()); +} + +void sendData(uint8_t* data, uint16_t len) { + Serial.print("connecting to "); + Serial.println(host); + // Use WiFiClient class to create TCP connections + WiFiClient client; + + if (!client.connect(host, port)) { + Serial.println("connection failed"); + return; + } + // This will send the data to the server + client.print("hello world"); + client.stop(); +} + +void setup() +{ + uint32_t ret = 0; + + /* + * Initialise serial output + */ + Serial.begin(38400); + Serial.println("Initializing ... "); + + /* + * Initialise OPTIGAâ„¢ Trust X + */ + printGreen("Begin Trust ... "); + ret = trustX.begin(); + ASSERT(ret); + printlnGreen("OK"); + + /* + * Speed up the chip (min is 6ma, maximum is 15ma) + */ + printGreen("Setting Current Limit... "); + ret = trustX.setCurrentLimit(15); + ASSERT(ret); + printlnGreen("OK"); + + /* + * Check the return value which we just set + */ + printGreen("Checking Power Limit... "); + uint8_t current_lim = 0; + ret = trustX.getCurrentLimit(current_lim); + ASSERT(ret); + if (current_lim == 15) { + printlnGreen("OK"); + } else { + printlnRed("Failed"); + while(1); + } +} + + +void checkButton(){ +if(digitalRead(button) != oldButton){ +delay(5); +if(digitalRead(button) != oldButton){ + if (oldButton == HIGH) { + // Presed down + } else { + // pressed up + } + oldButton = digitalRead(button); +} +} +} \ No newline at end of file diff --git a/staticdata.sig b/staticdata.sig new file mode 100644 index 0000000000000000000000000000000000000000..d114ba333f088d64bdddb09ef8687a859506569a GIT binary patch literal 71 zcmV-N0J#4!MFJoKAZs#JMoQ!DP-g@wOiAU$P5d@pJCLz-_QJJ;o$^cqAplM_0wDmv d+<(!Ds!x96-K`6P-dP=(y3*sT_R>y4NhK5|AU*&9 literal 0 HcmV?d00001 diff --git a/staticdata2.bin b/staticdata2.bin new file mode 100644 index 0000000..ea76a8f --- /dev/null +++ b/staticdata2.bin @@ -0,0 +1 @@ + nML‚§Ýµœk„õÃiÉ~Ö ·íÁî”?’ÇqØ#kä ~5ž¤Êû)åZìWAsôÇžš097«A³«Ö´•qs \ No newline at end of file diff --git a/test/README b/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html