Class ConsumerOptions
- java.lang.Object
-
- org.pgpainless.decryption_verification.ConsumerOptions
-
public class ConsumerOptions extends Object
Options for decryption and signature verification.
-
-
Constructor Summary
Constructors Constructor Description ConsumerOptions()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ConsumerOptionsaddDecryptionKey(org.bouncycastle.openpgp.PGPSecretKeyRing key)Add a key for message decryption.ConsumerOptionsaddDecryptionKey(org.bouncycastle.openpgp.PGPSecretKeyRing key, SecretKeyRingProtector keyRingProtector)Add a key for message decryption.ConsumerOptionsaddDecryptionKeys(org.bouncycastle.openpgp.PGPSecretKeyRingCollection keys, SecretKeyRingProtector keyRingProtector)Add the keys in the provided key collection for message decryption.ConsumerOptionsaddDecryptionPassphrase(Passphrase passphrase)Add a passphrase for message decryption.ConsumerOptionsaddVerificationCert(org.bouncycastle.openpgp.PGPPublicKeyRing verificationCert)Add a certificate (public key ring) for signature verification.ConsumerOptionsaddVerificationCerts(org.bouncycastle.openpgp.PGPPublicKeyRingCollection verificationCerts)Add a set of certificates (public key rings) for signature verification.ConsumerOptionsaddVerificationOfDetachedSignature(org.bouncycastle.openpgp.PGPSignature detachedSignature)Add a detached signature for the signature verification process.ConsumerOptionsaddVerificationOfDetachedSignatures(InputStream signatureInputStream)ConsumerOptionsaddVerificationOfDetachedSignatures(List<org.bouncycastle.openpgp.PGPSignature> detachedSignatures)Set<org.bouncycastle.openpgp.PGPPublicKeyRing>getCertificates()Set<org.bouncycastle.openpgp.PGPSecretKeyRing>getDecryptionKeys()Set<Passphrase>getDecryptionPassphrases()Set<org.bouncycastle.openpgp.PGPSignature>getDetachedSignatures()MissingPublicKeyCallbackgetMissingCertificateCallback()MultiPassStrategygetMultiPassStrategy()Return the currently configuredMultiPassStrategy.SecretKeyRingProtectorgetSecretKeyProtector(org.bouncycastle.openpgp.PGPSecretKeyRing decryptionKeyRing)SessionKeygetSessionKey()Return the session key.DategetVerifyNotAfter()Return the latest possible creation date on which signatures made on the message are considered valid.DategetVerifyNotBefore()Return the earliest creation date on which signatures on the message are considered valid.booleanisCleartextSigned()Return true if the message is cleartext signed.ConsumerOptionssetIgnoreMDCErrors(boolean ignoreMDCErrors)Deprecated.voidsetIsCleartextSigned()INTERNAL method to mark cleartext signed messages.ConsumerOptionssetMissingCertificateCallback(MissingPublicKeyCallback callback)Set a callback that's used when a certificate (public key) is missing for signature verification.ConsumerOptionssetMissingKeyPassphraseStrategy(MissingKeyPassphraseStrategy strategy)Specify theMissingKeyPassphraseStrategy.ConsumerOptionssetMultiPassStrategy(MultiPassStrategy multiPassStrategy)Set a custom multi-pass strategy for processing cleartext-signed messages.ConsumerOptionssetSessionKey(SessionKey sessionKey)Attempt decryption using a session key.ConsumerOptionsverifyNotAfter(Date timestamp)Consider signatures on the message made after the given timestamp invalid.ConsumerOptionsverifyNotBefore(Date timestamp)Consider signatures on the message made before the given timestamp invalid.
-
-
-
Constructor Detail
-
ConsumerOptions
public ConsumerOptions()
-
-
Method Detail
-
verifyNotBefore
public ConsumerOptions verifyNotBefore(Date timestamp)
Consider signatures on the message made before the given timestamp invalid. Null means no limitation.- Parameters:
timestamp- timestamp- Returns:
- options
-
getVerifyNotBefore
@Nullable public Date getVerifyNotBefore()
Return the earliest creation date on which signatures on the message are considered valid. Signatures made earlier than this date are considered invalid.- Returns:
- earliest allowed signature creation date or null
-
verifyNotAfter
public ConsumerOptions verifyNotAfter(Date timestamp)
Consider signatures on the message made after the given timestamp invalid. Null means no limitation.- Parameters:
timestamp- timestamp- Returns:
- options
-
getVerifyNotAfter
public Date getVerifyNotAfter()
Return the latest possible creation date on which signatures made on the message are considered valid. Signatures made later than this date are considered invalid.- Returns:
- Latest possible creation date or null.
-
addVerificationCert
public ConsumerOptions addVerificationCert(org.bouncycastle.openpgp.PGPPublicKeyRing verificationCert)
Add a certificate (public key ring) for signature verification.- Parameters:
verificationCert- certificate for signature verification- Returns:
- options
-
addVerificationCerts
public ConsumerOptions addVerificationCerts(org.bouncycastle.openpgp.PGPPublicKeyRingCollection verificationCerts)
Add a set of certificates (public key rings) for signature verification.- Parameters:
verificationCerts- certificates for signature verification- Returns:
- options
-
addVerificationOfDetachedSignatures
public ConsumerOptions addVerificationOfDetachedSignatures(InputStream signatureInputStream) throws IOException, org.bouncycastle.openpgp.PGPException
- Throws:
IOExceptionorg.bouncycastle.openpgp.PGPException
-
addVerificationOfDetachedSignatures
public ConsumerOptions addVerificationOfDetachedSignatures(List<org.bouncycastle.openpgp.PGPSignature> detachedSignatures)
-
addVerificationOfDetachedSignature
public ConsumerOptions addVerificationOfDetachedSignature(org.bouncycastle.openpgp.PGPSignature detachedSignature)
Add a detached signature for the signature verification process.- Parameters:
detachedSignature- detached signature- Returns:
- options
-
setMissingCertificateCallback
public ConsumerOptions setMissingCertificateCallback(MissingPublicKeyCallback callback)
Set a callback that's used when a certificate (public key) is missing for signature verification.- Parameters:
callback- callback- Returns:
- options
-
setSessionKey
public ConsumerOptions setSessionKey(@Nonnull SessionKey sessionKey)
Attempt decryption using a session key. Note: PGPainless does not yet support decryption with session keys.- Parameters:
sessionKey- session key- Returns:
- options
- See Also:
- RFC4880 on Session Keys
-
getSessionKey
@Nullable public SessionKey getSessionKey()
Return the session key.- Returns:
- session key or null
-
addDecryptionKey
public ConsumerOptions addDecryptionKey(@Nonnull org.bouncycastle.openpgp.PGPSecretKeyRing key)
Add a key for message decryption. The key is expected to be unencrypted.- Parameters:
key- unencrypted key- Returns:
- options
-
addDecryptionKey
public ConsumerOptions addDecryptionKey(@Nonnull org.bouncycastle.openpgp.PGPSecretKeyRing key, @Nonnull SecretKeyRingProtector keyRingProtector)
Add a key for message decryption. If the key is encrypted, theSecretKeyRingProtectoris used to decrypt it when needed.- Parameters:
key- keykeyRingProtector- protector for the secret key- Returns:
- options
-
addDecryptionKeys
public ConsumerOptions addDecryptionKeys(@Nonnull org.bouncycastle.openpgp.PGPSecretKeyRingCollection keys, @Nonnull SecretKeyRingProtector keyRingProtector)
Add the keys in the provided key collection for message decryption.- Parameters:
keys- key collectionkeyRingProtector- protector for encrypted secret keys- Returns:
- options
-
addDecryptionPassphrase
public ConsumerOptions addDecryptionPassphrase(@Nonnull Passphrase passphrase)
Add a passphrase for message decryption. This passphrase will be used to try to decrypt messages which were symmetrically encrypted for a passphrase.- Parameters:
passphrase- passphrase- Returns:
- options
- See Also:
- Symmetrically Encrypted Data Packet
-
getDecryptionKeys
@Nonnull public Set<org.bouncycastle.openpgp.PGPSecretKeyRing> getDecryptionKeys()
-
getDecryptionPassphrases
@Nonnull public Set<Passphrase> getDecryptionPassphrases()
-
getCertificates
@Nonnull public Set<org.bouncycastle.openpgp.PGPPublicKeyRing> getCertificates()
-
getMissingCertificateCallback
@Nullable public MissingPublicKeyCallback getMissingCertificateCallback()
-
getSecretKeyProtector
@Nonnull public SecretKeyRingProtector getSecretKeyProtector(org.bouncycastle.openpgp.PGPSecretKeyRing decryptionKeyRing)
-
getDetachedSignatures
@Nonnull public Set<org.bouncycastle.openpgp.PGPSignature> getDetachedSignatures()
-
setIgnoreMDCErrors
@Deprecated public ConsumerOptions setIgnoreMDCErrors(boolean ignoreMDCErrors)
Deprecated.By default, PGPainless will require encrypted messages to make use of SEIP data packets. Those are Symmetrically Encrypted Integrity Protected Data packets. Symmetrically Encrypted Data Packets without integrity protection are rejected by default. Furthermore, PGPainless will throw an exception if verification of the MDC error detection code of the SEIP packet fails. Failure of MDC verification indicates a tampered ciphertext, which might be the cause of an attack or data corruption. This method can be used to ignore MDC errors and allow PGPainless to consume encrypted data without integrity protection. If the flagignoreMDCErrors
is set to true, PGPainless will- not throw exceptions for SEIP packets with tampered ciphertext
- not throw exceptions for SEIP packets with tampered MDC
- not throw exceptions for MDCs with bad CTB
- not throw exceptions for MDCs with bad length
- Parameters:
ignoreMDCErrors- true if MDC errors or missing MDCs shall be ignored, false otherwise.- Returns:
- options
- See Also:
- Sym. Encrypted Integrity Protected Data Packet
-
setMissingKeyPassphraseStrategy
public ConsumerOptions setMissingKeyPassphraseStrategy(MissingKeyPassphraseStrategy strategy)
Specify theMissingKeyPassphraseStrategy. This strategy defines, how missing passphrases for unlocking secret keys are handled. In interactive mode (MissingKeyPassphraseStrategy.INTERACTIVE) PGPainless will try to obtain missing passphrases for secret keys via theSecretKeyRingProtectorsSecretKeyPassphraseProvidercallback. In non-interactice mode (MissingKeyPassphraseStrategy.THROW_EXCEPTION, PGPainless will instead throw aMissingPassphraseExceptioncontaining the ids of all keys for which there are missing passphrases.- Parameters:
strategy- strategy- Returns:
- options
-
setMultiPassStrategy
public ConsumerOptions setMultiPassStrategy(@Nonnull MultiPassStrategy multiPassStrategy)
Set a custom multi-pass strategy for processing cleartext-signed messages. UsesInMemoryMultiPassStrategyby default.- Parameters:
multiPassStrategy- multi-pass caching strategy- Returns:
- builder
-
getMultiPassStrategy
public MultiPassStrategy getMultiPassStrategy()
Return the currently configuredMultiPassStrategy. Defaults toInMemoryMultiPassStrategy.- Returns:
- multi-pass strategy
-
setIsCleartextSigned
public void setIsCleartextSigned()
INTERNAL method to mark cleartext signed messages. Do not call this manually.
-
isCleartextSigned
public boolean isCleartextSigned()
Return true if the message is cleartext signed.- Returns:
- cleartext signed
-
-