github-advanced-security[bot] commented on code in PR #11551: URL: https://github.com/apache/nifi/pull/11551#discussion_r3787697630
########## nifi-extension-bundles/nifi-cdc/nifi-cdc-mysql-bundle/nifi-cdc-mysql-processors/src/test/java/org/apache/nifi/cdc/mysql/processors/ssl/DelegatingSSLContextProviderMySQLDriverIT.java: ########## @@ -0,0 +1,175 @@ +/* + * 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. + */ +package org.apache.nifi.cdc.mysql.processors.ssl; + +import com.github.shyiko.mysql.binlog.network.SSLMode; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.testcontainers.mysql.MySQLContainer; +import org.testcontainers.utility.DockerImageName; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.security.KeyStore; +import java.security.Provider; +import java.security.SecureRandom; +import java.security.Security; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509TrustManager; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class DelegatingSSLContextProviderMySQLDriverIT { + + private static final String MYSQL_IMAGE = "mysql:8.4"; + + private static final String SSL_CONTEXT_PROTOCOL = "TLS"; + + private static final String MYSQL_CA_PATH = "/var/lib/mysql/ca.pem"; + + private static final String CERTIFICATE_TYPE = "X.509"; + + private static final String SSL_CIPHER_STATUS_QUERY = "SHOW SESSION STATUS LIKE 'Ssl_cipher'"; + + private static MySQLContainer mysql; + + @BeforeAll + static void startContainer() { + mysql = new MySQLContainer(DockerImageName.parse(MYSQL_IMAGE)); + mysql.start(); + } + + @AfterAll + static void stopContainer() { + if (mysql != null) { + mysql.stop(); + } + } + + @Test + void testRequiredModeUsesInjectedSslContext() throws Exception { + final AtomicBoolean trustManagerInvoked = new AtomicBoolean(false); + final SSLContext sslContext = SSLContext.getInstance(SSL_CONTEXT_PROTOCOL); + sslContext.init(null, new TrustManager[]{new RecordingTrustManager(trustManagerInvoked)}, new SecureRandom()); Review Comment: ## CodeQL / `TrustManager` that accepts all certificates This uses [TrustManager](1), which is defined in [DelegatingSSLContextProviderMySQLDriverIT$RecordingTrustManager](2) and trusts any certificate. [Show more details](https://github.com/apache/nifi/security/code-scanning/96) -- 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]
