]>
Commit | Line | Data |
---|---|---|
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"); | |
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"); | |
45 | return 1; | |
46 | } | |
47 | ||
48 | method_str = argv[1]; | |
49 | filename = argv[2]; | |
50 | ||
51 | if (!strcmp(method_str, CERTFP_NAME_CERT_SHA1)) { | |
52 | method = RB_SSL_CERTFP_METH_CERT_SHA1; | |
53 | prefix = CERTFP_PREFIX_CERT_SHA1; | |
54 | } else if (!strcmp(method_str, CERTFP_NAME_CERT_SHA256)) { | |
55 | method = RB_SSL_CERTFP_METH_CERT_SHA256; | |
56 | prefix = CERTFP_PREFIX_CERT_SHA256; | |
57 | } else if (!strcmp(method_str, CERTFP_NAME_CERT_SHA512)) { | |
58 | method = RB_SSL_CERTFP_METH_CERT_SHA512; | |
59 | prefix = CERTFP_PREFIX_CERT_SHA512; | |
60 | } else if (!strcmp(method_str, CERTFP_NAME_SPKI_SHA256)) { | |
61 | method = RB_SSL_CERTFP_METH_SPKI_SHA256; | |
62 | prefix = CERTFP_PREFIX_SPKI_SHA256; | |
63 | } else if (!strcmp(method_str, CERTFP_NAME_SPKI_SHA512)) { | |
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); | |
81 | for (i = 0; i < ret; i++) { | |
82 | printf("%02x", certfp[i]); | |
83 | } | |
84 | printf("\n"); | |
85 | return 0; | |
86 | } |