| 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" |
| 11 #include "remoting/protocol/auth_util.h" | 11 #include "remoting/protocol/auth_util.h" |
| 12 #include "remoting/protocol/v1_client_channel_authenticator.h" | 12 #include "remoting/protocol/v1_client_channel_authenticator.h" |
| 13 #include "remoting/protocol/v1_host_channel_authenticator.h" | 13 #include "remoting/protocol/v1_host_channel_authenticator.h" |
| 14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 15 | 15 |
| 16 using buzz::QName; | 16 using buzz::QName; |
| 17 using buzz::XmlElement; | 17 using buzz::XmlElement; |
| 18 | 18 |
| 19 namespace remoting { | 19 namespace remoting { |
| 20 namespace protocol { | 20 namespace protocol { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 const char kAuthenticationTag[] = "authentication"; | |
| 24 const char kAuthTokenTag[] = "auth-token"; | 23 const char kAuthTokenTag[] = "auth-token"; |
| 25 const char kCertificateTag[] = "certificate"; | 24 const char kCertificateTag[] = "certificate"; |
| 26 } // namespace | 25 } // namespace |
| 27 | 26 |
| 28 V1ClientAuthenticator::V1ClientAuthenticator( | 27 V1ClientAuthenticator::V1ClientAuthenticator( |
| 29 const std::string& local_jid, | 28 const std::string& local_jid, |
| 30 const std::string& shared_secret) | 29 const std::string& shared_secret) |
| 31 : local_jid_(local_jid), | 30 : local_jid_(local_jid), |
| 32 shared_secret_(shared_secret), | 31 shared_secret_(shared_secret), |
| 33 state_(MESSAGE_READY) { | 32 state_(MESSAGE_READY) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 57 if (remote_cert_.empty()) { | 56 if (remote_cert_.empty()) { |
| 58 state_ = REJECTED; | 57 state_ = REJECTED; |
| 59 } else { | 58 } else { |
| 60 state_ = ACCEPTED; | 59 state_ = ACCEPTED; |
| 61 } | 60 } |
| 62 } | 61 } |
| 63 | 62 |
| 64 XmlElement* V1ClientAuthenticator::GetNextMessage() { | 63 XmlElement* V1ClientAuthenticator::GetNextMessage() { |
| 65 DCHECK_EQ(state_, MESSAGE_READY); | 64 DCHECK_EQ(state_, MESSAGE_READY); |
| 66 | 65 |
| 67 XmlElement* authentication_tag = new XmlElement( | 66 XmlElement* message = CreateEmptyAuthenticatorMessage(); |
| 68 QName(kChromotingXmlNamespace, kAuthenticationTag)); | |
| 69 | |
| 70 std::string token = | 67 std::string token = |
| 71 protocol::GenerateSupportAuthToken(local_jid_, shared_secret_); | 68 protocol::GenerateSupportAuthToken(local_jid_, shared_secret_); |
| 72 | |
| 73 XmlElement* auth_token_tag = new XmlElement( | 69 XmlElement* auth_token_tag = new XmlElement( |
| 74 QName(kChromotingXmlNamespace, kAuthTokenTag)); | 70 QName(kChromotingXmlNamespace, kAuthTokenTag)); |
| 75 auth_token_tag->SetBodyText(token); | 71 auth_token_tag->SetBodyText(token); |
| 76 authentication_tag->AddElement(auth_token_tag); | 72 message->AddElement(auth_token_tag); |
| 77 | 73 |
| 78 state_ = WAITING_MESSAGE; | 74 state_ = WAITING_MESSAGE; |
| 79 return authentication_tag; | 75 return message; |
| 80 } | 76 } |
| 81 | 77 |
| 82 ChannelAuthenticator* | 78 ChannelAuthenticator* |
| 83 V1ClientAuthenticator::CreateChannelAuthenticator() const { | 79 V1ClientAuthenticator::CreateChannelAuthenticator() const { |
| 84 DCHECK_EQ(state_, ACCEPTED); | 80 DCHECK_EQ(state_, ACCEPTED); |
| 85 return new V1ClientChannelAuthenticator(remote_cert_, shared_secret_); | 81 return new V1ClientChannelAuthenticator(remote_cert_, shared_secret_); |
| 86 }; | 82 }; |
| 87 | 83 |
| 88 V1HostAuthenticator::V1HostAuthenticator( | 84 V1HostAuthenticator::V1HostAuthenticator( |
| 89 const std::string& local_cert, | 85 const std::string& local_cert, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 114 remote_jid_, shared_secret_, auth_token)) { | 110 remote_jid_, shared_secret_, auth_token)) { |
| 115 state_ = REJECTED; | 111 state_ = REJECTED; |
| 116 } else { | 112 } else { |
| 117 state_ = MESSAGE_READY; | 113 state_ = MESSAGE_READY; |
| 118 } | 114 } |
| 119 } | 115 } |
| 120 | 116 |
| 121 XmlElement* V1HostAuthenticator::GetNextMessage() { | 117 XmlElement* V1HostAuthenticator::GetNextMessage() { |
| 122 DCHECK_EQ(state_, MESSAGE_READY); | 118 DCHECK_EQ(state_, MESSAGE_READY); |
| 123 | 119 |
| 124 XmlElement* message = new XmlElement( | 120 XmlElement* message = CreateEmptyAuthenticatorMessage(); |
| 125 QName(kChromotingXmlNamespace, kAuthenticationTag)); | |
| 126 | |
| 127 buzz::XmlElement* certificate_tag = new XmlElement( | 121 buzz::XmlElement* certificate_tag = new XmlElement( |
| 128 buzz::QName(kChromotingXmlNamespace, kCertificateTag)); | 122 buzz::QName(kChromotingXmlNamespace, kCertificateTag)); |
| 129 std::string base64_cert; | 123 std::string base64_cert; |
| 130 if (!base::Base64Encode(local_cert_, &base64_cert)) { | 124 if (!base::Base64Encode(local_cert_, &base64_cert)) { |
| 131 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; | 125 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; |
| 132 } | 126 } |
| 133 certificate_tag->SetBodyText(base64_cert); | 127 certificate_tag->SetBodyText(base64_cert); |
| 134 message->AddElement(certificate_tag); | 128 message->AddElement(certificate_tag); |
| 135 | 129 |
| 136 state_ = ACCEPTED; | 130 state_ = ACCEPTED; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 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 |