10 #include "../common/util.h"
12 #include <openssl/bn.h>
13 #include <openssl/rsa.h>
27 fprintf(stderr
, "Hi. I'm tor-checkkey. Tell me a filename that "
28 "has a PEM-encoded RSA public key (like in a cert) and I'll "
29 "dump the modulus. Use the --digest option too and I'll "
30 "dump the digest.\n");
34 if (crypto_global_init(0, NULL
, NULL
)) {
35 fprintf(stderr
, "Couldn't initialize crypto library.\n");
39 if (!strcmp(v
[1], "--digest")) {
43 fprintf(stderr
, "too few arguments");
51 fname
= expand_filename(v
[fname_idx
]);
52 str
= read_file_to_str(fname
, 0, NULL
);
55 fprintf(stderr
, "Couldn't read %s\n", v
[fname_idx
]);
59 env
= crypto_new_pk_env();
60 if (crypto_pk_read_public_key_from_string(env
, str
, strlen(str
))<0) {
61 fprintf(stderr
, "Couldn't parse key.\n");
67 char digest
[HEX_DIGEST_LEN
+1];
68 if (crypto_pk_get_fingerprint(env
, digest
, 0)<0)
70 printf("%s\n",digest
);
72 rsa
= _crypto_pk_env_get_rsa(env
);
73 str
= BN_bn2hex(rsa
->n
);