Process implementation for TLS encrypted traffic.
Process implementation for TLS encrypted traffic.Please note that gnutls has some internal buffering, so please do not do some buffering on your own and also do not rely on flush(). Just write directly to the socket, as in PosixProcess::posixWriteDirect().
#include <fstream>
#include <iostream>
#include <poll.h>
{
int read(
char *buf,
int count)
override {
return posixRead(buf, count); }
void write(
const char *buf,
size_t count)
override
{
}
std::vector<PdCom::Variable> vars ,
std::vector<std::string> ) override
{
for (const auto &v : vars)
std::cout << "Found var " << v.getPath() << "\n";
running_ = false;
}
{
std::cout << "Connected!" << std::endl;
}
public:
void waitForSocket()
{
fd_set fds;
FD_ZERO(&fds);
FD_SET(fd_, &fds);
select(fd_ + 1, &fds, NULL, NULL, NULL);
}
MyProcess(const std::string &ca_pem, const char *host = "localhost") :
{
do {
std::cerr << "Handshaking\n";
}
bool running_ = true;
};
int main(int argc, char *argv[])
{
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <hostname> <Path to CA.pem>\n";
return -1;
}
std::ifstream ca_file(argv[2]);
std::string ca;
getline(ca_file, ca, '\0');
MyProcess p(ca, argv[1]);
while (p.running_) {
p.waitForSocket();
p.asyncData();
}
p.bye();
return 0;
}
Wrapper around POSIX socket.
Definition PosixProcess.h:44
void posixWriteDirect(const char *buf, size_t count)
Unbuffered Wrapper for write().
int posixRead(char *buf, int count)
Wrapper for read().
virtual void write(const char *buf, size_t count)=0
Write data to server.
virtual int read(char *buf, int count)=0
Read data from server.
virtual void connected()=0
Protocol initialization completed.
virtual void listReply(std::vector< Variable > variables, std::vector< std::string > dirs)
Reply to list() call.
bool list(const std::string &path="")
List a directory path.
Definition SecureProcess.h:46
bool handshake()
TLS Handshake.
static void InitLibrary()
GnuTls global initialization.