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


##########
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:
   Updated in 5d55facd7c7f853ed099d3bef89d0a0329b23043



##########
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);

Review Comment:
   Updated in 5d55facd7c7f853ed099d3bef89d0a0329b23043



##########
libminifi/src/utils/net/Ssl.cpp:
##########
@@ -0,0 +1,53 @@
+/**
+ * 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 "utils/net/Ssl.h"
+#include "controllers/SSLContextService.h"
+
+namespace org::apache::nifi::minifi::utils::net {
+
+std::optional<utils::net::SslData> getSslData(const core::ProcessContext& 
context, const core::Property& ssl_prop, const 
std::shared_ptr<core::logging::Logger>& logger) {
+  auto getSslContextService = [&]() -> 
std::shared_ptr<minifi::controllers::SSLContextService> {
+    if (auto ssl_service_name = context.getProperty(ssl_prop); 
ssl_service_name && !ssl_service_name->empty()) {
+      if (auto service = context.getControllerService(*ssl_service_name)) {
+        if (auto ssl_service = 
std::dynamic_pointer_cast<org::apache::nifi::minifi::controllers::SSLContextService>(service))
 {
+          return ssl_service;
+        } else {
+          logger->log_warn("SSL Context Service property is set to '%s', but 
it is not a valid SSLContextService.", *ssl_service_name);
+        }
+      } else {
+        logger->log_warn("SSL Context Service property is set to '%s', but the 
controller service could not be found.", *ssl_service_name);
+      }
+    } else {
+      logger->log_warn("No valid SSL Context Service property is set.");
+    }
+    return nullptr;
+  };
+
+  if (auto service = getSslContextService()) {
+    auto ssl_service = 
std::static_pointer_cast<minifi::controllers::SSLContextService>(service);

Review Comment:
   Updated in 5d55facd7c7f853ed099d3bef89d0a0329b23043



-- 
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: [email protected]

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

Reply via email to