exceptionfactory commented on a change in pull request #5457: URL: https://github.com/apache/nifi/pull/5457#discussion_r730861145
########## File path: nifi-nar-bundles/nifi-pgp-bundle/nifi-pgp-processors/src/main/java/org/apache/nifi/processors/pgp/SignContentPGP.java ########## @@ -0,0 +1,371 @@ +/* + * 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.processors.pgp; + +import org.apache.nifi.annotation.behavior.InputRequirement; +import org.apache.nifi.annotation.behavior.WritesAttribute; +import org.apache.nifi.annotation.behavior.WritesAttributes; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.SeeAlso; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.expression.ExpressionLanguageScope; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.flowfile.attributes.CoreAttributes; +import org.apache.nifi.pgp.service.api.PGPPrivateKeyService; +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.processors.pgp.attributes.CompressionAlgorithm; +import org.apache.nifi.processors.pgp.attributes.FileEncoding; +import org.apache.nifi.processors.pgp.attributes.HashAlgorithm; +import org.apache.nifi.processors.pgp.attributes.SigningStrategy; +import org.apache.nifi.processors.pgp.exception.PGPProcessException; +import org.apache.nifi.processors.pgp.io.EncodingStreamCallback; +import org.apache.nifi.processors.pgp.io.KeyIdentifierConverter; +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPLiteralDataGenerator; +import org.bouncycastle.openpgp.PGPOnePassSignature; +import org.bouncycastle.openpgp.PGPPrivateKey; +import org.bouncycastle.openpgp.PGPSignature; +import org.bouncycastle.openpgp.PGPSignatureGenerator; +import org.bouncycastle.openpgp.PGPUtil; +import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.security.SecureRandom; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +/** + * Sign Content using Open Pretty Good Privacy Private Keys + */ +@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED) +@Tags({"PGP", "GPG", "OpenPGP", "Encryption", "Signing", "RFC 4880"}) +@CapabilityDescription("Sign content using OpenPGP Private Keys") +@SeeAlso({DecryptContentPGP.class, EncryptContentPGP.class, VerifyContentPGP.class}) +@WritesAttributes({ + @WritesAttribute(attribute = PGPAttributeKey.COMPRESS_ALGORITHM, description = "Compression Algorithm"), + @WritesAttribute(attribute = PGPAttributeKey.COMPRESS_ALGORITHM_ID, description = "Compression Algorithm Identifier"), + @WritesAttribute(attribute = PGPAttributeKey.FILE_ENCODING, description = "File Encoding"), + @WritesAttribute(attribute = PGPAttributeKey.SIGNATURE_ALGORITHM, description = "Signature Algorithm including key and hash algorithm names"), + @WritesAttribute(attribute = PGPAttributeKey.SIGNATURE_HASH_ALGORITHM_ID, description = "Signature Hash Algorithm Identifier"), + @WritesAttribute(attribute = PGPAttributeKey.SIGNATURE_KEY_ALGORITHM_ID, description = "Signature Key Algorithm Identifier"), + @WritesAttribute(attribute = PGPAttributeKey.SIGNATURE_KEY_ID, description = "Signature Public Key Identifier"), + @WritesAttribute(attribute = PGPAttributeKey.SIGNATURE_TYPE_ID, description = "Signature Type Identifier"), + @WritesAttribute(attribute = PGPAttributeKey.SIGNATURE_VERSION, description = "Signature Version Number"), +}) +public class SignContentPGP extends AbstractProcessor { + + public static final Relationship SUCCESS = new Relationship.Builder() + .name("success") + .description("Content signing succeeded") + .build(); + + public static final Relationship FAILURE = new Relationship.Builder() + .name("failure") + .description("Content signing failed") + .build(); + + public static final PropertyDescriptor COMPRESSION_ALGORITHM = new PropertyDescriptor.Builder() + .name("compression-algorithm") + .displayName("Compression Algorithm") + .description("Compression Algorithm for signing") + .required(true) + .defaultValue(CompressionAlgorithm.ZIP.toString()) + .allowableValues(CompressionAlgorithm.values()) + .build(); + + public static final PropertyDescriptor FILE_ENCODING = new PropertyDescriptor.Builder() + .name("file-encoding") + .displayName("File Encoding") + .description("File Encoding for signing") + .required(true) + .defaultValue(FileEncoding.BINARY.toString()) + .allowableValues(FileEncoding.values()) + .build(); + + public static final PropertyDescriptor HASH_ALGORITHM = new PropertyDescriptor.Builder() + .name("hash-algorithm") + .displayName("Hash Algorithm") + .description("Hash Algorithm for signing") + .required(true) + .defaultValue(HashAlgorithm.SHA512.toString()) + .allowableValues(HashAlgorithm.values()) + .build(); + + public static final PropertyDescriptor SIGNING_STRATEGY = new PropertyDescriptor.Builder() + .name("signing-strategy") + .displayName("Signing Strategy") + .description("Strategy for writing files to success after signing") + .required(true) + .defaultValue(SigningStrategy.SIGNED.toString()) + .allowableValues(SigningStrategy.values()) Review comment: Thanks for the suggestion, adding a description sounds good. -- 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]
