[ 
https://issues.apache.org/jira/browse/NIFI-3594?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15981208#comment-15981208
 ] 

ASF GitHub Bot commented on NIFI-3594:
--------------------------------------

Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1686#discussion_r112957440
  
    --- Diff: 
nifi-commons/nifi-data-provenance-utils/src/main/java/org/apache/nifi/provenance/CryptoUtils.java
 ---
    @@ -0,0 +1,228 @@
    +/*
    + * 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.provenance;
    +
    +import java.io.BufferedReader;
    +import java.io.ByteArrayOutputStream;
    +import java.io.File;
    +import java.io.FileReader;
    +import java.io.IOException;
    +import java.security.KeyManagementException;
    +import java.security.NoSuchAlgorithmException;
    +import java.util.Arrays;
    +import java.util.Base64;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.regex.Pattern;
    +import javax.crypto.BadPaddingException;
    +import javax.crypto.Cipher;
    +import javax.crypto.IllegalBlockSizeException;
    +import javax.crypto.SecretKey;
    +import javax.crypto.spec.SecretKeySpec;
    +import org.apache.commons.lang3.StringUtils;
    +import org.apache.nifi.security.util.EncryptionMethod;
    +import org.apache.nifi.security.util.crypto.AESKeyedCipherProvider;
    +import org.apache.nifi.util.NiFiProperties;
    +import org.bouncycastle.util.encoders.Hex;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +public class CryptoUtils {
    +    private static final Logger logger = 
LoggerFactory.getLogger(StaticKeyProvider.class);
    +    private static final String STATIC_KEY_PROVIDER_CLASS_NAME = 
"org.apache.nifi.provenance.StaticKeyProvider";
    +    private static final String FILE_BASED_KEY_PROVIDER_CLASS_NAME = 
"org.apache.nifi.provenance.FileBasedKeyProvider";
    +    private static final Pattern HEX_PATTERN = 
Pattern.compile("(?i)^[0-9a-f]+$");
    +
    +    public static final int IV_LENGTH = 16;
    +
    +    public static boolean isUnlimitedStrengthCryptoAvailable() {
    +        try {
    +            return Cipher.getMaxAllowedKeyLength("AES") > 128;
    +        } catch (NoSuchAlgorithmException e) {
    +            logger.warn("Tried to determine if unlimited strength crypto 
is available but the AES algorithm is not available");
    +            return false;
    +        }
    +    }
    +
    +    /**
    +     * Utility method which returns true if the string is null, empty, or 
entirely whitespace.
    +     *
    +     * @param src the string to evaluate
    +     * @return true if empty
    +     */
    +    public static boolean isEmpty(String src) {
    +        return src == null || src.trim().isEmpty();
    +    }
    +
    +    /**
    +     * Concatenates multiple byte[] into a single byte[]. Because it uses 
a {@link ByteArrayOutputStream}
    +     * rather than {@link System#arraycopy(Object, int, Object, int, int)} 
the performance is much better
    +     * with an arbitrary number of input byte[]s.
    +     *
    +     * @param arrays the component byte[] in order
    +     * @return a concatenated byte[]
    +     * @throws IOException this should never be thrown
    +     */
    +    public static byte[] concatByteArrays(byte[]... arrays) throws 
IOException {
    +        ByteArrayOutputStream boas = new ByteArrayOutputStream();
    --- End diff --
    
    We're doing quite a lot of byte copying here, as the BAOS is potentially 
resizing a lot... then we call toByteArray() to copy it again. Would recommend 
calculating size of the arrays and then just creating an array of that size and 
copying the bytes directly. Alternatively, you could calculate the size of the 
arrays and pass that as an argument to BAOS so that it doesn't generate so much 
garbage - but this still has to copy the byte[] when baos.toByteArray() is 
called.


> Implement encrypted provenance repository
> -----------------------------------------
>
>                 Key: NIFI-3594
>                 URL: https://issues.apache.org/jira/browse/NIFI-3594
>             Project: Apache NiFi
>          Issue Type: Sub-task
>          Components: Core Framework
>    Affects Versions: 1.1.1
>            Reporter: Andy LoPresto
>            Assignee: Andy LoPresto
>              Labels: encryption, provenance, repository
>
> I am going to start with the provenance repository, as the new implementation 
> of {{WriteAheadProvenanceRepository}} has the most recent design decisions 
> and has not been available in a released version yet, so there should be 
> minimal backward compatibility concerns. 



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to