]>
Commit | Line | Data |
---|---|---|
aeb9cc10 DB |
1 | /* |
2 | This program signs the given file using the named certificate and private | |
3 | key in the given certificate database and places the signature in the named | |
4 | output file. | |
5 | ||
6 | Copyright (C) 2009-2011 Red Hat Inc. | |
7 | ||
8 | This file is part of systemtap, and is free software. You can | |
9 | redistribute it and/or modify it under the terms of the GNU General Public | |
10 | License as published by the Free Software Foundation; either version 2 of the | |
11 | License, or (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
e8daaf60 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
aeb9cc10 DB |
20 | */ |
21 | ||
22 | #include "config.h" | |
23 | ||
24 | extern "C" { | |
25 | #include <nspr.h> | |
26 | #include <nss.h> | |
27 | } | |
28 | #include <string> | |
29 | ||
30 | #include "util.h" | |
31 | #include "nsscommon.h" | |
32 | ||
33 | using namespace std; | |
34 | ||
35 | // Called by methods within nsscommon.cxx. | |
36 | extern "C" | |
37 | void | |
38 | nsscommon_error (const char *msg, int logit __attribute ((unused))) | |
39 | { | |
40 | clog << msg << endl << flush; | |
41 | } | |
42 | ||
43 | int | |
44 | main (int argc, char **argv) | |
45 | { | |
46 | setlocale (LC_ALL, ""); | |
47 | bindtextdomain (PACKAGE, LOCALEDIR); | |
48 | textdomain (PACKAGE); | |
49 | ||
50 | if (argc < 2) { | |
51 | nsscommon_error (_("Module name was not specified.")); | |
52 | return 1; | |
53 | } | |
54 | string module_name = argv[1]; | |
55 | ||
56 | string cert_db_path; | |
57 | if (argc >= 3) | |
58 | cert_db_path = argv[2]; | |
59 | else | |
60 | cert_db_path = server_cert_db_path (); | |
61 | ||
62 | const char *nickName = server_cert_nickname (); | |
63 | if (check_cert (cert_db_path, nickName) != 0) | |
64 | return 1; | |
65 | ||
66 | /* Call the NSPR initialization routines. */ | |
67 | PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1); | |
68 | ||
69 | /* Set the cert database password callback. */ | |
70 | PK11_SetPasswordFunc (nssPasswordCallback); | |
71 | ||
72 | /* Initialize NSS. */ | |
73 | SECStatus secStatus = nssInit (cert_db_path.c_str()); | |
74 | if (secStatus != SECSuccess) | |
75 | { | |
76 | // Message already issued. | |
77 | return 1; | |
78 | } | |
79 | ||
80 | sign_file (cert_db_path, nickName, module_name, module_name + ".sgn"); | |
81 | ||
82 | /* Shutdown NSS and exit NSPR gracefully. */ | |
83 | nssCleanup (cert_db_path.c_str ()); | |
84 | PR_Cleanup (); | |
85 | ||
86 | return 0; | |
87 | } | |
88 | ||
89 | /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ |