1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 * PKIX - NSS proxy functions
44 #include "pkix_pl_common.h"
49 pkix_Error2ASCII(PKIX_Error
*error
, void *plContext
)
52 char *asciiString
= NULL
;
53 PKIX_PL_String
*pkixString
= NULL
;
54 PKIX_Error
*errorResult
= NULL
;
56 errorResult
= PKIX_PL_Object_ToString
57 ((PKIX_PL_Object
*)error
, &pkixString
, plContext
);
58 if (errorResult
) goto cleanup
;
60 errorResult
= PKIX_PL_String_GetEncoded
63 (void **)&asciiString
,
70 if (PKIX_PL_Object_DecRef
71 ((PKIX_PL_Object
*)pkixString
, plContext
)){
77 PKIX_PL_Object_DecRef((PKIX_PL_Object
*)errorResult
, plContext
);
85 pkix_Object2ASCII(PKIX_PL_Object
*object
)
88 char *asciiString
= NULL
;
89 PKIX_PL_String
*pkixString
= NULL
;
90 PKIX_Error
*errorResult
= NULL
;
92 errorResult
= PKIX_PL_Object_ToString
93 (object
, &pkixString
, NULL
);
94 if (errorResult
) goto cleanup
;
96 errorResult
= PKIX_PL_String_GetEncoded
97 (pkixString
, PKIX_ESCASCII
, (void **)&asciiString
, &length
, NULL
);
102 if (PKIX_PL_Object_DecRef((PKIX_PL_Object
*)pkixString
, NULL
)){
111 return (asciiString
);
115 pkix_Cert2ASCII(PKIX_PL_Cert
*cert
)
117 PKIX_PL_X500Name
*issuer
= NULL
;
118 void *issuerAscii
= NULL
;
119 PKIX_PL_X500Name
*subject
= NULL
;
120 void *subjectAscii
= NULL
;
121 void *asciiString
= NULL
;
122 PKIX_Error
*errorResult
= NULL
;
123 PKIX_UInt32 numChars
;
124 PKIX_UInt32 refCount
= 0;
127 errorResult
= PKIX_PL_Cert_GetIssuer(cert
, &issuer
, NULL
);
128 if (errorResult
) goto cleanup
;
130 issuerAscii
= pkix_Object2ASCII((PKIX_PL_Object
*)issuer
);
133 errorResult
= PKIX_PL_Cert_GetSubject(cert
, &subject
, NULL
);
134 if (errorResult
) goto cleanup
;
137 subjectAscii
= pkix_Object2ASCII((PKIX_PL_Object
*)subject
);
140 /* errorResult = PKIX_PL_Object_GetRefCount((PKIX_PL_Object*)cert, &refCount, NULL); */
141 if (errorResult
) goto cleanup
;
143 errorResult
= PKIX_PL_Malloc(200, &asciiString
, NULL
);
144 if (errorResult
) goto cleanup
;
150 "Ref: %d Issuer=%s\nSubject=%s\n",
155 if (!numChars
) goto cleanup
;
160 if (PKIX_PL_Object_DecRef((PKIX_PL_Object
*)issuer
, NULL
)){
166 if (PKIX_PL_Object_DecRef((PKIX_PL_Object
*)subject
, NULL
)){
171 if (PKIX_PL_Free((PKIX_PL_Object
*)issuerAscii
, NULL
)){
175 if (PKIX_PL_Free((PKIX_PL_Object
*)subjectAscii
, NULL
)){
183 return (asciiString
);
188 PKIX_List
*pkixCertChain
,
191 PKIX_PL_Cert
*cert
= NULL
;
192 PKIX_UInt32 numCerts
= 0, i
= 0;
193 char *asciiResult
= NULL
;
195 PKIX_ENTER(CERTVFYPKIX
, "cert_PrintCertChain");
198 PKIX_List_GetLength(pkixCertChain
, &numCerts
, plContext
),
199 PKIX_LISTGETLENGTHFAILED
);
201 fprintf(stderr
, "\n");
203 for (i
= 0; i
< numCerts
; i
++){
206 (pkixCertChain
, i
, (PKIX_PL_Object
**)&cert
, plContext
),
207 PKIX_LISTGETITEMFAILED
);
209 asciiResult
= pkix_Cert2ASCII(cert
);
211 fprintf(stderr
, "CERT[%d]:\n%s\n", i
, asciiResult
);
213 PKIX_PL_Free(asciiResult
, plContext
);
222 PKIX_RETURN(CERTVFYPKIX
);
227 PKIX_PL_Cert
*pkixCert
,
230 char *asciiResult
= NULL
;
232 asciiResult
= pkix_Cert2ASCII(pkixCert
);
234 fprintf(stderr
, "CERT[0]:\n%s\n", asciiResult
);
236 PKIX_PL_Free(asciiResult
, plContext
);