v2_authenticator.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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
3// found in the LICENSE file.
4
5#ifndef REMOTING_PROTOCOL_V2_AUTHENTICATOR_H_
6#define REMOTING_PROTOCOL_V2_AUTHENTICATOR_H_
7
8#include <string>
9#include <queue>
10
11#include "base/compiler_specific.h"
12#include "base/gtest_prod_util.h"
13#include "base/memory/scoped_ptr.h"
14#include "crypto/p224_spake.h"
15#include "remoting/protocol/authenticator.h"
16
17namespace crypto {
18class RSAPrivateKey;
19}  // namespace crypto
20
21namespace remoting {
22namespace protocol {
23
24class V2Authenticator : public Authenticator {
25 public:
26  static bool IsEkeMessage(const buzz::XmlElement* message);
27
28  static scoped_ptr<Authenticator> CreateForClient(
29      const std::string& shared_secret,
30      State initial_state);
31
32  static scoped_ptr<Authenticator> CreateForHost(
33      const std::string& local_cert,
34      const crypto::RSAPrivateKey& local_private_key,
35      const std::string& shared_secret,
36      State initial_state);
37
38  virtual ~V2Authenticator();
39
40  // Authenticator interface.
41  virtual State state() const OVERRIDE;
42  virtual RejectionReason rejection_reason() const OVERRIDE;
43  virtual void ProcessMessage(const buzz::XmlElement* message) OVERRIDE;
44  virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE;
45  virtual scoped_ptr<ChannelAuthenticator>
46      CreateChannelAuthenticator() const OVERRIDE;
47
48 private:
49  FRIEND_TEST_ALL_PREFIXES(V2AuthenticatorTest, InvalidSecret);
50
51  V2Authenticator(crypto::P224EncryptedKeyExchange::PeerType type,
52                  const std::string& shared_secret,
53                  State initial_state);
54
55  bool is_host_side() const;
56
57  // Used only for host authenticators.
58  std::string local_cert_;
59  scoped_ptr<crypto::RSAPrivateKey> local_private_key_;
60  bool certificate_sent_;
61
62  // Used only for client authenticators.
63  std::string remote_cert_;
64
65  // Used for both host and client authenticators.
66  crypto::P224EncryptedKeyExchange key_exchange_impl_;
67  State state_;
68  RejectionReason rejection_reason_;
69  std::queue<std::string> pending_messages_;
70  std::string auth_key_;
71
72  DISALLOW_COPY_AND_ASSIGN(V2Authenticator);
73};
74
75}  // namespace protocol
76}  // namespace remoting
77
78#endif  // REMOTING_PROTOCOL_V2_AUTHENTICATOR_H_
79