2018-06-13 17:26:48 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Paul Schaub.
|
|
|
|
*
|
|
|
|
* Licensed 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.
|
|
|
|
*/
|
2018-07-18 18:23:06 +02:00
|
|
|
package org.pgpainless;
|
2018-06-02 21:21:35 +02:00
|
|
|
|
2021-05-31 15:33:42 +02:00
|
|
|
import java.util.Date;
|
|
|
|
|
2020-11-22 20:48:09 +01:00
|
|
|
import org.bouncycastle.openpgp.PGPKeyRing;
|
2020-10-23 16:44:21 +02:00
|
|
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
2018-07-18 18:23:06 +02:00
|
|
|
import org.pgpainless.decryption_verification.DecryptionBuilder;
|
|
|
|
import org.pgpainless.decryption_verification.DecryptionStream;
|
|
|
|
import org.pgpainless.encryption_signing.EncryptionBuilder;
|
|
|
|
import org.pgpainless.encryption_signing.EncryptionStream;
|
|
|
|
import org.pgpainless.key.generation.KeyRingBuilder;
|
2020-11-22 20:48:09 +01:00
|
|
|
import org.pgpainless.key.info.KeyRingInfo;
|
2020-11-19 17:51:57 +01:00
|
|
|
import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditor;
|
|
|
|
import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface;
|
2018-07-18 18:23:06 +02:00
|
|
|
import org.pgpainless.key.parsing.KeyRingReader;
|
2021-02-19 19:51:44 +01:00
|
|
|
import org.pgpainless.policy.Policy;
|
2021-05-15 18:44:03 +02:00
|
|
|
import org.pgpainless.signature.cleartext_signatures.VerifyCleartextSignatures;
|
|
|
|
import org.pgpainless.signature.cleartext_signatures.VerifyCleartextSignaturesImpl;
|
2018-06-02 21:21:35 +02:00
|
|
|
|
|
|
|
public class PGPainless {
|
|
|
|
|
2018-07-02 20:14:57 +02:00
|
|
|
/**
|
|
|
|
* Generate a new OpenPGP key ring.
|
|
|
|
* @return builder
|
|
|
|
*/
|
2018-06-02 21:21:35 +02:00
|
|
|
public static KeyRingBuilder generateKeyRing() {
|
|
|
|
return new KeyRingBuilder();
|
|
|
|
}
|
2018-06-04 14:50:09 +02:00
|
|
|
|
2018-07-02 20:14:57 +02:00
|
|
|
/**
|
|
|
|
* Read an existing OpenPGP key ring.
|
|
|
|
* @return builder
|
|
|
|
*/
|
|
|
|
public static KeyRingReader readKeyRing() {
|
|
|
|
return new KeyRingReader();
|
2018-06-04 14:50:09 +02:00
|
|
|
}
|
|
|
|
|
2020-11-29 15:33:54 +01:00
|
|
|
/**
|
|
|
|
* Create an {@link EncryptionStream}, which can be used to encrypt and/or sign data using OpenPGP.
|
2021-01-09 20:30:34 +01:00
|
|
|
*
|
2020-11-29 15:33:54 +01:00
|
|
|
* @return builder
|
|
|
|
*/
|
|
|
|
public static EncryptionBuilder encryptAndOrSign() {
|
2018-07-02 20:14:57 +02:00
|
|
|
return new EncryptionBuilder();
|
2018-06-04 14:50:09 +02:00
|
|
|
}
|
|
|
|
|
2020-11-29 15:33:54 +01:00
|
|
|
/**
|
|
|
|
* Create a {@link DecryptionStream}, which can be used to decrypt and/or verify data using OpenPGP.
|
2021-05-15 18:44:03 +02:00
|
|
|
*
|
2020-11-29 15:33:54 +01:00
|
|
|
* @return builder
|
|
|
|
*/
|
|
|
|
public static DecryptionBuilder decryptAndOrVerify() {
|
2018-07-02 20:14:57 +02:00
|
|
|
return new DecryptionBuilder();
|
2018-06-05 01:30:58 +02:00
|
|
|
}
|
2018-06-13 17:26:48 +02:00
|
|
|
|
2021-05-15 18:44:03 +02:00
|
|
|
/**
|
|
|
|
* Verify a cleartext-signed message.
|
2021-05-31 15:33:42 +02:00
|
|
|
* Cleartext signed messages are often found in emails and look like this:
|
|
|
|
* <pre>
|
|
|
|
* {@code
|
|
|
|
* -----BEGIN PGP SIGNED MESSAGE-----
|
|
|
|
* Hash: [Hash algorithm]
|
|
|
|
* [Human Readable Message Body]
|
|
|
|
* -----BEGIN PGP SIGNATURE-----
|
|
|
|
* [Signature]
|
|
|
|
* -----END PGP SIGNATURE-----
|
|
|
|
* }
|
|
|
|
* </pre>
|
2021-05-15 18:44:03 +02:00
|
|
|
*
|
|
|
|
* @return builder
|
|
|
|
*/
|
|
|
|
public static VerifyCleartextSignatures verifyCleartextSignedMessage() {
|
|
|
|
return new VerifyCleartextSignaturesImpl();
|
|
|
|
}
|
|
|
|
|
2021-05-31 15:33:42 +02:00
|
|
|
/**
|
|
|
|
* Make changes to a key ring.
|
|
|
|
* This method can be used to change key expiration dates and passphrases, or add/remove/revoke subkeys.
|
|
|
|
*
|
|
|
|
* After making the desired changes in the builder, the modified key ring can be extracted using {@link SecretKeyRingEditorInterface#done()}.
|
|
|
|
*
|
|
|
|
* @param secretKeys secret key ring
|
|
|
|
* @return builder
|
|
|
|
*/
|
2020-11-19 17:51:57 +01:00
|
|
|
public static SecretKeyRingEditorInterface modifyKeyRing(PGPSecretKeyRing secretKeys) {
|
|
|
|
return new SecretKeyRingEditor(secretKeys);
|
2020-10-23 16:44:21 +02:00
|
|
|
}
|
|
|
|
|
2020-11-22 20:48:09 +01:00
|
|
|
/**
|
|
|
|
* Quickly access information about a {@link org.bouncycastle.openpgp.PGPPublicKeyRing} / {@link PGPSecretKeyRing}.
|
2021-05-31 15:33:42 +02:00
|
|
|
* This method can be used to determine expiration dates, key flags and other information about a key.
|
|
|
|
*
|
|
|
|
* To evaluate a key at a given date (e.g. to determine if the key was allowed to create a certain signature)
|
|
|
|
* use {@link KeyRingInfo#KeyRingInfo(PGPKeyRing, Date)} instead.
|
2020-11-22 20:48:09 +01:00
|
|
|
*
|
|
|
|
* @param keyRing key ring
|
|
|
|
* @return access object
|
|
|
|
*/
|
|
|
|
public static KeyRingInfo inspectKeyRing(PGPKeyRing keyRing) {
|
|
|
|
return new KeyRingInfo(keyRing);
|
|
|
|
}
|
|
|
|
|
2021-05-31 15:33:42 +02:00
|
|
|
/**
|
|
|
|
* Access, and make changes to PGPainless policy on acceptable/default algorithms etc.
|
|
|
|
*
|
|
|
|
* @return policy
|
|
|
|
*/
|
2021-01-22 16:50:08 +01:00
|
|
|
public static Policy getPolicy() {
|
|
|
|
return Policy.getInstance();
|
|
|
|
}
|
2018-06-02 21:21:35 +02:00
|
|
|
}
|