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