alopresto commented on a change in pull request #3672: NIFI-6363 Additional Sensitive Property Providers URL: https://github.com/apache/nifi/pull/3672#discussion_r318217785
########## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/java/org/apache/nifi/properties/sensitive/keystore/KeyStoreSensitivePropertyProviderIT.java ########## @@ -0,0 +1,334 @@ +/* + * 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.properties.sensitive.keystore; + +import org.apache.nifi.properties.sensitive.AbstractSensitivePropertyProviderTest; +import org.apache.nifi.properties.sensitive.SensitivePropertyConfigurationException; +import org.apache.nifi.properties.sensitive.SensitivePropertyProvider; +import org.apache.nifi.security.util.CipherUtils; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.crypto.spec.SecretKeySpec; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.Security; +import java.security.cert.CertificateException; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + + +public class KeyStoreSensitivePropertyProviderIT extends AbstractSensitivePropertyProviderTest { + private static final Logger logger = LoggerFactory.getLogger(KeyStoreSensitivePropertyProviderIT.class); + + private static SecureRandom random = new SecureRandom(); + private static Map<String, KeyStoreTestCase> testCases = new HashMap<>(); + + private static class KeyStoreTestCase { + String storeType; // each test case has a KeyStore of this named type + String storePassword; // and has a random password + byte[] storeContents; // and has content serialized as bytes when built + + String keyAlias; // each test case also contains a key with this alias + String keyPassword; // and that key has a random password, too + } + + private static final String[] keyAlgos = {"RSA", "DSA", "ECDSA", "AES"}; + private static final int[] keySizes = {16, 24, 32}; + + @Rule + public TemporaryFolder tmpDir = new TemporaryFolder(); + + @BeforeClass + public static void setUpKeyPair() { + Security.addProvider(new BouncyCastleProvider()); + } + + @Before + public void setUpTest() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException { + final byte[] keyBytes = new byte[32]; Review comment: This will fail on systems that do not have the unlimited strength crypto jurisdiction policies installed. As more people move to 1.8 112+ we will be ok, but some users are still on 1.8 prior. Recommend using 16 byte / 128 bit key length. ---------------------------------------------------------------- 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] With regards, Apache Git Services
