2017-04-19 07:56:45 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
/*
|
|
|
|
* dumpcrl.c
|
|
|
|
*
|
|
|
|
* dump CRL sample application
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "pkix.h"
|
|
|
|
#include "testutil.h"
|
|
|
|
#include "prlong.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prthread.h"
|
|
|
|
#include "plarena.h"
|
|
|
|
#include "seccomon.h"
|
|
|
|
#include "secdert.h"
|
|
|
|
#include "secasn1t.h"
|
|
|
|
#include "certt.h"
|
|
|
|
|
|
|
|
static void *plContext = NULL;
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
static void
|
|
|
|
printUsage(void)
|
|
|
|
{
|
|
|
|
(void)printf("\nUSAGE:\tdumpcrl <crlFile>\n");
|
|
|
|
(void)printf("\tParses a CRL located at <crlFile> "
|
|
|
|
"and displays it.\n");
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
static void
|
|
|
|
printFailure(char *msg)
|
|
|
|
{
|
|
|
|
(void)printf("FAILURE: %s\n", msg);
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PKIX_PL_CRL *
|
|
|
|
createCRL(char *inFileName)
|
|
|
|
{
|
2020-01-24 01:47:36 +00:00
|
|
|
PKIX_PL_ByteArray *byteArray = NULL;
|
|
|
|
PKIX_PL_CRL *crl = NULL;
|
|
|
|
PKIX_Error *error = NULL;
|
|
|
|
PRFileDesc *inFile = NULL;
|
|
|
|
SECItem crlDER;
|
|
|
|
void *buf = NULL;
|
|
|
|
PKIX_UInt32 len;
|
|
|
|
SECStatus rv;
|
|
|
|
|
|
|
|
PKIX_TEST_STD_VARS();
|
|
|
|
|
|
|
|
crlDER.data = NULL;
|
|
|
|
|
|
|
|
inFile = PR_Open(inFileName, PR_RDONLY, 0);
|
|
|
|
|
|
|
|
if (!inFile) {
|
|
|
|
printFailure("Unable to open crl file");
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
rv = SECU_ReadDERFromFile(&crlDER, inFile, PR_FALSE, PR_FALSE);
|
|
|
|
if (!rv) {
|
|
|
|
buf = (void *)crlDER.data;
|
|
|
|
len = crlDER.len;
|
|
|
|
|
|
|
|
error = PKIX_PL_ByteArray_Create(buf, len, &byteArray, plContext);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
printFailure("PKIX_PL_ByteArray_Create failed");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
error = PKIX_PL_CRL_Create(byteArray, &crl, plContext);
|
|
|
|
if (error) {
|
|
|
|
printFailure("PKIX_PL_CRL_Create failed");
|
2017-04-19 07:56:45 +00:00
|
|
|
goto cleanup;
|
2020-01-24 01:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SECITEM_FreeItem(&crlDER, PR_FALSE);
|
2017-04-19 07:56:45 +00:00
|
|
|
} else {
|
2020-01-24 01:47:36 +00:00
|
|
|
printFailure("Unable to read DER from crl file");
|
|
|
|
goto cleanup;
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
2020-01-24 01:47:36 +00:00
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (inFile) {
|
|
|
|
PR_Close(inFile);
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (error) {
|
|
|
|
SECITEM_FreeItem(&crlDER, PR_FALSE);
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (byteArray) {
|
|
|
|
PKIX_PL_Object_DecRef((PKIX_PL_Object *)(byteArray), plContext);
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
PKIX_TEST_RETURN();
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
return (crl);
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
int
|
|
|
|
dumpcrl(int argc, char *argv[])
|
2017-04-19 07:56:45 +00:00
|
|
|
{
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
PKIX_PL_String *string = NULL;
|
|
|
|
PKIX_PL_CRL *crl = NULL;
|
|
|
|
PKIX_Error *error = NULL;
|
|
|
|
char *ascii = NULL;
|
|
|
|
PKIX_UInt32 length;
|
|
|
|
PKIX_UInt32 actualMinorVersion;
|
|
|
|
PKIX_UInt32 j = 0;
|
|
|
|
PKIX_Boolean useArenas = PKIX_FALSE;
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
PKIX_TEST_STD_VARS();
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
printUsage();
|
|
|
|
return (0);
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
useArenas = PKIX_TEST_ARENAS_ARG(argv[1]);
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
PKIX_Initialize(PKIX_TRUE, /* nssInitNeeded */
|
|
|
|
useArenas,
|
|
|
|
PKIX_MAJOR_VERSION,
|
|
|
|
PKIX_MINOR_VERSION,
|
|
|
|
PKIX_MINOR_VERSION,
|
|
|
|
&actualMinorVersion,
|
|
|
|
&plContext);
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
crl = createCRL(argv[j + 1]);
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (crl) {
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
error = PKIX_PL_Object_ToString((PKIX_PL_Object *)crl, &string, plContext);
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (error) {
|
|
|
|
printFailure("Unable to get string representation "
|
|
|
|
"of crl");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
error = PKIX_PL_String_GetEncoded(string,
|
|
|
|
PKIX_ESCASCII,
|
|
|
|
(void **)&ascii,
|
|
|
|
&length,
|
|
|
|
plContext);
|
|
|
|
if (error || !ascii) {
|
|
|
|
printFailure("Unable to get ASCII encoding of string");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
(void)printf("OUTPUT:\n%s\n", ascii);
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
} else {
|
|
|
|
printFailure("Unable to create CRL");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (crl) {
|
|
|
|
PKIX_PL_Object_DecRef((PKIX_PL_Object *)(crl), plContext);
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (string) {
|
|
|
|
PKIX_PL_Object_DecRef((PKIX_PL_Object *)(string), plContext);
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
if (ascii) {
|
|
|
|
PKIX_PL_Free((PKIX_PL_Object *)(ascii), plContext);
|
|
|
|
}
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
PKIX_Shutdown(plContext);
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
PKIX_TEST_RETURN();
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
endTests("DUMPCRL");
|
2017-04-19 07:56:45 +00:00
|
|
|
|
2020-01-24 01:47:36 +00:00
|
|
|
return (0);
|
2017-04-19 07:56:45 +00:00
|
|
|
}
|