#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 remoting {
class RsaKeyPair;
namespace protocol {
class SslHmacChannelAuthenticator : public ChannelAuthenticator,
public base::NonThreadSafe {
public:
enum LegacyMode {
NONE,
SEND_ONLY,
RECEIVE_ONLY,
};
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();
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);
std::string auth_key_;
std::string local_cert_;
scoped_refptr<RsaKeyPair> local_key_pair_;
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);
};
}
}
#endif