blob: e0be6d728738b4e6f2b8ae58139267a5235b12ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#define CRYPTO_PRIVATE
#include <stdio.h>
#include <stdlib.h>
#include "crypto.h"
#include "log.h"
#include "util.h"
#include "compat.h"
#include <openssl/bn.h>
#include <openssl/rsa.h>
int main(int c, char **v)
{
crypto_pk_env_t *env;
char *str;
RSA *rsa;
init_logging();
if (c < 2) {
fprintf(stderr, "Hi. I'm tor-checkkey. Tell me a filename that has a PEM-encoded RSA public key (like in a cert) and I'll dump the modulus.\n");
return 1;
}
if (crypto_global_init(0)) {
fprintf(stderr, "Couldn't initialize crypto library.\n");
return 1;
}
str = read_file_to_str(v[1], 0, NULL);
if (!str) {
fprintf(stderr, "Couldn't read %s\n", v[1]);
return 1;
}
env = crypto_new_pk_env();
if (crypto_pk_read_public_key_from_string(env, str, strlen(str))<0) {
fprintf(stderr, "Couldn't parse key.\n");
return 1;
}
tor_free(str);
rsa = _crypto_pk_env_get_rsa(env);
str = BN_bn2hex(rsa->n);
printf("%s\n", str);
return 0;
}
|