diff --git a/sbotc.1 b/sbotc.1 index 60e52f6..0a741fc 100644 --- a/sbotc.1 +++ b/sbotc.1 @@ -19,7 +19,7 @@ | .Op Fl c Ar cap .Op Fl k Ar key -.Op Fl K Ar keypair_seed +.Op Fl K Ar keypair .Oc . .Oo @@ -91,8 +91,8 @@ and .It Fl k Ar key The key to connect to. Default is your public key, as read from your private key file. -.It Fl K Ar keypair_seed -Private key seed to use for secret-handshake. Default is to use the private key +.It Fl K Ar keypair +Private key or private key seed to use for secret-handshake. Default is to use the private key from your .Pa ~/.ssb/secret file or other secret file according to the environmental variables described in diff --git a/sbotc.c b/sbotc.c index f2a60cc..7c6b120 100644 --- a/sbotc.c +++ b/sbotc.c @@ -394,6 +394,15 @@ static int pubkey_decode(const char *key_str, unsigned char 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) { jsmntok_t *end = tok + tok->size + 1; 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 (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 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"); rc = crypto_sign_seed_keypair(public_key, private_key, 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) {