mirror of https://github.com/OpenIPC/firmware.git
wifibroadcast-ng: update key generator
parent
ea7cbf170e
commit
75079ca6f5
|
@ -17,12 +17,11 @@
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
unsigned char drone_publickey[crypto_box_PUBLICKEYBYTES];
|
unsigned char publickey[crypto_box_PUBLICKEYBYTES];
|
||||||
unsigned char drone_secretkey[crypto_box_SECRETKEYBYTES];
|
unsigned char secretkey[crypto_box_SECRETKEYBYTES];
|
||||||
unsigned char gs_publickey[crypto_box_PUBLICKEYBYTES];
|
|
||||||
unsigned char gs_secretkey[crypto_box_SECRETKEYBYTES];
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
|
@ -35,38 +34,26 @@ int main(int argc, char **argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *seed = argv[1];
|
char seed[32];
|
||||||
|
strncpy(seed, argv[1], sizeof(seed));
|
||||||
printf("Using passphrase: %s\n", seed);
|
printf("Using passphrase: %s\n", seed);
|
||||||
|
|
||||||
if (crypto_box_seed_keypair(drone_publickey, drone_secretkey, seed) != 0 ||
|
if (crypto_box_seed_keypair(publickey, secretkey, seed) != 0) {
|
||||||
crypto_box_seed_keypair(gs_publickey, gs_secretkey, seed) != 0) {
|
printf("Unable to generate key\n");
|
||||||
printf("Unable to generate keys\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *drone = "/etc/drone.key";
|
const char *key = "/etc/drone.key";
|
||||||
if ((fp = fopen(drone, "w")) == NULL) {
|
if ((fp = fopen(key, "w")) == NULL) {
|
||||||
printf("Unable to save: %s\n", drone);
|
printf("Unable to save: %s\n", key);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite(drone_secretkey, crypto_box_SECRETKEYBYTES, 1, fp);
|
fwrite(secretkey, crypto_box_SECRETKEYBYTES, 1, fp);
|
||||||
fwrite(gs_publickey, crypto_box_PUBLICKEYBYTES, 1, fp);
|
fwrite(publickey, crypto_box_PUBLICKEYBYTES, 1, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
printf("Drone keypair saved: %s\n", drone);
|
printf("Key saved: %s\n", key);
|
||||||
|
|
||||||
const char *station = "/tmp/gs.key";
|
|
||||||
if ((fp = fopen(station, "w")) == NULL) {
|
|
||||||
printf("Unable to save: %s\n", station);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fwrite(gs_secretkey, crypto_box_SECRETKEYBYTES, 1, fp);
|
|
||||||
fwrite(drone_publickey, crypto_box_PUBLICKEYBYTES, 1, fp);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
printf("Station keypair saved: %s\n", station);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue