version 1.445, 2022/01/05 04:50:11 |
version 1.451, 2022/05/08 22:58:35 |
|
|
{ |
{ |
size_t i, slen, plen = strlen(keypath); |
size_t i, slen, plen = strlen(keypath); |
char *privpath = xstrdup(keypath); |
char *privpath = xstrdup(keypath); |
const char *suffixes[] = { "-cert.pub", ".pub", NULL }; |
static const char * const suffixes[] = { "-cert.pub", ".pub", NULL }; |
struct sshkey *ret = NULL, *privkey = NULL; |
struct sshkey *ret = NULL, *privkey = NULL; |
int r; |
int r, waspub = 0; |
|
struct stat st; |
|
|
/* |
/* |
* If passed a public key filename, then try to locate the corresponding |
* If passed a public key filename, then try to locate the corresponding |
|
|
privpath[plen - slen] = '\0'; |
privpath[plen - slen] = '\0'; |
debug_f("%s looks like a public key, using private key " |
debug_f("%s looks like a public key, using private key " |
"path %s instead", keypath, privpath); |
"path %s instead", keypath, privpath); |
|
waspub = 1; |
} |
} |
if ((privkey = load_identity(privpath, NULL)) == NULL) { |
if (waspub && stat(privpath, &st) != 0 && errno == ENOENT) |
error("Couldn't load identity %s", keypath); |
fatal("No private key found for public key \"%s\"", keypath); |
goto done; |
if ((r = sshkey_load_private(privpath, "", &privkey, NULL)) != 0 && |
} |
(r != SSH_ERR_KEY_WRONG_PASSPHRASE)) { |
|
debug_fr(r, "load private key \"%s\"", privpath); |
|
fatal("No private key found for \"%s\"", privpath); |
|
} else if (privkey == NULL) |
|
privkey = load_identity(privpath, NULL); |
|
|
if (!sshkey_equal_public(pubkey, privkey)) { |
if (!sshkey_equal_public(pubkey, privkey)) { |
error("Public key %s doesn't match private %s", |
error("Public key %s doesn't match private %s", |
keypath, privpath); |
keypath, privpath); |
|
|
return sig_match_principals(identity_file, cert_key_id, |
return sig_match_principals(identity_file, cert_key_id, |
opts, nopts); |
opts, nopts); |
} else if (strncmp(sign_op, "sign", 4) == 0) { |
} else if (strncmp(sign_op, "sign", 4) == 0) { |
|
/* NB. cert_principals is actually namespace, via -n */ |
if (cert_principals == NULL || |
if (cert_principals == NULL || |
*cert_principals == '\0') { |
*cert_principals == '\0') { |
error("Too few arguments for sign: " |
error("Too few arguments for sign: " |
|
|
return sig_sign(identity_file, cert_principals, |
return sig_sign(identity_file, cert_principals, |
argc, argv, opts, nopts); |
argc, argv, opts, nopts); |
} else if (strncmp(sign_op, "check-novalidate", 16) == 0) { |
} else if (strncmp(sign_op, "check-novalidate", 16) == 0) { |
|
/* NB. cert_principals is actually namespace, via -n */ |
|
if (cert_principals == NULL || |
|
*cert_principals == '\0') { |
|
error("Too few arguments for check-novalidate: " |
|
"missing namespace"); |
|
exit(1); |
|
} |
if (ca_key_path == NULL) { |
if (ca_key_path == NULL) { |
error("Too few arguments for check-novalidate: " |
error("Too few arguments for check-novalidate: " |
"missing signature file"); |
"missing signature file"); |
|
|
return sig_verify(ca_key_path, cert_principals, |
return sig_verify(ca_key_path, cert_principals, |
NULL, NULL, NULL, opts, nopts); |
NULL, NULL, NULL, opts, nopts); |
} else if (strncmp(sign_op, "verify", 6) == 0) { |
} else if (strncmp(sign_op, "verify", 6) == 0) { |
|
/* NB. cert_principals is actually namespace, via -n */ |
if (cert_principals == NULL || |
if (cert_principals == NULL || |
*cert_principals == '\0') { |
*cert_principals == '\0') { |
error("Too few arguments for verify: " |
error("Too few arguments for verify: " |
|
|
} |
} |
if (cert_key_id == NULL) { |
if (cert_key_id == NULL) { |
error("Too few arguments for verify: " |
error("Too few arguments for verify: " |
"missing principal ID"); |
"missing principal identity"); |
exit(1); |
exit(1); |
} |
} |
return sig_verify(ca_key_path, cert_principals, |
return sig_verify(ca_key_path, cert_principals, |