version 1.188, 2010/04/23 01:47:41 |
version 1.196, 2010/08/04 05:40:39 |
|
|
u_int64_t cert_valid_to = ~0ULL; |
u_int64_t cert_valid_to = ~0ULL; |
|
|
/* Certificate options */ |
/* Certificate options */ |
#define CRITOPT_X_FWD (1) |
#define CERTOPT_X_FWD (1) |
#define CRITOPT_AGENT_FWD (1<<1) |
#define CERTOPT_AGENT_FWD (1<<1) |
#define CRITOPT_PORT_FWD (1<<2) |
#define CERTOPT_PORT_FWD (1<<2) |
#define CRITOPT_PTY (1<<3) |
#define CERTOPT_PTY (1<<3) |
#define CRITOPT_USER_RC (1<<4) |
#define CERTOPT_USER_RC (1<<4) |
#define CRITOPT_DEFAULT (CRITOPT_X_FWD|CRITOPT_AGENT_FWD| \ |
#define CERTOPT_DEFAULT (CERTOPT_X_FWD|CERTOPT_AGENT_FWD| \ |
CRITOPT_PORT_FWD|CRITOPT_PTY| \ |
CERTOPT_PORT_FWD|CERTOPT_PTY|CERTOPT_USER_RC) |
CRITOPT_USER_RC) |
u_int32_t certflags_flags = CERTOPT_DEFAULT; |
u_int32_t critical_flags = CRITOPT_DEFAULT; |
char *certflags_command = NULL; |
char *critical_command = NULL; |
char *certflags_src_addr = NULL; |
char *critical_src_addr = NULL; |
|
|
|
/* Dump public key file in format used by real and the original SSH 2 */ |
/* Conversion to/from various formats */ |
int convert_to_ssh2 = 0; |
int convert_to = 0; |
int convert_from_ssh2 = 0; |
int convert_from = 0; |
|
enum { |
|
FMT_RFC4716, |
|
FMT_PKCS8, |
|
FMT_PEM |
|
} convert_format = FMT_RFC4716; |
int print_public = 0; |
int print_public = 0; |
int print_generic = 0; |
int print_generic = 0; |
|
|
char *key_type_name = NULL; |
char *key_type_name = NULL; |
|
|
|
|
/* argv0 */ |
/* argv0 */ |
extern char *__progname; |
extern char *__progname; |
|
|
|
|
#define SSH_COM_PRIVATE_KEY_MAGIC 0x3f6ff9eb |
#define SSH_COM_PRIVATE_KEY_MAGIC 0x3f6ff9eb |
|
|
static void |
static void |
do_convert_to_ssh2(struct passwd *pw) |
do_convert_to_ssh2(struct passwd *pw, Key *k) |
{ |
{ |
Key *k; |
|
u_int len; |
u_int len; |
u_char *blob; |
u_char *blob; |
char comment[61]; |
char comment[61]; |
struct stat st; |
|
|
|
if (!have_identity) |
|
ask_filename(pw, "Enter file in which the key is"); |
|
if (stat(identity_file, &st) < 0) { |
|
perror(identity_file); |
|
exit(1); |
|
} |
|
if ((k = key_load_public(identity_file, NULL)) == NULL) { |
|
if ((k = load_identity(identity_file)) == NULL) { |
|
fprintf(stderr, "load failed\n"); |
|
exit(1); |
|
} |
|
} |
|
if (k->type == KEY_RSA1) { |
|
fprintf(stderr, "version 1 keys are not supported\n"); |
|
exit(1); |
|
} |
|
if (key_to_blob(k, &blob, &len) <= 0) { |
if (key_to_blob(k, &blob, &len) <= 0) { |
fprintf(stderr, "key_to_blob failed\n"); |
fprintf(stderr, "key_to_blob failed\n"); |
exit(1); |
exit(1); |
|
|
} |
} |
|
|
static void |
static void |
|
do_convert_to_pkcs8(Key *k) |
|
{ |
|
switch (key_type_plain(k->type)) { |
|
case KEY_RSA: |
|
if (!PEM_write_RSA_PUBKEY(stdout, k->rsa)) |
|
fatal("PEM_write_RSA_PUBKEY failed"); |
|
break; |
|
case KEY_DSA: |
|
if (!PEM_write_DSA_PUBKEY(stdout, k->dsa)) |
|
fatal("PEM_write_DSA_PUBKEY failed"); |
|
break; |
|
default: |
|
fatal("%s: unsupported key type %s", __func__, key_type(k)); |
|
} |
|
exit(0); |
|
} |
|
|
|
static void |
|
do_convert_to_pem(Key *k) |
|
{ |
|
switch (key_type_plain(k->type)) { |
|
case KEY_RSA: |
|
if (!PEM_write_RSAPublicKey(stdout, k->rsa)) |
|
fatal("PEM_write_RSAPublicKey failed"); |
|
break; |
|
#if notyet /* OpenSSH 0.9.8 lacks this function */ |
|
case KEY_DSA: |
|
if (!PEM_write_DSAPublicKey(stdout, k->dsa)) |
|
fatal("PEM_write_DSAPublicKey failed"); |
|
break; |
|
#endif |
|
default: |
|
fatal("%s: unsupported key type %s", __func__, key_type(k)); |
|
} |
|
exit(0); |
|
} |
|
|
|
static void |
|
do_convert_to(struct passwd *pw) |
|
{ |
|
Key *k; |
|
struct stat st; |
|
|
|
if (!have_identity) |
|
ask_filename(pw, "Enter file in which the key is"); |
|
if (stat(identity_file, &st) < 0) |
|
fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
|
if ((k = key_load_public(identity_file, NULL)) == NULL) { |
|
if ((k = load_identity(identity_file)) == NULL) { |
|
fprintf(stderr, "load failed\n"); |
|
exit(1); |
|
} |
|
} |
|
if (k->type == KEY_RSA1) { |
|
fprintf(stderr, "version 1 keys are not supported\n"); |
|
exit(1); |
|
} |
|
|
|
switch (convert_format) { |
|
case FMT_RFC4716: |
|
do_convert_to_ssh2(pw, k); |
|
break; |
|
case FMT_PKCS8: |
|
do_convert_to_pkcs8(k); |
|
break; |
|
case FMT_PEM: |
|
do_convert_to_pem(k); |
|
break; |
|
default: |
|
fatal("%s: unknown key format %d", __func__, convert_format); |
|
} |
|
exit(0); |
|
} |
|
|
|
static void |
buffer_get_bignum_bits(Buffer *b, BIGNUM *value) |
buffer_get_bignum_bits(Buffer *b, BIGNUM *value) |
{ |
{ |
u_int bignum_bits = buffer_get_int(b); |
u_int bignum_bits = buffer_get_int(b); |
|
|
} |
} |
|
|
static void |
static void |
do_convert_from_ssh2(struct passwd *pw) |
do_convert_from_ssh2(struct passwd *pw, Key **k, int *private) |
{ |
{ |
Key *k; |
|
int blen; |
int blen; |
u_int len; |
u_int len; |
char line[1024]; |
char line[1024]; |
u_char blob[8096]; |
u_char blob[8096]; |
char encoded[8096]; |
char encoded[8096]; |
struct stat st; |
int escaped = 0; |
int escaped = 0, private = 0, ok; |
|
FILE *fp; |
FILE *fp; |
|
|
if (!have_identity) |
if ((fp = fopen(identity_file, "r")) == NULL) |
ask_filename(pw, "Enter file in which the key is"); |
fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
if (stat(identity_file, &st) < 0) { |
|
perror(identity_file); |
|
exit(1); |
|
} |
|
fp = fopen(identity_file, "r"); |
|
if (fp == NULL) { |
|
perror(identity_file); |
|
exit(1); |
|
} |
|
encoded[0] = '\0'; |
encoded[0] = '\0'; |
while ((blen = get_line(fp, line, sizeof(line))) != -1) { |
while ((blen = get_line(fp, line, sizeof(line))) != -1) { |
if (line[blen - 1] == '\\') |
if (line[blen - 1] == '\\') |
|
|
if (strncmp(line, "----", 4) == 0 || |
if (strncmp(line, "----", 4) == 0 || |
strstr(line, ": ") != NULL) { |
strstr(line, ": ") != NULL) { |
if (strstr(line, SSH_COM_PRIVATE_BEGIN) != NULL) |
if (strstr(line, SSH_COM_PRIVATE_BEGIN) != NULL) |
private = 1; |
*private = 1; |
if (strstr(line, " END ") != NULL) { |
if (strstr(line, " END ") != NULL) { |
break; |
break; |
} |
} |
|
|
fprintf(stderr, "uudecode failed.\n"); |
fprintf(stderr, "uudecode failed.\n"); |
exit(1); |
exit(1); |
} |
} |
k = private ? |
*k = *private ? |
do_convert_private_ssh2_from_blob(blob, blen) : |
do_convert_private_ssh2_from_blob(blob, blen) : |
key_from_blob(blob, blen); |
key_from_blob(blob, blen); |
if (k == NULL) { |
if (*k == NULL) { |
fprintf(stderr, "decode blob failed.\n"); |
fprintf(stderr, "decode blob failed.\n"); |
exit(1); |
exit(1); |
} |
} |
ok = private ? |
fclose(fp); |
(k->type == KEY_DSA ? |
} |
PEM_write_DSAPrivateKey(stdout, k->dsa, NULL, NULL, 0, NULL, NULL) : |
|
PEM_write_RSAPrivateKey(stdout, k->rsa, NULL, NULL, 0, NULL, NULL)) : |
static void |
key_write(k, stdout); |
do_convert_from_pkcs8(Key **k, int *private) |
|
{ |
|
EVP_PKEY *pubkey; |
|
FILE *fp; |
|
|
|
if ((fp = fopen(identity_file, "r")) == NULL) |
|
fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
|
if ((pubkey = PEM_read_PUBKEY(fp, NULL, NULL, NULL)) == NULL) { |
|
fatal("%s: %s is not a recognised public key format", __func__, |
|
identity_file); |
|
} |
|
fclose(fp); |
|
switch (EVP_PKEY_type(pubkey->type)) { |
|
case EVP_PKEY_RSA: |
|
*k = key_new(KEY_UNSPEC); |
|
(*k)->type = KEY_RSA; |
|
(*k)->rsa = EVP_PKEY_get1_RSA(pubkey); |
|
break; |
|
case EVP_PKEY_DSA: |
|
*k = key_new(KEY_UNSPEC); |
|
(*k)->type = KEY_DSA; |
|
(*k)->dsa = EVP_PKEY_get1_DSA(pubkey); |
|
break; |
|
default: |
|
fatal("%s: unsupported pubkey type %d", __func__, |
|
EVP_PKEY_type(pubkey->type)); |
|
} |
|
EVP_PKEY_free(pubkey); |
|
return; |
|
} |
|
|
|
static void |
|
do_convert_from_pem(Key **k, int *private) |
|
{ |
|
FILE *fp; |
|
RSA *rsa; |
|
#ifdef notyet |
|
DSA *dsa; |
|
#endif |
|
|
|
if ((fp = fopen(identity_file, "r")) == NULL) |
|
fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
|
if ((rsa = PEM_read_RSAPublicKey(fp, NULL, NULL, NULL)) != NULL) { |
|
*k = key_new(KEY_UNSPEC); |
|
(*k)->type = KEY_RSA; |
|
(*k)->rsa = rsa; |
|
fclose(fp); |
|
return; |
|
} |
|
#if notyet /* OpenSSH 0.9.8 lacks this function */ |
|
rewind(fp); |
|
if ((dsa = PEM_read_DSAPublicKey(fp, NULL, NULL, NULL)) != NULL) { |
|
*k = key_new(KEY_UNSPEC); |
|
(*k)->type = KEY_DSA; |
|
(*k)->dsa = dsa; |
|
fclose(fp); |
|
return; |
|
} |
|
#endif |
|
fatal("%s: unrecognised raw private key format", __func__); |
|
} |
|
|
|
static void |
|
do_convert_from(struct passwd *pw) |
|
{ |
|
Key *k = NULL; |
|
int private = 0, ok = 0; |
|
struct stat st; |
|
|
|
if (!have_identity) |
|
ask_filename(pw, "Enter file in which the key is"); |
|
if (stat(identity_file, &st) < 0) |
|
fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
|
|
|
switch (convert_format) { |
|
case FMT_RFC4716: |
|
do_convert_from_ssh2(pw, &k, &private); |
|
break; |
|
case FMT_PKCS8: |
|
do_convert_from_pkcs8(&k, &private); |
|
break; |
|
case FMT_PEM: |
|
do_convert_from_pem(&k, &private); |
|
break; |
|
default: |
|
fatal("%s: unknown key format %d", __func__, convert_format); |
|
} |
|
|
|
if (!private) |
|
ok = key_write(k, stdout); |
|
if (ok) |
|
fprintf(stdout, "\n"); |
|
else { |
|
switch (k->type) { |
|
case KEY_DSA: |
|
ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL, |
|
NULL, 0, NULL, NULL); |
|
break; |
|
case KEY_RSA: |
|
ok = PEM_write_RSAPrivateKey(stdout, k->rsa, NULL, |
|
NULL, 0, NULL, NULL); |
|
break; |
|
default: |
|
fatal("%s: unsupported key type %s", __func__, |
|
key_type(k)); |
|
} |
|
} |
|
|
if (!ok) { |
if (!ok) { |
fprintf(stderr, "key write failed\n"); |
fprintf(stderr, "key write failed\n"); |
exit(1); |
exit(1); |
} |
} |
key_free(k); |
key_free(k); |
if (!private) |
|
fprintf(stdout, "\n"); |
|
fclose(fp); |
|
exit(0); |
exit(0); |
} |
} |
|
|
|
|
comment = NULL; |
comment = NULL; |
} |
} |
|
|
f = fopen(identity_file, "r"); |
if ((f = fopen(identity_file, "r")) == NULL) |
if (f != NULL) { |
fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
while (fgets(line, sizeof(line), f)) { |
|
if ((cp = strchr(line, '\n')) == NULL) { |
|
error("line %d too long: %.40s...", |
|
num + 1, line); |
|
skip = 1; |
|
continue; |
|
} |
|
num++; |
|
if (skip) { |
|
skip = 0; |
|
continue; |
|
} |
|
*cp = '\0'; |
|
|
|
/* Skip leading whitespace, empty and comment lines. */ |
while (fgets(line, sizeof(line), f)) { |
for (cp = line; *cp == ' ' || *cp == '\t'; cp++) |
if ((cp = strchr(line, '\n')) == NULL) { |
; |
error("line %d too long: %.40s...", |
if (!*cp || *cp == '\n' || *cp == '#') |
num + 1, line); |
continue; |
skip = 1; |
i = strtol(cp, &ep, 10); |
continue; |
if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) { |
} |
int quoted = 0; |
num++; |
comment = cp; |
if (skip) { |
for (; *cp && (quoted || (*cp != ' ' && |
skip = 0; |
*cp != '\t')); cp++) { |
continue; |
if (*cp == '\\' && cp[1] == '"') |
} |
cp++; /* Skip both */ |
*cp = '\0'; |
else if (*cp == '"') |
|
quoted = !quoted; |
/* Skip leading whitespace, empty and comment lines. */ |
} |
for (cp = line; *cp == ' ' || *cp == '\t'; cp++) |
if (!*cp) |
; |
continue; |
if (!*cp || *cp == '\n' || *cp == '#') |
*cp++ = '\0'; |
continue; |
|
i = strtol(cp, &ep, 10); |
|
if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) { |
|
int quoted = 0; |
|
comment = cp; |
|
for (; *cp && (quoted || (*cp != ' ' && |
|
*cp != '\t')); cp++) { |
|
if (*cp == '\\' && cp[1] == '"') |
|
cp++; /* Skip both */ |
|
else if (*cp == '"') |
|
quoted = !quoted; |
} |
} |
ep = cp; |
if (!*cp) |
public = key_new(KEY_RSA1); |
continue; |
|
*cp++ = '\0'; |
|
} |
|
ep = cp; |
|
public = key_new(KEY_RSA1); |
|
if (key_read(public, &cp) != 1) { |
|
cp = ep; |
|
key_free(public); |
|
public = key_new(KEY_UNSPEC); |
if (key_read(public, &cp) != 1) { |
if (key_read(public, &cp) != 1) { |
cp = ep; |
|
key_free(public); |
key_free(public); |
public = key_new(KEY_UNSPEC); |
continue; |
if (key_read(public, &cp) != 1) { |
|
key_free(public); |
|
continue; |
|
} |
|
} |
} |
comment = *cp ? cp : comment; |
|
fp = key_fingerprint(public, fptype, rep); |
|
ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART); |
|
printf("%u %s %s (%s)\n", key_size(public), fp, |
|
comment ? comment : "no comment", key_type(public)); |
|
if (log_level >= SYSLOG_LEVEL_VERBOSE) |
|
printf("%s\n", ra); |
|
xfree(ra); |
|
xfree(fp); |
|
key_free(public); |
|
invalid = 0; |
|
} |
} |
fclose(f); |
comment = *cp ? cp : comment; |
|
fp = key_fingerprint(public, fptype, rep); |
|
ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART); |
|
printf("%u %s %s (%s)\n", key_size(public), fp, |
|
comment ? comment : "no comment", key_type(public)); |
|
if (log_level >= SYSLOG_LEVEL_VERBOSE) |
|
printf("%s\n", ra); |
|
xfree(ra); |
|
xfree(fp); |
|
key_free(public); |
|
invalid = 0; |
} |
} |
|
fclose(f); |
|
|
if (invalid) { |
if (invalid) { |
printf("%s is not a public key file.\n", identity_file); |
printf("%s is not a public key file.\n", identity_file); |
exit(1); |
exit(1); |
|
|
have_identity = 1; |
have_identity = 1; |
} |
} |
if ((in = fopen(identity_file, "r")) == NULL) |
if ((in = fopen(identity_file, "r")) == NULL) |
fatal("fopen: %s", strerror(errno)); |
fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
|
|
/* |
/* |
* Find hosts goes to stdout, hash and deletions happen in-place |
* Find hosts goes to stdout, hash and deletions happen in-place |
|
|
buffer_free(&b); |
buffer_free(&b); |
} |
} |
|
|
|
#define OPTIONS_CRITICAL 1 |
|
#define OPTIONS_EXTENSIONS 2 |
static void |
static void |
prepare_options_buf(Buffer *c) |
prepare_options_buf(Buffer *c, int which) |
{ |
{ |
buffer_clear(c); |
buffer_clear(c); |
if ((critical_flags & CRITOPT_X_FWD) != 0) |
if ((which & OPTIONS_CRITICAL) != 0 && |
add_flag_option(c, "permit-X11-forwarding"); |
certflags_command != NULL) |
if ((critical_flags & CRITOPT_AGENT_FWD) != 0) |
add_string_option(c, "force-command", certflags_command); |
|
if ((which & OPTIONS_EXTENSIONS) != 0 && |
|
(certflags_flags & CERTOPT_AGENT_FWD) != 0) |
add_flag_option(c, "permit-agent-forwarding"); |
add_flag_option(c, "permit-agent-forwarding"); |
if ((critical_flags & CRITOPT_PORT_FWD) != 0) |
if ((which & OPTIONS_EXTENSIONS) != 0 && |
|
(certflags_flags & CERTOPT_PORT_FWD) != 0) |
add_flag_option(c, "permit-port-forwarding"); |
add_flag_option(c, "permit-port-forwarding"); |
if ((critical_flags & CRITOPT_PTY) != 0) |
if ((which & OPTIONS_EXTENSIONS) != 0 && |
|
(certflags_flags & CERTOPT_PTY) != 0) |
add_flag_option(c, "permit-pty"); |
add_flag_option(c, "permit-pty"); |
if ((critical_flags & CRITOPT_USER_RC) != 0) |
if ((which & OPTIONS_EXTENSIONS) != 0 && |
|
(certflags_flags & CERTOPT_USER_RC) != 0) |
add_flag_option(c, "permit-user-rc"); |
add_flag_option(c, "permit-user-rc"); |
if (critical_command != NULL) |
if ((which & OPTIONS_EXTENSIONS) != 0 && |
add_string_option(c, "force-command", critical_command); |
(certflags_flags & CERTOPT_X_FWD) != 0) |
if (critical_src_addr != NULL) |
add_flag_option(c, "permit-X11-forwarding"); |
add_string_option(c, "source-address", critical_src_addr); |
if ((which & OPTIONS_CRITICAL) != 0 && |
|
certflags_src_addr != NULL) |
|
add_string_option(c, "source-address", certflags_src_addr); |
} |
} |
|
|
static void |
static void |
|
|
public->cert->principals = plist; |
public->cert->principals = plist; |
public->cert->valid_after = cert_valid_from; |
public->cert->valid_after = cert_valid_from; |
public->cert->valid_before = cert_valid_to; |
public->cert->valid_before = cert_valid_to; |
prepare_options_buf(&public->cert->critical); |
if (v00) { |
|
prepare_options_buf(&public->cert->critical, |
|
OPTIONS_CRITICAL|OPTIONS_EXTENSIONS); |
|
} else { |
|
prepare_options_buf(&public->cert->critical, |
|
OPTIONS_CRITICAL); |
|
prepare_options_buf(&public->cert->extensions, |
|
OPTIONS_EXTENSIONS); |
|
} |
public->cert->signature_key = key_from_private(ca); |
public->cert->signature_key = key_from_private(ca); |
|
|
if (key_certify(public, ca) != 0) |
if (key_certify(public, ca) != 0) |
|
|
char *val; |
char *val; |
|
|
if (strcmp(opt, "clear") == 0) |
if (strcmp(opt, "clear") == 0) |
critical_flags = 0; |
certflags_flags = 0; |
else if (strcasecmp(opt, "no-x11-forwarding") == 0) |
else if (strcasecmp(opt, "no-x11-forwarding") == 0) |
critical_flags &= ~CRITOPT_X_FWD; |
certflags_flags &= ~CERTOPT_X_FWD; |
else if (strcasecmp(opt, "permit-x11-forwarding") == 0) |
else if (strcasecmp(opt, "permit-x11-forwarding") == 0) |
critical_flags |= CRITOPT_X_FWD; |
certflags_flags |= CERTOPT_X_FWD; |
else if (strcasecmp(opt, "no-agent-forwarding") == 0) |
else if (strcasecmp(opt, "no-agent-forwarding") == 0) |
critical_flags &= ~CRITOPT_AGENT_FWD; |
certflags_flags &= ~CERTOPT_AGENT_FWD; |
else if (strcasecmp(opt, "permit-agent-forwarding") == 0) |
else if (strcasecmp(opt, "permit-agent-forwarding") == 0) |
critical_flags |= CRITOPT_AGENT_FWD; |
certflags_flags |= CERTOPT_AGENT_FWD; |
else if (strcasecmp(opt, "no-port-forwarding") == 0) |
else if (strcasecmp(opt, "no-port-forwarding") == 0) |
critical_flags &= ~CRITOPT_PORT_FWD; |
certflags_flags &= ~CERTOPT_PORT_FWD; |
else if (strcasecmp(opt, "permit-port-forwarding") == 0) |
else if (strcasecmp(opt, "permit-port-forwarding") == 0) |
critical_flags |= CRITOPT_PORT_FWD; |
certflags_flags |= CERTOPT_PORT_FWD; |
else if (strcasecmp(opt, "no-pty") == 0) |
else if (strcasecmp(opt, "no-pty") == 0) |
critical_flags &= ~CRITOPT_PTY; |
certflags_flags &= ~CERTOPT_PTY; |
else if (strcasecmp(opt, "permit-pty") == 0) |
else if (strcasecmp(opt, "permit-pty") == 0) |
critical_flags |= CRITOPT_PTY; |
certflags_flags |= CERTOPT_PTY; |
else if (strcasecmp(opt, "no-user-rc") == 0) |
else if (strcasecmp(opt, "no-user-rc") == 0) |
critical_flags &= ~CRITOPT_USER_RC; |
certflags_flags &= ~CERTOPT_USER_RC; |
else if (strcasecmp(opt, "permit-user-rc") == 0) |
else if (strcasecmp(opt, "permit-user-rc") == 0) |
critical_flags |= CRITOPT_USER_RC; |
certflags_flags |= CERTOPT_USER_RC; |
else if (strncasecmp(opt, "force-command=", 14) == 0) { |
else if (strncasecmp(opt, "force-command=", 14) == 0) { |
val = opt + 14; |
val = opt + 14; |
if (*val == '\0') |
if (*val == '\0') |
fatal("Empty force-command option"); |
fatal("Empty force-command option"); |
if (critical_command != NULL) |
if (certflags_command != NULL) |
fatal("force-command already specified"); |
fatal("force-command already specified"); |
critical_command = xstrdup(val); |
certflags_command = xstrdup(val); |
} else if (strncasecmp(opt, "source-address=", 15) == 0) { |
} else if (strncasecmp(opt, "source-address=", 15) == 0) { |
val = opt + 15; |
val = opt + 15; |
if (*val == '\0') |
if (*val == '\0') |
fatal("Empty source-address option"); |
fatal("Empty source-address option"); |
if (critical_src_addr != NULL) |
if (certflags_src_addr != NULL) |
fatal("source-address already specified"); |
fatal("source-address already specified"); |
if (addr_match_cidr_list(NULL, val) != 0) |
if (addr_match_cidr_list(NULL, val) != 0) |
fatal("Invalid source-address list"); |
fatal("Invalid source-address list"); |
critical_src_addr = xstrdup(val); |
certflags_src_addr = xstrdup(val); |
} else |
} else |
fatal("Unsupported certificate option \"%s\"", opt); |
fatal("Unsupported certificate option \"%s\"", opt); |
} |
} |
|
|
static void |
static void |
|
show_options(const Buffer *optbuf, int v00, int in_critical) |
|
{ |
|
u_char *name, *data; |
|
u_int dlen; |
|
Buffer options, option; |
|
|
|
buffer_init(&options); |
|
buffer_append(&options, buffer_ptr(optbuf), buffer_len(optbuf)); |
|
|
|
buffer_init(&option); |
|
while (buffer_len(&options) != 0) { |
|
name = buffer_get_string(&options, NULL); |
|
data = buffer_get_string_ptr(&options, &dlen); |
|
buffer_append(&option, data, dlen); |
|
printf(" %s", name); |
|
if ((v00 || !in_critical) && |
|
(strcmp(name, "permit-X11-forwarding") == 0 || |
|
strcmp(name, "permit-agent-forwarding") == 0 || |
|
strcmp(name, "permit-port-forwarding") == 0 || |
|
strcmp(name, "permit-pty") == 0 || |
|
strcmp(name, "permit-user-rc") == 0)) |
|
printf("\n"); |
|
else if ((v00 || in_critical) && |
|
(strcmp(name, "force-command") == 0 || |
|
strcmp(name, "source-address") == 0)) { |
|
data = buffer_get_string(&option, NULL); |
|
printf(" %s\n", data); |
|
xfree(data); |
|
} else { |
|
printf(" UNKNOWN OPTION (len %u)\n", |
|
buffer_len(&option)); |
|
buffer_clear(&option); |
|
} |
|
xfree(name); |
|
if (buffer_len(&option) != 0) |
|
fatal("Option corrupt: extra data at end"); |
|
} |
|
buffer_free(&option); |
|
buffer_free(&options); |
|
} |
|
|
|
static void |
do_show_cert(struct passwd *pw) |
do_show_cert(struct passwd *pw) |
{ |
{ |
Key *key; |
Key *key; |
struct stat st; |
struct stat st; |
char *key_fp, *ca_fp; |
char *key_fp, *ca_fp; |
Buffer options, option; |
u_int i, v00; |
u_char *name, *data; |
|
u_int i, dlen, v00; |
|
|
|
if (!have_identity) |
if (!have_identity) |
ask_filename(pw, "Enter file in which the key is"); |
ask_filename(pw, "Enter file in which the key is"); |
if (stat(identity_file, &st) < 0) { |
if (stat(identity_file, &st) < 0) |
perror(identity_file); |
fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
exit(1); |
|
} |
|
if ((key = key_load_public(identity_file, NULL)) == NULL) |
if ((key = key_load_public(identity_file, NULL)) == NULL) |
fatal("%s is not a public key", identity_file); |
fatal("%s is not a public key", identity_file); |
if (!key_is_cert(key)) |
if (!key_is_cert(key)) |
|
|
printf("(none)\n"); |
printf("(none)\n"); |
else { |
else { |
printf("\n"); |
printf("\n"); |
buffer_init(&options); |
show_options(&key->cert->critical, v00, 1); |
buffer_append(&options, |
|
buffer_ptr(&key->cert->critical), |
|
buffer_len(&key->cert->critical)); |
|
buffer_init(&option); |
|
while (buffer_len(&options) != 0) { |
|
name = buffer_get_string(&options, NULL); |
|
data = buffer_get_string_ptr(&options, &dlen); |
|
buffer_append(&option, data, dlen); |
|
printf(" %s", name); |
|
if (strcmp(name, "permit-X11-forwarding") == 0 || |
|
strcmp(name, "permit-agent-forwarding") == 0 || |
|
strcmp(name, "permit-port-forwarding") == 0 || |
|
strcmp(name, "permit-pty") == 0 || |
|
strcmp(name, "permit-user-rc") == 0) |
|
printf("\n"); |
|
else if (strcmp(name, "force-command") == 0 || |
|
strcmp(name, "source-address") == 0) { |
|
data = buffer_get_string(&option, NULL); |
|
printf(" %s\n", data); |
|
xfree(data); |
|
} else { |
|
printf(" UNKNOWN OPTION (len %u)\n", |
|
buffer_len(&option)); |
|
buffer_clear(&option); |
|
} |
|
xfree(name); |
|
if (buffer_len(&option) != 0) |
|
fatal("Option corrupt: extra data at end"); |
|
} |
|
buffer_free(&option); |
|
buffer_free(&options); |
|
} |
} |
if (!v00) { |
if (!v00) { |
printf(" Extensions: "); |
printf(" Extensions: "); |
|
|
printf("(none)\n"); |
printf("(none)\n"); |
else { |
else { |
printf("\n"); |
printf("\n"); |
buffer_init(&options); |
show_options(&key->cert->extensions, v00, 0); |
buffer_append(&options, |
|
buffer_ptr(&key->cert->extensions), |
|
buffer_len(&key->cert->extensions)); |
|
buffer_init(&option); |
|
while (buffer_len(&options) != 0) { |
|
name = buffer_get_string(&options, NULL); |
|
(void)buffer_get_string_ptr(&options, &dlen); |
|
printf(" %s UNKNOWN OPTION " |
|
"(len %u)\n", name, dlen); |
|
xfree(name); |
|
} |
|
buffer_free(&option); |
|
buffer_free(&options); |
|
} |
} |
} |
} |
exit(0); |
exit(0); |
|
|
#ifdef ENABLE_PKCS11 |
#ifdef ENABLE_PKCS11 |
fprintf(stderr, " -D pkcs11 Download public key from pkcs11 token.\n"); |
fprintf(stderr, " -D pkcs11 Download public key from pkcs11 token.\n"); |
#endif |
#endif |
fprintf(stderr, " -e Convert OpenSSH to RFC 4716 key file.\n"); |
fprintf(stderr, " -e Export OpenSSH to foreign format key file.\n"); |
fprintf(stderr, " -F hostname Find hostname in known hosts file.\n"); |
fprintf(stderr, " -F hostname Find hostname in known hosts file.\n"); |
fprintf(stderr, " -f filename Filename of the key file.\n"); |
fprintf(stderr, " -f filename Filename of the key file.\n"); |
fprintf(stderr, " -G file Generate candidates for DH-GEX moduli.\n"); |
fprintf(stderr, " -G file Generate candidates for DH-GEX moduli.\n"); |
|
|
fprintf(stderr, " -H Hash names in known_hosts file.\n"); |
fprintf(stderr, " -H Hash names in known_hosts file.\n"); |
fprintf(stderr, " -h Generate host certificate instead of a user certificate.\n"); |
fprintf(stderr, " -h Generate host certificate instead of a user certificate.\n"); |
fprintf(stderr, " -I key_id Key identifier to include in certificate.\n"); |
fprintf(stderr, " -I key_id Key identifier to include in certificate.\n"); |
fprintf(stderr, " -i Convert RFC 4716 to OpenSSH key file.\n"); |
fprintf(stderr, " -i Import foreign format to OpenSSH key file.\n"); |
fprintf(stderr, " -L Print the contents of a certificate.\n"); |
fprintf(stderr, " -L Print the contents of a certificate.\n"); |
fprintf(stderr, " -l Show fingerprint of key file.\n"); |
fprintf(stderr, " -l Show fingerprint of key file.\n"); |
fprintf(stderr, " -M memory Amount of memory (MB) to use for generating DH-GEX moduli.\n"); |
fprintf(stderr, " -M memory Amount of memory (MB) to use for generating DH-GEX moduli.\n"); |
fprintf(stderr, " -n name,... User/host principal names to include in certificate\n"); |
fprintf(stderr, " -m key_fmt Conversion format for -e/-i (PEM|PKCS8|RFC4716).\n"); |
fprintf(stderr, " -N phrase Provide new passphrase.\n"); |
fprintf(stderr, " -N phrase Provide new passphrase.\n"); |
|
fprintf(stderr, " -n name,... User/host principal names to include in certificate\n"); |
fprintf(stderr, " -O option Specify a certificate option.\n"); |
fprintf(stderr, " -O option Specify a certificate option.\n"); |
fprintf(stderr, " -P phrase Provide old passphrase.\n"); |
fprintf(stderr, " -P phrase Provide old passphrase.\n"); |
fprintf(stderr, " -p Change passphrase of private key file.\n"); |
fprintf(stderr, " -p Change passphrase of private key file.\n"); |
fprintf(stderr, " -q Quiet.\n"); |
fprintf(stderr, " -q Quiet.\n"); |
fprintf(stderr, " -R hostname Remove host from known_hosts file.\n"); |
fprintf(stderr, " -R hostname Remove host from known_hosts file.\n"); |
fprintf(stderr, " -r hostname Print DNS resource record.\n"); |
fprintf(stderr, " -r hostname Print DNS resource record.\n"); |
fprintf(stderr, " -s ca_key Certify keys with CA key.\n"); |
|
fprintf(stderr, " -S start Start point (hex) for generating DH-GEX moduli.\n"); |
fprintf(stderr, " -S start Start point (hex) for generating DH-GEX moduli.\n"); |
|
fprintf(stderr, " -s ca_key Certify keys with CA key.\n"); |
fprintf(stderr, " -T file Screen candidates for DH-GEX moduli.\n"); |
fprintf(stderr, " -T file Screen candidates for DH-GEX moduli.\n"); |
fprintf(stderr, " -t type Specify type of key to create.\n"); |
fprintf(stderr, " -t type Specify type of key to create.\n"); |
fprintf(stderr, " -V from:to Specify certificate validity interval.\n"); |
fprintf(stderr, " -V from:to Specify certificate validity interval.\n"); |
|
|
struct passwd *pw; |
struct passwd *pw; |
struct stat st; |
struct stat st; |
int opt, type, fd; |
int opt, type, fd; |
|
u_int maxbits; |
u_int32_t memory = 0, generator_wanted = 0, trials = 100; |
u_int32_t memory = 0, generator_wanted = 0, trials = 100; |
int do_gen_candidates = 0, do_screen_candidates = 0; |
int do_gen_candidates = 0, do_screen_candidates = 0; |
BIGNUM *start = NULL; |
BIGNUM *start = NULL; |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
while ((opt = getopt(argc, argv, "degiqpclBHLhvxXyF:b:f:t:D:I:P:N:n:" |
while ((opt = getopt(argc, argv, "degiqpclBHLhvxXyF:b:f:t:D:I:P:m:N:n:" |
"O:C:r:g:R:T:G:M:S:s:a:V:W:z:")) != -1) { |
"O:C:r:g:R:T:G:M:S:s:a:V:W:z:")) != -1) { |
switch (opt) { |
switch (opt) { |
case 'b': |
case 'b': |
|
|
case 'B': |
case 'B': |
print_bubblebabble = 1; |
print_bubblebabble = 1; |
break; |
break; |
|
case 'm': |
|
if (strcasecmp(optarg, "RFC4716") == 0 || |
|
strcasecmp(optarg, "ssh2") == 0) { |
|
convert_format = FMT_RFC4716; |
|
break; |
|
} |
|
if (strcasecmp(optarg, "PKCS8") == 0) { |
|
convert_format = FMT_PKCS8; |
|
break; |
|
} |
|
if (strcasecmp(optarg, "PEM") == 0) { |
|
convert_format = FMT_PEM; |
|
break; |
|
} |
|
fatal("Unsupported conversion format \"%s\"", optarg); |
case 'n': |
case 'n': |
cert_principals = optarg; |
cert_principals = optarg; |
break; |
break; |
|
|
case 'e': |
case 'e': |
case 'x': |
case 'x': |
/* export key */ |
/* export key */ |
convert_to_ssh2 = 1; |
convert_to = 1; |
break; |
break; |
case 'h': |
case 'h': |
cert_key_type = SSH2_CERT_TYPE_HOST; |
cert_key_type = SSH2_CERT_TYPE_HOST; |
critical_flags = 0; |
certflags_flags = 0; |
break; |
break; |
case 'i': |
case 'i': |
case 'X': |
case 'X': |
/* import key */ |
/* import key */ |
convert_from_ssh2 = 1; |
convert_from = 1; |
break; |
break; |
case 'y': |
case 'y': |
print_public = 1; |
print_public = 1; |
|
|
do_change_passphrase(pw); |
do_change_passphrase(pw); |
if (change_comment) |
if (change_comment) |
do_change_comment(pw); |
do_change_comment(pw); |
if (convert_to_ssh2) |
if (convert_to) |
do_convert_to_ssh2(pw); |
do_convert_to(pw); |
if (convert_from_ssh2) |
if (convert_from) |
do_convert_from_ssh2(pw); |
do_convert_from(pw); |
if (print_public) |
if (print_public) |
do_print_public(pw); |
do_print_public(pw); |
if (rr_hostname != NULL) { |
if (rr_hostname != NULL) { |
|
|
} |
} |
if (bits == 0) |
if (bits == 0) |
bits = (type == KEY_DSA) ? DEFAULT_BITS_DSA : DEFAULT_BITS; |
bits = (type == KEY_DSA) ? DEFAULT_BITS_DSA : DEFAULT_BITS; |
|
maxbits = (type == KEY_DSA) ? |
|
OPENSSL_DSA_MAX_MODULUS_BITS : OPENSSL_RSA_MAX_MODULUS_BITS; |
|
if (bits > maxbits) { |
|
fprintf(stderr, "key bits exceeds maximum %d\n", maxbits); |
|
exit(1); |
|
} |
if (type == KEY_DSA && bits != 1024) |
if (type == KEY_DSA && bits != 1024) |
fatal("DSA keys must be 1024 bits"); |
fatal("DSA keys must be 1024 bits"); |
if (!quiet) |
if (!quiet) |