alopresto commented on a change in pull request #3542: NIFI-6363 Integrates AWS KMS SPP. Refactors SSPP. URL: https://github.com/apache/nifi/pull/3542#discussion_r296356394
########## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/main/java/org/apache/nifi/properties/sensitive/aws/kms/AWSKMSSensitivePropertyProvider.java ########## @@ -0,0 +1,160 @@ +/* + * 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.aws.kms; + +import com.amazonaws.services.kms.AWSKMS; +import com.amazonaws.services.kms.AWSKMSClientBuilder; +import com.amazonaws.services.kms.model.DecryptRequest; +import com.amazonaws.services.kms.model.DecryptResult; +import com.amazonaws.services.kms.model.EncryptRequest; +import com.amazonaws.services.kms.model.EncryptResult; +import java.nio.ByteBuffer; +import org.apache.commons.lang3.StringUtils; +import org.apache.nifi.properties.sensitive.SensitivePropertyMetadata; +import org.apache.nifi.properties.sensitive.SensitivePropertyProtectionException; +import org.apache.nifi.properties.sensitive.SensitivePropertyProvider; +import org.bouncycastle.util.encoders.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This provider uses the AWS SDK to interact with the AWS KMS. Values are encoded/decoded base64, using the + * standard encoders from bouncycastle. + */ +public class AWSKMSSensitivePropertyProvider implements SensitivePropertyProvider { + private static final Logger logger = LoggerFactory.getLogger(AWSKMSSensitivePropertyProvider.class); + + private static final String IMPLEMENTATION_NAME = "AWS KMS Sensitive Property Provider"; + protected static final String IMPLEMENTATION_KEY = "aws/kms/"; + + private AWSKMS client; + private final String key; + + public AWSKMSSensitivePropertyProvider(String keyId) { + this.key = validateKey(keyId); + this.client = AWSKMSClientBuilder.standard().build(); + } + + private String validateKey(String keyId) { Review comment: I would add a Javadoc explanation that this doesn't just "validate" the key by checking true/false, but also strips the key identifier prefix, returning just the AWS KMS lookup ID. ---------------------------------------------------------------- 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
