build checksums for charon plugins
[strongswan.git] / src / libstrongswan / fips / fips_signer.c
1 /*
2 * Copyright (C) 2007 Bruno Krieg, Daniel Wydler
3 * Hochschule fuer Technik Rapperswil, Switzerland
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <stdio.h>
17
18 #include <crypto/hashers/hasher.h>
19 #include "fips.h"
20
21 int main(int argc, char* argv[])
22 {
23 FILE *f;
24 char *hmac_key = "strongSwan Version " VERSION;
25 char hmac_signature[BUF_LEN];
26
27 /* initialize library */
28 library_init(STRONGSWAN_CONF);
29 #ifdef USE_SHA1
30 lib->plugins->load(lib->plugins, PLUGINDIR "/sha1/.libs", "sha1");
31 #endif
32 #ifdef USE_OPENSSL
33 lib->plugins->load(lib->plugins, PLUGINDIR "/openssl/.libs", "openssl");
34 #endif
35 lib->plugins->load(lib->plugins, PLUGINDIR "/hmac/.libs", "hmac");
36
37 if (!fips_compute_hmac_signature(hmac_key, hmac_signature))
38 {
39 exit(1);
40 }
41
42 /**
43 * write computed HMAC signature to fips_signature.h
44 */
45 f = fopen("fips_signature.h", "wt");
46
47 if (f == NULL)
48 {
49 exit(1);
50 }
51 fprintf(f, "/* SHA-1 HMAC signature computed over TEXT and RODATA of libstrongswan\n");
52 fprintf(f, " *\n");
53 fprintf(f, " * This file has been automatically generated by fips_signer\n");
54 fprintf(f, " * Do not edit manually!\n");
55 fprintf(f, " */\n");
56 fprintf(f, "\n");
57 fprintf(f, "#ifndef FIPS_SIGNATURE_H_\n");
58 fprintf(f, "#define FIPS_SIGNATURE_H_\n");
59 fprintf(f, "\n");
60 fprintf(f, "const char *hmac_key = \"%s\";\n", hmac_key);
61 fprintf(f, "const char *hmac_signature = \"%s\";\n", hmac_signature);
62 fprintf(f, "\n");
63 fprintf(f, "#endif /* FIPS_SIGNATURE_H_ @} */\n");
64 fclose(f);
65
66 library_deinit();
67 exit(0);
68 }