1// Copyright 2014 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_SECURE_CHANNEL_FACTORY_H_
6#define REMOTING_PROTOCOL_SECURE_CHANNEL_FACTORY_H_
7
8#include <map>
9
10#include "base/basictypes.h"
11#include "net/base/net_errors.h"
12#include "remoting/protocol/stream_channel_factory.h"
13
14namespace remoting {
15namespace protocol {
16
17class Authenticator;
18class ChannelAuthenticator;
19
20// StreamChannelFactory wrapper that authenticates every channel it creates.
21// When CreateChannel() is called it first calls the wrapped
22// StreamChannelFactory to create a channel and then uses the specified
23// Authenticator to secure and authenticate the new channel before returning it
24// to the caller.
25class SecureChannelFactory : public StreamChannelFactory {
26 public:
27  // Both parameters must outlive the object.
28  SecureChannelFactory(StreamChannelFactory* channel_factory,
29                       Authenticator* authenticator);
30  virtual ~SecureChannelFactory();
31
32  // StreamChannelFactory interface.
33  virtual void CreateChannel(const std::string& name,
34                             const ChannelCreatedCallback& callback) OVERRIDE;
35  virtual void CancelChannelCreation(const std::string& name) OVERRIDE;
36
37 private:
38  typedef std::map<std::string, ChannelAuthenticator*> AuthenticatorMap;
39
40  void OnBaseChannelCreated(const std::string& name,
41                            const ChannelCreatedCallback& callback,
42                            scoped_ptr<net::StreamSocket> socket);
43
44  void OnSecureChannelCreated(const std::string& name,
45                              const ChannelCreatedCallback& callback,
46                              int error,
47                              scoped_ptr<net::StreamSocket> socket);
48
49  StreamChannelFactory* channel_factory_;
50  Authenticator* authenticator_;
51
52  AuthenticatorMap channel_authenticators_;
53
54  DISALLOW_COPY_AND_ASSIGN(SecureChannelFactory);
55};
56
57}  // namespace protocol
58}  // namespace remoting
59
60#endif  // REMOTING_PROTOCOL_SECURE_CHANNEL_FACTORY_H_
61