Skip to content

Commit

Permalink
NO-SNOW Remove FIPS test (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mbobowski authored Nov 5, 2024
1 parent bb4c070 commit 1ddba0a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@

import com.snowflake.kafka.connector.config.IcebergConfigValidator;
import com.snowflake.kafka.connector.internal.EncryptionUtils;
import com.snowflake.kafka.connector.internal.FIPSTest;
import com.snowflake.kafka.connector.internal.TestUtils;
import com.snowflake.kafka.connector.internal.streaming.DefaultStreamingConfigValidator;
import com.snowflake.kafka.connector.internal.streaming.IngestionMethodConfig;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.security.PrivateKey;
import java.security.Security;
import java.util.Map;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfoBuilder;
import org.bouncycastle.pkcs.jcajce.JcaPKCS8EncryptedPrivateKeyInfoBuilder;
import org.bouncycastle.pkcs.jcajce.JcePKCSPBEOutputEncryptorBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -30,7 +38,7 @@ public class ConnectorConfigValidatorLogsTest {
public void testRSAPasswordOutput() throws IOException, OperatorCreationException {
// given
String testPasswd = "TestPassword1234!";
String testKey = FIPSTest.generateAESKey(TestUtils.getPrivateKey(), testPasswd.toCharArray());
String testKey = generateAESKey(TestUtils.getPrivateKey(), testPasswd.toCharArray());
Map<String, String> testConf = getConfig();
testConf.remove(SnowflakeSinkConnectorConfig.SNOWFLAKE_PRIVATE_KEY);
testConf.put(SnowflakeSinkConnectorConfig.SNOWFLAKE_PRIVATE_KEY, testKey);
Expand Down Expand Up @@ -85,4 +93,20 @@ private boolean logFileContains(String str) throws IOException {
fileReader.close();
return false;
}

private String generateAESKey(PrivateKey key, char[] passwd)
throws IOException, OperatorCreationException {
Security.addProvider(new BouncyCastleFipsProvider());
StringWriter writer = new StringWriter();
JcaPEMWriter pemWriter = new JcaPEMWriter(writer);
PKCS8EncryptedPrivateKeyInfoBuilder pkcs8EncryptedPrivateKeyInfoBuilder =
new JcaPKCS8EncryptedPrivateKeyInfoBuilder(key);
pemWriter.writeObject(
pkcs8EncryptedPrivateKeyInfoBuilder.build(
new JcePKCSPBEOutputEncryptorBuilder(NISTObjectIdentifiers.id_aes256_CBC)
.setProvider("BCFIPS")
.build(passwd)));
pemWriter.close();
return writer.toString();
}
}
55 changes: 0 additions & 55 deletions src/test/java/com/snowflake/kafka/connector/internal/FIPSTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public class TestUtils {
private static final String AZ_CREDENTIAL_TYPE_CODE = "code";

private static final Random random = new Random();
private static final String DES_RSA_KEY = "des_rsa_key";
public static final String TEST_CONNECTOR_NAME = "TEST_CONNECTOR";
private static final Pattern BROKEN_RECORD_PATTERN =
Pattern.compile("^[^/]+/[^/]+/(\\d+)/(\\d+)_(key|value)_(\\d+)\\.gz$");
Expand Down Expand Up @@ -485,10 +484,6 @@ public static ResultSet showTable(String tableName) {
return executeQuery(query);
}

static String getDesRsaKey() {
return getProfile(PROFILE_PATH).get(DES_RSA_KEY).asText();
}

/**
* create a random name for test
*
Expand Down

0 comments on commit 1ddba0a

Please sign in to comment.