add encryption
This commit is contained in:
@@ -71,6 +71,15 @@ int PIClientServer::Client::write(const void * d, const size_t s) {
|
||||
}
|
||||
|
||||
|
||||
void PIClientServer::Client::enableSymmetricEncryption(const PIByteArray & key) {
|
||||
if (key.isNotEmpty()) {
|
||||
stream.setCryptEnabled(true);
|
||||
stream.setCryptKey(key);
|
||||
} else
|
||||
stream.setCryptEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
void PIClientServer::Client::createForServer(PIEthernet * tcp_) {
|
||||
tcp = tcp_;
|
||||
tcp->setParameter(PIEthernet::KeepConnection, false);
|
||||
|
||||
@@ -91,6 +91,11 @@ void PIClientServer::Server::setMaxClients(int new_max_clients) {
|
||||
}
|
||||
|
||||
|
||||
void PIClientServer::Server::enableSymmetricEncryption(const PIByteArray & key) {
|
||||
crypt_key = key;
|
||||
}
|
||||
|
||||
|
||||
void PIClientServer::Server::stopServer() {
|
||||
if (!tcp_server) return;
|
||||
tcp_server->stopAndWait();
|
||||
@@ -98,8 +103,9 @@ void PIClientServer::Server::stopServer() {
|
||||
|
||||
|
||||
void PIClientServer::Server::newClient(Client * c) {
|
||||
c->readed_func = [this, c](PIByteArray ba) { readed(c, ba); };
|
||||
clients << c;
|
||||
c->enableSymmetricEncryption(crypt_key);
|
||||
c->readed_func = [this, c](PIByteArray ba) { readed(c, ba); };
|
||||
c->tcp->startThreadedRead();
|
||||
c->connected();
|
||||
piCout << "New client";
|
||||
|
||||
Reference in New Issue
Block a user