blob: 320466ce12143ad60445afd95230a24266c58098 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_PROTOCOL_SSL_HMAC_CHANNEL_AUTHENTICATOR_H_
#define REMOTING_PROTOCOL_SSL_HMAC_CHANNEL_AUTHENTICATOR_H_
#include <string>
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "remoting/protocol/channel_authenticator.h"
namespace net {
class CertVerifier;
class DrainableIOBuffer;
class GrowableIOBuffer;
class SSLSocket;
class TransportSecurityState;
} // namespace net
namespace remoting {
class RsaKeyPair;
namespace protocol {
// SslHmacChannelAuthenticator implements ChannelAuthenticator that
// secures channels using SSL and authenticates them with a shared
// secret HMAC.
class SslHmacChannelAuthenticator : public ChannelAuthenticator,
public base::NonThreadSafe {
public:
enum LegacyMode {
NONE,
SEND_ONLY,
RECEIVE_ONLY,
};
// CreateForClient() and CreateForHost() create an authenticator
// instances for client and host. |auth_key| specifies shared key
// known by both host and client. In case of V1Authenticator the
// |auth_key| is set to access code. For EKE-based authentication
// |auth_key| is the key established using EKE over the signaling
// channel.
static scoped_ptr<SslHmacChannelAuthenticator> CreateForClient(
const std::string& remote_cert,
const std::string& auth_key);
static scoped_ptr<SslHmacChannelAuthenticator> CreateForHost(
const std::string& local_cert,
scoped_refptr<RsaKeyPair> key_pair,
const std::string& auth_key);
virtual ~SslHmacChannelAuthenticator();
// ChannelAuthenticator interface.
virtual void SecureAndAuthenticate(
scoped_ptr<net::StreamSocket> socket,
const DoneCallback& done_callback) OVERRIDE;
private:
SslHmacChannelAuthenticator(const std::string& auth_key);
bool is_ssl_server();
void OnConnected(int result);
void WriteAuthenticationBytes(bool* callback_called);
void OnAuthBytesWritten(int result);
bool HandleAuthBytesWritten(int result, bool* callback_called);
void ReadAuthenticationBytes();
void OnAuthBytesRead(int result);
bool HandleAuthBytesRead(int result);
bool VerifyAuthBytes(const std::string& received_auth_bytes);
void CheckDone(bool* callback_called);
void NotifyError(int error);
// The mutual secret used for authentication.
std::string auth_key_;
// Used in the SERVER mode only.
std::string local_cert_;
scoped_refptr<RsaKeyPair> local_key_pair_;
// Used in the CLIENT mode only.
std::string remote_cert_;
scoped_ptr<net::CertVerifier> cert_verifier_;
scoped_ptr<net::TransportSecurityState> transport_security_state_;
scoped_ptr<net::SSLSocket> socket_;
DoneCallback done_callback_;
scoped_refptr<net::DrainableIOBuffer> auth_write_buf_;
scoped_refptr<net::GrowableIOBuffer> auth_read_buf_;
DISALLOW_COPY_AND_ASSIGN(SslHmacChannelAuthenticator);
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_SSL_HMAC_CHANNEL_AUTHENTICATOR_H_
|