Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | /* |
michael@0 | 5 | * nss_pkix_proxy.h |
michael@0 | 6 | * |
michael@0 | 7 | * PKIX - NSS proxy functions |
michael@0 | 8 | * |
michael@0 | 9 | */ |
michael@0 | 10 | #include "cert.h" |
michael@0 | 11 | #include "pkix_pl_common.h" |
michael@0 | 12 | |
michael@0 | 13 | #ifdef DEBUG |
michael@0 | 14 | |
michael@0 | 15 | char * |
michael@0 | 16 | pkix_Error2ASCII(PKIX_Error *error, void *plContext) |
michael@0 | 17 | { |
michael@0 | 18 | PKIX_UInt32 length; |
michael@0 | 19 | char *asciiString = NULL; |
michael@0 | 20 | PKIX_PL_String *pkixString = NULL; |
michael@0 | 21 | PKIX_Error *errorResult = NULL; |
michael@0 | 22 | |
michael@0 | 23 | errorResult = PKIX_PL_Object_ToString |
michael@0 | 24 | ((PKIX_PL_Object*)error, &pkixString, plContext); |
michael@0 | 25 | if (errorResult) goto cleanup; |
michael@0 | 26 | |
michael@0 | 27 | errorResult = PKIX_PL_String_GetEncoded |
michael@0 | 28 | (pkixString, |
michael@0 | 29 | PKIX_ESCASCII, |
michael@0 | 30 | (void **)&asciiString, |
michael@0 | 31 | &length, |
michael@0 | 32 | plContext); |
michael@0 | 33 | |
michael@0 | 34 | cleanup: |
michael@0 | 35 | |
michael@0 | 36 | if (pkixString){ |
michael@0 | 37 | if (PKIX_PL_Object_DecRef |
michael@0 | 38 | ((PKIX_PL_Object*)pkixString, plContext)){ |
michael@0 | 39 | return (NULL); |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | if (errorResult){ |
michael@0 | 44 | PKIX_PL_Object_DecRef((PKIX_PL_Object*)errorResult, plContext); |
michael@0 | 45 | return (NULL); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | return (asciiString); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | char * |
michael@0 | 52 | pkix_Object2ASCII(PKIX_PL_Object *object) |
michael@0 | 53 | { |
michael@0 | 54 | PKIX_UInt32 length; |
michael@0 | 55 | char *asciiString = NULL; |
michael@0 | 56 | PKIX_PL_String *pkixString = NULL; |
michael@0 | 57 | PKIX_Error *errorResult = NULL; |
michael@0 | 58 | |
michael@0 | 59 | errorResult = PKIX_PL_Object_ToString |
michael@0 | 60 | (object, &pkixString, NULL); |
michael@0 | 61 | if (errorResult) goto cleanup; |
michael@0 | 62 | |
michael@0 | 63 | errorResult = PKIX_PL_String_GetEncoded |
michael@0 | 64 | (pkixString, PKIX_ESCASCII, (void **)&asciiString, &length, NULL); |
michael@0 | 65 | |
michael@0 | 66 | cleanup: |
michael@0 | 67 | |
michael@0 | 68 | if (pkixString){ |
michael@0 | 69 | if (PKIX_PL_Object_DecRef((PKIX_PL_Object*)pkixString, NULL)){ |
michael@0 | 70 | return (NULL); |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | if (errorResult){ |
michael@0 | 75 | return (NULL); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | return (asciiString); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | char * |
michael@0 | 82 | pkix_Cert2ASCII(PKIX_PL_Cert *cert) |
michael@0 | 83 | { |
michael@0 | 84 | PKIX_PL_X500Name *issuer = NULL; |
michael@0 | 85 | void *issuerAscii = NULL; |
michael@0 | 86 | PKIX_PL_X500Name *subject = NULL; |
michael@0 | 87 | void *subjectAscii = NULL; |
michael@0 | 88 | void *asciiString = NULL; |
michael@0 | 89 | PKIX_Error *errorResult = NULL; |
michael@0 | 90 | PKIX_UInt32 numChars; |
michael@0 | 91 | PKIX_UInt32 refCount = 0; |
michael@0 | 92 | |
michael@0 | 93 | /* Issuer */ |
michael@0 | 94 | errorResult = PKIX_PL_Cert_GetIssuer(cert, &issuer, NULL); |
michael@0 | 95 | if (errorResult) goto cleanup; |
michael@0 | 96 | |
michael@0 | 97 | issuerAscii = pkix_Object2ASCII((PKIX_PL_Object*)issuer); |
michael@0 | 98 | |
michael@0 | 99 | /* Subject */ |
michael@0 | 100 | errorResult = PKIX_PL_Cert_GetSubject(cert, &subject, NULL); |
michael@0 | 101 | if (errorResult) goto cleanup; |
michael@0 | 102 | |
michael@0 | 103 | if (subject){ |
michael@0 | 104 | subjectAscii = pkix_Object2ASCII((PKIX_PL_Object*)subject); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | /* errorResult = PKIX_PL_Object_GetRefCount((PKIX_PL_Object*)cert, &refCount, NULL); */ |
michael@0 | 108 | if (errorResult) goto cleanup; |
michael@0 | 109 | |
michael@0 | 110 | errorResult = PKIX_PL_Malloc(200, &asciiString, NULL); |
michael@0 | 111 | if (errorResult) goto cleanup; |
michael@0 | 112 | |
michael@0 | 113 | numChars = |
michael@0 | 114 | PR_snprintf |
michael@0 | 115 | (asciiString, |
michael@0 | 116 | 200, |
michael@0 | 117 | "Ref: %d Subject=%s\nIssuer=%s\n", |
michael@0 | 118 | refCount, |
michael@0 | 119 | subjectAscii, |
michael@0 | 120 | issuerAscii); |
michael@0 | 121 | |
michael@0 | 122 | if (!numChars) goto cleanup; |
michael@0 | 123 | |
michael@0 | 124 | cleanup: |
michael@0 | 125 | |
michael@0 | 126 | if (issuer){ |
michael@0 | 127 | if (PKIX_PL_Object_DecRef((PKIX_PL_Object*)issuer, NULL)){ |
michael@0 | 128 | return (NULL); |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | if (subject){ |
michael@0 | 133 | if (PKIX_PL_Object_DecRef((PKIX_PL_Object*)subject, NULL)){ |
michael@0 | 134 | return (NULL); |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | if (PKIX_PL_Free((PKIX_PL_Object*)issuerAscii, NULL)){ |
michael@0 | 139 | return (NULL); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | if (PKIX_PL_Free((PKIX_PL_Object*)subjectAscii, NULL)){ |
michael@0 | 143 | return (NULL); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | if (errorResult){ |
michael@0 | 147 | return (NULL); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | return (asciiString); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | PKIX_Error * |
michael@0 | 154 | cert_PrintCertChain( |
michael@0 | 155 | PKIX_List *pkixCertChain, |
michael@0 | 156 | void *plContext) |
michael@0 | 157 | { |
michael@0 | 158 | PKIX_PL_Cert *cert = NULL; |
michael@0 | 159 | PKIX_UInt32 numCerts = 0, i = 0; |
michael@0 | 160 | char *asciiResult = NULL; |
michael@0 | 161 | |
michael@0 | 162 | PKIX_ENTER(CERTVFYPKIX, "cert_PrintCertChain"); |
michael@0 | 163 | |
michael@0 | 164 | PKIX_CHECK( |
michael@0 | 165 | PKIX_List_GetLength(pkixCertChain, &numCerts, plContext), |
michael@0 | 166 | PKIX_LISTGETLENGTHFAILED); |
michael@0 | 167 | |
michael@0 | 168 | fprintf(stderr, "\n"); |
michael@0 | 169 | |
michael@0 | 170 | for (i = 0; i < numCerts; i++){ |
michael@0 | 171 | PKIX_CHECK |
michael@0 | 172 | (PKIX_List_GetItem |
michael@0 | 173 | (pkixCertChain, i, (PKIX_PL_Object**)&cert, plContext), |
michael@0 | 174 | PKIX_LISTGETITEMFAILED); |
michael@0 | 175 | |
michael@0 | 176 | asciiResult = pkix_Cert2ASCII(cert); |
michael@0 | 177 | |
michael@0 | 178 | fprintf(stderr, "CERT[%d]:\n%s\n", i, asciiResult); |
michael@0 | 179 | |
michael@0 | 180 | PKIX_PL_Free(asciiResult, plContext); |
michael@0 | 181 | asciiResult = NULL; |
michael@0 | 182 | |
michael@0 | 183 | PKIX_DECREF(cert); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | cleanup: |
michael@0 | 187 | PKIX_DECREF(cert); |
michael@0 | 188 | |
michael@0 | 189 | PKIX_RETURN(CERTVFYPKIX); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | void |
michael@0 | 193 | cert_PrintCert( |
michael@0 | 194 | PKIX_PL_Cert *pkixCert, |
michael@0 | 195 | void *plContext) |
michael@0 | 196 | { |
michael@0 | 197 | char *asciiResult = NULL; |
michael@0 | 198 | |
michael@0 | 199 | asciiResult = pkix_Cert2ASCII(pkixCert); |
michael@0 | 200 | |
michael@0 | 201 | fprintf(stderr, "CERT[0]:\n%s\n", asciiResult); |
michael@0 | 202 | |
michael@0 | 203 | PKIX_PL_Free(asciiResult, plContext); |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | #endif /* DEBUG */ |