| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "remoting/protocol/v1_authenticator.h" | 5 #include "remoting/protocol/v1_authenticator.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "crypto/rsa_private_key.h" | 9 #include "crypto/rsa_private_key.h" |
| 10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 ChannelAuthenticator* | 82 ChannelAuthenticator* |
| 83 V1ClientAuthenticator::CreateChannelAuthenticator() const { | 83 V1ClientAuthenticator::CreateChannelAuthenticator() const { |
| 84 DCHECK_EQ(state_, ACCEPTED); | 84 DCHECK_EQ(state_, ACCEPTED); |
| 85 return new V1ClientChannelAuthenticator(remote_cert_, shared_secret_); | 85 return new V1ClientChannelAuthenticator(remote_cert_, shared_secret_); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 V1HostAuthenticator::V1HostAuthenticator( | 88 V1HostAuthenticator::V1HostAuthenticator( |
| 89 const std::string& local_cert, | 89 const std::string& local_cert, |
| 90 crypto::RSAPrivateKey* local_private_key, | 90 const crypto::RSAPrivateKey* local_private_key, |
| 91 const std::string& shared_secret, | 91 const std::string& shared_secret, |
| 92 const std::string& remote_jid) | 92 const std::string& remote_jid) |
| 93 : local_cert_(local_cert), | 93 : local_cert_(local_cert), |
| 94 local_private_key_(local_private_key), | 94 local_private_key_(local_private_key->Copy()), |
| 95 shared_secret_(shared_secret), | 95 shared_secret_(shared_secret), |
| 96 remote_jid_(remote_jid), | 96 remote_jid_(remote_jid), |
| 97 state_(WAITING_MESSAGE) { | 97 state_(WAITING_MESSAGE) { |
| 98 } | 98 } |
| 99 | 99 |
| 100 V1HostAuthenticator::~V1HostAuthenticator() { | 100 V1HostAuthenticator::~V1HostAuthenticator() { |
| 101 } | 101 } |
| 102 | 102 |
| 103 Authenticator::State V1HostAuthenticator::state() const { | 103 Authenticator::State V1HostAuthenticator::state() const { |
| 104 return state_; | 104 return state_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 134 message->AddElement(certificate_tag); | 134 message->AddElement(certificate_tag); |
| 135 | 135 |
| 136 state_ = ACCEPTED; | 136 state_ = ACCEPTED; |
| 137 return message; | 137 return message; |
| 138 } | 138 } |
| 139 | 139 |
| 140 ChannelAuthenticator* | 140 ChannelAuthenticator* |
| 141 V1HostAuthenticator::CreateChannelAuthenticator() const { | 141 V1HostAuthenticator::CreateChannelAuthenticator() const { |
| 142 DCHECK_EQ(state_, ACCEPTED); | 142 DCHECK_EQ(state_, ACCEPTED); |
| 143 return new V1HostChannelAuthenticator( | 143 return new V1HostChannelAuthenticator( |
| 144 local_cert_, local_private_key_, shared_secret_); | 144 local_cert_, local_private_key_.get(), shared_secret_); |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 V1HostAuthenticatorFactory::V1HostAuthenticatorFactory( | 147 V1HostAuthenticatorFactory::V1HostAuthenticatorFactory( |
| 148 const std::string& local_cert, | 148 const std::string& local_cert, |
| 149 crypto::RSAPrivateKey* local_private_key, | 149 const crypto::RSAPrivateKey* local_private_key, |
| 150 const std::string& shared_secret) | 150 const std::string& shared_secret) |
| 151 : local_cert_(local_cert), | 151 : local_cert_(local_cert), |
| 152 local_private_key_(local_private_key->Copy()), |
| 152 shared_secret_(shared_secret) { | 153 shared_secret_(shared_secret) { |
| 153 DCHECK(local_private_key); | |
| 154 | |
| 155 // TODO(hclam): Need a better way to clone a key. See crbug.com/105220 . | |
| 156 std::vector<uint8> key_bytes; | |
| 157 CHECK(local_private_key->ExportPrivateKey(&key_bytes)); | |
| 158 local_private_key_.reset( | |
| 159 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes)); | |
| 160 CHECK(local_private_key_.get()); | 154 CHECK(local_private_key_.get()); |
| 161 } | 155 } |
| 162 | 156 |
| 163 V1HostAuthenticatorFactory::~V1HostAuthenticatorFactory() { | 157 V1HostAuthenticatorFactory::~V1HostAuthenticatorFactory() { |
| 164 } | 158 } |
| 165 | 159 |
| 166 Authenticator* V1HostAuthenticatorFactory::CreateAuthenticator( | 160 Authenticator* V1HostAuthenticatorFactory::CreateAuthenticator( |
| 167 const std::string& remote_jid, | 161 const std::string& remote_jid, |
| 168 const buzz::XmlElement* first_message) { | 162 const buzz::XmlElement* first_message) { |
| 169 return new V1HostAuthenticator(local_cert_, local_private_key_.get(), | 163 return new V1HostAuthenticator(local_cert_, local_private_key_.get(), |
| 170 shared_secret_, remote_jid); | 164 shared_secret_, remote_jid); |
| 171 } | 165 } |
| 172 | 166 |
| 173 } // namespace remoting | 167 } // namespace remoting |
| 174 } // namespace protocol | 168 } // namespace protocol |
| OLD | NEW |