michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include "secutil.h" michael@0: #include "nss.h" michael@0: michael@0: unsigned char binary_line[64 * 1024]; michael@0: michael@0: int michael@0: main(int argc, const char ** argv) michael@0: { michael@0: int skip_count = 0; michael@0: int bytes_read; michael@0: char line[133]; michael@0: michael@0: if (argc > 1) { michael@0: skip_count = atoi(argv[1]); michael@0: } michael@0: if (argc > 2 || skip_count < 0) { michael@0: printf("Usage: %s [ skip_columns ] \n", argv[0]); michael@0: return 1; michael@0: } michael@0: michael@0: NSS_NoDB_Init(NULL); michael@0: michael@0: while (fgets(line, 132, stdin) && (bytes_read = strlen(line)) > 0 ) { michael@0: int bytes_written; michael@0: char * found; michael@0: char * in = line + skip_count; michael@0: int left = bytes_read - skip_count; michael@0: int is_cert; michael@0: int is_serial; michael@0: int is_name; michael@0: int is_hash; michael@0: int use_pp = 0; michael@0: int out = 0; michael@0: SECItem der = {siBuffer, NULL, 0 }; michael@0: michael@0: line[bytes_read] = 0; michael@0: if (bytes_read <= skip_count) michael@0: continue; michael@0: fwrite(in, 1, left, stdout); michael@0: found = strstr(in, "MULTILINE_OCTAL"); michael@0: if (!found) michael@0: continue; michael@0: fflush(stdout); michael@0: michael@0: is_cert = (NULL != strstr(in, "CKA_VALUE")); michael@0: is_serial = (NULL != strstr(in, "CKA_SERIAL_NUMBER")); michael@0: is_name = (NULL != strstr(in, "CKA_ISSUER")) || michael@0: (NULL != strstr(in, "CKA_SUBJECT")); michael@0: is_hash = (NULL != strstr(in, "_HASH")); michael@0: while (fgets(line, 132, stdin) && michael@0: (bytes_read = strlen(line)) > 0 ) { michael@0: in = line + skip_count; michael@0: left = bytes_read - skip_count; michael@0: michael@0: if ((left >= 3) && !strncmp(in, "END", 3)) michael@0: break; michael@0: while (left >= 4) { michael@0: if (in[0] == '\\' && isdigit(in[1]) && michael@0: isdigit(in[2]) && isdigit(in[3])) { michael@0: left -= 4; michael@0: binary_line[out++] = ((in[1] - '0') << 6) | michael@0: ((in[2] - '0') << 3) | michael@0: (in[3] - '0'); michael@0: in += 4; michael@0: } else michael@0: break; michael@0: } michael@0: } michael@0: der.data = binary_line; michael@0: der.len = out; michael@0: if (is_cert) michael@0: SECU_PrintSignedData(stdout, &der, "Certificate", 0, michael@0: SECU_PrintCertificate); michael@0: else if (is_name) michael@0: SECU_PrintDERName(stdout, &der, "Name", 0); michael@0: else if (is_serial) { michael@0: if (out > 2 && binary_line[0] == 2 && michael@0: out == 2 + binary_line[1]) { michael@0: der.data += 2; michael@0: der.len -= 2; michael@0: SECU_PrintInteger(stdout, &der, "DER Serial Number", 0); michael@0: } else michael@0: SECU_PrintInteger(stdout, &der, "Raw Serial Number", 0); michael@0: } else if (is_hash) michael@0: SECU_PrintAsHex(stdout, &der, "Hash", 0); michael@0: else michael@0: SECU_PrintBuf(stdout, "Other", binary_line, out); michael@0: } michael@0: NSS_Shutdown(); michael@0: return 0; michael@0: } michael@0: