2 * mkfingerprint.c: Create certificate fingerprints using librb
3 * Copyright 2016 simon Arlott
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.
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.
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
27 int main(int argc
, char *argv
[])
29 uint8_t certfp
[RB_SSL_CERTFP_LEN
+1] = { 0 };
30 const char *method_str
;
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");
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
;
67 printf("Unknown method: %s\n", method_str
);
71 ret
= rb_get_ssl_certfp_file(filename
, certfp
, method
);
75 } else if (ret
== 0) {
76 fprintf(stderr
, "Unknown error\n");
81 for (i
= 0; i
< ret
; i
++) {
82 printf("%02x", certfp
[i
]);