Allow specifying full private key

main
cel 5 years ago
parent f1337fffb2
commit c183d6074d

@ -19,7 +19,7 @@
| |
.Op Fl c Ar cap .Op Fl c Ar cap
.Op Fl k Ar key .Op Fl k Ar key
.Op Fl K Ar keypair_seed .Op Fl K Ar keypair
.Oc .Oc
. .
.Oo .Oo
@ -91,8 +91,8 @@ and
.It Fl k Ar key .It Fl k Ar key
The key to connect to. Default is your public key, as read from your The key to connect to. Default is your public key, as read from your
private key file. private key file.
.It Fl K Ar keypair_seed .It Fl K Ar keypair
Private key seed to use for secret-handshake. Default is to use the private key Private key or private key seed to use for secret-handshake. Default is to use the private key
from your from your
.Pa ~/.ssb/secret .Pa ~/.ssb/secret
file or other secret file according to the environmental variables described in file or other secret file according to the environmental variables described in

@ -394,6 +394,15 @@ static int pubkey_decode(const char *key_str, unsigned char key[32]) {
return base64_decode(key_str, 44, key, 32); return base64_decode(key_str, 44, key, 32);
} }
static int seckey_decode(const char *key_str, unsigned char key[64]) {
if (!key_str) { errno = EPROTO; return -1; }
if (!*key_str) { errno = EPROTO; return -1; }
if (*key_str == '@') key_str++;
size_t len = strlen(key_str);
if (len > 8 && memcmp(key_str + len - 8, ".ed25519", 8) == 0) len -= 8;
return base64_decode(key_str, len, key, 64);
}
static jsmntok_t *json_lookup(const char *buf, jsmntok_t *tok, const char *prop, size_t prop_len) { static jsmntok_t *json_lookup(const char *buf, jsmntok_t *tok, const char *prop, size_t prop_len) {
jsmntok_t *end = tok + tok->size + 1; jsmntok_t *end = tok + tok->size + 1;
if (tok->type != JSMN_OBJECT) { errno = EPROTO; return NULL; } if (tok->type != JSMN_OBJECT) { errno = EPROTO; return NULL; }
@ -1134,7 +1143,14 @@ int main(int argc, char *argv[]) {
if (rc < 0) errx(0, "unable to convert method name"); if (rc < 0) errx(0, "unable to convert method name");
} }
if (keypair_seed_str) { if (keypair_seed_str == NULL) {
read_private_key(app_dir, private_key);
memcpy(public_key, private_key+32, 32);
} else if (strlen(keypair_seed_str) > 55) {
rc = seckey_decode(keypair_seed_str, private_key);
if (rc < 0) err(1, "unable to decode private key");
memcpy(public_key, private_key+32, 32);
} else if (keypair_seed_str) {
unsigned char seed[crypto_sign_SEEDBYTES]; unsigned char seed[crypto_sign_SEEDBYTES];
unsigned char ed25519_skpk[crypto_sign_ed25519_SECRETKEYBYTES]; unsigned char ed25519_skpk[crypto_sign_ed25519_SECRETKEYBYTES];
@ -1144,9 +1160,6 @@ int main(int argc, char *argv[]) {
if (rc < 0) err(1, "unable to convert private key to seed"); if (rc < 0) err(1, "unable to convert private key to seed");
rc = crypto_sign_seed_keypair(public_key, private_key, seed); rc = crypto_sign_seed_keypair(public_key, private_key, seed);
if (rc < 0) err(1, "unable to generate keypair from seed"); if (rc < 0) err(1, "unable to generate keypair from seed");
} else {
read_private_key(app_dir, private_key);
memcpy(public_key, private_key+32, 32);
} }
if (key) { if (key) {

Loading…
Cancel
Save