summaryrefslogtreecommitdiffstats
path: root/security/nss/cmd/pp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--security/nss/cmd/pp/Makefile47
-rw-r--r--security/nss/cmd/pp/manifest.mn19
-rw-r--r--security/nss/cmd/pp/pp.c200
-rw-r--r--security/nss/cmd/pp/pp.gyp30
-rw-r--r--security/nss/cmd/ppcertdata/Makefile48
-rw-r--r--security/nss/cmd/ppcertdata/manifest.mn22
-rw-r--r--security/nss/cmd/ppcertdata/ppcertdata.c99
7 files changed, 465 insertions, 0 deletions
diff --git a/security/nss/cmd/pp/Makefile b/security/nss/cmd/pp/Makefile
new file mode 100644
index 0000000000..6e1d4ecdfc
--- /dev/null
+++ b/security/nss/cmd/pp/Makefile
@@ -0,0 +1,47 @@
+#! gmake
+#
+# 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/.
+
+#######################################################################
+# (1) Include initial platform-independent assignments (MANDATORY). #
+#######################################################################
+
+include manifest.mn
+
+#######################################################################
+# (2) Include "global" configuration information. (OPTIONAL) #
+#######################################################################
+
+include $(CORE_DEPTH)/coreconf/config.mk
+
+#######################################################################
+# (3) Include "component" configuration information. (OPTIONAL) #
+#######################################################################
+
+#######################################################################
+# (4) Include "local" platform-dependent assignments (OPTIONAL). #
+#######################################################################
+
+include ../platlibs.mk
+
+#######################################################################
+# (5) Execute "global" rules. (OPTIONAL) #
+#######################################################################
+
+include $(CORE_DEPTH)/coreconf/rules.mk
+
+#######################################################################
+# (6) Execute "component" rules. (OPTIONAL) #
+#######################################################################
+
+
+
+#######################################################################
+# (7) Execute "local" rules. (OPTIONAL). #
+#######################################################################
+
+
+include ../platrules.mk
+
diff --git a/security/nss/cmd/pp/manifest.mn b/security/nss/cmd/pp/manifest.mn
new file mode 100644
index 0000000000..de6126ae4a
--- /dev/null
+++ b/security/nss/cmd/pp/manifest.mn
@@ -0,0 +1,19 @@
+#
+# 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/.
+
+CORE_DEPTH = ../..
+
+# MODULE public and private header directories are implicitly REQUIRED.
+MODULE = nss
+
+# This next line is used by .mk files
+# and gets translated into $LINCS in manifest.mnw
+REQUIRES = seccmd dbm
+
+DEFINES = -DNSPR20
+
+CSRCS = pp.c
+
+PROGRAM = pp
diff --git a/security/nss/cmd/pp/pp.c b/security/nss/cmd/pp/pp.c
new file mode 100644
index 0000000000..b89b9ad0d9
--- /dev/null
+++ b/security/nss/cmd/pp/pp.c
@@ -0,0 +1,200 @@
+/* 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/. */
+
+/*
+ * Pretty-print some well-known BER or DER encoded data (e.g. certificates,
+ * keys, pkcs7)
+ */
+
+#include "secutil.h"
+
+#if defined(__sun) && !defined(SVR4)
+extern int fprintf(FILE *, char *, ...);
+#endif
+
+#include "plgetopt.h"
+
+#include "pk11func.h"
+#include "nspr.h"
+#include "nss.h"
+
+static void
+Usage(char *progName)
+{
+ fprintf(stderr,
+ "Usage: %s [-t type] [-a] [-i input] [-o output] [-w] [-u]\n",
+ progName);
+ fprintf(stderr, "Pretty prints a file containing ASN.1 data in DER or ascii format.\n");
+ fprintf(stderr, "%-14s Specify input and display type:", "-t type");
+ fprintf(stderr, " %s (sk),", SEC_CT_PRIVATE_KEY);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "%-14s %s (pk), %s (c), %s (cr),\n", "", SEC_CT_PUBLIC_KEY,
+ SEC_CT_CERTIFICATE, SEC_CT_CERTIFICATE_REQUEST);
+ fprintf(stderr, "%-14s %s (ci), %s (p7), %s (p12), %s or %s (n).\n", "",
+ SEC_CT_CERTIFICATE_ID, SEC_CT_PKCS7, SEC_CT_PKCS12,
+ SEC_CT_CRL, SEC_CT_NAME);
+ fprintf(stderr, "%-14s (Use either the long type name or the shortcut.)\n", "");
+ fprintf(stderr, "%-14s Input is in ascii encoded form (RFC1113)\n",
+ "-a");
+ fprintf(stderr, "%-14s Define an input file to use (default is stdin)\n",
+ "-i input");
+ fprintf(stderr, "%-14s Define an output file to use (default is stdout)\n",
+ "-o output");
+ fprintf(stderr, "%-14s Don't wrap long output lines\n",
+ "-w");
+ fprintf(stderr, "%-14s Use UTF-8 (default is to show non-ascii as .)\n",
+ "-u");
+ exit(-1);
+}
+
+int
+main(int argc, char **argv)
+{
+ int rv, ascii;
+ char *progName;
+ FILE *outFile;
+ PRFileDesc *inFile;
+ SECItem der, data;
+ char *typeTag;
+ PLOptState *optstate;
+ PRBool wrap = PR_TRUE;
+
+ progName = strrchr(argv[0], '/');
+ progName = progName ? progName + 1 : argv[0];
+
+ ascii = 0;
+ inFile = 0;
+ outFile = 0;
+ typeTag = 0;
+ optstate = PL_CreateOptState(argc, argv, "at:i:o:uw");
+ while (PL_GetNextOpt(optstate) == PL_OPT_OK) {
+ switch (optstate->option) {
+ case '?':
+ Usage(progName);
+ break;
+
+ case 'a':
+ ascii = 1;
+ break;
+
+ case 'i':
+ inFile = PR_Open(optstate->value, PR_RDONLY, 0);
+ if (!inFile) {
+ fprintf(stderr, "%s: unable to open \"%s\" for reading\n",
+ progName, optstate->value);
+ PORT_Free(typeTag);
+ PL_DestroyOptState(optstate);
+ return -1;
+ }
+ break;
+
+ case 'o':
+ outFile = fopen(optstate->value, "w");
+ if (!outFile) {
+ fprintf(stderr, "%s: unable to open \"%s\" for writing\n",
+ progName, optstate->value);
+ PORT_Free(typeTag);
+ PL_DestroyOptState(optstate);
+ return -1;
+ }
+ break;
+
+ case 't':
+ typeTag = strdup(optstate->value);
+ break;
+
+ case 'u':
+ SECU_EnableUtf8Display(PR_TRUE);
+ break;
+
+ case 'w':
+ wrap = PR_FALSE;
+ break;
+ }
+ }
+ PL_DestroyOptState(optstate);
+ if (!typeTag)
+ Usage(progName);
+
+ if (!inFile)
+ inFile = PR_STDIN;
+ if (!outFile)
+ outFile = stdout;
+
+ PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
+ rv = NSS_NoDB_Init(NULL);
+ if (rv != SECSuccess) {
+ fprintf(stderr, "%s: NSS_NoDB_Init failed (%s)\n",
+ progName, SECU_Strerror(PORT_GetError()));
+ exit(1);
+ }
+ SECU_RegisterDynamicOids();
+
+ rv = SECU_ReadDERFromFile(&der, inFile, ascii, PR_FALSE);
+ if (rv != SECSuccess) {
+ fprintf(stderr, "%s: SECU_ReadDERFromFile failed\n", progName);
+ exit(1);
+ }
+
+ /* Data is untyped, using the specified type */
+ data.data = der.data;
+ data.len = der.len;
+
+ SECU_EnableWrap(wrap);
+
+ /* Pretty print it */
+ if (PORT_Strcmp(typeTag, SEC_CT_CERTIFICATE) == 0 ||
+ PORT_Strcmp(typeTag, "c") == 0) {
+ rv = SECU_PrintSignedData(outFile, &data, "Certificate", 0,
+ (SECU_PPFunc)SECU_PrintCertificate);
+ } else if (PORT_Strcmp(typeTag, SEC_CT_CERTIFICATE_ID) == 0 ||
+ PORT_Strcmp(typeTag, "ci") == 0) {
+ rv = SECU_PrintSignedContent(outFile, &data, 0, 0,
+ SECU_PrintDumpDerIssuerAndSerial);
+ } else if (PORT_Strcmp(typeTag, SEC_CT_CERTIFICATE_REQUEST) == 0 ||
+ PORT_Strcmp(typeTag, "cr") == 0) {
+ rv = SECU_PrintSignedData(outFile, &data, "Certificate Request", 0,
+ SECU_PrintCertificateRequest);
+ } else if (PORT_Strcmp(typeTag, SEC_CT_CRL) == 0) {
+ rv = SECU_PrintSignedData(outFile, &data, "CRL", 0, SECU_PrintCrl);
+ } else if (PORT_Strcmp(typeTag, SEC_CT_PRIVATE_KEY) == 0 ||
+ PORT_Strcmp(typeTag, "sk") == 0) {
+ rv = SECU_PrintPrivateKey(outFile, &data, "Private Key", 0);
+ } else if (PORT_Strcmp(typeTag, SEC_CT_PUBLIC_KEY) == 0 ||
+ PORT_Strcmp(typeTag, "pk") == 0) {
+ rv = SECU_PrintSubjectPublicKeyInfo(outFile, &data, "Public Key", 0);
+ } else if (PORT_Strcmp(typeTag, SEC_CT_PKCS7) == 0 ||
+ PORT_Strcmp(typeTag, "p7") == 0) {
+ rv = SECU_PrintPKCS7ContentInfo(outFile, &data,
+ "PKCS #7 Content Info", 0);
+ } else if (PORT_Strcmp(typeTag, SEC_CT_NAME) == 0 ||
+ PORT_Strcmp(typeTag, "n") == 0) {
+ rv = SECU_PrintDERName(outFile, &data, "Name", 0);
+ } else if (PORT_Strcmp(typeTag, SEC_CT_PKCS12) == 0 ||
+ PORT_Strcmp(typeTag, "p12") == 0) {
+ rv = SECU_PrintPKCS12(outFile, &data, "PKCS #12 File", 0);
+ } else {
+ fprintf(stderr, "%s: don't know how to print out '%s' files\n",
+ progName, typeTag);
+ SECU_PrintAny(outFile, &data, "File contains", 0);
+ return -1;
+ }
+
+ PORT_Free(typeTag);
+
+ if (inFile != PR_STDIN)
+ PR_Close(inFile);
+ PORT_Free(der.data);
+ if (rv) {
+ fprintf(stderr, "%s: problem converting data (%s)\n",
+ progName, SECU_Strerror(PORT_GetError()));
+ }
+ if (NSS_Shutdown() != SECSuccess) {
+ fprintf(stderr, "%s: NSS_Shutdown failed (%s)\n",
+ progName, SECU_Strerror(PORT_GetError()));
+ rv = SECFailure;
+ }
+ PR_Cleanup();
+ return rv;
+}
diff --git a/security/nss/cmd/pp/pp.gyp b/security/nss/cmd/pp/pp.gyp
new file mode 100644
index 0000000000..c0fef6ac95
--- /dev/null
+++ b/security/nss/cmd/pp/pp.gyp
@@ -0,0 +1,30 @@
+# 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/.
+{
+ 'includes': [
+ '../../coreconf/config.gypi',
+ '../../cmd/platlibs.gypi'
+ ],
+ 'targets': [
+ {
+ 'target_name': 'pp',
+ 'type': 'executable',
+ 'sources': [
+ 'pp.c'
+ ],
+ 'dependencies': [
+ '<(DEPTH)/exports.gyp:dbm_exports',
+ '<(DEPTH)/exports.gyp:nss_exports'
+ ]
+ }
+ ],
+ 'target_defaults': {
+ 'defines': [
+ 'NSPR20'
+ ]
+ },
+ 'variables': {
+ 'module': 'nss'
+ }
+} \ No newline at end of file
diff --git a/security/nss/cmd/ppcertdata/Makefile b/security/nss/cmd/ppcertdata/Makefile
new file mode 100644
index 0000000000..2aaef8fe5b
--- /dev/null
+++ b/security/nss/cmd/ppcertdata/Makefile
@@ -0,0 +1,48 @@
+#! gmake
+#
+# 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/.
+
+#######################################################################
+# (1) Include initial platform-independent assignments (MANDATORY). #
+#######################################################################
+
+include manifest.mn
+
+#######################################################################
+# (2) Include "global" configuration information. (OPTIONAL) #
+#######################################################################
+
+include $(CORE_DEPTH)/coreconf/config.mk
+
+#######################################################################
+# (3) Include "component" configuration information. (OPTIONAL) #
+#######################################################################
+
+#######################################################################
+# (4) Include "local" platform-dependent assignments (OPTIONAL). #
+#######################################################################
+
+include ../platlibs.mk
+
+
+#######################################################################
+# (5) Execute "global" rules. (OPTIONAL) #
+#######################################################################
+
+include $(CORE_DEPTH)/coreconf/rules.mk
+
+#######################################################################
+# (6) Execute "component" rules. (OPTIONAL) #
+#######################################################################
+
+
+
+#######################################################################
+# (7) Execute "local" rules. (OPTIONAL). #
+#######################################################################
+
+
+include ../platrules.mk
+
diff --git a/security/nss/cmd/ppcertdata/manifest.mn b/security/nss/cmd/ppcertdata/manifest.mn
new file mode 100644
index 0000000000..142a773caa
--- /dev/null
+++ b/security/nss/cmd/ppcertdata/manifest.mn
@@ -0,0 +1,22 @@
+#
+# 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/.
+
+CORE_DEPTH = ../..
+
+# MODULE public and private header directories are implicitly REQUIRED.
+MODULE = nss
+
+# This next line is used by .mk files
+# and gets translated into $LINCS in manifest.mnw
+# The MODULE is always implicitly required.
+# Listing it here in REQUIRES makes it appear twice in the cc command line.
+REQUIRES = seccmd
+
+#DEFINES = -DNSPR20
+
+CSRCS = ppcertdata.c
+
+PROGRAM = ppcertdata
+
diff --git a/security/nss/cmd/ppcertdata/ppcertdata.c b/security/nss/cmd/ppcertdata/ppcertdata.c
new file mode 100644
index 0000000000..be12e9354a
--- /dev/null
+++ b/security/nss/cmd/ppcertdata/ppcertdata.c
@@ -0,0 +1,99 @@
+/* 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/. */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include "secutil.h"
+#include "nss.h"
+
+unsigned char binary_line[64 * 1024];
+
+int
+main(int argc, const char** argv)
+{
+ int skip_count = 0;
+ int bytes_read;
+ char line[133];
+
+ if (argc > 1) {
+ skip_count = atoi(argv[1]);
+ }
+ if (argc > 2 || skip_count < 0) {
+ printf("Usage: %s [ skip_columns ] \n", argv[0]);
+ return 1;
+ }
+
+ NSS_NoDB_Init(NULL);
+
+ while (fgets(line, 132, stdin) && (bytes_read = strlen(line)) > 0) {
+ int bytes_written;
+ char* found;
+ char* in = line + skip_count;
+ int left = bytes_read - skip_count;
+ int is_cert;
+ int is_serial;
+ int is_name;
+ int is_hash;
+ int use_pp = 0;
+ int out = 0;
+ SECItem der = { siBuffer, NULL, 0 };
+
+ line[bytes_read] = 0;
+ if (bytes_read <= skip_count)
+ continue;
+ fwrite(in, 1, left, stdout);
+ found = strstr(in, "MULTILINE_OCTAL");
+ if (!found)
+ continue;
+ fflush(stdout);
+
+ is_cert = (NULL != strstr(in, "CKA_VALUE"));
+ is_serial = (NULL != strstr(in, "CKA_SERIAL_NUMBER"));
+ is_name = (NULL != strstr(in, "CKA_ISSUER")) ||
+ (NULL != strstr(in, "CKA_SUBJECT"));
+ is_hash = (NULL != strstr(in, "_HASH"));
+ while (fgets(line, 132, stdin) &&
+ (bytes_read = strlen(line)) > 0) {
+ in = line + skip_count;
+ left = bytes_read - skip_count;
+
+ if ((left >= 3) && !strncmp(in, "END", 3))
+ break;
+ while (left >= 4) {
+ if (in[0] == '\\' && isdigit(in[1]) &&
+ isdigit(in[2]) && isdigit(in[3])) {
+ left -= 4;
+ binary_line[out++] = ((in[1] - '0') << 6) |
+ ((in[2] - '0') << 3) |
+ (in[3] - '0');
+ in += 4;
+ } else
+ break;
+ }
+ }
+ der.data = binary_line;
+ der.len = out;
+ if (is_cert)
+ SECU_PrintSignedData(stdout, &der, "Certificate", 0,
+ SECU_PrintCertificate);
+ else if (is_name)
+ SECU_PrintDERName(stdout, &der, "Name", 0);
+ else if (is_serial) {
+ if (out > 2 && binary_line[0] == 2 &&
+ out == 2 + binary_line[1]) {
+ der.data += 2;
+ der.len -= 2;
+ SECU_PrintInteger(stdout, &der, "DER Serial Number", 0);
+ } else
+ SECU_PrintInteger(stdout, &der, "Raw Serial Number", 0);
+ } else if (is_hash)
+ SECU_PrintAsHex(stdout, &der, "Hash", 0);
+ else
+ SECU_PrintBuf(stdout, "Other", binary_line, out);
+ }
+ NSS_Shutdown();
+ return 0;
+}