|
Lines 691-705
read_bignum(char **cpp, BIGNUM * value)
Link Here
|
| 691 |
} |
691 |
} |
| 692 |
|
692 |
|
| 693 |
static int |
693 |
static int |
| 694 |
write_bignum(FILE *f, BIGNUM *num) |
694 |
write_bignum(char **s, BIGNUM *num) |
| 695 |
{ |
695 |
{ |
| 696 |
char *buf = BN_bn2dec(num); |
696 |
*s = BN_bn2dec(num); |
| 697 |
if (buf == NULL) { |
697 |
if (*s == NULL) { |
| 698 |
error("write_bignum: BN_bn2dec() failed"); |
698 |
error("write_bignum: BN_bn2dec() failed"); |
| 699 |
return 0; |
699 |
return 0; |
| 700 |
} |
700 |
} |
| 701 |
fprintf(f, " %s", buf); |
|
|
| 702 |
OPENSSL_free(buf); |
| 703 |
return 1; |
701 |
return 1; |
| 704 |
} |
702 |
} |
| 705 |
#endif |
703 |
#endif |
|
Lines 889-899
key_read(Key *ret, char **cpp)
Link Here
|
| 889 |
} |
887 |
} |
| 890 |
|
888 |
|
| 891 |
int |
889 |
int |
| 892 |
key_write(const Key *key, FILE *f) |
890 |
key_write_str(const Key *key, char **s) |
| 893 |
{ |
891 |
{ |
| 894 |
int n, success = 0; |
892 |
int n, success = 0; |
| 895 |
#ifdef WITH_SSH1 |
893 |
#ifdef WITH_SSH1 |
| 896 |
u_int bits = 0; |
894 |
u_int bits = 0; |
|
|
895 |
char *se = NULL, *sn = NULL; |
| 897 |
#endif |
896 |
#endif |
| 898 |
u_int len; |
897 |
u_int len; |
| 899 |
u_char *blob; |
898 |
u_char *blob; |
|
Lines 917-928
key_write(const Key *key, FILE *f)
Link Here
|
| 917 |
return 0; |
916 |
return 0; |
| 918 |
/* size of modulus 'n' */ |
917 |
/* size of modulus 'n' */ |
| 919 |
bits = BN_num_bits(key->rsa->n); |
918 |
bits = BN_num_bits(key->rsa->n); |
| 920 |
fprintf(f, "%u", bits); |
919 |
if (!write_bignum(&se, key->rsa->e) || |
| 921 |
if (write_bignum(f, key->rsa->e) && |
920 |
!write_bignum(&sn, key->rsa->n)) { |
| 922 |
write_bignum(f, key->rsa->n)) |
921 |
error("key_write_str: failed for RSA key"); |
| 923 |
return 1; |
922 |
goto done; |
| 924 |
error("key_write: failed for RSA key"); |
923 |
} |
| 925 |
return 0; |
924 |
xasprintf(s, "%u %s %s", bits, se, sn); |
|
|
925 |
success = 1; |
| 926 |
done: |
| 927 |
if (se != NULL) |
| 928 |
OPENSSL_free(se); |
| 929 |
if (sn != NULL) |
| 930 |
OPENSSL_free(sn); |
| 931 |
return success; |
| 926 |
#endif |
932 |
#endif |
| 927 |
#ifdef WITH_OPENSSL |
933 |
#ifdef WITH_OPENSSL |
| 928 |
case KEY_DSA: |
934 |
case KEY_DSA: |
|
Lines 958-964
key_write(const Key *key, FILE *f)
Link Here
|
| 958 |
uu = xmalloc(2*len); |
964 |
uu = xmalloc(2*len); |
| 959 |
n = uuencode(blob, len, uu, 2*len); |
965 |
n = uuencode(blob, len, uu, 2*len); |
| 960 |
if (n > 0) { |
966 |
if (n > 0) { |
| 961 |
fprintf(f, "%s %s", key_ssh_name(key), uu); |
967 |
xasprintf(s, "%s %s", key_ssh_name(key), uu); |
| 962 |
success = 1; |
968 |
success = 1; |
| 963 |
} |
969 |
} |
| 964 |
free(blob); |
970 |
free(blob); |
|
Lines 967-972
key_write(const Key *key, FILE *f)
Link Here
|
| 967 |
return success; |
973 |
return success; |
| 968 |
} |
974 |
} |
| 969 |
|
975 |
|
|
|
976 |
int |
| 977 |
key_write(const Key *key, FILE *f) |
| 978 |
{ |
| 979 |
char *s; |
| 980 |
|
| 981 |
if (!key_write_str(key, &s)) |
| 982 |
return 0; |
| 983 |
fputs(s, f); |
| 984 |
free(s); |
| 985 |
|
| 986 |
return 1; |
| 987 |
} |
| 988 |
|
| 970 |
const char * |
989 |
const char * |
| 971 |
key_cert_type(const Key *k) |
990 |
key_cert_type(const Key *k) |
| 972 |
{ |
991 |
{ |