comparison nss/lib/certhigh/certvfypkixprint.c @ 0:1e5118fa0cb1

This is NSS with a Cmake Buildsyste To compile a static NSS library for Windows we've used the Chromium-NSS fork and added a Cmake buildsystem to compile it statically for Windows. See README.chromium for chromium changes and README.trustbridge for our modifications.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 28 Jul 2014 10:47:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e5118fa0cb1
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 * nss_pkix_proxy.h
6 *
7 * PKIX - NSS proxy functions
8 *
9 */
10 #include "cert.h"
11 #include "pkix_pl_common.h"
12
13 #ifdef DEBUG
14
15 char *
16 pkix_Error2ASCII(PKIX_Error *error, void *plContext)
17 {
18 PKIX_UInt32 length;
19 char *asciiString = NULL;
20 PKIX_PL_String *pkixString = NULL;
21 PKIX_Error *errorResult = NULL;
22
23 errorResult = PKIX_PL_Object_ToString
24 ((PKIX_PL_Object*)error, &pkixString, plContext);
25 if (errorResult) goto cleanup;
26
27 errorResult = PKIX_PL_String_GetEncoded
28 (pkixString,
29 PKIX_ESCASCII,
30 (void **)&asciiString,
31 &length,
32 plContext);
33
34 cleanup:
35
36 if (pkixString){
37 if (PKIX_PL_Object_DecRef
38 ((PKIX_PL_Object*)pkixString, plContext)){
39 return (NULL);
40 }
41 }
42
43 if (errorResult){
44 PKIX_PL_Object_DecRef((PKIX_PL_Object*)errorResult, plContext);
45 return (NULL);
46 }
47
48 return (asciiString);
49 }
50
51 char *
52 pkix_Object2ASCII(PKIX_PL_Object *object)
53 {
54 PKIX_UInt32 length;
55 char *asciiString = NULL;
56 PKIX_PL_String *pkixString = NULL;
57 PKIX_Error *errorResult = NULL;
58
59 errorResult = PKIX_PL_Object_ToString
60 (object, &pkixString, NULL);
61 if (errorResult) goto cleanup;
62
63 errorResult = PKIX_PL_String_GetEncoded
64 (pkixString, PKIX_ESCASCII, (void **)&asciiString, &length, NULL);
65
66 cleanup:
67
68 if (pkixString){
69 if (PKIX_PL_Object_DecRef((PKIX_PL_Object*)pkixString, NULL)){
70 return (NULL);
71 }
72 }
73
74 if (errorResult){
75 return (NULL);
76 }
77
78 return (asciiString);
79 }
80
81 char *
82 pkix_Cert2ASCII(PKIX_PL_Cert *cert)
83 {
84 PKIX_PL_X500Name *issuer = NULL;
85 void *issuerAscii = NULL;
86 PKIX_PL_X500Name *subject = NULL;
87 void *subjectAscii = NULL;
88 void *asciiString = NULL;
89 PKIX_Error *errorResult = NULL;
90 PKIX_UInt32 numChars;
91 PKIX_UInt32 refCount = 0;
92
93 /* Issuer */
94 errorResult = PKIX_PL_Cert_GetIssuer(cert, &issuer, NULL);
95 if (errorResult) goto cleanup;
96
97 issuerAscii = pkix_Object2ASCII((PKIX_PL_Object*)issuer);
98
99 /* Subject */
100 errorResult = PKIX_PL_Cert_GetSubject(cert, &subject, NULL);
101 if (errorResult) goto cleanup;
102
103 if (subject){
104 subjectAscii = pkix_Object2ASCII((PKIX_PL_Object*)subject);
105 }
106
107 /* errorResult = PKIX_PL_Object_GetRefCount((PKIX_PL_Object*)cert, &refCount, NULL); */
108 if (errorResult) goto cleanup;
109
110 errorResult = PKIX_PL_Malloc(200, &asciiString, NULL);
111 if (errorResult) goto cleanup;
112
113 numChars =
114 PR_snprintf
115 (asciiString,
116 200,
117 "Ref: %d Subject=%s\nIssuer=%s\n",
118 refCount,
119 subjectAscii,
120 issuerAscii);
121
122 if (!numChars) goto cleanup;
123
124 cleanup:
125
126 if (issuer){
127 if (PKIX_PL_Object_DecRef((PKIX_PL_Object*)issuer, NULL)){
128 return (NULL);
129 }
130 }
131
132 if (subject){
133 if (PKIX_PL_Object_DecRef((PKIX_PL_Object*)subject, NULL)){
134 return (NULL);
135 }
136 }
137
138 if (PKIX_PL_Free((PKIX_PL_Object*)issuerAscii, NULL)){
139 return (NULL);
140 }
141
142 if (PKIX_PL_Free((PKIX_PL_Object*)subjectAscii, NULL)){
143 return (NULL);
144 }
145
146 if (errorResult){
147 return (NULL);
148 }
149
150 return (asciiString);
151 }
152
153 PKIX_Error *
154 cert_PrintCertChain(
155 PKIX_List *pkixCertChain,
156 void *plContext)
157 {
158 PKIX_PL_Cert *cert = NULL;
159 PKIX_UInt32 numCerts = 0, i = 0;
160 char *asciiResult = NULL;
161
162 PKIX_ENTER(CERTVFYPKIX, "cert_PrintCertChain");
163
164 PKIX_CHECK(
165 PKIX_List_GetLength(pkixCertChain, &numCerts, plContext),
166 PKIX_LISTGETLENGTHFAILED);
167
168 fprintf(stderr, "\n");
169
170 for (i = 0; i < numCerts; i++){
171 PKIX_CHECK
172 (PKIX_List_GetItem
173 (pkixCertChain, i, (PKIX_PL_Object**)&cert, plContext),
174 PKIX_LISTGETITEMFAILED);
175
176 asciiResult = pkix_Cert2ASCII(cert);
177
178 fprintf(stderr, "CERT[%d]:\n%s\n", i, asciiResult);
179
180 PKIX_PL_Free(asciiResult, plContext);
181 asciiResult = NULL;
182
183 PKIX_DECREF(cert);
184 }
185
186 cleanup:
187 PKIX_DECREF(cert);
188
189 PKIX_RETURN(CERTVFYPKIX);
190 }
191
192 void
193 cert_PrintCert(
194 PKIX_PL_Cert *pkixCert,
195 void *plContext)
196 {
197 char *asciiResult = NULL;
198
199 asciiResult = pkix_Cert2ASCII(pkixCert);
200
201 fprintf(stderr, "CERT[0]:\n%s\n", asciiResult);
202
203 PKIX_PL_Free(asciiResult, plContext);
204 }
205
206 #endif /* DEBUG */
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)