OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/protocol/me2me_host_authenticator_factory.h" | |
6 | |
7 #include "base/string_util.h" | |
8 #include "crypto/rsa_private_key.h" | |
9 #include "remoting/protocol/v1_authenticator.h" | |
10 #include "remoting/protocol/v2_authenticator.h" | |
11 | |
12 namespace remoting { | |
13 namespace protocol { | |
14 | |
15 Me2MeHostAuthenticatorFactory::Me2MeHostAuthenticatorFactory( | |
16 const std::string& local_jid, | |
17 const std::string& local_cert, | |
18 const crypto::RSAPrivateKey* local_private_key, | |
19 const std::string& shared_secret) | |
20 : local_cert_(local_cert), | |
21 local_private_key_(local_private_key->Copy()), | |
22 shared_secret_(shared_secret) { | |
23 // Verify that |local_jid| is bare. | |
24 DCHECK_EQ(local_jid.find('/'), std::string::npos); | |
25 local_jid_prefix_ = local_jid + '/'; | |
26 } | |
27 | |
28 Me2MeHostAuthenticatorFactory::~Me2MeHostAuthenticatorFactory() { | |
29 } | |
30 | |
31 Authenticator* Me2MeHostAuthenticatorFactory::CreateAuthenticator( | |
32 const std::string& remote_jid, | |
33 const buzz::XmlElement* first_message) { | |
34 // Reject incoming connection if the client's jid is not an ASCII string. | |
35 if (!IsStringASCII(remote_jid)) { | |
36 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid; | |
37 return false; | |
38 } | |
39 | |
40 // Check that the client has the same bare jid as the host, i.e. | |
41 // client's full JID starts with host's bare jid. Comparison is case | |
42 // insensitive. | |
43 if (!StartsWithASCII(remote_jid, local_jid_prefix_, false)) { | |
44 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid; | |
45 return NULL; | |
46 } | |
47 | |
48 if (V2Authenticator::IsEkeMessage(first_message)) { | |
Wez
2012/01/09 23:04:47
Comment this out since V2 is not ready yet?
Sergey Ulanov
2012/01/09 23:08:13
Done.
| |
49 return V2Authenticator::CreateForHost( | |
50 local_cert_, local_private_key_.get(), shared_secret_); | |
51 } | |
52 | |
53 // TODO(sergeyu): Old clients still use V1 auth protocol. Remove | |
54 // this once we are done migrating to V2. | |
55 return new V1HostAuthenticator(local_cert_, local_private_key_.get(), | |
56 shared_secret_, remote_jid); | |
57 } | |
58 | |
59 } // namespace protocol | |
60 } // namespace remoting | |
OLD | NEW |