Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: chrome/third_party/mozilla_security_manager/nsNSSCertHelper.cpp

Issue 2733014: gtk: Certificate viewer should show both A-label and U-label for CN and SubjectAltName IDNs (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: clarify comment Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 24 matching lines...) Expand all
35 * and other provisions required by the GPL or the LGPL. If you do not delete 35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under 36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL. 37 * the terms of any one of the MPL, the GPL or the LGPL.
38 * 38 *
39 * ***** END LICENSE BLOCK ***** */ 39 * ***** END LICENSE BLOCK ***** */
40 40
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 46
46 #include "app/l10n_util.h" 47 #include "app/l10n_util.h"
47 #include "base/i18n/number_formatting.h" 48 #include "base/i18n/number_formatting.h"
48 #include "base/utf_string_conversions.h" 49 #include "base/utf_string_conversions.h"
49 #include "chrome/third_party/mozilla_security_manager/nsNSSCertTrust.h" 50 #include "chrome/third_party/mozilla_security_manager/nsNSSCertTrust.h"
50 #include "grit/generated_resources.h" 51 #include "grit/generated_resources.h"
51 #include "net/base/net_util.h" 52 #include "net/base/net_util.h"
52 53
53 namespace { 54 namespace {
54 55
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return ret; 160 return ret;
160 } 161 }
161 162
162 std::string ProcessRawBits(SECItem* data) { 163 std::string ProcessRawBits(SECItem* data) {
163 SECItem bytedata; 164 SECItem bytedata;
164 bytedata.data = data->data; 165 bytedata.data = data->data;
165 bytedata.len = data->len / 8; 166 bytedata.len = data->len / 8;
166 return ProcessRawBytes(&bytedata); 167 return ProcessRawBytes(&bytedata);
167 } 168 }
168 169
170 std::string ProcessIDN(const std::string& input) {
171 // Convert the ASCII input to a string16 for ICU.
172 string16 input16;
173 input16.reserve(input.length());
174 std::copy(input.begin(), input.end(), std::back_inserter(input16));
175
176 string16 output16;
177 output16.resize(input.length());
178
179 UErrorCode status = U_ZERO_ERROR;
180 int output_chars = uidna_IDNToUnicode(input16.data(), input.length(),
181 &output16[0], output16.length(),
182 UIDNA_DEFAULT, NULL, &status);
183 if (status == U_ZERO_ERROR) {
184 output16.resize(output_chars);
185 } else if (status != U_BUFFER_OVERFLOW_ERROR) {
186 return input;
187 } else {
188 output16.resize(output_chars);
189 output_chars = uidna_IDNToUnicode(input16.data(), input.length(),
190 &output16[0], output16.length(),
191 UIDNA_DEFAULT, NULL, &status);
192 if (status != U_ZERO_ERROR)
193 return input;
194 DCHECK_EQ(static_cast<size_t>(output_chars), output16.length());
195 output16.resize(output_chars); // Just to be safe.
196 }
197
198 if (input16 == output16)
199 return input; // Input did not contain any encoded data.
200
201 // Input contained encoded data, return formatted string showing original and
202 // decoded forms.
203 return l10n_util::GetStringFUTF8(IDS_CERT_INFO_IDN_VALUE_FORMAT,
204 input16, output16);
205 }
206
169 std::string DumpOidString(SECItem* oid) { 207 std::string DumpOidString(SECItem* oid) {
170 char* pr_string = CERT_GetOidString(oid); 208 char* pr_string = CERT_GetOidString(oid);
171 if (pr_string) { 209 if (pr_string) {
172 std::string rv = pr_string; 210 std::string rv = pr_string;
173 PR_smprintf_free(pr_string); 211 PR_smprintf_free(pr_string);
174 return rv; 212 return rv;
175 } 213 }
176 214
177 return ProcessRawBytes(oid); 215 return ProcessRawBytes(oid);
178 } 216 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 else 414 else
377 string_id = -1; 415 string_id = -1;
378 break; 416 break;
379 } 417 }
380 if (string_id >= 0) 418 if (string_id >= 0)
381 return l10n_util::GetStringUTF8(string_id); 419 return l10n_util::GetStringUTF8(string_id);
382 420
383 return DumpOidString(oid); 421 return DumpOidString(oid);
384 } 422 }
385 423
386
387 // Get a display string from a Relative Distinguished Name. 424 // Get a display string from a Relative Distinguished Name.
388 std::string ProcessRDN(CERTRDN* rdn) { 425 std::string ProcessRDN(CERTRDN* rdn) {
389 std::string rv; 426 std::string rv;
390 427
391 CERTAVA** avas = rdn->avas; 428 CERTAVA** avas = rdn->avas;
392 for (size_t i = 0; avas[i] != NULL; ++i) { 429 for (size_t i = 0; avas[i] != NULL; ++i) {
393 rv += GetOIDText(&avas[i]->type); 430 rv += GetOIDText(&avas[i]->type);
394 SECItem* decode_item = CERT_DecodeAVAValue(&avas[i]->value); 431 SECItem* decode_item = CERT_DecodeAVAValue(&avas[i]->value);
395 if (decode_item) { 432 if (decode_item) {
396 // TODO(mattm): Pass decode_item to CERT_RFC1485_EscapeAndQuote. 433 // TODO(mattm): Pass decode_item to CERT_RFC1485_EscapeAndQuote.
397 rv += " = "; 434 rv += " = ";
398 std::string value(reinterpret_cast<char*>(decode_item->data), 435 std::string value(reinterpret_cast<char*>(decode_item->data),
399 decode_item->len); 436 decode_item->len);
437 if (SECOID_FindOIDTag(&avas[i]->type) == SEC_OID_AVA_COMMON_NAME)
438 value = ProcessIDN(value);
400 rv += value; 439 rv += value;
401 SECITEM_FreeItem(decode_item, PR_TRUE); 440 SECITEM_FreeItem(decode_item, PR_TRUE);
402 } 441 }
403 rv += '\n'; 442 rv += '\n';
404 } 443 }
405 444
406 return rv; 445 return rv;
407 } 446 }
408 447
409 std::string ProcessName(CERTName* name) { 448 std::string ProcessName(CERTName* name) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 } 533 }
495 case certRFC822Name: 534 case certRFC822Name:
496 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_RFC822_NAME); 535 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_RFC822_NAME);
497 value = std::string(reinterpret_cast<char*>(current->name.other.data), 536 value = std::string(reinterpret_cast<char*>(current->name.other.data),
498 current->name.other.len); 537 current->name.other.len);
499 break; 538 break;
500 case certDNSName: 539 case certDNSName:
501 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_DNS_NAME); 540 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_DNS_NAME);
502 value = std::string(reinterpret_cast<char*>(current->name.other.data), 541 value = std::string(reinterpret_cast<char*>(current->name.other.data),
503 current->name.other.len); 542 current->name.other.len);
543 value = ProcessIDN(value);
504 break; 544 break;
505 case certX400Address: 545 case certX400Address:
506 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_X400_ADDRESS); 546 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_X400_ADDRESS);
507 value = ProcessRawBytes(&current->name.other); 547 value = ProcessRawBytes(&current->name.other);
508 break; 548 break;
509 case certDirectoryName: 549 case certDirectoryName:
510 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_DIRECTORY_NAME); 550 key = l10n_util::GetStringUTF8(IDS_CERT_GENERAL_NAME_DIRECTORY_NAME);
511 value = ProcessName(&current->name.directoryName); 551 value = ProcessName(&current->name.directoryName);
512 break; 552 break;
513 case certEDIPartyName: 553 case certEDIPartyName:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 601
562 std::string ProcessGeneralNames(PRArenaPool* arena, 602 std::string ProcessGeneralNames(PRArenaPool* arena,
563 CERTGeneralName* name_list) { 603 CERTGeneralName* name_list) {
564 std::string rv; 604 std::string rv;
565 CERTGeneralName* current = name_list; 605 CERTGeneralName* current = name_list;
566 606
567 do { 607 do {
568 std::string text = ProcessGeneralName(arena, current); 608 std::string text = ProcessGeneralName(arena, current);
569 if (text.empty()) 609 if (text.empty())
570 break; 610 break;
571 rv += text + '\n'; 611 rv += text;
572 current = CERT_GetNextGeneralName(current); 612 current = CERT_GetNextGeneralName(current);
573 } while (current != name_list); 613 } while (current != name_list);
574 return rv; 614 return rv;
575 } 615 }
576 616
577 std::string ProcessAltName(SECItem* extension_data) { 617 std::string ProcessAltName(SECItem* extension_data) {
578 CERTGeneralName* name_list; 618 CERTGeneralName* name_list;
579 619
580 ScopedPRArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); 620 ScopedPRArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE));
581 CHECK(arena.get()); 621 CHECK(arena.get());
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 if (trust.HasPeer(PR_FALSE, PR_TRUE, PR_FALSE) && cert->emailAddr) 980 if (trust.HasPeer(PR_FALSE, PR_TRUE, PR_FALSE) && cert->emailAddr)
941 return EMAIL_CERT; 981 return EMAIL_CERT;
942 if (CERT_IsCACert(cert, NULL)) 982 if (CERT_IsCACert(cert, NULL))
943 return CA_CERT; 983 return CA_CERT;
944 if (cert->emailAddr) 984 if (cert->emailAddr)
945 return EMAIL_CERT; 985 return EMAIL_CERT;
946 return UNKNOWN_CERT; 986 return UNKNOWN_CERT;
947 } 987 }
948 988
949 } // namespace mozilla_security_manager 989 } // namespace mozilla_security_manager
OLDNEW
« no previous file with comments | « chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698