OLD | NEW |
1 /* ***** BEGIN LICENSE BLOCK ***** | 1 /* ***** BEGIN LICENSE BLOCK ***** |
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
3 * | 3 * |
4 * The contents of this file are subject to the Mozilla Public License Version | 4 * The contents of this file are subject to the Mozilla Public License Version |
5 * 1.1 (the "License"); you may not use this file except in compliance with | 5 * 1.1 (the "License"); you may not use this file except in compliance with |
6 * the License. You may obtain a copy of the License at | 6 * the License. You may obtain a copy of the License at |
7 * http://www.mozilla.org/MPL/ | 7 * http://www.mozilla.org/MPL/ |
8 * | 8 * |
9 * Software distributed under the License is distributed on an "AS IS" basis, | 9 * Software distributed under the License is distributed on an "AS IS" basis, |
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h" | 41 #include "chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h" |
42 | 42 |
43 #include <keyhi.h> | 43 #include <keyhi.h> |
44 #include <prprf.h> | 44 #include <prprf.h> |
45 #include <unicode/uidna.h> | 45 #include <unicode/uidna.h> |
46 | 46 |
47 #include "app/l10n_util.h" | 47 #include "app/l10n_util.h" |
48 #include "base/i18n/number_formatting.h" | 48 #include "base/i18n/number_formatting.h" |
49 #include "base/string_number_conversions.h" | 49 #include "base/string_number_conversions.h" |
50 #include "base/utf_string_conversions.h" | 50 #include "base/utf_string_conversions.h" |
| 51 #include "chrome/common/net/x509_certificate_model.h" |
51 #include "grit/generated_resources.h" | 52 #include "grit/generated_resources.h" |
52 #include "net/base/net_util.h" | 53 #include "net/base/net_util.h" |
53 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h" | 54 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h" |
54 | 55 |
55 namespace { | 56 namespace { |
56 | 57 |
57 std::string BMPtoUTF8(PRArenaPool* arena, unsigned char* data, | 58 std::string BMPtoUTF8(PRArenaPool* arena, unsigned char* data, |
58 unsigned int len) { | 59 unsigned int len) { |
59 if (len % 2 != 0) | 60 if (len % 2 != 0) |
60 return l10n_util::GetStringUTF8(IDS_CERT_EXTENSION_DUMP_ERROR); | 61 return l10n_util::GetStringUTF8(IDS_CERT_EXTENSION_DUMP_ERROR); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 return ret; | 162 return ret; |
162 } | 163 } |
163 | 164 |
164 std::string ProcessRawBits(SECItem* data) { | 165 std::string ProcessRawBits(SECItem* data) { |
165 SECItem bytedata; | 166 SECItem bytedata; |
166 bytedata.data = data->data; | 167 bytedata.data = data->data; |
167 bytedata.len = data->len / 8; | 168 bytedata.len = data->len / 8; |
168 return ProcessRawBytes(&bytedata); | 169 return ProcessRawBytes(&bytedata); |
169 } | 170 } |
170 | 171 |
171 std::string ProcessIDN(const std::string& input) { | |
172 // Convert the ASCII input to a string16 for ICU. | |
173 string16 input16; | |
174 input16.reserve(input.length()); | |
175 std::copy(input.begin(), input.end(), std::back_inserter(input16)); | |
176 | |
177 string16 output16; | |
178 output16.resize(input.length()); | |
179 | |
180 UErrorCode status = U_ZERO_ERROR; | |
181 int output_chars = uidna_IDNToUnicode(input16.data(), input.length(), | |
182 &output16[0], output16.length(), | |
183 UIDNA_DEFAULT, NULL, &status); | |
184 if (status == U_ZERO_ERROR) { | |
185 output16.resize(output_chars); | |
186 } else if (status != U_BUFFER_OVERFLOW_ERROR) { | |
187 return input; | |
188 } else { | |
189 output16.resize(output_chars); | |
190 output_chars = uidna_IDNToUnicode(input16.data(), input.length(), | |
191 &output16[0], output16.length(), | |
192 UIDNA_DEFAULT, NULL, &status); | |
193 if (status != U_ZERO_ERROR) | |
194 return input; | |
195 DCHECK_EQ(static_cast<size_t>(output_chars), output16.length()); | |
196 output16.resize(output_chars); // Just to be safe. | |
197 } | |
198 | |
199 if (input16 == output16) | |
200 return input; // Input did not contain any encoded data. | |
201 | |
202 // Input contained encoded data, return formatted string showing original and | |
203 // decoded forms. | |
204 return l10n_util::GetStringFUTF8(IDS_CERT_INFO_IDN_VALUE_FORMAT, | |
205 input16, output16); | |
206 } | |
207 | |
208 std::string DumpOidString(SECItem* oid) { | 172 std::string DumpOidString(SECItem* oid) { |
209 char* pr_string = CERT_GetOidString(oid); | 173 char* pr_string = CERT_GetOidString(oid); |
210 if (pr_string) { | 174 if (pr_string) { |
211 std::string rv = pr_string; | 175 std::string rv = pr_string; |
212 PR_smprintf_free(pr_string); | 176 PR_smprintf_free(pr_string); |
213 return rv; | 177 return rv; |
214 } | 178 } |
215 | 179 |
216 return ProcessRawBytes(oid); | 180 return ProcessRawBytes(oid); |
217 } | 181 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 CERTAVA** avas = rdn->avas; | 399 CERTAVA** avas = rdn->avas; |
436 for (size_t i = 0; avas[i] != NULL; ++i) { | 400 for (size_t i = 0; avas[i] != NULL; ++i) { |
437 rv += GetOIDText(&avas[i]->type); | 401 rv += GetOIDText(&avas[i]->type); |
438 SECItem* decode_item = CERT_DecodeAVAValue(&avas[i]->value); | 402 SECItem* decode_item = CERT_DecodeAVAValue(&avas[i]->value); |
439 if (decode_item) { | 403 if (decode_item) { |
440 // TODO(mattm): Pass decode_item to CERT_RFC1485_EscapeAndQuote. | 404 // TODO(mattm): Pass decode_item to CERT_RFC1485_EscapeAndQuote. |
441 rv += " = "; | 405 rv += " = "; |
442 std::string value(reinterpret_cast<char*>(decode_item->data), | 406 std::string value(reinterpret_cast<char*>(decode_item->data), |
443 decode_item->len); | 407 decode_item->len); |
444 if (SECOID_FindOIDTag(&avas[i]->type) == SEC_OID_AVA_COMMON_NAME) | 408 if (SECOID_FindOIDTag(&avas[i]->type) == SEC_OID_AVA_COMMON_NAME) |
445 value = ProcessIDN(value); | 409 value = x509_certificate_model::ProcessIDN(value); |
446 rv += value; | 410 rv += value; |
447 SECITEM_FreeItem(decode_item, PR_TRUE); | 411 SECITEM_FreeItem(decode_item, PR_TRUE); |
448 } | 412 } |
449 rv += '\n'; | 413 rv += '\n'; |
450 } | 414 } |
451 | 415 |
452 return rv; | 416 return rv; |
453 } | 417 } |
454 | 418 |
455 std::string ProcessName(CERTName* name) { | 419 std::string ProcessName(CERTName* name) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 } | 504 } |
541 case certRFC822Name: | 505 case certRFC822Name: |
542 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_RFC822_NAME); | 506 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_RFC822_NAME); |
543 value = std::string(reinterpret_cast<char*>(current->name.other.data), | 507 value = std::string(reinterpret_cast<char*>(current->name.other.data), |
544 current->name.other.len); | 508 current->name.other.len); |
545 break; | 509 break; |
546 case certDNSName: | 510 case certDNSName: |
547 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_DNS_NAME); | 511 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_DNS_NAME); |
548 value = std::string(reinterpret_cast<char*>(current->name.other.data), | 512 value = std::string(reinterpret_cast<char*>(current->name.other.data), |
549 current->name.other.len); | 513 current->name.other.len); |
550 value = ProcessIDN(value); | 514 value = x509_certificate_model::ProcessIDN(value); |
551 break; | 515 break; |
552 case certX400Address: | 516 case certX400Address: |
553 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_X400_ADDRESS); | 517 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_X400_ADDRESS); |
554 value = ProcessRawBytes(¤t->name.other); | 518 value = ProcessRawBytes(¤t->name.other); |
555 break; | 519 break; |
556 case certDirectoryName: | 520 case certDirectoryName: |
557 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_DIRECTORY_NAME); | 521 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_DIRECTORY_NAME); |
558 value = ProcessName(¤t->name.directoryName); | 522 value = ProcessName(¤t->name.directoryName); |
559 break; | 523 break; |
560 case certEDIPartyName: | 524 case certEDIPartyName: |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 if (trust.HasPeer(PR_FALSE, PR_TRUE, PR_FALSE) && cert->emailAddr) | 1064 if (trust.HasPeer(PR_FALSE, PR_TRUE, PR_FALSE) && cert->emailAddr) |
1101 return net::EMAIL_CERT; | 1065 return net::EMAIL_CERT; |
1102 if (CERT_IsCACert(cert, NULL)) | 1066 if (CERT_IsCACert(cert, NULL)) |
1103 return net::CA_CERT; | 1067 return net::CA_CERT; |
1104 if (cert->emailAddr) | 1068 if (cert->emailAddr) |
1105 return net::EMAIL_CERT; | 1069 return net::EMAIL_CERT; |
1106 return net::UNKNOWN_CERT; | 1070 return net::UNKNOWN_CERT; |
1107 } | 1071 } |
1108 | 1072 |
1109 } // namespace mozilla_security_manager | 1073 } // namespace mozilla_security_manager |
OLD | NEW |