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 "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
10 #include "remoting/base/rsa_key_pair.h" | 10 #include "remoting/base/rsa_key_pair.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return scoped_ptr<Authenticator>(result.Pass()); | 55 return scoped_ptr<Authenticator>(result.Pass()); |
56 } | 56 } |
57 | 57 |
58 V2Authenticator::V2Authenticator( | 58 V2Authenticator::V2Authenticator( |
59 crypto::P224EncryptedKeyExchange::PeerType type, | 59 crypto::P224EncryptedKeyExchange::PeerType type, |
60 const std::string& shared_secret, | 60 const std::string& shared_secret, |
61 Authenticator::State initial_state) | 61 Authenticator::State initial_state) |
62 : certificate_sent_(false), | 62 : certificate_sent_(false), |
63 key_exchange_impl_(type, shared_secret), | 63 key_exchange_impl_(type, shared_secret), |
64 state_(initial_state), | 64 state_(initial_state), |
| 65 has_auth_started_(false), |
65 rejection_reason_(INVALID_CREDENTIALS) { | 66 rejection_reason_(INVALID_CREDENTIALS) { |
66 pending_messages_.push(key_exchange_impl_.GetMessage()); | 67 pending_messages_.push(key_exchange_impl_.GetMessage()); |
67 } | 68 } |
68 | 69 |
69 V2Authenticator::~V2Authenticator() { | 70 V2Authenticator::~V2Authenticator() { |
70 } | 71 } |
71 | 72 |
72 Authenticator::State V2Authenticator::state() const { | 73 Authenticator::State V2Authenticator::state() const { |
73 if (state_ == ACCEPTED && !pending_messages_.empty()) | 74 if (state_ == ACCEPTED && !pending_messages_.empty()) |
74 return MESSAGE_READY; | 75 return MESSAGE_READY; |
75 return state_; | 76 return state_; |
76 } | 77 } |
77 | 78 |
| 79 bool V2Authenticator::has_auth_started() const { |
| 80 return has_auth_started_; |
| 81 } |
| 82 |
78 Authenticator::RejectionReason V2Authenticator::rejection_reason() const { | 83 Authenticator::RejectionReason V2Authenticator::rejection_reason() const { |
79 DCHECK_EQ(state(), REJECTED); | 84 DCHECK_EQ(state(), REJECTED); |
80 return rejection_reason_; | 85 return rejection_reason_; |
81 } | 86 } |
82 | 87 |
83 void V2Authenticator::ProcessMessage(const buzz::XmlElement* message, | 88 void V2Authenticator::ProcessMessage(const buzz::XmlElement* message, |
84 const base::Closure& resume_callback) { | 89 const base::Closure& resume_callback) { |
85 ProcessMessageInternal(message); | 90 ProcessMessageInternal(message); |
86 resume_callback.Run(); | 91 resume_callback.Run(); |
87 } | 92 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 state_ = REJECTED; | 128 state_ = REJECTED; |
124 rejection_reason_ = PROTOCOL_ERROR; | 129 rejection_reason_ = PROTOCOL_ERROR; |
125 return; | 130 return; |
126 } | 131 } |
127 | 132 |
128 P224EncryptedKeyExchange::Result result = | 133 P224EncryptedKeyExchange::Result result = |
129 key_exchange_impl_.ProcessMessage(spake_message); | 134 key_exchange_impl_.ProcessMessage(spake_message); |
130 switch (result) { | 135 switch (result) { |
131 case P224EncryptedKeyExchange::kResultPending: | 136 case P224EncryptedKeyExchange::kResultPending: |
132 pending_messages_.push(key_exchange_impl_.GetMessage()); | 137 pending_messages_.push(key_exchange_impl_.GetMessage()); |
| 138 has_auth_started_ = true; |
133 break; | 139 break; |
134 | 140 |
135 case P224EncryptedKeyExchange::kResultFailed: | 141 case P224EncryptedKeyExchange::kResultFailed: |
136 state_ = REJECTED; | 142 state_ = REJECTED; |
137 rejection_reason_ = INVALID_CREDENTIALS; | 143 rejection_reason_ = INVALID_CREDENTIALS; |
138 return; | 144 return; |
139 | 145 |
140 case P224EncryptedKeyExchange::kResultSuccess: | 146 case P224EncryptedKeyExchange::kResultSuccess: |
141 auth_key_ = key_exchange_impl_.GetKey(); | 147 auth_key_ = key_exchange_impl_.GetKey(); |
142 state_ = ACCEPTED; | 148 state_ = ACCEPTED; |
143 return; | 149 return; |
144 } | 150 } |
145 } | 151 } |
146 | |
147 state_ = MESSAGE_READY; | 152 state_ = MESSAGE_READY; |
148 } | 153 } |
149 | 154 |
150 scoped_ptr<buzz::XmlElement> V2Authenticator::GetNextMessage() { | 155 scoped_ptr<buzz::XmlElement> V2Authenticator::GetNextMessage() { |
151 DCHECK_EQ(state(), MESSAGE_READY); | 156 DCHECK_EQ(state(), MESSAGE_READY); |
152 | 157 |
153 scoped_ptr<buzz::XmlElement> message = CreateEmptyAuthenticatorMessage(); | 158 scoped_ptr<buzz::XmlElement> message = CreateEmptyAuthenticatorMessage(); |
154 | 159 |
155 DCHECK(!pending_messages_.empty()); | 160 DCHECK(!pending_messages_.empty()); |
156 while (!pending_messages_.empty()) { | 161 while (!pending_messages_.empty()) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 remote_cert_, auth_key_).Pass()); | 200 remote_cert_, auth_key_).Pass()); |
196 } | 201 } |
197 } | 202 } |
198 | 203 |
199 bool V2Authenticator::is_host_side() const { | 204 bool V2Authenticator::is_host_side() const { |
200 return local_key_pair_.get() != NULL; | 205 return local_key_pair_.get() != NULL; |
201 } | 206 } |
202 | 207 |
203 } // namespace protocol | 208 } // namespace protocol |
204 } // namespace remoting | 209 } // namespace remoting |
OLD | NEW |