OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cert/ct_signed_certificate_timestamp_log_param.h" | 5 #include "net/cert/ct_signed_certificate_timestamp_log_param.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "net/cert/ct_sct_to_string.h" |
16 #include "net/cert/ct_verify_result.h" | 17 #include "net/cert/ct_verify_result.h" |
17 #include "net/cert/signed_certificate_timestamp.h" | 18 #include "net/cert/signed_certificate_timestamp.h" |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Converts a numeric |origin| to text describing the SCT's origin | |
24 const char* OriginToString(ct::SignedCertificateTimestamp::Origin origin) { | |
25 switch (origin) { | |
26 case ct::SignedCertificateTimestamp::SCT_EMBEDDED: | |
27 return "embedded_in_certificate"; | |
28 case ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION: | |
29 return "tls_extension"; | |
30 case ct::SignedCertificateTimestamp::SCT_FROM_OCSP_RESPONSE: | |
31 return "ocsp"; | |
32 case ct::SignedCertificateTimestamp::SCT_ORIGIN_MAX: | |
33 break; | |
34 } | |
35 | |
36 return "unknown"; | |
37 } | |
38 | |
39 // Converts a numeric |hash_algorithm| to its textual representation | |
40 const char* HashAlgorithmToString( | |
41 ct::DigitallySigned::HashAlgorithm hash_algorithm) { | |
42 switch (hash_algorithm) { | |
43 case ct::DigitallySigned::HASH_ALGO_NONE: | |
44 return "NONE"; | |
45 case ct::DigitallySigned::HASH_ALGO_MD5: | |
46 return "MD5"; | |
47 case ct::DigitallySigned::HASH_ALGO_SHA1: | |
48 return "SHA1"; | |
49 case ct::DigitallySigned::HASH_ALGO_SHA224: | |
50 return "SHA224"; | |
51 case ct::DigitallySigned::HASH_ALGO_SHA256: | |
52 return "SHA256"; | |
53 case ct::DigitallySigned::HASH_ALGO_SHA384: | |
54 return "SHA384"; | |
55 case ct::DigitallySigned::HASH_ALGO_SHA512: | |
56 return "SHA512"; | |
57 } | |
58 | |
59 return "unknown"; | |
60 } | |
61 | |
62 // Converts a numeric |signature_algorithm| to its textual representation | |
63 const char* SignatureAlgorithmToString( | |
64 ct::DigitallySigned::SignatureAlgorithm signature_algorithm) { | |
65 switch (signature_algorithm) { | |
66 case ct::DigitallySigned::SIG_ALGO_ANONYMOUS: | |
67 return "ANONYMOUS"; | |
68 case ct::DigitallySigned::SIG_ALGO_RSA: | |
69 return "RSA"; | |
70 case ct::DigitallySigned::SIG_ALGO_DSA: | |
71 return "DSA"; | |
72 case ct::DigitallySigned::SIG_ALGO_ECDSA: | |
73 return "ECDSA"; | |
74 } | |
75 | |
76 return "unknown"; | |
77 } | |
78 | |
79 // Base64 encode the given |value| string and put it in |dict| with the | 24 // Base64 encode the given |value| string and put it in |dict| with the |
80 // description |key|. | 25 // description |key|. |
81 void SetBinaryData( | 26 void SetBinaryData( |
82 const char* key, | 27 const char* key, |
83 const std::string& value, | 28 const std::string& value, |
84 base::DictionaryValue* dict) { | 29 base::DictionaryValue* dict) { |
85 std::string b64_value; | 30 std::string b64_value; |
86 base::Base64Encode(value, &b64_value); | 31 base::Base64Encode(value, &b64_value); |
87 | 32 |
88 dict->SetString(key, b64_value); | 33 dict->SetString(key, b64_value); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 98 |
154 SetBinaryData("embedded_scts", *embedded_scts, dict.get()); | 99 SetBinaryData("embedded_scts", *embedded_scts, dict.get()); |
155 SetBinaryData("scts_from_ocsp_response", *sct_list_from_ocsp, dict.get()); | 100 SetBinaryData("scts_from_ocsp_response", *sct_list_from_ocsp, dict.get()); |
156 SetBinaryData("scts_from_tls_extension", *sct_list_from_tls_extension, | 101 SetBinaryData("scts_from_tls_extension", *sct_list_from_tls_extension, |
157 dict.get()); | 102 dict.get()); |
158 | 103 |
159 return std::move(dict); | 104 return std::move(dict); |
160 } | 105 } |
161 | 106 |
162 } // namespace net | 107 } // namespace net |
OLD | NEW |