You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/07/27 11:54:29 UTC

[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1370: MINIFICPP-1866 Secure connection for ListenSyslog, ListenTCP

adamdebreceni commented on code in PR #1370:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1370#discussion_r930969826


##########
libminifi/test/Utils.h:
##########
@@ -115,6 +119,43 @@ void sendMessagesViaTCP(const std::vector<std::string_view>& contents, uint64_t
     tcp_message += '\n';
     socket.send(asio::buffer(tcp_message, tcp_message.size()), 0, err);
   }
-  REQUIRE(!err);
+  if (err) {
+    return false;
+  }
   socket.close();
+  return true;
 }
+
+bool sendMessagesViaSSL(const std::vector<std::string_view>& contents, uint64_t port, const std::string& ca_cert_path, const std::optional<minifi::utils::net::SslData>& ssl_data = std::nullopt) {
+  asio::ssl::context ctx(asio::ssl::context::sslv23);
+  ctx.load_verify_file(ca_cert_path);
+  if (ssl_data) {
+    ctx.set_verify_mode(asio::ssl::verify_peer);
+    ctx.use_certificate_file(ssl_data->cert_loc, asio::ssl::context::pem);
+    ctx.use_private_key_file(ssl_data->key_loc, asio::ssl::context::pem);
+  }
+  asio::io_context io_context;
+  asio::ssl::stream<asio::ip::tcp::socket> socket(io_context, ctx);
+  asio::ip::tcp::endpoint remote_endpoint(asio::ip::address::from_string("127.0.0.1"), port);
+  asio::error_code err;
+  socket.lowest_layer().connect(remote_endpoint, err);
+  if (err) {
+    return false;
+  }
+  socket.handshake(asio::ssl::stream_base::client, err);
+  if (err) {
+    return false;
+  }
+  for (auto& content : contents) {
+    std::string tcp_message(content);
+    tcp_message += '\n';
+    socket.write_some(asio::buffer(tcp_message, tcp_message.size()));

Review Comment:
   `write_some` does not seem to guarantee that all bytes are written (it returns the number of written bytes), the docs mention a `write` function to achieve complete write (could not find it)



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org