Certificates

- Added certificate verification callback.
This commit is contained in:
Paul Beckingham 2013-10-29 23:02:32 -04:00
parent 5a0dfa634c
commit eda9ac56da
4 changed files with 69 additions and 12 deletions

View file

@ -88,10 +88,21 @@ int CmdSync::execute (std::string& output)
if (credentials.size () != 3)
throw std::string (STRING_CMD_SYNC_BAD_CRED);
bool trust = context.config.getBoolean ("taskd.trust");
/*
File ca (context.config.get ("taskd.ca"));
if (ca._data != "" && ! ca.exists ())
throw std::string (STRING_CMD_SYNC_BAD_CA);
*/
File certificate (context.config.get ("taskd.certificate"));
if (! certificate.exists ())
throw std::string (STRING_CMD_SYNC_BAD_CERT);
File key (context.config.get ("taskd.key"));
if (! key.exists ())
throw std::string (STRING_CMD_SYNC_BAD_KEY);
// If this is a first-time initialization, send pending.data, not
// backlog.data.
std::string payload = "";
@ -146,7 +157,7 @@ int CmdSync::execute (std::string& output)
signal (SIGUSR2, SIG_IGN);
Msg response;
if (send (connection, certificate._data, request, response))
if (send (connection, certificate._data, key._data, trust, request, response))
{
std::string code = response.get ("code");
if (code == "200")
@ -304,6 +315,8 @@ int CmdSync::execute (std::string& output)
bool CmdSync::send (
const std::string& to,
const std::string& certificate,
const std::string& key,
bool trust,
const Msg& request,
Msg& response)
{
@ -315,14 +328,13 @@ bool CmdSync::send (
std::string server = to.substr (0, colon);
std::string port = to.substr (colon + 1);
File cert (certificate);
try
{
// A very basic TLS client, with X.509 authentication.
TLSClient client;
client.debug (context.config.getInteger ("debug.tls"));
client.init (cert);
client.trust (trust);
client.init (certificate, key);
client.connect (server, port);
client.send (request.serialize () + "\n");

View file

@ -39,7 +39,7 @@ public:
int execute (std::string&);
private:
bool send (const std::string&, const std::string&, const Msg&, Msg&);
bool send (const std::string&, const std::string&, const std::string&, bool, const Msg&, Msg&);
};
#endif