| 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 "remoting/protocol/v2_authenticator.h" | 5 #include "remoting/protocol/v2_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 17 matching lines...) Expand all Loading... |
| 28 "certificate" }; | 28 "certificate" }; |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 bool V2Authenticator::IsEkeMessage(const buzz::XmlElement* message) { | 33 bool V2Authenticator::IsEkeMessage(const buzz::XmlElement* message) { |
| 34 return message->FirstNamed(kEkeTag) != NULL; | 34 return message->FirstNamed(kEkeTag) != NULL; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 V2Authenticator* V2Authenticator::CreateForClient( | 38 scoped_ptr<Authenticator> V2Authenticator::CreateForClient( |
| 39 const std::string& shared_secret) { | 39 const std::string& shared_secret) { |
| 40 return new V2Authenticator( | 40 return scoped_ptr<Authenticator>(new V2Authenticator( |
| 41 P224EncryptedKeyExchange::kPeerTypeClient, shared_secret); | 41 P224EncryptedKeyExchange::kPeerTypeClient, shared_secret)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // static | 44 // static |
| 45 V2Authenticator* V2Authenticator::CreateForHost( | 45 scoped_ptr<Authenticator> V2Authenticator::CreateForHost( |
| 46 const std::string& local_cert, | 46 const std::string& local_cert, |
| 47 const crypto::RSAPrivateKey& local_private_key, | 47 const crypto::RSAPrivateKey& local_private_key, |
| 48 const std::string& shared_secret) { | 48 const std::string& shared_secret) { |
| 49 V2Authenticator* result = new V2Authenticator( | 49 V2Authenticator* result = new V2Authenticator( |
| 50 P224EncryptedKeyExchange::kPeerTypeServer, shared_secret); | 50 P224EncryptedKeyExchange::kPeerTypeServer, shared_secret); |
| 51 result->local_cert_ = local_cert; | 51 result->local_cert_ = local_cert; |
| 52 result->local_private_key_.reset(local_private_key.Copy()); | 52 result->local_private_key_.reset(local_private_key.Copy()); |
| 53 result->state_ = WAITING_MESSAGE; | 53 result->state_ = WAITING_MESSAGE; |
| 54 return result; | 54 return scoped_ptr<Authenticator>(result); |
| 55 } | 55 } |
| 56 | 56 |
| 57 V2Authenticator::V2Authenticator( | 57 V2Authenticator::V2Authenticator( |
| 58 crypto::P224EncryptedKeyExchange::PeerType type, | 58 crypto::P224EncryptedKeyExchange::PeerType type, |
| 59 const std::string& shared_secret) | 59 const std::string& shared_secret) |
| 60 : certificate_sent_(false), | 60 : certificate_sent_(false), |
| 61 key_exchange_impl_(type, shared_secret), | 61 key_exchange_impl_(type, shared_secret), |
| 62 state_(MESSAGE_READY) { | 62 state_(MESSAGE_READY) { |
| 63 pending_messages_.push(key_exchange_impl_.GetMessage()); | 63 pending_messages_.push(key_exchange_impl_.GetMessage()); |
| 64 } | 64 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 case P224EncryptedKeyExchange::kResultSuccess: | 122 case P224EncryptedKeyExchange::kResultSuccess: |
| 123 auth_key_ = key_exchange_impl_.GetKey(); | 123 auth_key_ = key_exchange_impl_.GetKey(); |
| 124 state_ = ACCEPTED; | 124 state_ = ACCEPTED; |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 state_ = MESSAGE_READY; | 129 state_ = MESSAGE_READY; |
| 130 } | 130 } |
| 131 | 131 |
| 132 buzz::XmlElement* V2Authenticator::GetNextMessage() { | 132 scoped_ptr<buzz::XmlElement> V2Authenticator::GetNextMessage() { |
| 133 DCHECK_EQ(state(), MESSAGE_READY); | 133 DCHECK_EQ(state(), MESSAGE_READY); |
| 134 | 134 |
| 135 buzz::XmlElement* message = CreateEmptyAuthenticatorMessage(); | 135 scoped_ptr<buzz::XmlElement> message = CreateEmptyAuthenticatorMessage(); |
| 136 | 136 |
| 137 DCHECK(!pending_messages_.empty()); | 137 DCHECK(!pending_messages_.empty()); |
| 138 while (!pending_messages_.empty()) { | 138 while (!pending_messages_.empty()) { |
| 139 const std::string& spake_message = pending_messages_.front(); | 139 const std::string& spake_message = pending_messages_.front(); |
| 140 std::string base64_message; | 140 std::string base64_message; |
| 141 if (!base::Base64Encode(spake_message, &base64_message)) { | 141 if (!base::Base64Encode(spake_message, &base64_message)) { |
| 142 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; | 142 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; |
| 143 continue; | 143 continue; |
| 144 } | 144 } |
| 145 | 145 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 156 if (!base::Base64Encode(local_cert_, &base64_cert)) { | 156 if (!base::Base64Encode(local_cert_, &base64_cert)) { |
| 157 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; | 157 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; |
| 158 } | 158 } |
| 159 certificate_tag->SetBodyText(base64_cert); | 159 certificate_tag->SetBodyText(base64_cert); |
| 160 message->AddElement(certificate_tag); | 160 message->AddElement(certificate_tag); |
| 161 } | 161 } |
| 162 | 162 |
| 163 if (state_ != ACCEPTED) { | 163 if (state_ != ACCEPTED) { |
| 164 state_ = WAITING_MESSAGE; | 164 state_ = WAITING_MESSAGE; |
| 165 } | 165 } |
| 166 return message; | 166 return message.Pass(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 ChannelAuthenticator* V2Authenticator::CreateChannelAuthenticator() const { | 169 scoped_ptr<ChannelAuthenticator> |
| 170 V2Authenticator::CreateChannelAuthenticator() const { |
| 170 DCHECK_EQ(state(), ACCEPTED); | 171 DCHECK_EQ(state(), ACCEPTED); |
| 171 CHECK(!auth_key_.empty()); | 172 CHECK(!auth_key_.empty()); |
| 172 | 173 |
| 173 if (is_host_side()) { | 174 if (is_host_side()) { |
| 174 return SslHmacChannelAuthenticator::CreateForHost( | 175 return scoped_ptr<ChannelAuthenticator>( |
| 175 local_cert_, local_private_key_.get(), auth_key_); | 176 SslHmacChannelAuthenticator::CreateForHost( |
| 177 local_cert_, local_private_key_.get(), auth_key_).Pass()); |
| 176 } else { | 178 } else { |
| 177 return SslHmacChannelAuthenticator::CreateForClient( | 179 return scoped_ptr<ChannelAuthenticator>( |
| 178 remote_cert_, auth_key_); | 180 SslHmacChannelAuthenticator::CreateForClient( |
| 181 remote_cert_, auth_key_).Pass()); |
| 179 } | 182 } |
| 180 } | 183 } |
| 181 | 184 |
| 182 bool V2Authenticator::is_host_side() const { | 185 bool V2Authenticator::is_host_side() const { |
| 183 return local_private_key_.get() != NULL; | 186 return local_private_key_.get() != NULL; |
| 184 } | 187 } |
| 185 | 188 |
| 186 } // namespace protocol | 189 } // namespace protocol |
| 187 } // namespace remoting | 190 } // namespace remoting |
| OLD | NEW |