lordgamez commented on a change in pull request #978:
URL: https://github.com/apache/nifi-minifi-cpp/pull/978#discussion_r564368411



##########
File path: 
extensions/standard-processors/tests/integration/TLSClientSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,221 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+class SimpleSSLTestServer  {
+ public:
+  SimpleSSLTestServer(const SSL_METHOD* method, std::string port, std::string 
path)
+      : port_(port) {
+    ctx_ = SSL_CTX_new(method);
+    configure_context(path);
+  }
+
+  ~SimpleSSLTestServer() {
+      SSL_shutdown(ssl_);
+      SSL_free(ssl_);
+      SSL_CTX_free(ctx_);
+  }
+
+  void waitForConnection() {
+    isRunning_ = true;
+    sock_ = create_socket(std::stoi(port_));
+    server_read_thread_ = std::thread([this]() -> void {
+      while (isRunning_) {
+        struct sockaddr_in addr;
+        uint len = sizeof(addr);
+
+        int client = accept(sock_, (struct sockaddr*)&addr, &len);
+        ssl_ = SSL_new(ctx_);
+        SSL_set_fd(ssl_, client);
+        successful = (SSL_accept(ssl_) == 1);
+      }
+    });
+  }
+
+  bool isRunning_;

Review comment:
       Use snake_case for variables. Same in 
TLSServerSocketSupportedProtocolsTest.cpp 

##########
File path: 
extensions/standard-processors/tests/integration/TLSClientSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,221 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+class SimpleSSLTestServer  {
+ public:
+  SimpleSSLTestServer(const SSL_METHOD* method, std::string port, std::string 
path)

Review comment:
       Use const& for std::string parameters. This should apply for all 
functions below.

##########
File path: 
extensions/standard-processors/tests/integration/TLSClientSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,221 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+class SimpleSSLTestServer  {
+ public:
+  SimpleSSLTestServer(const SSL_METHOD* method, std::string port, std::string 
path)
+      : port_(port) {
+    ctx_ = SSL_CTX_new(method);
+    configure_context(path);
+  }
+
+  ~SimpleSSLTestServer() {
+      SSL_shutdown(ssl_);
+      SSL_free(ssl_);
+      SSL_CTX_free(ctx_);
+  }
+
+  void waitForConnection() {
+    isRunning_ = true;
+    sock_ = create_socket(std::stoi(port_));
+    server_read_thread_ = std::thread([this]() -> void {
+      while (isRunning_) {
+        struct sockaddr_in addr;
+        uint len = sizeof(addr);
+
+        int client = accept(sock_, (struct sockaddr*)&addr, &len);
+        ssl_ = SSL_new(ctx_);
+        SSL_set_fd(ssl_, client);
+        successful = (SSL_accept(ssl_) == 1);
+      }
+    });
+  }
+
+  bool isRunning_;
+  std::thread server_read_thread_;
+  int sock_;
+  bool successful;
+
+ private:
+  SSL_CTX *ctx_;
+  SSL* ssl_;
+  std::string port_;
+  uint16_t listeners_;
+
+  void configure_context(std::string path) {
+      SSL_CTX_set_ecdh_auto(ctx_, 1);
+      /* Set the key and cert */
+      assert(SSL_CTX_use_certificate_file(ctx_, (path + "cn.crt.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+      assert(SSL_CTX_use_PrivateKey_file(ctx_, (path + "cn.ckey.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+  }
+
+  int create_socket(int port) {
+    int s;
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(port);
+    addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+    s = socket(AF_INET, SOCK_STREAM, 0);
+    if (s < 0) {
+      perror("Unable to create socket");
+      exit(EXIT_FAILURE);
+    }
+
+    if (bind(s, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
+      perror("Unable to bind");
+      exit(EXIT_FAILURE);
+    }
+
+    if (listen(s, 1) < 0) {
+      perror("Unable to listen");
+      exit(EXIT_FAILURE);
+    }
+
+    return s;
+  }
+};
+
+class SimpleSSLTestServerTLSv1  : public SimpleSSLTestServer {
+ public:
+  SimpleSSLTestServerTLSv1(std::string port, std::string path) : 
SimpleSSLTestServer(TLSv1_server_method(), port, path) {
+  }
+};
+
+class SimpleSSLTestServerTLSv1_1  : public SimpleSSLTestServer {
+ public:
+  SimpleSSLTestServerTLSv1_1(std::string port, std::string path) : 
SimpleSSLTestServer(TLSv1_1_server_method(), port, path) {
+  }
+};
+
+class SimpleSSLTestServerTLSv1_2  : public SimpleSSLTestServer {
+ public:
+  SimpleSSLTestServerTLSv1_2(std::string port, std::string path) : 
SimpleSSLTestServer(TLSv1_2_server_method(), port, path) {
+  }
+};
+
+class TLSClientSocketSupportedProtocolsTest {
+ public:
+  TLSClientSocketSupportedProtocolsTest()
+      : configuration_(std::make_shared<minifi::Configure>()) {
+  }
+
+  void run() {
+    configureSecurity();
+
+    runAssertions();
+  }
+
+  void setKeyDir(const std::string key_dir) {
+    this->key_dir = key_dir;

Review comment:
       use "_" suffix for members to distinguish from local variables, you can 
avoid the `this` keyword that way. Same 
inTLSServerSocketSupportedProtocolsTest.cpp 

##########
File path: 
extensions/standard-processors/tests/integration/TLSClientSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,221 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+class SimpleSSLTestServer  {
+ public:
+  SimpleSSLTestServer(const SSL_METHOD* method, std::string port, std::string 
path)
+      : port_(port) {
+    ctx_ = SSL_CTX_new(method);
+    configure_context(path);
+  }
+
+  ~SimpleSSLTestServer() {
+      SSL_shutdown(ssl_);
+      SSL_free(ssl_);
+      SSL_CTX_free(ctx_);
+  }
+
+  void waitForConnection() {
+    isRunning_ = true;
+    sock_ = create_socket(std::stoi(port_));
+    server_read_thread_ = std::thread([this]() -> void {
+      while (isRunning_) {
+        struct sockaddr_in addr;
+        uint len = sizeof(addr);
+
+        int client = accept(sock_, (struct sockaddr*)&addr, &len);
+        ssl_ = SSL_new(ctx_);
+        SSL_set_fd(ssl_, client);
+        successful = (SSL_accept(ssl_) == 1);
+      }
+    });
+  }
+
+  bool isRunning_;
+  std::thread server_read_thread_;
+  int sock_;
+  bool successful;
+
+ private:
+  SSL_CTX *ctx_;
+  SSL* ssl_;
+  std::string port_;
+  uint16_t listeners_;
+
+  void configure_context(std::string path) {
+      SSL_CTX_set_ecdh_auto(ctx_, 1);
+      /* Set the key and cert */
+      assert(SSL_CTX_use_certificate_file(ctx_, (path + "cn.crt.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+      assert(SSL_CTX_use_PrivateKey_file(ctx_, (path + "cn.ckey.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+  }
+
+  int create_socket(int port) {
+    int s;
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(port);
+    addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+    s = socket(AF_INET, SOCK_STREAM, 0);
+    if (s < 0) {
+      perror("Unable to create socket");
+      exit(EXIT_FAILURE);
+    }
+
+    if (bind(s, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
+      perror("Unable to bind");
+      exit(EXIT_FAILURE);
+    }
+
+    if (listen(s, 1) < 0) {
+      perror("Unable to listen");
+      exit(EXIT_FAILURE);
+    }
+
+    return s;
+  }
+};
+
+class SimpleSSLTestServerTLSv1  : public SimpleSSLTestServer {
+ public:
+  SimpleSSLTestServerTLSv1(std::string port, std::string path) : 
SimpleSSLTestServer(TLSv1_server_method(), port, path) {
+  }
+};
+
+class SimpleSSLTestServerTLSv1_1  : public SimpleSSLTestServer {
+ public:
+  SimpleSSLTestServerTLSv1_1(std::string port, std::string path) : 
SimpleSSLTestServer(TLSv1_1_server_method(), port, path) {
+  }
+};
+
+class SimpleSSLTestServerTLSv1_2  : public SimpleSSLTestServer {
+ public:
+  SimpleSSLTestServerTLSv1_2(std::string port, std::string path) : 
SimpleSSLTestServer(TLSv1_2_server_method(), port, path) {
+  }
+};
+
+class TLSClientSocketSupportedProtocolsTest {
+ public:
+  TLSClientSocketSupportedProtocolsTest()
+      : configuration_(std::make_shared<minifi::Configure>()) {
+  }
+
+  void run() {
+    configureSecurity();
+
+    runAssertions();
+  }
+
+  void setKeyDir(const std::string key_dir) {
+    this->key_dir = key_dir;
+  }
+
+ protected:
+  void configureSecurity() {
+    host_ = org::apache::nifi::minifi::io::Socket::getMyHostName();
+    port_ = "3684";
+    if (!key_dir.empty()) {
+      configuration_->set(minifi::Configure::nifi_remote_input_secure, "true");
+      configuration_->set(minifi::Configure::nifi_security_client_certificate, 
key_dir + "cn.crt.pem");
+      configuration_->set(minifi::Configure::nifi_security_client_private_key, 
key_dir + "cn.ckey.pem");
+      configuration_->set(minifi::Configure::nifi_security_client_pass_phrase, 
key_dir + "cn.pass");
+      
configuration_->set(minifi::Configure::nifi_security_client_ca_certificate, 
key_dir + "nifi-cert.pem");
+      configuration_->set(minifi::Configure::nifi_default_directory, key_dir);
+    }
+  }
+
+  void runAssertions() {
+    {
+      SimpleSSLTestServerTLSv1 server(port_, key_dir);
+      server.waitForConnection();
+
+      std::shared_ptr<org::apache::nifi::minifi::io::TLSContext> 
socket_context = 
std::make_shared<org::apache::nifi::minifi::io::TLSContext>(configuration_);
+      client_socket_ = 
std::make_shared<org::apache::nifi::minifi::io::TLSSocket>(socket_context, 
host_, std::stoi(port_), 0);
+      assert(client_socket_->initialize() != 0);
+      shutdown(server.sock_, SHUT_RD);
+      close(server.sock_);
+      server.isRunning_ = false;
+      server.server_read_thread_.join();
+    }
+    {
+      SimpleSSLTestServerTLSv1_1 server(port_, key_dir);
+      server.waitForConnection();
+
+      std::shared_ptr<org::apache::nifi::minifi::io::TLSContext> 
socket_context = 
std::make_shared<org::apache::nifi::minifi::io::TLSContext>(configuration_);
+      client_socket_ = 
std::make_shared<org::apache::nifi::minifi::io::TLSSocket>(socket_context, 
host_, std::stoi(port_), 0);
+      assert(client_socket_->initialize() != 0);
+      shutdown(server.sock_, SHUT_RD);
+      close(server.sock_);
+      server.isRunning_ = false;
+      server.server_read_thread_.join();
+    }
+    {
+      SimpleSSLTestServerTLSv1_2 server(port_, key_dir);
+      server.waitForConnection();
+
+      std::shared_ptr<org::apache::nifi::minifi::io::TLSContext> 
socket_context = 
std::make_shared<org::apache::nifi::minifi::io::TLSContext>(configuration_);
+      client_socket_ = 
std::make_shared<org::apache::nifi::minifi::io::TLSSocket>(socket_context, 
host_, std::stoi(port_), 0);
+      assert(client_socket_->initialize() == 0);
+      shutdown(server.sock_, SHUT_RD);
+      close(server.sock_);
+      server.isRunning_ = false;
+      server.server_read_thread_.join();
+    }
+  }
+
+ protected:
+    std::shared_ptr<org::apache::nifi::minifi::io::TLSSocket> client_socket_;
+    std::string host_;
+    std::string port_;
+    std::string key_dir;
+    std::shared_ptr<minifi::Configure> configuration_;
+};
+
+static void sigpipe_handle(int /*x*/) {

Review comment:
       I don't think `/*x*/` is needed here as that name does not have 
additional info about the parameter. Either remove or rename it. Same in 
TLSServerSocketSupportedProtocolsTest.cpp 

##########
File path: 
extensions/standard-processors/tests/integration/TLSClientSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,221 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+class SimpleSSLTestServer  {
+ public:
+  SimpleSSLTestServer(const SSL_METHOD* method, std::string port, std::string 
path)
+      : port_(port) {
+    ctx_ = SSL_CTX_new(method);
+    configure_context(path);
+  }
+
+  ~SimpleSSLTestServer() {
+      SSL_shutdown(ssl_);
+      SSL_free(ssl_);
+      SSL_CTX_free(ctx_);
+  }
+
+  void waitForConnection() {
+    isRunning_ = true;
+    sock_ = create_socket(std::stoi(port_));
+    server_read_thread_ = std::thread([this]() -> void {
+      while (isRunning_) {
+        struct sockaddr_in addr;
+        uint len = sizeof(addr);
+
+        int client = accept(sock_, (struct sockaddr*)&addr, &len);
+        ssl_ = SSL_new(ctx_);
+        SSL_set_fd(ssl_, client);
+        successful = (SSL_accept(ssl_) == 1);
+      }
+    });
+  }
+
+  bool isRunning_;
+  std::thread server_read_thread_;
+  int sock_;
+  bool successful;
+
+ private:
+  SSL_CTX *ctx_;
+  SSL* ssl_;
+  std::string port_;
+  uint16_t listeners_;
+
+  void configure_context(std::string path) {
+      SSL_CTX_set_ecdh_auto(ctx_, 1);
+      /* Set the key and cert */
+      assert(SSL_CTX_use_certificate_file(ctx_, (path + "cn.crt.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+      assert(SSL_CTX_use_PrivateKey_file(ctx_, (path + "cn.ckey.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+  }
+
+  int create_socket(int port) {
+    int s;

Review comment:
       Use a more readable name, also this declaration can be moved to the 
place of initialization.

##########
File path: 
extensions/standard-processors/tests/integration/TLSServerSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,217 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+class SimpleSSLTestClient  {
+ public:
+  SimpleSSLTestClient(const SSL_METHOD* method, std::string host, std::string 
port) :
+    host_(host),
+    port_(port) {
+      ctx_ = SSL_CTX_new(method);
+      sfd_ = openConnection(host_.c_str(), port_.c_str());
+      if (ctx_ != nullptr)
+        ssl_ = SSL_new(ctx_);
+      if (ssl_ != nullptr)
+        SSL_set_fd(ssl_, sfd_);
+  }
+
+  ~SimpleSSLTestClient() {
+    SSL_free(ssl_);
+    close(sfd_);
+    SSL_CTX_free(ctx_);
+  }
+
+  bool canConnect() {
+    const int status = SSL_connect(ssl_);
+    bool successfulConnection = (status == 1);
+    return successfulConnection;
+  }
+
+ private:
+  SSL_CTX *ctx_;
+  SSL* ssl_;
+  int sfd_;
+  std::string host_;
+  std::string port_;
+
+  int openConnection(const char *hostname, const char *port) {
+    constexpr int ERROR_STATUS = -1;
+    struct hostent *host;
+    if ((host = gethostbyname(hostname)) == nullptr) {
+        perror(hostname);
+        exit(EXIT_FAILURE);
+    }
+    struct addrinfo hints = {0}, *addrs;
+    hints.ai_family = AF_UNSPEC;
+    hints.ai_socktype = SOCK_STREAM;
+    hints.ai_protocol = IPPROTO_TCP;
+    const int status = getaddrinfo(hostname, port, &hints, &addrs);
+    if (status != 0) {
+        fprintf(stderr, "%s: %s\n", hostname, gai_strerror(status));
+        exit(EXIT_FAILURE);
+    }
+    int sfd, err;
+    for (struct addrinfo *addr = addrs; addr != nullptr; addr = addr->ai_next) 
{
+        sfd = socket(addrs->ai_family, addrs->ai_socktype, addrs->ai_protocol);
+        if (sfd == ERROR_STATUS) {
+            err = errno;
+            continue;
+        }
+        if (connect(sfd, addr->ai_addr, addr->ai_addrlen) == 0) {
+            break;
+        }
+        err = errno;
+        sfd = ERROR_STATUS;
+        close(sfd);
+    }
+    freeaddrinfo(addrs);
+    if (sfd == ERROR_STATUS) {
+        fprintf(stderr, "%s: %s\n", hostname, strerror(err));
+        exit(EXIT_FAILURE);
+    }
+    return sfd;
+  }
+};
+
+class SimpleSSLTestClientTLSv1  : public SimpleSSLTestClient {
+ public:
+  SimpleSSLTestClientTLSv1(std::string host, std::string port) : 
SimpleSSLTestClient(TLSv1_client_method(), host, port) {
+  }
+};
+
+class SimpleSSLTestClientTLSv1_1  : public SimpleSSLTestClient {
+ public:
+  SimpleSSLTestClientTLSv1_1(std::string host, std::string port) : 
SimpleSSLTestClient(TLSv1_1_client_method(), host, port) {
+  }
+};
+
+class SimpleSSLTestClientTLSv1_2  : public SimpleSSLTestClient {
+ public:
+  SimpleSSLTestClientTLSv1_2(std::string host, std::string port) : 
SimpleSSLTestClient(TLSv1_2_client_method(), host, port) {
+  }
+};
+
+class TLSServerSocketSupportedProtocolsTest {
+ public:
+    TLSServerSocketSupportedProtocolsTest()
+        : isRunning_{ false }, 
configuration_(std::make_shared<minifi::Configure>()) {
+    }
+
+    void run() {
+      configureSecurity();
+
+      createServerSocket();
+
+      runAssertions();
+    }
+
+    void setKeyDir(const std::string key_dir) {
+      this->key_dir = key_dir;
+    }
+
+ protected:
+    void configureSecurity() {
+      host_ = org::apache::nifi::minifi::io::Socket::getMyHostName();
+      port_ = "3684";
+      if (!key_dir.empty()) {
+        configuration_->set(minifi::Configure::nifi_remote_input_secure, 
"true");
+        
configuration_->set(minifi::Configure::nifi_security_client_certificate, 
key_dir + "cn.crt.pem");
+        
configuration_->set(minifi::Configure::nifi_security_client_private_key, 
key_dir + "cn.ckey.pem");
+        
configuration_->set(minifi::Configure::nifi_security_client_pass_phrase, 
key_dir + "cn.pass");
+        
configuration_->set(minifi::Configure::nifi_security_client_ca_certificate, 
key_dir + "nifi-cert.pem");
+        configuration_->set(minifi::Configure::nifi_default_directory, 
key_dir);
+      }
+    }
+
+    void createServerSocket() {
+      std::shared_ptr<org::apache::nifi::minifi::io::TLSContext> 
socket_context = 
std::make_shared<org::apache::nifi::minifi::io::TLSContext>(configuration_);
+      server_socket_ = 
std::make_shared<org::apache::nifi::minifi::io::TLSServerSocket>(socket_context,
 host_, std::stoi(port_), 3);
+      assert(0 == server_socket_->initialize());
+
+      isRunning_ = true;
+      check = [this]() -> bool {
+        return isRunning_;
+      };
+      handler = [this](std::vector<uint8_t> *b, int *size) {

Review comment:
       Use a more descriptive name for `b`

##########
File path: 
extensions/standard-processors/tests/integration/TLSClientSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,221 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+class SimpleSSLTestServer  {
+ public:
+  SimpleSSLTestServer(const SSL_METHOD* method, std::string port, std::string 
path)
+      : port_(port) {
+    ctx_ = SSL_CTX_new(method);
+    configure_context(path);
+  }
+
+  ~SimpleSSLTestServer() {
+      SSL_shutdown(ssl_);
+      SSL_free(ssl_);
+      SSL_CTX_free(ctx_);
+  }
+
+  void waitForConnection() {
+    isRunning_ = true;
+    sock_ = create_socket(std::stoi(port_));
+    server_read_thread_ = std::thread([this]() -> void {
+      while (isRunning_) {
+        struct sockaddr_in addr;
+        uint len = sizeof(addr);
+
+        int client = accept(sock_, (struct sockaddr*)&addr, &len);
+        ssl_ = SSL_new(ctx_);
+        SSL_set_fd(ssl_, client);
+        successful = (SSL_accept(ssl_) == 1);
+      }
+    });
+  }
+
+  bool isRunning_;
+  std::thread server_read_thread_;
+  int sock_;
+  bool successful;
+
+ private:
+  SSL_CTX *ctx_;
+  SSL* ssl_;
+  std::string port_;
+  uint16_t listeners_;
+
+  void configure_context(std::string path) {
+      SSL_CTX_set_ecdh_auto(ctx_, 1);
+      /* Set the key and cert */
+      assert(SSL_CTX_use_certificate_file(ctx_, (path + "cn.crt.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+      assert(SSL_CTX_use_PrivateKey_file(ctx_, (path + "cn.ckey.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+  }
+
+  int create_socket(int port) {
+    int s;
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(port);
+    addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+    s = socket(AF_INET, SOCK_STREAM, 0);
+    if (s < 0) {
+      perror("Unable to create socket");

Review comment:
       We could use our core::logging::Logger instead

##########
File path: 
extensions/standard-processors/tests/integration/TLSClientSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,221 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+class SimpleSSLTestServer  {
+ public:
+  SimpleSSLTestServer(const SSL_METHOD* method, std::string port, std::string 
path)
+      : port_(port) {
+    ctx_ = SSL_CTX_new(method);
+    configure_context(path);
+  }
+
+  ~SimpleSSLTestServer() {
+      SSL_shutdown(ssl_);
+      SSL_free(ssl_);
+      SSL_CTX_free(ctx_);
+  }
+
+  void waitForConnection() {
+    isRunning_ = true;
+    sock_ = create_socket(std::stoi(port_));
+    server_read_thread_ = std::thread([this]() -> void {
+      while (isRunning_) {
+        struct sockaddr_in addr;
+        uint len = sizeof(addr);
+
+        int client = accept(sock_, (struct sockaddr*)&addr, &len);
+        ssl_ = SSL_new(ctx_);
+        SSL_set_fd(ssl_, client);
+        successful = (SSL_accept(ssl_) == 1);
+      }
+    });
+  }
+
+  bool isRunning_;
+  std::thread server_read_thread_;
+  int sock_;
+  bool successful;
+
+ private:
+  SSL_CTX *ctx_;
+  SSL* ssl_;
+  std::string port_;
+  uint16_t listeners_;
+
+  void configure_context(std::string path) {
+      SSL_CTX_set_ecdh_auto(ctx_, 1);
+      /* Set the key and cert */
+      assert(SSL_CTX_use_certificate_file(ctx_, (path + "cn.crt.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+      assert(SSL_CTX_use_PrivateKey_file(ctx_, (path + "cn.ckey.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+  }
+
+  int create_socket(int port) {
+    int s;
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(port);
+    addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+    s = socket(AF_INET, SOCK_STREAM, 0);
+    if (s < 0) {
+      perror("Unable to create socket");
+      exit(EXIT_FAILURE);
+    }
+
+    if (bind(s, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
+      perror("Unable to bind");
+      exit(EXIT_FAILURE);
+    }
+
+    if (listen(s, 1) < 0) {
+      perror("Unable to listen");
+      exit(EXIT_FAILURE);
+    }
+
+    return s;
+  }
+};
+
+class SimpleSSLTestServerTLSv1  : public SimpleSSLTestServer {
+ public:
+  SimpleSSLTestServerTLSv1(std::string port, std::string path) : 
SimpleSSLTestServer(TLSv1_server_method(), port, path) {
+  }
+};
+
+class SimpleSSLTestServerTLSv1_1  : public SimpleSSLTestServer {
+ public:
+  SimpleSSLTestServerTLSv1_1(std::string port, std::string path) : 
SimpleSSLTestServer(TLSv1_1_server_method(), port, path) {
+  }
+};
+
+class SimpleSSLTestServerTLSv1_2  : public SimpleSSLTestServer {
+ public:
+  SimpleSSLTestServerTLSv1_2(std::string port, std::string path) : 
SimpleSSLTestServer(TLSv1_2_server_method(), port, path) {
+  }
+};
+
+class TLSClientSocketSupportedProtocolsTest {
+ public:
+  TLSClientSocketSupportedProtocolsTest()
+      : configuration_(std::make_shared<minifi::Configure>()) {
+  }
+
+  void run() {
+    configureSecurity();
+
+    runAssertions();
+  }
+
+  void setKeyDir(const std::string key_dir) {
+    this->key_dir = key_dir;
+  }
+
+ protected:
+  void configureSecurity() {
+    host_ = org::apache::nifi::minifi::io::Socket::getMyHostName();
+    port_ = "3684";
+    if (!key_dir.empty()) {
+      configuration_->set(minifi::Configure::nifi_remote_input_secure, "true");
+      configuration_->set(minifi::Configure::nifi_security_client_certificate, 
key_dir + "cn.crt.pem");
+      configuration_->set(minifi::Configure::nifi_security_client_private_key, 
key_dir + "cn.ckey.pem");
+      configuration_->set(minifi::Configure::nifi_security_client_pass_phrase, 
key_dir + "cn.pass");
+      
configuration_->set(minifi::Configure::nifi_security_client_ca_certificate, 
key_dir + "nifi-cert.pem");
+      configuration_->set(minifi::Configure::nifi_default_directory, key_dir);
+    }
+  }
+
+  void runAssertions() {

Review comment:
       To me this doesn't really seem like running assertions, but running 
separate testcases with different servers types and verifying the same 
behavior. It might be better to use the catch2 test framework here with 
different sections for different servers, or just separate test cases.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to