version 1.199, 2010/08/16 04:06:06 |
version 1.200, 2010/08/31 11:54:45 |
|
|
/* Number of bits in the RSA/DSA key. This value can be set on the command line. */ |
/* Number of bits in the RSA/DSA key. This value can be set on the command line. */ |
#define DEFAULT_BITS 2048 |
#define DEFAULT_BITS 2048 |
#define DEFAULT_BITS_DSA 1024 |
#define DEFAULT_BITS_DSA 1024 |
|
#define DEFAULT_BITS_ECDSA 521 |
u_int32_t bits = 0; |
u_int32_t bits = 0; |
|
|
/* |
/* |
|
|
case KEY_DSA: |
case KEY_DSA: |
name = _PATH_SSH_CLIENT_ID_DSA; |
name = _PATH_SSH_CLIENT_ID_DSA; |
break; |
break; |
|
case KEY_ECDSA_CERT: |
|
case KEY_ECDSA: |
|
name = _PATH_SSH_CLIENT_ID_ECDSA; |
|
break; |
case KEY_RSA_CERT: |
case KEY_RSA_CERT: |
case KEY_RSA_CERT_V00: |
case KEY_RSA_CERT_V00: |
case KEY_RSA: |
case KEY_RSA: |
|
|
if (!PEM_write_DSA_PUBKEY(stdout, k->dsa)) |
if (!PEM_write_DSA_PUBKEY(stdout, k->dsa)) |
fatal("PEM_write_DSA_PUBKEY failed"); |
fatal("PEM_write_DSA_PUBKEY failed"); |
break; |
break; |
|
case KEY_ECDSA: |
|
if (!PEM_write_EC_PUBKEY(stdout, k->ecdsa)) |
|
fatal("PEM_write_EC_PUBKEY failed"); |
|
break; |
default: |
default: |
fatal("%s: unsupported key type %s", __func__, key_type(k)); |
fatal("%s: unsupported key type %s", __func__, key_type(k)); |
} |
} |
|
|
fatal("PEM_write_DSAPublicKey failed"); |
fatal("PEM_write_DSAPublicKey failed"); |
break; |
break; |
#endif |
#endif |
|
/* XXX ECDSA? */ |
default: |
default: |
fatal("%s: unsupported key type %s", __func__, key_type(k)); |
fatal("%s: unsupported key type %s", __func__, key_type(k)); |
} |
} |
|
|
(*k)->type = KEY_DSA; |
(*k)->type = KEY_DSA; |
(*k)->dsa = EVP_PKEY_get1_DSA(pubkey); |
(*k)->dsa = EVP_PKEY_get1_DSA(pubkey); |
break; |
break; |
|
case EVP_PKEY_EC: |
|
*k = key_new(KEY_UNSPEC); |
|
(*k)->type = KEY_ECDSA; |
|
(*k)->ecdsa = EVP_PKEY_get1_EC_KEY(pubkey); |
|
(*k)->ecdsa_nid = key_ecdsa_group_to_nid( |
|
EC_KEY_get0_group((*k)->ecdsa)); |
|
break; |
default: |
default: |
fatal("%s: unsupported pubkey type %d", __func__, |
fatal("%s: unsupported pubkey type %d", __func__, |
EVP_PKEY_type(pubkey->type)); |
EVP_PKEY_type(pubkey->type)); |
|
|
fclose(fp); |
fclose(fp); |
return; |
return; |
} |
} |
|
/* XXX ECDSA */ |
#endif |
#endif |
fatal("%s: unrecognised raw private key format", __func__); |
fatal("%s: unrecognised raw private key format", __func__); |
} |
} |
|
|
ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL, |
ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL, |
NULL, 0, NULL, NULL); |
NULL, 0, NULL, NULL); |
break; |
break; |
|
case KEY_ECDSA: |
|
ok = PEM_write_ECPrivateKey(stdout, k->ecdsa, NULL, |
|
NULL, 0, NULL, NULL); |
|
break; |
case KEY_RSA: |
case KEY_RSA: |
ok = PEM_write_RSAPrivateKey(stdout, k->rsa, NULL, |
ok = PEM_write_RSAPrivateKey(stdout, k->rsa, NULL, |
NULL, 0, NULL, NULL); |
NULL, 0, NULL, NULL); |
|
|
tmp = tilde_expand_filename(argv[i], pw->pw_uid); |
tmp = tilde_expand_filename(argv[i], pw->pw_uid); |
if ((public = key_load_public(tmp, &comment)) == NULL) |
if ((public = key_load_public(tmp, &comment)) == NULL) |
fatal("%s: unable to open \"%s\"", __func__, tmp); |
fatal("%s: unable to open \"%s\"", __func__, tmp); |
if (public->type != KEY_RSA && public->type != KEY_DSA) |
if (public->type != KEY_RSA && public->type != KEY_DSA && |
|
public->type != KEY_ECDSA) |
fatal("%s: key \"%s\" type %s cannot be certified", |
fatal("%s: key \"%s\" type %s cannot be certified", |
__func__, tmp, key_type(public)); |
__func__, tmp, key_type(public)); |
|
|
|
|
fprintf(stderr, "unknown key type %s\n", key_type_name); |
fprintf(stderr, "unknown key type %s\n", key_type_name); |
exit(1); |
exit(1); |
} |
} |
if (bits == 0) |
if (bits == 0) { |
bits = (type == KEY_DSA) ? DEFAULT_BITS_DSA : DEFAULT_BITS; |
if (type == KEY_DSA) |
|
bits = DEFAULT_BITS_DSA; |
|
else if (type == KEY_ECDSA) |
|
bits = DEFAULT_BITS_ECDSA; |
|
else |
|
bits = DEFAULT_BITS; |
|
} |
maxbits = (type == KEY_DSA) ? |
maxbits = (type == KEY_DSA) ? |
OPENSSL_DSA_MAX_MODULUS_BITS : OPENSSL_RSA_MAX_MODULUS_BITS; |
OPENSSL_DSA_MAX_MODULUS_BITS : OPENSSL_RSA_MAX_MODULUS_BITS; |
if (bits > maxbits) { |
if (bits > maxbits) { |
|
|
} |
} |
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"); |
|
else if (type == KEY_ECDSA && key_ecdsa_bits_to_nid(bits) == -1) |
|
fatal("Invalid ECDSA key length - valid lengths are " |
|
"256, 384 or 521 bits"); |
if (!quiet) |
if (!quiet) |
printf("Generating public/private %s key pair.\n", key_type_name); |
printf("Generating public/private %s key pair.\n", key_type_name); |
private = key_generate(type, bits); |
private = key_generate(type, bits); |