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 * dump CRL sample application
57 void *plContext
= NULL
;
59 void printUsage(void){
60 (void) printf("\nUSAGE:\tdumpcrl <crlFile>\n");
61 (void) printf("\tParses a CRL located at <crlFile> "
62 "and displays it.\n");
65 void printFailure(char *msg
){
66 (void) printf("FAILURE: %s\n", msg
);
70 createCRL(char *inFileName
)
72 PKIX_PL_ByteArray
*byteArray
= NULL
;
73 PKIX_PL_CRL
*crl
= NULL
;
74 PKIX_Error
*error
= NULL
;
75 PRFileDesc
*inFile
= NULL
;
85 inFile
= PR_Open(inFileName
, PR_RDONLY
, 0);
88 printFailure("Unable to open crl file");
91 rv
= SECU_ReadDERFromFile(&crlDER
, inFile
, PR_FALSE
);
93 buf
= (void *)crlDER
.data
;
96 error
= PKIX_PL_ByteArray_Create
97 (buf
, len
, &byteArray
, plContext
);
100 printFailure("PKIX_PL_ByteArray_Create failed");
104 error
= PKIX_PL_CRL_Create(byteArray
, &crl
, plContext
);
106 printFailure("PKIX_PL_CRL_Create failed");
110 SECITEM_FreeItem(&crlDER
, PR_FALSE
);
112 printFailure("Unable to read DER from crl file");
124 SECITEM_FreeItem(&crlDER
, PR_FALSE
);
128 PKIX_PL_Object_DecRef((PKIX_PL_Object
*)(byteArray
), plContext
);
136 int main(int argc
, char *argv
[])
139 PKIX_PL_String
*string
= NULL
;
140 PKIX_PL_CRL
*crl
= NULL
;
141 PKIX_Error
*error
= NULL
;
144 PKIX_UInt32 actualMinorVersion
;
146 PKIX_Boolean useArenas
= PKIX_FALSE
;
148 PKIX_TEST_STD_VARS();
155 useArenas
= PKIX_TEST_ARENAS_ARG(argv
[1]);
158 (PKIX_TRUE
, /* nssInitNeeded */
166 crl
= createCRL(argv
[j
+1]);
170 error
= PKIX_PL_Object_ToString
171 ((PKIX_PL_Object
*)crl
, &string
, plContext
);
174 printFailure("Unable to get string representation "
179 error
= PKIX_PL_String_GetEncoded
185 if (error
|| !ascii
){
186 printFailure("Unable to get ASCII encoding of string");
190 (void) printf("OUTPUT:\n%s\n", ascii
);
193 printFailure("Unable to create CRL");
200 PKIX_PL_Object_DecRef((PKIX_PL_Object
*)(crl
), plContext
);
204 PKIX_PL_Object_DecRef((PKIX_PL_Object
*)(string
), plContext
);
208 PKIX_PL_Free((PKIX_PL_Object
*)(ascii
), plContext
);
211 PKIX_Shutdown(plContext
);