12 #include <openssl/bn.h>
13 #include <openssl/rsa.h>
15 int main(int c
, char **v
)
25 fprintf(stderr
, "Hi. I'm tor-checkkey. Tell me a filename that "
26 "has a PEM-encoded RSA public key (like in a cert) and I'll "
27 "dump the modulus. Use the --digest option too and I'll "
28 "dump the digest.\n");
32 if (crypto_global_init(0)) {
33 fprintf(stderr
, "Couldn't initialize crypto library.\n");
37 if (!strcmp(v
[1], "--digest")) {
41 fprintf(stderr
, "too few arguments");
49 str
= read_file_to_str(v
[fname_idx
], 0, NULL
);
51 fprintf(stderr
, "Couldn't read %s\n", v
[fname_idx
]);
55 env
= crypto_new_pk_env();
56 if (crypto_pk_read_public_key_from_string(env
, str
, strlen(str
))<0) {
57 fprintf(stderr
, "Couldn't parse key.\n");
63 char digest
[HEX_DIGEST_LEN
+1];
64 if (crypto_pk_get_fingerprint(env
, digest
, 0)<0)
66 printf("%s\n",digest
);
68 rsa
= _crypto_pk_env_get_rsa(env
);
69 str
= BN_bn2hex(rsa
->n
);