|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #include <plarena.h> |
|
6 #include <prerror.h> |
|
7 #include <prio.h> |
|
8 #include <prprf.h> |
|
9 #include <seccomon.h> |
|
10 #include <secmod.h> |
|
11 #include <jar.h> |
|
12 #include <secutil.h> |
|
13 |
|
14 /* These are installation functions that make calls to the security library. |
|
15 * We don't want to include security include files in the C++ code too much. |
|
16 */ |
|
17 |
|
18 static char* PR_fgets(char *buf, int size, PRFileDesc *file); |
|
19 |
|
20 /*************************************************************************** |
|
21 * |
|
22 * P k 1 1 I n s t a l l _ A d d N e w M o d u l e |
|
23 */ |
|
24 int |
|
25 Pk11Install_AddNewModule(char* moduleName, char* dllPath, |
|
26 unsigned long defaultMechanismFlags, |
|
27 unsigned long cipherEnableFlags) |
|
28 { |
|
29 return (SECMOD_AddNewModule(moduleName, dllPath, |
|
30 SECMOD_PubMechFlagstoInternal(defaultMechanismFlags), |
|
31 SECMOD_PubCipherFlagstoInternal(cipherEnableFlags)) |
|
32 == SECSuccess) ? 0 : -1; |
|
33 } |
|
34 |
|
35 /************************************************************************* |
|
36 * |
|
37 * P k 1 1 I n s t a l l _ U s e r V e r i f y J a r |
|
38 * |
|
39 * Gives the user feedback on the signatures of a JAR files, asks them |
|
40 * whether they actually want to continue. |
|
41 * Assumes the jar structure has already been created and is valid. |
|
42 * Returns 0 if the user wants to continue the installation, nonzero |
|
43 * if the user wishes to abort. |
|
44 */ |
|
45 short |
|
46 Pk11Install_UserVerifyJar(JAR *jar, PRFileDesc *out, PRBool query) |
|
47 { |
|
48 JAR_Context *ctx; |
|
49 JAR_Cert *fing; |
|
50 JAR_Item *item; |
|
51 char stdinbuf[80]; |
|
52 int count=0; |
|
53 |
|
54 CERTCertificate *cert, *prev=NULL; |
|
55 |
|
56 PR_fprintf(out, "\nThis installation JAR file was signed by:\n"); |
|
57 |
|
58 ctx = JAR_find(jar, NULL, jarTypeSign); |
|
59 |
|
60 while(JAR_find_next(ctx, &item) >= 0 ) { |
|
61 fing = (JAR_Cert*) item->data; |
|
62 cert = fing->cert; |
|
63 if(cert==prev) { |
|
64 continue; |
|
65 } |
|
66 |
|
67 count++; |
|
68 PR_fprintf(out, "----------------------------------------------\n"); |
|
69 if(cert) { |
|
70 if(cert->nickname) { |
|
71 PR_fprintf(out, "**NICKNAME**\n%s\n", cert->nickname); |
|
72 } |
|
73 if(cert->subjectName) { |
|
74 PR_fprintf(out, "**SUBJECT NAME**\n%s\n", cert->subjectName); } |
|
75 if(cert->issuerName) { |
|
76 PR_fprintf(out, "**ISSUER NAME**\n%s\n", cert->issuerName); |
|
77 } |
|
78 } else { |
|
79 PR_fprintf(out, "No matching certificate could be found.\n"); |
|
80 } |
|
81 PR_fprintf(out, "----------------------------------------------\n\n"); |
|
82 |
|
83 prev=cert; |
|
84 } |
|
85 |
|
86 JAR_find_end(ctx); |
|
87 |
|
88 if(count==0) { |
|
89 PR_fprintf(out, "No signatures found: JAR FILE IS UNSIGNED.\n"); |
|
90 } |
|
91 |
|
92 if(query) { |
|
93 PR_fprintf(out, |
|
94 "Do you wish to continue this installation? (y/n) "); |
|
95 |
|
96 if(PR_fgets(stdinbuf, 80, PR_STDIN) != NULL) { |
|
97 char *response; |
|
98 |
|
99 if( (response=strtok(stdinbuf, " \t\n\r")) ) { |
|
100 if( !PL_strcasecmp(response, "y") || |
|
101 !PL_strcasecmp(response, "yes") ) { |
|
102 return 0; |
|
103 } |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 return 1; |
|
109 } |
|
110 |
|
111 /************************************************************************** |
|
112 * |
|
113 * P R _ f g e t s |
|
114 * |
|
115 * fgets implemented with NSPR. |
|
116 */ |
|
117 static char* |
|
118 PR_fgets(char *buf, int size, PRFileDesc *file) |
|
119 { |
|
120 int i; |
|
121 int status; |
|
122 char c; |
|
123 |
|
124 i=0; |
|
125 while(i < size-1) { |
|
126 status = PR_Read(file, (void*) &c, 1); |
|
127 if(status==-1) { |
|
128 return NULL; |
|
129 } else if(status==0) { |
|
130 break; |
|
131 } |
|
132 buf[i++] = c; |
|
133 if(c=='\n') { |
|
134 break; |
|
135 } |
|
136 } |
|
137 buf[i]='\0'; |
|
138 |
|
139 return buf; |
|
140 } |
|
141 |
|
142 /************************************************************************** |
|
143 * |
|
144 * m y S E C U _ E r r o r S t r i n g |
|
145 * |
|
146 */ |
|
147 const char* mySECU_ErrorString(PRErrorCode errnum) |
|
148 { |
|
149 return SECU_Strerror(errnum); |
|
150 } |