]>
Commit | Line | Data |
---|---|---|
03469187 SA |
1 | /* |
2 | * mkfingerprint.c: Create certificate fingerprints using librb | |
3 | * Copyright 2016 simon Arlott | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
18 | * USA | |
19 | */ | |
20 | #include <stdio.h> | |
21 | #include <string.h> | |
22 | #include <stdlib.h> | |
23 | #include <unistd.h> | |
24 | #include "rb_lib.h" | |
25 | #include "certfp.h" | |
26 | ||
27 | int main(int argc, char *argv[]) | |
28 | { | |
29 | uint8_t certfp[RB_SSL_CERTFP_LEN+1] = { 0 }; | |
30 | const char *method_str; | |
31 | const char *filename; | |
32 | int method; | |
33 | const char *prefix; | |
34 | int ret; | |
35 | int i; | |
36 | ||
37 | if (argc != 3) { | |
38 | printf("mkfingerprint <method> <filename>\n"); | |
f590c59d SA |
39 | printf(" Valid methods: " |
40 | CERTFP_NAME_CERT_SHA1 ", " | |
41 | CERTFP_NAME_CERT_SHA256 ", " | |
42 | CERTFP_NAME_CERT_SHA512 ", " | |
43 | CERTFP_NAME_SPKI_SHA256 ", " | |
44 | CERTFP_NAME_SPKI_SHA512 "\n"); | |
03469187 SA |
45 | return 1; |
46 | } | |
47 | ||
48 | method_str = argv[1]; | |
49 | filename = argv[2]; | |
50 | ||
f590c59d | 51 | if (!strcmp(method_str, CERTFP_NAME_CERT_SHA1)) { |
03469187 SA |
52 | method = RB_SSL_CERTFP_METH_CERT_SHA1; |
53 | prefix = CERTFP_PREFIX_CERT_SHA1; | |
f590c59d | 54 | } else if (!strcmp(method_str, CERTFP_NAME_CERT_SHA256)) { |
03469187 SA |
55 | method = RB_SSL_CERTFP_METH_CERT_SHA256; |
56 | prefix = CERTFP_PREFIX_CERT_SHA256; | |
f590c59d | 57 | } else if (!strcmp(method_str, CERTFP_NAME_CERT_SHA512)) { |
03469187 SA |
58 | method = RB_SSL_CERTFP_METH_CERT_SHA512; |
59 | prefix = CERTFP_PREFIX_CERT_SHA512; | |
f590c59d | 60 | } else if (!strcmp(method_str, CERTFP_NAME_SPKI_SHA256)) { |
03469187 SA |
61 | method = RB_SSL_CERTFP_METH_SPKI_SHA256; |
62 | prefix = CERTFP_PREFIX_SPKI_SHA256; | |
f590c59d | 63 | } else if (!strcmp(method_str, CERTFP_NAME_SPKI_SHA512)) { |
03469187 SA |
64 | method = RB_SSL_CERTFP_METH_SPKI_SHA512; |
65 | prefix = CERTFP_PREFIX_SPKI_SHA512; | |
66 | } else { | |
67 | printf("Unknown method: %s\n", method_str); | |
68 | return 1; | |
69 | } | |
70 | ||
71 | ret = rb_get_ssl_certfp_file(filename, certfp, method); | |
72 | if (ret < 0) { | |
73 | perror(filename); | |
74 | return 1; | |
75 | } else if (ret == 0) { | |
76 | fprintf(stderr, "Unknown error\n"); | |
77 | return 1; | |
78 | } | |
79 | ||
80 | printf("%s", prefix); | |
707bc7cd | 81 | for (i = 0; i < ret; i++) { |
03469187 SA |
82 | printf("%02x", certfp[i]); |
83 | } | |
84 | printf("\n"); | |
85 | return 0; | |
86 | } |