secure_channel_factory.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef REMOTING_PROTOCOL_SECURE_CHANNEL_FACTORY_H_
  5. #define REMOTING_PROTOCOL_SECURE_CHANNEL_FACTORY_H_
  6. #include <map>
  7. #include "base/memory/raw_ptr.h"
  8. #include "net/base/net_errors.h"
  9. #include "remoting/protocol/stream_channel_factory.h"
  10. namespace remoting {
  11. namespace protocol {
  12. class Authenticator;
  13. class ChannelAuthenticator;
  14. // StreamChannelFactory wrapper that authenticates every channel it creates.
  15. // When CreateChannel() is called it first calls the wrapped
  16. // StreamChannelFactory to create a channel and then uses the specified
  17. // Authenticator to secure and authenticate the new channel before returning it
  18. // to the caller.
  19. class SecureChannelFactory : public StreamChannelFactory {
  20. public:
  21. // Both parameters must outlive the object.
  22. SecureChannelFactory(StreamChannelFactory* channel_factory,
  23. Authenticator* authenticator);
  24. SecureChannelFactory(const SecureChannelFactory&) = delete;
  25. SecureChannelFactory& operator=(const SecureChannelFactory&) = delete;
  26. ~SecureChannelFactory() override;
  27. // StreamChannelFactory interface.
  28. void CreateChannel(const std::string& name,
  29. ChannelCreatedCallback callback) override;
  30. void CancelChannelCreation(const std::string& name) override;
  31. private:
  32. typedef std::map<std::string, ChannelAuthenticator*> AuthenticatorMap;
  33. void OnBaseChannelCreated(const std::string& name,
  34. ChannelCreatedCallback callback,
  35. std::unique_ptr<P2PStreamSocket> socket);
  36. void OnSecureChannelCreated(const std::string& name,
  37. ChannelCreatedCallback callback,
  38. int error,
  39. std::unique_ptr<P2PStreamSocket> socket);
  40. raw_ptr<StreamChannelFactory> channel_factory_;
  41. raw_ptr<Authenticator> authenticator_;
  42. AuthenticatorMap channel_authenticators_;
  43. };
  44. } // namespace protocol
  45. } // namespace remoting
  46. #endif // REMOTING_PROTOCOL_SECURE_CHANNEL_FACTORY_H_