summaryrefslogtreecommitdiff
path: root/cmd/ppcertdata
diff options
context:
space:
mode:
authorKai Engert <kaie@kuix.de>2013-02-28 12:44:50 +0100
committerKai Engert <kaie@kuix.de>2013-02-28 12:44:50 +0100
commit3ecd967b2a9e23403935e2bc932597f7e03e7f24 (patch)
tree4b0f054f0354c2dbe401f86d864c04c6034c1621 /cmd/ppcertdata
parentf45b9ca74a609e0521d0cc4b7fc91603774992df (diff)
downloadnss-hg-3ecd967b2a9e23403935e2bc932597f7e03e7f24.tar.gz
Bug 845556, reorganize NSS directory layout, moving files, very large changeset! r=wtc
Diffstat (limited to 'cmd/ppcertdata')
-rw-r--r--cmd/ppcertdata/Makefile48
-rw-r--r--cmd/ppcertdata/manifest.mn22
-rw-r--r--cmd/ppcertdata/ppcertdata.c100
3 files changed, 170 insertions, 0 deletions
diff --git a/cmd/ppcertdata/Makefile b/cmd/ppcertdata/Makefile
new file mode 100644
index 000000000..2aaef8fe5
--- /dev/null
+++ b/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/cmd/ppcertdata/manifest.mn b/cmd/ppcertdata/manifest.mn
new file mode 100644
index 000000000..30a47aa5b
--- /dev/null
+++ b/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/cmd/ppcertdata/ppcertdata.c b/cmd/ppcertdata/ppcertdata.c
new file mode 100644
index 000000000..e1fb287b2
--- /dev/null
+++ b/cmd/ppcertdata/ppcertdata.c
@@ -0,0 +1,100 @@
+/* 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;
+}
+