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/me2me_host_authenticator_factory.h" | 5 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "remoting/base/rsa_key_pair.h" | 9 #include "remoting/base/rsa_key_pair.h" |
10 #include "remoting/protocol/channel_authenticator.h" | 10 #include "remoting/protocol/channel_authenticator.h" |
11 #include "remoting/protocol/negotiating_host_authenticator.h" | 11 #include "remoting/protocol/negotiating_host_authenticator.h" |
12 #include "remoting/protocol/token_validator.h" | 12 #include "remoting/protocol/token_validator.h" |
| 13 #include "remoting/signaling/jid_util.h" |
13 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
14 | 15 |
15 namespace remoting { | 16 namespace remoting { |
16 namespace protocol { | 17 namespace protocol { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Authenticator that accepts one message and rejects connection after that. | 21 // Authenticator that accepts one message and rejects connection after that. |
21 class RejectingAuthenticator : public Authenticator { | 22 class RejectingAuthenticator : public Authenticator { |
22 public: | 23 public: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 const std::string& remote_jid, | 109 const std::string& remote_jid, |
109 const buzz::XmlElement* first_message) { | 110 const buzz::XmlElement* first_message) { |
110 | 111 |
111 std::string remote_jid_prefix; | 112 std::string remote_jid_prefix; |
112 | 113 |
113 if (!use_service_account_) { | 114 if (!use_service_account_) { |
114 // JID prefixes may not match the host owner email, for example, in cases | 115 // JID prefixes may not match the host owner email, for example, in cases |
115 // where the host owner account does not have an email associated with it. | 116 // where the host owner account does not have an email associated with it. |
116 // In those cases, the only guarantee we have is that JIDs for the same | 117 // In those cases, the only guarantee we have is that JIDs for the same |
117 // account will have the same prefix. | 118 // account will have the same prefix. |
118 size_t slash_pos = local_jid.find('/'); | 119 if (!SplitJidResource(local_jid, &remote_jid_prefix, nullptr)) { |
119 if (slash_pos == std::string::npos) { | |
120 LOG(DFATAL) << "Invalid local JID:" << local_jid; | 120 LOG(DFATAL) << "Invalid local JID:" << local_jid; |
121 return make_scoped_ptr(new RejectingAuthenticator()); | 121 return make_scoped_ptr(new RejectingAuthenticator()); |
122 } | 122 } |
123 remote_jid_prefix = local_jid.substr(0, slash_pos); | |
124 } else { | 123 } else { |
125 // TODO(rmsousa): This only works for cases where the JID prefix matches | 124 // TODO(rmsousa): This only works for cases where the JID prefix matches |
126 // the host owner email. Figure out a way to verify the JID in other cases. | 125 // the host owner email. Figure out a way to verify the JID in other cases. |
127 remote_jid_prefix = host_owner_; | 126 remote_jid_prefix = host_owner_; |
128 } | 127 } |
129 | 128 |
130 // Verify that the client's jid is an ASCII string, and then check that the | 129 // Verify that the client's jid is an ASCII string, and then check that the |
131 // client JID has the expected prefix. Comparison is case insensitive. | 130 // client JID has the expected prefix. Comparison is case insensitive. |
132 if (!base::IsStringASCII(remote_jid) || | 131 if (!base::IsStringASCII(remote_jid) || |
133 !StartsWithASCII(remote_jid, remote_jid_prefix + '/', false)) { | 132 !StartsWithASCII(remote_jid, remote_jid_prefix + '/', false)) { |
(...skipping 12 matching lines...) Expand all Loading... |
146 return NegotiatingHostAuthenticator::CreateWithSharedSecret( | 145 return NegotiatingHostAuthenticator::CreateWithSharedSecret( |
147 local_cert_, key_pair_, shared_secret_hash_.value, | 146 local_cert_, key_pair_, shared_secret_hash_.value, |
148 shared_secret_hash_.hash_function, pairing_registry_); | 147 shared_secret_hash_.hash_function, pairing_registry_); |
149 } | 148 } |
150 | 149 |
151 return make_scoped_ptr(new RejectingAuthenticator()); | 150 return make_scoped_ptr(new RejectingAuthenticator()); |
152 } | 151 } |
153 | 152 |
154 } // namespace protocol | 153 } // namespace protocol |
155 } // namespace remoting | 154 } // namespace remoting |
OLD | NEW |