Chromium Code Reviews| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 // receive a status of NONE in a serialized SSLStatus. | 43 // receive a status of NONE in a serialized SSLStatus. |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 namespace content { | 51 namespace content { |
| 52 | 52 |
| 53 std::string SerializeSecurityInfo(const SSLStatus& ssl_status) { | 53 std::string SerializeSecurityInfo(const SSLStatus& ssl_status) { |
|
nasko
2016/09/01 17:15:22
The result of this is never persisted on disk, rig
davidben
2016/09/02 21:48:05
I don't think so, no. (We've done other incompatib
| |
| 54 base::Pickle pickle; | 54 base::Pickle pickle; |
| 55 pickle.WriteInt(ssl_status.security_style); | 55 pickle.WriteInt(ssl_status.security_style); |
| 56 pickle.WriteInt(ssl_status.cert_id); | 56 pickle.WriteInt(ssl_status.cert_id); |
| 57 pickle.WriteUInt32(ssl_status.cert_status); | 57 pickle.WriteUInt32(ssl_status.cert_status); |
| 58 pickle.WriteInt(ssl_status.security_bits); | 58 pickle.WriteInt(ssl_status.security_bits); |
| 59 pickle.WriteInt(ssl_status.key_exchange_info); | 59 pickle.WriteUInt16(ssl_status.key_exchange_group); |
| 60 pickle.WriteInt(ssl_status.connection_status); | 60 pickle.WriteInt(ssl_status.connection_status); |
| 61 pickle.WriteUInt32(ssl_status.sct_statuses.size()); | 61 pickle.WriteUInt32(ssl_status.sct_statuses.size()); |
| 62 for (const auto& sct_status : ssl_status.sct_statuses) { | 62 for (const auto& sct_status : ssl_status.sct_statuses) { |
| 63 pickle.WriteUInt32(sct_status); | 63 pickle.WriteUInt32(sct_status); |
| 64 } | 64 } |
| 65 pickle.WriteBool(ssl_status.pkp_bypassed); | 65 pickle.WriteBool(ssl_status.pkp_bypassed); |
| 66 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); | 66 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool DeserializeSecurityInfo(const std::string& state, SSLStatus* ssl_status) { | 69 bool DeserializeSecurityInfo(const std::string& state, SSLStatus* ssl_status) { |
| 70 *ssl_status = SSLStatus(); | 70 *ssl_status = SSLStatus(); |
| 71 | 71 |
| 72 if (state.empty()) { | 72 if (state.empty()) { |
| 73 // No SSL used. | 73 // No SSL used. |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 | 76 |
| 77 base::Pickle pickle(state.data(), base::checked_cast<int>(state.size())); | 77 base::Pickle pickle(state.data(), base::checked_cast<int>(state.size())); |
| 78 base::PickleIterator iter(pickle); | 78 base::PickleIterator iter(pickle); |
| 79 int security_style; | 79 int security_style; |
| 80 if (!iter.ReadInt(&security_style) || !iter.ReadInt(&ssl_status->cert_id) || | 80 if (!iter.ReadInt(&security_style) || !iter.ReadInt(&ssl_status->cert_id) || |
| 81 !iter.ReadUInt32(&ssl_status->cert_status) || | 81 !iter.ReadUInt32(&ssl_status->cert_status) || |
| 82 !iter.ReadInt(&ssl_status->security_bits) || | 82 !iter.ReadInt(&ssl_status->security_bits) || |
| 83 !iter.ReadInt(&ssl_status->key_exchange_info) || | 83 !iter.ReadUInt16(&ssl_status->key_exchange_group) || |
| 84 !iter.ReadInt(&ssl_status->connection_status)) { | 84 !iter.ReadInt(&ssl_status->connection_status)) { |
| 85 *ssl_status = SSLStatus(); | 85 *ssl_status = SSLStatus(); |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 uint32_t num_sct_statuses; | 89 uint32_t num_sct_statuses; |
| 90 if (!iter.ReadUInt32(&num_sct_statuses)) { | 90 if (!iter.ReadUInt32(&num_sct_statuses)) { |
| 91 return false; | 91 return false; |
| 92 } | 92 } |
| 93 | 93 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 112 } | 112 } |
| 113 | 113 |
| 114 ssl_status->security_style = static_cast<SecurityStyle>(security_style); | 114 ssl_status->security_style = static_cast<SecurityStyle>(security_style); |
| 115 | 115 |
| 116 // Sanity check |security_bits|: the only allowed negative value is -1. | 116 // Sanity check |security_bits|: the only allowed negative value is -1. |
| 117 if (ssl_status->security_bits < -1) { | 117 if (ssl_status->security_bits < -1) { |
| 118 *ssl_status = SSLStatus(); | 118 *ssl_status = SSLStatus(); |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Sanity check |key_exchange_info|: 0 or greater. | |
| 123 if (ssl_status->key_exchange_info < 0) { | |
| 124 *ssl_status = SSLStatus(); | |
| 125 return false; | |
| 126 } | |
| 127 | |
| 128 return true; | 122 return true; |
| 129 } | 123 } |
| 130 | 124 |
| 131 } // namespace content | 125 } // namespace content |
| OLD | NEW |