Sync
- Implemented sync over TLS. - Obsoleted the Socket code, replacing it with TLSClient, TLSServer. - Added task server details to the 'diagnostics' command output. - 'rc.debug.tls' controls the GnuTLS log level. - Removed redundant cmake diagnostics.
This commit is contained in:
@@ -213,14 +213,6 @@ int CmdDiagnostics::execute (std::string& output)
|
||||
<< location.mode ()
|
||||
<< "\n";
|
||||
|
||||
out << " Server: "
|
||||
<< context.config.get ("taskd.server")
|
||||
<< "\n";
|
||||
|
||||
out << " Cert: "
|
||||
<< context.config.get ("taskd.certificate")
|
||||
<< "\n";
|
||||
|
||||
out << " Locking: "
|
||||
<< (context.config.getBoolean ("locking")
|
||||
? STRING_CMD_DIAG_ENABLED
|
||||
@@ -236,7 +228,25 @@ int CmdDiagnostics::execute (std::string& output)
|
||||
else if ((peditor = getenv ("EDITOR")) != NULL)
|
||||
out << " $EDITOR: " << peditor << "\n";
|
||||
|
||||
out << "\n";
|
||||
out << " Server: "
|
||||
<< context.config.get ("taskd.server")
|
||||
<< "\n";
|
||||
|
||||
out << " Cert: "
|
||||
<< context.config.get ("taskd.certificate")
|
||||
<< "\n";
|
||||
|
||||
// Get credentials, but mask out the key.
|
||||
std::string credentials = context.config.get ("taskd.credentials");
|
||||
std::string::size_type last_slash = credentials.rfind ('/');
|
||||
if (last_slash != std::string::npos)
|
||||
credentials = credentials.substr (0, last_slash)
|
||||
+ "/"
|
||||
+ std::string (credentials.length () - last_slash - 1, '*');
|
||||
|
||||
out << " Creds: "
|
||||
<< credentials
|
||||
<< "\n\n";
|
||||
|
||||
// External commands.
|
||||
out << bold.colorize (STRING_CMD_DIAG_EXTERNAL)
|
||||
|
||||
@@ -25,15 +25,12 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <inttypes.h>
|
||||
#include <Context.h>
|
||||
#include <cmake.h>
|
||||
#include <Socket.h> // TODO Socket is obsolete.
|
||||
/*
|
||||
#include <TLSClient.h>
|
||||
*/
|
||||
#include <Color.h>
|
||||
#include <text.h>
|
||||
#include <i18n.h>
|
||||
@@ -77,6 +74,10 @@ int CmdSync::execute (std::string& output)
|
||||
if (credentials.size () != 3)
|
||||
throw std::string (STRING_CMD_SYNC_BAD_CRED);
|
||||
|
||||
std::string certificate = context.config.get ("taskd.certificate");
|
||||
if (certificate == "")
|
||||
throw std::string (STRING_CMD_SYNC_BAD_CERT);
|
||||
|
||||
// Read backlog.data.
|
||||
std::string payload = "";
|
||||
File backlog (context.config.get ("data.location") + "/backlog.data");
|
||||
@@ -110,7 +111,7 @@ int CmdSync::execute (std::string& output)
|
||||
<< "\n";
|
||||
|
||||
Msg response;
|
||||
if (send (connection, request, response))
|
||||
if (send (connection, certificate, request, response))
|
||||
{
|
||||
std::string code = response.get ("code");
|
||||
if (code == "200")
|
||||
@@ -259,6 +260,7 @@ int CmdSync::execute (std::string& output)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CmdSync::send (
|
||||
const std::string& to,
|
||||
const std::string& certificate,
|
||||
const Msg& request,
|
||||
Msg& response)
|
||||
{
|
||||
@@ -270,23 +272,14 @@ bool CmdSync::send (
|
||||
std::string server = to.substr (0, colon);
|
||||
std::string port = to.substr (colon + 1);
|
||||
|
||||
File cert (certificate);
|
||||
|
||||
try
|
||||
{
|
||||
// TODO Socket is obsolete.
|
||||
Socket s;
|
||||
s.connect (server, port);
|
||||
s.write (request.serialize () + "\n");
|
||||
|
||||
std::string incoming;
|
||||
s.read (incoming);
|
||||
s.close ();
|
||||
|
||||
/*
|
||||
// A very basic TLS client, with X.509 authentication.
|
||||
TLSClient client;
|
||||
client.debug (); // TODO if (context.config.get ("debug"))
|
||||
client.limit (1024); // TODO ???
|
||||
client.init ("pki/client.cert.pem"); // TODO ???
|
||||
client.debug (context.config.getInteger ("debug.tls"));
|
||||
client.init (cert);
|
||||
client.connect (server, port);
|
||||
|
||||
client.send (request.serialize () + "\n");
|
||||
@@ -294,7 +287,6 @@ bool CmdSync::send (
|
||||
std::string incoming;
|
||||
client.recv (incoming);
|
||||
client.bye ();
|
||||
*/
|
||||
|
||||
response.parse (incoming);
|
||||
return true;
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
int execute (std::string&);
|
||||
|
||||
private:
|
||||
bool send (const std::string&, const Msg&, Msg&);
|
||||
bool send (const std::string&, const std::string&, const Msg&, Msg&);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user