OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/ssl_status_serialization.h" | 5 #include "content/common/ssl_status_serialization.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string> | |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/pickle.h" | 11 #include "base/pickle.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 // Checks that an integer |security_style| is a valid SecurityStyle enum | 15 // Checks that an integer |security_style| is a valid SecurityStyle enum |
15 // value. Returns true if valid, false otherwise. | 16 // value. Returns true if valid, false otherwise. |
16 bool CheckSecurityStyle(int security_style) { | 17 bool CheckSecurityStyle(int security_style) { |
17 switch (security_style) { | 18 switch (security_style) { |
(...skipping 18 matching lines...) Expand all Loading... | |
36 pickle.WriteUInt32(ssl_status.cert_status); | 37 pickle.WriteUInt32(ssl_status.cert_status); |
37 pickle.WriteInt(ssl_status.security_bits); | 38 pickle.WriteInt(ssl_status.security_bits); |
38 pickle.WriteInt(ssl_status.key_exchange_info); | 39 pickle.WriteInt(ssl_status.key_exchange_info); |
39 pickle.WriteInt(ssl_status.connection_status); | 40 pickle.WriteInt(ssl_status.connection_status); |
40 pickle.WriteInt(ssl_status.signed_certificate_timestamp_ids.size()); | 41 pickle.WriteInt(ssl_status.signed_certificate_timestamp_ids.size()); |
41 for (SignedCertificateTimestampIDStatusList::const_iterator iter = | 42 for (SignedCertificateTimestampIDStatusList::const_iterator iter = |
42 ssl_status.signed_certificate_timestamp_ids.begin(); | 43 ssl_status.signed_certificate_timestamp_ids.begin(); |
43 iter != ssl_status.signed_certificate_timestamp_ids.end(); ++iter) { | 44 iter != ssl_status.signed_certificate_timestamp_ids.end(); ++iter) { |
44 pickle.WriteInt(iter->id); | 45 pickle.WriteInt(iter->id); |
45 pickle.WriteUInt16(iter->status); | 46 pickle.WriteUInt16(iter->status); |
47 pickle.WriteUInt16(iter->version); | |
Eran Messeri
2016/03/09 21:04:35
If that's saved to disk (I think it is, not entire
| |
48 pickle.WriteString(iter->logId); | |
49 pickle.WriteInt64(iter->timestamp); | |
50 pickle.WriteUInt16(iter->signature.hash_algorithm); | |
51 pickle.WriteUInt16(iter->signature.signature_algorithm); | |
52 pickle.WriteString(iter->signature.signature_data); | |
53 pickle.WriteUInt16(iter->origin); | |
54 pickle.WriteString(iter->logDescription); | |
46 } | 55 } |
47 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); | 56 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); |
48 } | 57 } |
49 | 58 |
50 bool DeserializeSecurityInfo(const std::string& state, SSLStatus* ssl_status) { | 59 bool DeserializeSecurityInfo(const std::string& state, SSLStatus* ssl_status) { |
51 *ssl_status = SSLStatus(); | 60 *ssl_status = SSLStatus(); |
52 | 61 |
53 if (state.empty()) { | 62 if (state.empty()) { |
54 // No SSL used. | 63 // No SSL used. |
55 return true; | 64 return true; |
(...skipping 28 matching lines...) Expand all Loading... | |
84 | 93 |
85 // Sanity check |key_exchange_info|: 0 or greater. | 94 // Sanity check |key_exchange_info|: 0 or greater. |
86 if (ssl_status->key_exchange_info < 0) { | 95 if (ssl_status->key_exchange_info < 0) { |
87 *ssl_status = SSLStatus(); | 96 *ssl_status = SSLStatus(); |
88 return false; | 97 return false; |
89 } | 98 } |
90 | 99 |
91 for (; num_scts_to_read > 0; --num_scts_to_read) { | 100 for (; num_scts_to_read > 0; --num_scts_to_read) { |
92 int id; | 101 int id; |
93 uint16_t status; | 102 uint16_t status; |
94 if (!iter.ReadInt(&id) || !iter.ReadUInt16(&status)) { | 103 uint16_t version; |
104 std::string logId; | |
105 int64_t timestamp; | |
106 uint16_t hashAlgorithm; | |
107 uint16_t signatureAlgorithm; | |
108 std::string signatureData; | |
109 uint16_t origin; | |
110 std::string logDescription; | |
111 if (!iter.ReadInt(&id) | |
112 || !iter.ReadUInt16(&status) | |
113 || !iter.ReadUInt16(&version) | |
114 || !iter.ReadString(&logId) | |
115 || !iter.ReadInt64(×tamp) | |
116 || !iter.ReadUInt16(&hashAlgorithm) | |
117 || !iter.ReadUInt16(&signatureAlgorithm) | |
118 || !iter.ReadString(&signatureData) | |
119 || !iter.ReadUInt16(&origin) | |
120 || !iter.ReadString(&logDescription)) { | |
95 *ssl_status = SSLStatus(); | 121 *ssl_status = SSLStatus(); |
96 return false; | 122 return false; |
97 } | 123 } |
98 | 124 |
125 net::ct::DigitallySigned signature( | |
126 static_cast<net::ct::DigitallySigned::HashAlgorithm>(hashAlgorithm), | |
127 static_cast<net::ct::DigitallySigned::SignatureAlgorithm>( | |
128 signatureAlgorithm), | |
129 signatureData); | |
130 | |
99 ssl_status->signed_certificate_timestamp_ids.push_back( | 131 ssl_status->signed_certificate_timestamp_ids.push_back( |
100 SignedCertificateTimestampIDAndStatus( | 132 SignedCertificateTimestampIDAndStatus( |
101 id, static_cast<net::ct::SCTVerifyStatus>(status))); | 133 id, |
134 static_cast<net::ct::SCTVerifyStatus>(status), | |
135 static_cast<net::ct::SignedCertificateTimestamp::Version>(version), | |
136 logId, | |
137 timestamp, | |
138 signature, | |
139 static_cast<net::ct::SignedCertificateTimestamp::Origin>(origin), | |
140 logDescription)); | |
102 } | 141 } |
103 | 142 |
104 return true; | 143 return true; |
105 } | 144 } |
106 | 145 |
107 } // namespace content | 146 } // namespace content |
OLD | NEW |