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/. */
7
* dump certificate sample application
24
static void *plContext = NULL;
27
void printUsage(void){
28
(void) printf("\nUSAGE:\tdumpcert <certFile>\n");
29
(void) printf("\tParses a certificate located at <certFile> "
30
"and displays it.\n");
34
void printFailure(char *msg){
35
(void) printf("FAILURE: %s\n", msg);
39
createCert(char *inFileName)
41
PKIX_PL_ByteArray *byteArray = NULL;
42
PKIX_PL_Cert *cert = NULL;
43
PKIX_Error *error = NULL;
44
PRFileDesc *inFile = NULL;
48
SECStatus rv = SECFailure;
52
inFile = PR_Open(inFileName, PR_RDONLY, 0);
55
printFailure("Unable to open cert file");
58
rv = SECU_ReadDERFromFile(&certDER, inFile, PR_FALSE, PR_FALSE);
60
buf = (void *)certDER.data;
63
error = PKIX_PL_ByteArray_Create
64
(buf, len, &byteArray, plContext);
67
printFailure("PKIX_PL_ByteArray_Create failed");
71
error = PKIX_PL_Cert_Create
72
(byteArray, &cert, plContext);
75
printFailure("PKIX_PL_Cert_Create failed");
79
printFailure("Unable to read DER from cert file");
90
if (rv == SECSuccess){
91
SECITEM_FreeItem(&certDER, PR_FALSE);
95
PKIX_PL_Object_DecRef((PKIX_PL_Object *)(byteArray), plContext);
101
int dumpcert(int argc, char *argv[])
104
PKIX_PL_String *string = NULL;
105
PKIX_PL_Cert *cert = NULL;
106
PKIX_Error *error = NULL;
108
PKIX_UInt32 length = 0;
110
PKIX_Boolean useArenas = PKIX_FALSE;
111
PKIX_UInt32 actualMinorVersion;
113
PKIX_TEST_STD_VARS();
120
useArenas = PKIX_TEST_ARENAS_ARG(argv[1]);
123
(PKIX_TRUE, /* nssInitNeeded */
131
cert = createCert(argv[1+j]);
135
error = PKIX_PL_Object_ToString
136
((PKIX_PL_Object *)cert, &string, plContext);
139
printFailure("Unable to get string representation "
144
error = PKIX_PL_String_GetEncoded
151
if (error || !ascii){
152
printFailure("Unable to get ASCII encoding of string");
156
(void) printf("OUTPUT:\n%s\n", ascii);
159
printFailure("Unable to create certificate");
166
PKIX_PL_Object_DecRef((PKIX_PL_Object *)(cert), plContext);
170
PKIX_PL_Object_DecRef((PKIX_PL_Object *)(string), plContext);
174
PKIX_PL_Free((PKIX_PL_Object *)(ascii), plContext);
177
PKIX_Shutdown(plContext);
181
endTests("DUMPCERT");