From 4c8839b2ba1108b6772c61a6ae74a16a96a81a37 Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 24 Jul 2011 21:53:11 +0200 Subject: [PATCH] vcard: read keys from filesystem --- default-files/README | 6 +++++ default-files/priv.key | 1 + default-files/pubx.key | 1 + default-files/puby.key | 1 + firmware/applications/vcard.c | 49 +++++++++++++++++++++++++++++------ 5 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 default-files/README create mode 100644 default-files/priv.key create mode 100644 default-files/pubx.key create mode 100644 default-files/puby.key diff --git a/default-files/README b/default-files/README new file mode 100644 index 0000000..4f5b8d2 --- /dev/null +++ b/default-files/README @@ -0,0 +1,6 @@ +This directory contains some default files +for the filesystem of your r0ket: + +pubx.key - X component of the public key +puby.key - Y component of the public key +priv.key - Private key diff --git a/default-files/priv.key b/default-files/priv.key new file mode 100644 index 0000000..f563d38 --- /dev/null +++ b/default-files/priv.key @@ -0,0 +1 @@ +0e10e787036941e6c78daf8a0e8e1dbfac68e26d2 diff --git a/default-files/pubx.key b/default-files/pubx.key new file mode 100644 index 0000000..edba23f --- /dev/null +++ b/default-files/pubx.key @@ -0,0 +1 @@ +1c56d302cf642a8e1ba4b48cc4fbe2845ee32dce7 diff --git a/default-files/puby.key b/default-files/puby.key new file mode 100644 index 0000000..fa73c14 --- /dev/null +++ b/default-files/puby.key @@ -0,0 +1 @@ +45f46eb303edf2e62f74bd68368d979e265ee3c03 diff --git a/firmware/applications/vcard.c b/firmware/applications/vcard.c index a5bf28a..60342e7 100644 --- a/firmware/applications/vcard.c +++ b/firmware/applications/vcard.c @@ -18,20 +18,40 @@ FATFS FatFs[_VOLUMES]; /* File system object for logical drive */ /**************************************************************************/ uint8_t mac[5] = {1,2,3,2,1}; -char *Px = "1c56d302cf642a8e1ba4b48cc4fbe2845ee32dce7"; -char *Py = "45f46eb303edf2e62f74bd68368d979e265ee3c03"; -char *Priv ="0e10e787036941e6c78daf8a0e8e1dbfac68e26d2"; -void sendPublicKey(char *px, char *py) +void sendPublicKey(void) { uint8_t exp[2 + 4*NUMWORDS + 2]; + char buf[42]; + UINT readbytes; + FIL file; + + if( f_open(&file, "pubx.key", FA_OPEN_EXISTING|FA_READ) ){ + return; + } + if( f_read(&file, buf, 41, &readbytes) || readbytes != 41 ){ + return; + } + f_close(&file); + buf[41] = 0; + exp[0] = 'P'; - bitstr_parse_export((char*)exp+2, px); + bitstr_parse_export((char*)exp+2, buf); exp[1] = 'X'; nrf_snd_pkt_crc(32, exp); delayms(10); + + if( f_open(&file, "puby.key", FA_OPEN_EXISTING|FA_READ) ){ + return; + } + if( f_read(&file, buf, 41, &readbytes) || readbytes != 41 ){ + return; + } + f_close(&file); + buf[41] = 0; + exp[1] = 'Y'; - bitstr_parse_export((char*)exp+2, py); + bitstr_parse_export((char*)exp+2, buf); nrf_snd_pkt_crc(32, exp); delayms(10); } @@ -116,7 +136,7 @@ int sendKeys(void) while( !done ){ lcdClear(); lcdPrintln("Sending PUBKEY");lcdRefresh(); - sendPublicKey(Px,Py); + sendPublicKey(); sendMac(); lcdPrintln("Done"); lcdPrintln("Right=OK"); @@ -185,6 +205,19 @@ void receiveFile(void) if( sendKeys() ) return; + char priv[42]; + UINT readbytes; + FIL file; + + if( f_open(&file, "priv.key", FA_OPEN_EXISTING|FA_READ) ){ + return; + } + if( f_read(&file, priv, 41, &readbytes) || readbytes != 41 ){ + return; + } + f_close(&file); + priv[41] = 0; + uint8_t done = 0; uint8_t key; uint8_t k1[16], k2[16], rx[4*NUMWORDS], ry[4*NUMWORDS]; @@ -204,7 +237,7 @@ void receiveFile(void) continue; lcdPrintln("Creating key"); lcdRefresh(); - ECIES_decryptkeygen(rx, ry, k1, k2, Priv); + ECIES_decryptkeygen(rx, ry, k1, k2, priv); if( filetransfer_receive(mac,(uint32_t*)k1) < 0 ) continue; lcdPrintln("Right=OK");