| 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/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "crypto/rsa_private_key.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_authenticator.h" | 11 #include "remoting/protocol/negotiating_authenticator.h" |
| 12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 13 | 13 |
| 14 namespace remoting { | 14 namespace remoting { |
| 15 namespace protocol { | 15 namespace protocol { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Authenticator that accepts one message and rejects connection after that. | 19 // Authenticator that accepts one message and rejects connection after that. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 State state_; | 56 State state_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 Me2MeHostAuthenticatorFactory::Me2MeHostAuthenticatorFactory( | 61 Me2MeHostAuthenticatorFactory::Me2MeHostAuthenticatorFactory( |
| 62 const std::string& local_cert, | 62 const std::string& local_cert, |
| 63 const crypto::RSAPrivateKey& local_private_key, | 63 scoped_refptr<RsaKeyPair> key_pair, |
| 64 const SharedSecretHash& shared_secret_hash) | 64 const SharedSecretHash& shared_secret_hash) |
| 65 : local_cert_(local_cert), | 65 : local_cert_(local_cert), |
| 66 local_private_key_(local_private_key.Copy()), | 66 key_pair_(key_pair), |
| 67 shared_secret_hash_(shared_secret_hash) { | 67 shared_secret_hash_(shared_secret_hash) { |
| 68 } | 68 } |
| 69 | 69 |
| 70 Me2MeHostAuthenticatorFactory::~Me2MeHostAuthenticatorFactory() { | 70 Me2MeHostAuthenticatorFactory::~Me2MeHostAuthenticatorFactory() { |
| 71 } | 71 } |
| 72 | 72 |
| 73 scoped_ptr<Authenticator> Me2MeHostAuthenticatorFactory::CreateAuthenticator( | 73 scoped_ptr<Authenticator> Me2MeHostAuthenticatorFactory::CreateAuthenticator( |
| 74 const std::string& local_jid, | 74 const std::string& local_jid, |
| 75 const std::string& remote_jid, | 75 const std::string& remote_jid, |
| 76 const buzz::XmlElement* first_message) { | 76 const buzz::XmlElement* first_message) { |
| 77 | 77 |
| 78 size_t slash_pos = local_jid.find('/'); | 78 size_t slash_pos = local_jid.find('/'); |
| 79 if (slash_pos == std::string::npos) { | 79 if (slash_pos == std::string::npos) { |
| 80 LOG(DFATAL) << "Invalid local JID:" << local_jid; | 80 LOG(DFATAL) << "Invalid local JID:" << local_jid; |
| 81 return scoped_ptr<Authenticator>(new RejectingAuthenticator()); | 81 return scoped_ptr<Authenticator>(new RejectingAuthenticator()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Verify that the client's jid is an ASCII string, and then check | 84 // Verify that the client's jid is an ASCII string, and then check |
| 85 // that the client has the same bare jid as the host, i.e. client's | 85 // that the client has the same bare jid as the host, i.e. client's |
| 86 // full JID starts with host's bare jid. Comparison is case | 86 // full JID starts with host's bare jid. Comparison is case |
| 87 // insensitive. | 87 // insensitive. |
| 88 if (!IsStringASCII(remote_jid) || | 88 if (!IsStringASCII(remote_jid) || |
| 89 !StartsWithASCII(remote_jid, local_jid.substr(0, slash_pos + 1), false)) { | 89 !StartsWithASCII(remote_jid, local_jid.substr(0, slash_pos + 1), false)) { |
| 90 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid; | 90 LOG(ERROR) << "Rejecting incoming connection from " << remote_jid; |
| 91 return scoped_ptr<Authenticator>(new RejectingAuthenticator()); | 91 return scoped_ptr<Authenticator>(new RejectingAuthenticator()); |
| 92 } | 92 } |
| 93 | 93 |
| 94 return NegotiatingAuthenticator::CreateForHost( | 94 return NegotiatingAuthenticator::CreateForHost( |
| 95 local_cert_, *local_private_key_, shared_secret_hash_.value, | 95 local_cert_, key_pair_, shared_secret_hash_.value, |
| 96 shared_secret_hash_.hash_function); | 96 shared_secret_hash_.hash_function); |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace protocol | 99 } // namespace protocol |
| 100 } // namespace remoting | 100 } // namespace remoting |
| OLD | NEW |