vcard: read keys from filesystem
This commit is contained in:
parent
f79d3b49f4
commit
4c8839b2ba
|
@ -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
|
|
@ -0,0 +1 @@
|
||||||
|
0e10e787036941e6c78daf8a0e8e1dbfac68e26d2
|
|
@ -0,0 +1 @@
|
||||||
|
1c56d302cf642a8e1ba4b48cc4fbe2845ee32dce7
|
|
@ -0,0 +1 @@
|
||||||
|
45f46eb303edf2e62f74bd68368d979e265ee3c03
|
|
@ -18,20 +18,40 @@ FATFS FatFs[_VOLUMES]; /* File system object for logical drive */
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
uint8_t mac[5] = {1,2,3,2,1};
|
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];
|
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';
|
exp[0] = 'P';
|
||||||
bitstr_parse_export((char*)exp+2, px);
|
bitstr_parse_export((char*)exp+2, buf);
|
||||||
exp[1] = 'X';
|
exp[1] = 'X';
|
||||||
nrf_snd_pkt_crc(32, exp);
|
nrf_snd_pkt_crc(32, exp);
|
||||||
delayms(10);
|
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';
|
exp[1] = 'Y';
|
||||||
bitstr_parse_export((char*)exp+2, py);
|
bitstr_parse_export((char*)exp+2, buf);
|
||||||
nrf_snd_pkt_crc(32, exp);
|
nrf_snd_pkt_crc(32, exp);
|
||||||
delayms(10);
|
delayms(10);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +136,7 @@ int sendKeys(void)
|
||||||
while( !done ){
|
while( !done ){
|
||||||
lcdClear();
|
lcdClear();
|
||||||
lcdPrintln("Sending PUBKEY");lcdRefresh();
|
lcdPrintln("Sending PUBKEY");lcdRefresh();
|
||||||
sendPublicKey(Px,Py);
|
sendPublicKey();
|
||||||
sendMac();
|
sendMac();
|
||||||
lcdPrintln("Done");
|
lcdPrintln("Done");
|
||||||
lcdPrintln("Right=OK");
|
lcdPrintln("Right=OK");
|
||||||
|
@ -185,6 +205,19 @@ void receiveFile(void)
|
||||||
if( sendKeys() )
|
if( sendKeys() )
|
||||||
return;
|
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 done = 0;
|
||||||
uint8_t key;
|
uint8_t key;
|
||||||
uint8_t k1[16], k2[16], rx[4*NUMWORDS], ry[4*NUMWORDS];
|
uint8_t k1[16], k2[16], rx[4*NUMWORDS], ry[4*NUMWORDS];
|
||||||
|
@ -204,7 +237,7 @@ void receiveFile(void)
|
||||||
continue;
|
continue;
|
||||||
lcdPrintln("Creating key");
|
lcdPrintln("Creating key");
|
||||||
lcdRefresh();
|
lcdRefresh();
|
||||||
ECIES_decryptkeygen(rx, ry, k1, k2, Priv);
|
ECIES_decryptkeygen(rx, ry, k1, k2, priv);
|
||||||
if( filetransfer_receive(mac,(uint32_t*)k1) < 0 )
|
if( filetransfer_receive(mac,(uint32_t*)k1) < 0 )
|
||||||
continue;
|
continue;
|
||||||
lcdPrintln("Right=OK");
|
lcdPrintln("Right=OK");
|
||||||
|
|
Loading…
Reference in New Issue