Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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/. */
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>
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 */
18 static char* PR_fgets(char *buf, int size, PRFileDesc *file);
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 }
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;
54 CERTCertificate *cert, *prev=NULL;
56 PR_fprintf(out, "\nThis installation JAR file was signed by:\n");
58 ctx = JAR_find(jar, NULL, jarTypeSign);
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 }
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");
83 prev=cert;
84 }
86 JAR_find_end(ctx);
88 if(count==0) {
89 PR_fprintf(out, "No signatures found: JAR FILE IS UNSIGNED.\n");
90 }
92 if(query) {
93 PR_fprintf(out,
94 "Do you wish to continue this installation? (y/n) ");
96 if(PR_fgets(stdinbuf, 80, PR_STDIN) != NULL) {
97 char *response;
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 }
108 return 1;
109 }
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;
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';
139 return buf;
140 }
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 }