From d82d18ef54b8680da805a7617103bbcbbceb1b89 Mon Sep 17 00:00:00 2001 From: "nelson%bolyard.com" Date: Sat, 11 Sep 2010 22:03:43 +0000 Subject: [PATCH] Fix parsing of serial numbers git-svn-id: svn://10.0.0.236/trunk@261196 18797224-902f-48f8-a5cc-f745e15eee43 --- .../security/nss/cmd/ppcertdata/ppcertdata.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mozilla/security/nss/cmd/ppcertdata/ppcertdata.c b/mozilla/security/nss/cmd/ppcertdata/ppcertdata.c index aaf44109c8c..0e74c046aa8 100644 --- a/mozilla/security/nss/cmd/ppcertdata/ppcertdata.c +++ b/mozilla/security/nss/cmd/ppcertdata/ppcertdata.c @@ -68,6 +68,7 @@ main(int argc, const char ** argv) int is_cert; int is_serial; int is_name; + int is_hash; int use_pp = 0; int out = 0; SECItem der = {siBuffer, NULL, 0 }; @@ -85,6 +86,7 @@ main(int argc, const char ** argv) 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; @@ -111,11 +113,18 @@ main(int argc, const char ** argv) SECU_PrintCertificate); else if (is_name) SECU_PrintDERName(stdout, &der, "Name", 0); - else if (is_serial) - SECU_PrintInteger(stdout, &der, "Serial Number", 0); - else + 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); - /* SECU_PrintBuf(stdout, "Hash", binary_line, out); */ + else + SECU_PrintBuf(stdout, "Other", binary_line, out); } NSS_Shutdown(); return 0;