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/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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 if (remote_cert_.empty()) { | 55 if (remote_cert_.empty()) { |
56 state_ = REJECTED; | 56 state_ = REJECTED; |
57 } else { | 57 } else { |
58 state_ = ACCEPTED; | 58 state_ = ACCEPTED; |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 XmlElement* V1ClientAuthenticator::GetNextMessage() { | 62 scoped_ptr<XmlElement> V1ClientAuthenticator::GetNextMessage() { |
63 DCHECK_EQ(state_, MESSAGE_READY); | 63 DCHECK_EQ(state_, MESSAGE_READY); |
64 | 64 |
65 XmlElement* message = CreateEmptyAuthenticatorMessage(); | 65 scoped_ptr<XmlElement> message = CreateEmptyAuthenticatorMessage(); |
66 std::string token = | 66 std::string token = |
67 protocol::GenerateSupportAuthToken(local_jid_, shared_secret_); | 67 protocol::GenerateSupportAuthToken(local_jid_, shared_secret_); |
68 XmlElement* auth_token_tag = new XmlElement( | 68 XmlElement* auth_token_tag = new XmlElement( |
69 QName(kChromotingXmlNamespace, kAuthTokenTag)); | 69 QName(kChromotingXmlNamespace, kAuthTokenTag)); |
70 auth_token_tag->SetBodyText(token); | 70 auth_token_tag->SetBodyText(token); |
71 message->AddElement(auth_token_tag); | 71 message->AddElement(auth_token_tag); |
72 | 72 |
73 state_ = WAITING_MESSAGE; | 73 state_ = WAITING_MESSAGE; |
74 return message; | 74 return message.Pass(); |
75 } | 75 } |
76 | 76 |
77 ChannelAuthenticator* | 77 scoped_ptr<ChannelAuthenticator> |
78 V1ClientAuthenticator::CreateChannelAuthenticator() const { | 78 V1ClientAuthenticator::CreateChannelAuthenticator() const { |
79 DCHECK_EQ(state_, ACCEPTED); | 79 DCHECK_EQ(state_, ACCEPTED); |
80 SslHmacChannelAuthenticator* result = | 80 scoped_ptr<SslHmacChannelAuthenticator> result = |
81 SslHmacChannelAuthenticator::CreateForClient( | 81 SslHmacChannelAuthenticator::CreateForClient( |
82 remote_cert_, shared_secret_); | 82 remote_cert_, shared_secret_); |
83 result->SetLegacyOneWayMode(SslHmacChannelAuthenticator::SEND_ONLY); | 83 result->SetLegacyOneWayMode(SslHmacChannelAuthenticator::SEND_ONLY); |
84 return result; | 84 return scoped_ptr<ChannelAuthenticator>(result.Pass()); |
85 }; | 85 }; |
86 | 86 |
87 V1HostAuthenticator::V1HostAuthenticator( | 87 V1HostAuthenticator::V1HostAuthenticator( |
88 const std::string& local_cert, | 88 const std::string& local_cert, |
89 const crypto::RSAPrivateKey& local_private_key, | 89 const crypto::RSAPrivateKey& local_private_key, |
90 const std::string& shared_secret, | 90 const std::string& shared_secret, |
91 const std::string& remote_jid) | 91 const std::string& remote_jid) |
92 : local_cert_(local_cert), | 92 : local_cert_(local_cert), |
93 local_private_key_(local_private_key.Copy()), | 93 local_private_key_(local_private_key.Copy()), |
94 shared_secret_(shared_secret), | 94 shared_secret_(shared_secret), |
(...skipping 15 matching lines...) Expand all Loading... |
110 message->TextNamed(buzz::QName(kChromotingXmlNamespace, kAuthTokenTag)); | 110 message->TextNamed(buzz::QName(kChromotingXmlNamespace, kAuthTokenTag)); |
111 | 111 |
112 if (!protocol::VerifySupportAuthToken( | 112 if (!protocol::VerifySupportAuthToken( |
113 remote_jid_, shared_secret_, auth_token)) { | 113 remote_jid_, shared_secret_, auth_token)) { |
114 state_ = REJECTED; | 114 state_ = REJECTED; |
115 } else { | 115 } else { |
116 state_ = MESSAGE_READY; | 116 state_ = MESSAGE_READY; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 XmlElement* V1HostAuthenticator::GetNextMessage() { | 120 scoped_ptr<XmlElement> V1HostAuthenticator::GetNextMessage() { |
121 DCHECK_EQ(state_, MESSAGE_READY); | 121 DCHECK_EQ(state_, MESSAGE_READY); |
122 | 122 |
123 XmlElement* message = CreateEmptyAuthenticatorMessage(); | 123 scoped_ptr<XmlElement> message = CreateEmptyAuthenticatorMessage(); |
124 buzz::XmlElement* certificate_tag = new XmlElement( | 124 buzz::XmlElement* certificate_tag = new XmlElement( |
125 buzz::QName(kChromotingXmlNamespace, kCertificateTag)); | 125 buzz::QName(kChromotingXmlNamespace, kCertificateTag)); |
126 std::string base64_cert; | 126 std::string base64_cert; |
127 if (!base::Base64Encode(local_cert_, &base64_cert)) { | 127 if (!base::Base64Encode(local_cert_, &base64_cert)) { |
128 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; | 128 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; |
129 } | 129 } |
130 certificate_tag->SetBodyText(base64_cert); | 130 certificate_tag->SetBodyText(base64_cert); |
131 message->AddElement(certificate_tag); | 131 message->AddElement(certificate_tag); |
132 | 132 |
133 state_ = ACCEPTED; | 133 state_ = ACCEPTED; |
134 return message; | 134 return message.Pass(); |
135 } | 135 } |
136 | 136 |
137 ChannelAuthenticator* | 137 scoped_ptr<ChannelAuthenticator> |
138 V1HostAuthenticator::CreateChannelAuthenticator() const { | 138 V1HostAuthenticator::CreateChannelAuthenticator() const { |
139 DCHECK_EQ(state_, ACCEPTED); | 139 DCHECK_EQ(state_, ACCEPTED); |
140 SslHmacChannelAuthenticator* result = | 140 scoped_ptr<SslHmacChannelAuthenticator> result = |
141 SslHmacChannelAuthenticator::CreateForHost( | 141 SslHmacChannelAuthenticator::CreateForHost( |
142 local_cert_, local_private_key_.get(), shared_secret_); | 142 local_cert_, local_private_key_.get(), shared_secret_); |
143 result->SetLegacyOneWayMode(SslHmacChannelAuthenticator::RECEIVE_ONLY); | 143 result->SetLegacyOneWayMode(SslHmacChannelAuthenticator::RECEIVE_ONLY); |
144 return result; | 144 return scoped_ptr<ChannelAuthenticator>(result.Pass()); |
145 }; | 145 }; |
146 | 146 |
147 } // namespace remoting | 147 } // namespace remoting |
148 } // namespace protocol | 148 } // namespace protocol |
OLD | NEW |