001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.model.dataformat;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlRootElement;
023
024import org.apache.camel.model.DataFormatDefinition;
025import org.apache.camel.spi.Metadata;
026
027/**
028 * Encrypt and decrypt messages using Java Cryptographic Extension (JCE) and PGP.
029 */
030@Metadata(firstVersion = "2.9.0", label = "dataformat,transformation,security", title = "PGP")
031@XmlRootElement(name = "pgp")
032@XmlAccessorType(XmlAccessType.FIELD)
033public class PGPDataFormat extends DataFormatDefinition {
034    @XmlAttribute
035    private String keyUserid;
036    @XmlAttribute
037    private String signatureKeyUserid;
038    @XmlAttribute
039    private String password;
040    @XmlAttribute
041    private String signaturePassword;
042    @XmlAttribute
043    private String keyFileName;
044    @XmlAttribute
045    private String signatureKeyFileName;
046    @XmlAttribute
047    private String signatureKeyRing;
048    @XmlAttribute
049    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
050    private String armored;
051    @XmlAttribute
052    @Metadata(defaultValue = "true", javaType = "java.lang.Boolean")
053    private String integrity;
054    @XmlAttribute
055    private String provider;
056    @XmlAttribute
057    @Metadata(javaType = "java.lang.Integer")
058    private String algorithm;
059    @XmlAttribute
060    @Metadata(javaType = "java.lang.Integer")
061    private String compressionAlgorithm;
062    @XmlAttribute
063    @Metadata(javaType = "java.lang.Integer")
064    private String hashAlgorithm;
065    @XmlAttribute
066    private String signatureVerificationOption;
067
068    public PGPDataFormat() {
069        super("pgp");
070    }
071
072    public String getSignatureKeyUserid() {
073        return signatureKeyUserid;
074    }
075
076    /**
077     * User ID of the key in the PGP keyring used for signing (during
078     * encryption) or signature verification (during decryption). During the
079     * signature verification process the specified User ID restricts the public
080     * keys from the public keyring which can be used for the verification. If
081     * no User ID is specified for the signature verficiation then any public
082     * key in the public keyring can be used for the verification. Can also be
083     * only a part of a user ID. For example, if the user ID is "Test User
084     * <test@camel.com>" then you can use the part "Test User" or
085     * "<test@camel.com>" to address the User ID.
086     */
087    public void setSignatureKeyUserid(String signatureKeyUserid) {
088        this.signatureKeyUserid = signatureKeyUserid;
089    }
090
091    public String getSignaturePassword() {
092        return signaturePassword;
093    }
094
095    /**
096     * Password used when opening the private key used for signing (during
097     * encryption).
098     */
099    public void setSignaturePassword(String signaturePassword) {
100        this.signaturePassword = signaturePassword;
101    }
102
103    public String getSignatureKeyFileName() {
104        return signatureKeyFileName;
105    }
106
107    /**
108     * Filename of the keyring to use for signing (during encryption) or for
109     * signature verification (during decryption); must be accessible as a
110     * classpath resource (but you can specify a location in the file system by
111     * using the "file:" prefix).
112     */
113    public void setSignatureKeyFileName(String signatureKeyFileName) {
114        this.signatureKeyFileName = signatureKeyFileName;
115    }
116
117    public String getSignatureKeyRing() {
118        return signatureKeyRing;
119    }
120
121    /**
122     * Keyring used for signing/verifying as byte array. You can not set the
123     * signatureKeyFileName and signatureKeyRing at the same time.
124     */
125    public void setSignatureKeyRing(String signatureKeyRing) {
126        this.signatureKeyRing = signatureKeyRing;
127    }
128
129    public String getHashAlgorithm() {
130        return hashAlgorithm;
131    }
132
133    /**
134     * Signature hash algorithm; possible values are defined in
135     * org.bouncycastle.bcpg.HashAlgorithmTags; for example 2 (= SHA1), 8 (=
136     * SHA256), 9 (= SHA384), 10 (= SHA512), 11 (=SHA224). Only relevant for
137     * signing.
138     */
139    public void setHashAlgorithm(String hashAlgorithm) {
140        this.hashAlgorithm = hashAlgorithm;
141    }
142
143    public String getArmored() {
144        return armored;
145    }
146
147    /**
148     * This option will cause PGP to base64 encode the encrypted text, making it
149     * available for copy/paste, etc.
150     */
151    public void setArmored(String armored) {
152        this.armored = armored;
153    }
154
155    public String getIntegrity() {
156        return integrity;
157    }
158
159    /**
160     * Adds an integrity check/sign into the encryption file.
161     * <p/>
162     * The default value is true.
163     */
164    public void setIntegrity(String integrity) {
165        this.integrity = integrity;
166    }
167
168    public String getKeyFileName() {
169        return keyFileName;
170    }
171
172    /**
173     * Filename of the keyring; must be accessible as a classpath resource (but
174     * you can specify a location in the file system by using the "file:"
175     * prefix).
176     */
177    public void setKeyFileName(String keyFileName) {
178        this.keyFileName = keyFileName;
179    }
180
181    public String getKeyUserid() {
182        return keyUserid;
183    }
184
185    /**
186     * The user ID of the key in the PGP keyring used during encryption. Can
187     * also be only a part of a user ID. For example, if the user ID is "Test
188     * User <test@camel.com>" then you can use the part "Test User" or
189     * "<test@camel.com>" to address the user ID.
190     */
191    public void setKeyUserid(String keyUserid) {
192        this.keyUserid = keyUserid;
193    }
194
195    public String getPassword() {
196        return password;
197    }
198
199    public String getAlgorithm() {
200        return algorithm;
201    }
202
203    /**
204     * Symmetric key encryption algorithm; possible values are defined in
205     * org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags; for example 2 (= TRIPLE
206     * DES), 3 (= CAST5), 4 (= BLOWFISH), 6 (= DES), 7 (= AES_128). Only
207     * relevant for encrypting.
208     */
209    public void setAlgorithm(String algorithm) {
210        this.algorithm = algorithm;
211    }
212
213    public String getCompressionAlgorithm() {
214        return compressionAlgorithm;
215    }
216
217    /**
218     * Compression algorithm; possible values are defined in
219     * org.bouncycastle.bcpg.CompressionAlgorithmTags; for example 0 (=
220     * UNCOMPRESSED), 1 (= ZIP), 2 (= ZLIB), 3 (= BZIP2). Only relevant for
221     * encrypting.
222     */
223    public void setCompressionAlgorithm(String compressionAlgorithm) {
224        this.compressionAlgorithm = compressionAlgorithm;
225    }
226
227    /**
228     * Password used when opening the private key (not used for encryption).
229     */
230    public void setPassword(String password) {
231        this.password = password;
232    }
233
234    public String getProvider() {
235        return provider;
236    }
237
238    /**
239     * Java Cryptography Extension (JCE) provider, default is Bouncy Castle
240     * ("BC"). Alternatively you can use, for example, the IAIK JCE provider; in
241     * this case the provider must be registered beforehand and the Bouncy
242     * Castle provider must not be registered beforehand. The Sun JCE provider
243     * does not work.
244     */
245    public void setProvider(String provider) {
246        this.provider = provider;
247    }
248
249    public String getSignatureVerificationOption() {
250        return signatureVerificationOption;
251    }
252
253    /**
254     * Controls the behavior for verifying the signature during unmarshaling.
255     * There are 4 values possible: "optional": The PGP message may or may not
256     * contain signatures; if it does contain signatures, then a signature
257     * verification is executed. "required": The PGP message must contain at
258     * least one signature; if this is not the case an exception (PGPException)
259     * is thrown. A signature verification is executed. "ignore": Contained
260     * signatures in the PGP message are ignored; no signature verification is
261     * executed. "no_signature_allowed": The PGP message must not contain a
262     * signature; otherwise an exception (PGPException) is thrown.
263     */
264    public void setSignatureVerificationOption(String signatureVerificationOption) {
265        this.signatureVerificationOption = signatureVerificationOption;
266    }
267}