mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-05 12:05:58 +01:00
Remove deprecated OpenPgpMetadata class
This commit is contained in:
parent
2425d9c6f7
commit
effff757e1
19 changed files with 123 additions and 518 deletions
|
@ -1,380 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.decryption_verification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPLiteralData;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.pgpainless.algorithm.CompressionAlgorithm;
|
||||
import org.pgpainless.algorithm.StreamEncoding;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.exception.SignatureValidationException;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
import org.pgpainless.util.SessionKey;
|
||||
|
||||
/**
|
||||
* Legacy class containing metadata about an OpenPGP message.
|
||||
* It is advised to use {@link MessageMetadata} instead.
|
||||
*
|
||||
* TODO: Remove in 1.6.X
|
||||
*/
|
||||
public class OpenPgpMetadata {
|
||||
|
||||
private final Set<Long> recipientKeyIds;
|
||||
private final SubkeyIdentifier decryptionKey;
|
||||
private final List<SignatureVerification> verifiedInbandSignatures;
|
||||
private final List<SignatureVerification.Failure> invalidInbandSignatures;
|
||||
private final List<SignatureVerification> verifiedDetachedSignatures;
|
||||
private final List<SignatureVerification.Failure> invalidDetachedSignatures;
|
||||
private final SessionKey sessionKey;
|
||||
private final CompressionAlgorithm compressionAlgorithm;
|
||||
private final String fileName;
|
||||
private final Date modificationDate;
|
||||
private final StreamEncoding fileEncoding;
|
||||
private final boolean cleartextSigned;
|
||||
|
||||
public OpenPgpMetadata(Set<Long> recipientKeyIds,
|
||||
SubkeyIdentifier decryptionKey,
|
||||
SessionKey sessionKey,
|
||||
CompressionAlgorithm algorithm,
|
||||
List<SignatureVerification> verifiedInbandSignatures,
|
||||
List<SignatureVerification.Failure> invalidInbandSignatures,
|
||||
List<SignatureVerification> verifiedDetachedSignatures,
|
||||
List<SignatureVerification.Failure> invalidDetachedSignatures,
|
||||
String fileName,
|
||||
Date modificationDate,
|
||||
StreamEncoding fileEncoding,
|
||||
boolean cleartextSigned) {
|
||||
|
||||
this.recipientKeyIds = Collections.unmodifiableSet(recipientKeyIds);
|
||||
this.decryptionKey = decryptionKey;
|
||||
this.sessionKey = sessionKey;
|
||||
this.compressionAlgorithm = algorithm;
|
||||
this.verifiedInbandSignatures = Collections.unmodifiableList(verifiedInbandSignatures);
|
||||
this.invalidInbandSignatures = Collections.unmodifiableList(invalidInbandSignatures);
|
||||
this.verifiedDetachedSignatures = Collections.unmodifiableList(verifiedDetachedSignatures);
|
||||
this.invalidDetachedSignatures = Collections.unmodifiableList(invalidDetachedSignatures);
|
||||
this.fileName = fileName;
|
||||
this.modificationDate = modificationDate;
|
||||
this.fileEncoding = fileEncoding;
|
||||
this.cleartextSigned = cleartextSigned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a set of key-ids the messages was encrypted for.
|
||||
*
|
||||
* @return recipient ids
|
||||
*/
|
||||
public @Nonnull Set<Long> getRecipientKeyIds() {
|
||||
return recipientKeyIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true, if the message was encrypted.
|
||||
*
|
||||
* @return true if encrypted, false otherwise
|
||||
*/
|
||||
public boolean isEncrypted() {
|
||||
return sessionKey != null && sessionKey.getAlgorithm() != SymmetricKeyAlgorithm.NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link SubkeyIdentifier} of the key that was used to decrypt the message.
|
||||
* This can be null if the message was decrypted using a {@link org.pgpainless.util.Passphrase}, or if it was not
|
||||
* encrypted at all (e.g. signed only).
|
||||
*
|
||||
* @return subkey identifier of decryption key
|
||||
*/
|
||||
public @Nullable SubkeyIdentifier getDecryptionKey() {
|
||||
return decryptionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the algorithm that was used to symmetrically encrypt the message.
|
||||
*
|
||||
* @return encryption algorithm
|
||||
*/
|
||||
public @Nullable SymmetricKeyAlgorithm getSymmetricKeyAlgorithm() {
|
||||
return sessionKey == null ? null : sessionKey.getAlgorithm();
|
||||
}
|
||||
|
||||
public @Nullable SessionKey getSessionKey() {
|
||||
return sessionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link CompressionAlgorithm} that was used to compress the message.
|
||||
*
|
||||
* @return compression algorithm
|
||||
*/
|
||||
public @Nullable CompressionAlgorithm getCompressionAlgorithm() {
|
||||
return compressionAlgorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a set of all signatures on the message.
|
||||
* Note: This method returns just the signatures. There is no guarantee that the signatures are verified or even correct.
|
||||
*
|
||||
* Use {@link #getVerifiedSignatures()} instead to get all verified signatures.
|
||||
* @return unverified and verified signatures
|
||||
*/
|
||||
public @Nonnull Set<PGPSignature> getSignatures() {
|
||||
Set<PGPSignature> signatures = new HashSet<>();
|
||||
for (SignatureVerification v : getVerifiedDetachedSignatures()) {
|
||||
signatures.add(v.getSignature());
|
||||
}
|
||||
for (SignatureVerification v : getVerifiedInbandSignatures()) {
|
||||
signatures.add(v.getSignature());
|
||||
}
|
||||
for (SignatureVerification.Failure f : getInvalidDetachedSignatures()) {
|
||||
signatures.add(f.getSignatureVerification().getSignature());
|
||||
}
|
||||
for (SignatureVerification.Failure f : getInvalidInbandSignatures()) {
|
||||
signatures.add(f.getSignatureVerification().getSignature());
|
||||
}
|
||||
return signatures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the message contained at least one signature.
|
||||
*
|
||||
* Note: This method does not reflect, whether the signature on the message is correct.
|
||||
* Use {@link #isVerified()} instead to determine, if the message carries a verifiable signature.
|
||||
*
|
||||
* @return true if message contains at least one unverified or verified signature, false otherwise.
|
||||
*/
|
||||
public boolean isSigned() {
|
||||
return !getSignatures().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a map of all verified signatures on the message.
|
||||
* The map contains verified signatures as value, with the {@link SubkeyIdentifier} of the key that was used to verify
|
||||
* the signature as the maps keys.
|
||||
*
|
||||
* @return verified detached and one-pass signatures
|
||||
*/
|
||||
public Map<SubkeyIdentifier, PGPSignature> getVerifiedSignatures() {
|
||||
Map<SubkeyIdentifier, PGPSignature> verifiedSignatures = new ConcurrentHashMap<>();
|
||||
for (SignatureVerification detachedSignature : getVerifiedDetachedSignatures()) {
|
||||
verifiedSignatures.put(detachedSignature.getSigningKey(), detachedSignature.getSignature());
|
||||
}
|
||||
for (SignatureVerification inbandSignatures : verifiedInbandSignatures) {
|
||||
verifiedSignatures.put(inbandSignatures.getSigningKey(), inbandSignatures.getSignature());
|
||||
}
|
||||
|
||||
return verifiedSignatures;
|
||||
}
|
||||
|
||||
public List<SignatureVerification> getVerifiedInbandSignatures() {
|
||||
return verifiedInbandSignatures;
|
||||
}
|
||||
|
||||
public List<SignatureVerification> getVerifiedDetachedSignatures() {
|
||||
return verifiedDetachedSignatures;
|
||||
}
|
||||
|
||||
public List<SignatureVerification.Failure> getInvalidInbandSignatures() {
|
||||
return invalidInbandSignatures;
|
||||
}
|
||||
|
||||
public List<SignatureVerification.Failure> getInvalidDetachedSignatures() {
|
||||
return invalidDetachedSignatures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true, if the message is signed and at least one signature on the message was verified successfully.
|
||||
*
|
||||
* @return true if message is verified, false otherwise
|
||||
*/
|
||||
public boolean isVerified() {
|
||||
return !getVerifiedSignatures().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true, if the message contains at least one verified signature made by a key in the
|
||||
* given certificate.
|
||||
*
|
||||
* @param certificate certificate
|
||||
* @return true if message was signed by the certificate (and the signature is valid), false otherwise
|
||||
*/
|
||||
public boolean containsVerifiedSignatureFrom(PGPPublicKeyRing certificate) {
|
||||
for (PGPPublicKey key : certificate) {
|
||||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(key);
|
||||
if (containsVerifiedSignatureFrom(fingerprint)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true, if the message contains at least one valid signature made by the key with the given
|
||||
* fingerprint, false otherwise.
|
||||
*
|
||||
* The fingerprint might be of the signing subkey, or the primary key of the signing certificate.
|
||||
*
|
||||
* @param fingerprint fingerprint of primary key or signing subkey
|
||||
* @return true if validly signed, false otherwise
|
||||
*/
|
||||
public boolean containsVerifiedSignatureFrom(OpenPgpFingerprint fingerprint) {
|
||||
for (SubkeyIdentifier verifiedSigningKey : getVerifiedSignatures().keySet()) {
|
||||
if (verifiedSigningKey.getPrimaryKeyFingerprint().equals(fingerprint) ||
|
||||
verifiedSigningKey.getSubkeyFingerprint().equals(fingerprint)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the encrypted / signed file.
|
||||
*
|
||||
* @return file name
|
||||
*/
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true, if the encrypted data is intended for your eyes only.
|
||||
*
|
||||
* @return true if for-your-eyes-only
|
||||
*/
|
||||
public boolean isForYourEyesOnly() {
|
||||
return PGPLiteralData.CONSOLE.equals(getFileName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the modification date of the encrypted / signed file.
|
||||
*
|
||||
* @return modification date
|
||||
*/
|
||||
public Date getModificationDate() {
|
||||
return modificationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the encoding format of the encrypted / signed file.
|
||||
*
|
||||
* @return encoding
|
||||
*/
|
||||
public StreamEncoding getFileEncoding() {
|
||||
return fileEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the message was signed using the cleartext signature framework.
|
||||
*
|
||||
* @return true if cleartext signed.
|
||||
*/
|
||||
public boolean isCleartextSigned() {
|
||||
return cleartextSigned;
|
||||
}
|
||||
|
||||
public static Builder getBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final Set<Long> recipientFingerprints = new HashSet<>();
|
||||
private SessionKey sessionKey;
|
||||
private SubkeyIdentifier decryptionKey;
|
||||
private CompressionAlgorithm compressionAlgorithm = CompressionAlgorithm.UNCOMPRESSED;
|
||||
private String fileName;
|
||||
private StreamEncoding fileEncoding;
|
||||
private Date modificationDate;
|
||||
private boolean cleartextSigned = false;
|
||||
|
||||
private final List<SignatureVerification> verifiedInbandSignatures = new ArrayList<>();
|
||||
private final List<SignatureVerification> verifiedDetachedSignatures = new ArrayList<>();
|
||||
private final List<SignatureVerification.Failure> invalidInbandSignatures = new ArrayList<>();
|
||||
private final List<SignatureVerification.Failure> invalidDetachedSignatures = new ArrayList<>();
|
||||
|
||||
|
||||
public Builder addRecipientKeyId(Long keyId) {
|
||||
this.recipientFingerprints.add(keyId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDecryptionKey(SubkeyIdentifier decryptionKey) {
|
||||
this.decryptionKey = decryptionKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSessionKey(SessionKey sessionKey) {
|
||||
this.sessionKey = sessionKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCompressionAlgorithm(CompressionAlgorithm algorithm) {
|
||||
this.compressionAlgorithm = algorithm;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setFileName(@Nullable String fileName) {
|
||||
this.fileName = fileName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setModificationDate(Date modificationDate) {
|
||||
this.modificationDate = modificationDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setFileEncoding(StreamEncoding encoding) {
|
||||
this.fileEncoding = encoding;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addVerifiedInbandSignature(SignatureVerification signatureVerification) {
|
||||
this.verifiedInbandSignatures.add(signatureVerification);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addVerifiedDetachedSignature(SignatureVerification signatureVerification) {
|
||||
this.verifiedDetachedSignatures.add(signatureVerification);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addInvalidInbandSignature(SignatureVerification signatureVerification, SignatureValidationException e) {
|
||||
this.invalidInbandSignatures.add(new SignatureVerification.Failure(signatureVerification, e));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addInvalidDetachedSignature(SignatureVerification signatureVerification, SignatureValidationException e) {
|
||||
this.invalidDetachedSignatures.add(new SignatureVerification.Failure(signatureVerification, e));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCleartextSigned() {
|
||||
this.cleartextSigned = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OpenPgpMetadata build() {
|
||||
return new OpenPgpMetadata(
|
||||
recipientFingerprints, decryptionKey,
|
||||
sessionKey, compressionAlgorithm,
|
||||
verifiedInbandSignatures, invalidInbandSignatures,
|
||||
verifiedDetachedSignatures, invalidDetachedSignatures,
|
||||
fileName, modificationDate, fileEncoding, cleartextSigned);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,16 +18,4 @@ abstract class DecryptionStream: InputStream() {
|
|||
* @return message metadata
|
||||
*/
|
||||
abstract val metadata: MessageMetadata
|
||||
|
||||
/**
|
||||
* Return a [OpenPgpMetadata] object containing information about the decrypted / verified message.
|
||||
* The [DecryptionStream] MUST be closed via [close] before the metadata object can be accessed.
|
||||
*
|
||||
* @return message metadata
|
||||
* @deprecated use [metadata] instead.
|
||||
*/
|
||||
@Deprecated("Use of OpenPgpMetadata is discouraged.",
|
||||
ReplaceWith("metadata"))
|
||||
val result: OpenPgpMetadata
|
||||
get() = metadata.toLegacyMetadata()
|
||||
}
|
|
@ -130,6 +130,6 @@ public class OnePassSignatureVerificationWithPartialLengthLiteralDataRegressionT
|
|||
|
||||
Streams.pipeAll(decryptionStream, out);
|
||||
decryptionStream.close();
|
||||
decryptionStream.getResult();
|
||||
decryptionStream.getMetadata();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,9 +122,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void noInputEncodingBinaryDataBinarySig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.BINARY, false);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -136,9 +136,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void noInputEncodingBinaryDataTextSig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT, StreamEncoding.BINARY, false);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -150,9 +150,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void noInputEncodingTextDataBinarySig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.TEXT, false);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -164,9 +164,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void noInputEncodingTextDataTextSig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT, StreamEncoding.TEXT, false);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -178,9 +178,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void noInputEncodingUtf8DataBinarySig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.UTF8, false);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -192,9 +192,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void noInputEncodingUtf8DataTextSig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT, StreamEncoding.UTF8, false);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -207,9 +207,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void inputEncodingBinaryDataBinarySig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.BINARY, true);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -221,9 +221,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void inputEncodingBinaryDataTextSig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT, StreamEncoding.BINARY, true);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -235,9 +235,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void inputEncodingTextDataBinarySig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.TEXT, true);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -249,9 +249,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void inputEncodingTextDataTextSig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT, StreamEncoding.TEXT, true);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -263,9 +263,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void inputEncodingUtf8DataBinarySig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.UTF8, true);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -277,9 +277,9 @@ public class CanonicalizedDataEncryptionTest {
|
|||
@Test
|
||||
public void inputEncodingUtf8DataTextSig() throws PGPException, IOException {
|
||||
String msg = encryptAndSign(message, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT, StreamEncoding.UTF8, true);
|
||||
OpenPgpMetadata metadata = decryptAndVerify(msg);
|
||||
MessageMetadata metadata = decryptAndVerify(msg);
|
||||
|
||||
if (!metadata.isVerified()) {
|
||||
if (!metadata.isVerifiedSigned()) {
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println("Not verified. Session-Key: " + metadata.getSessionKey());
|
||||
System.out.println(msg);
|
||||
|
@ -360,7 +360,7 @@ public class CanonicalizedDataEncryptionTest {
|
|||
return msg;
|
||||
}
|
||||
|
||||
private OpenPgpMetadata decryptAndVerify(String msg) throws PGPException, IOException {
|
||||
private MessageMetadata decryptAndVerify(String msg) throws PGPException, IOException {
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8));
|
||||
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(in)
|
||||
|
@ -371,7 +371,7 @@ public class CanonicalizedDataEncryptionTest {
|
|||
Streams.drain(decryptionStream);
|
||||
decryptionStream.close();
|
||||
|
||||
return decryptionStream.getResult();
|
||||
return decryptionStream.getMetadata();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -439,8 +439,8 @@ public class CanonicalizedDataEncryptionTest {
|
|||
|
||||
Streams.pipeAll(decryptionStream, decrypted);
|
||||
decryptionStream.close();
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
assertTrue(metadata.isVerified(), "Not verified! Sig Type: " + sigType + " StreamEncoding: " + streamEncoding);
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
assertTrue(metadata.isVerifiedSigned(), "Not verified! Sig Type: " + sigType + " StreamEncoding: " + streamEncoding);
|
||||
|
||||
assertArrayEquals(msg, decrypted.toByteArray());
|
||||
}
|
||||
|
|
|
@ -96,11 +96,11 @@ public class CleartextSignatureVerificationTest {
|
|||
Streams.pipeAll(decryptionStream, out);
|
||||
decryptionStream.close();
|
||||
|
||||
OpenPgpMetadata result = decryptionStream.getResult();
|
||||
assertTrue(result.isVerified());
|
||||
assertTrue(result.isCleartextSigned());
|
||||
MessageMetadata result = decryptionStream.getMetadata();
|
||||
assertTrue(result.isVerifiedSigned());
|
||||
assertTrue(result.isUsingCleartextSignatureFramework());
|
||||
|
||||
PGPSignature signature = result.getVerifiedSignatures().values().iterator().next();
|
||||
PGPSignature signature = result.getVerifiedSignatures().iterator().next().getSignature();
|
||||
|
||||
assertEquals(signature.getKeyID(), signingKeys.getPublicKey().getKeyID());
|
||||
assertArrayEquals(MESSAGE_BODY, out.toByteArray());
|
||||
|
@ -125,10 +125,10 @@ public class CleartextSignatureVerificationTest {
|
|||
Streams.pipeAll(decryptionStream, out);
|
||||
decryptionStream.close();
|
||||
|
||||
OpenPgpMetadata result = decryptionStream.getResult();
|
||||
assertTrue(result.isVerified());
|
||||
MessageMetadata result = decryptionStream.getMetadata();
|
||||
assertTrue(result.isVerifiedSigned());
|
||||
|
||||
PGPSignature signature = result.getVerifiedSignatures().values().iterator().next();
|
||||
PGPSignature signature = result.getVerifiedSignatures().iterator().next().getSignature();
|
||||
|
||||
assertEquals(signature.getKeyID(), signingKeys.getPublicKey().getKeyID());
|
||||
FileInputStream fileIn = new FileInputStream(file);
|
||||
|
@ -178,7 +178,7 @@ public class CleartextSignatureVerificationTest {
|
|||
Streams.pipeAll(decryptionStream, out);
|
||||
decryptionStream.close();
|
||||
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
assertEquals(1, metadata.getVerifiedSignatures().size());
|
||||
}
|
||||
|
||||
|
@ -210,8 +210,8 @@ public class CleartextSignatureVerificationTest {
|
|||
Streams.pipeAll(verificationStream, msgOut);
|
||||
verificationStream.close();
|
||||
|
||||
OpenPgpMetadata metadata = verificationStream.getResult();
|
||||
assertTrue(metadata.isVerified());
|
||||
MessageMetadata metadata = verificationStream.getMetadata();
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -64,7 +64,7 @@ public class DecryptAndVerifyMessageTest {
|
|||
Streams.pipeAll(decryptor, toPlain);
|
||||
decryptor.close();
|
||||
toPlain.close();
|
||||
OpenPgpMetadata metadata = decryptor.getResult();
|
||||
MessageMetadata metadata = decryptor.getMetadata();
|
||||
|
||||
byte[] expected = TestKeys.TEST_MESSAGE_01_PLAIN.getBytes(UTF8);
|
||||
byte[] actual = toPlain.toByteArray();
|
||||
|
@ -72,14 +72,13 @@ public class DecryptAndVerifyMessageTest {
|
|||
assertArrayEquals(expected, actual);
|
||||
|
||||
assertTrue(metadata.isEncrypted());
|
||||
assertTrue(metadata.isSigned());
|
||||
assertFalse(metadata.isCleartextSigned());
|
||||
assertTrue(metadata.isVerified());
|
||||
assertFalse(metadata.isUsingCleartextSignatureFramework());
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
assertEquals(CompressionAlgorithm.ZLIB, metadata.getCompressionAlgorithm());
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getSymmetricKeyAlgorithm());
|
||||
assertEquals(1, metadata.getSignatures().size());
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getEncryptionAlgorithm());
|
||||
assertEquals(1, metadata.getVerifiedSignatures().size());
|
||||
assertTrue(metadata.containsVerifiedSignatureFrom(TestKeys.JULIET_FINGERPRINT));
|
||||
assertEquals(1, metadata.getVerifiedSignatures().size());
|
||||
assertTrue(metadata.isVerifiedSignedBy(TestKeys.JULIET_FINGERPRINT));
|
||||
assertEquals(new SubkeyIdentifier(TestKeys.JULIET_FINGERPRINT), metadata.getDecryptionKey());
|
||||
}
|
||||
|
||||
|
@ -104,7 +103,7 @@ public class DecryptAndVerifyMessageTest {
|
|||
|
||||
decryptor.close();
|
||||
toPlain.close();
|
||||
OpenPgpMetadata metadata = decryptor.getResult();
|
||||
MessageMetadata metadata = decryptor.getMetadata();
|
||||
|
||||
byte[] expected = TestKeys.TEST_MESSAGE_01_PLAIN.getBytes(UTF8);
|
||||
byte[] actual = toPlain.toByteArray();
|
||||
|
@ -112,14 +111,13 @@ public class DecryptAndVerifyMessageTest {
|
|||
assertArrayEquals(expected, actual);
|
||||
|
||||
assertTrue(metadata.isEncrypted());
|
||||
assertTrue(metadata.isSigned());
|
||||
assertFalse(metadata.isCleartextSigned());
|
||||
assertTrue(metadata.isVerified());
|
||||
assertFalse(metadata.isUsingCleartextSignatureFramework());
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
assertEquals(CompressionAlgorithm.ZLIB, metadata.getCompressionAlgorithm());
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getSymmetricKeyAlgorithm());
|
||||
assertEquals(1, metadata.getSignatures().size());
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getEncryptionAlgorithm());
|
||||
assertEquals(1, metadata.getVerifiedSignatures().size());
|
||||
assertTrue(metadata.containsVerifiedSignatureFrom(TestKeys.JULIET_FINGERPRINT));
|
||||
assertEquals(1, metadata.getVerifiedSignatures().size());
|
||||
assertTrue(metadata.isVerifiedSignedBy(TestKeys.JULIET_FINGERPRINT));
|
||||
assertEquals(new SubkeyIdentifier(TestKeys.JULIET_FINGERPRINT), metadata.getDecryptionKey());
|
||||
}
|
||||
|
||||
|
|
|
@ -139,8 +139,9 @@ public class DecryptHiddenRecipientMessageTest {
|
|||
Streams.pipeAll(decryptionStream, out);
|
||||
decryptionStream.close();
|
||||
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
assertEquals(0, metadata.getRecipientKeyIds().size());
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
assertEquals(1, metadata.getRecipientKeyIds().size());
|
||||
assertEquals(0L, metadata.getRecipientKeyIds().get(0));
|
||||
|
||||
KeyRingInfo info = new KeyRingInfo(secretKeys);
|
||||
List<PGPPublicKey> encryptionKeys = info.getEncryptionSubkeys(EncryptionPurpose.ANY);
|
||||
|
|
|
@ -104,9 +104,9 @@ public class IgnoreUnknownSignatureVersionsTest {
|
|||
"ou1uiXJaDzZ6wQfB\n" +
|
||||
"=uHRc\n" +
|
||||
"-----END PGP SIGNATURE-----\n";
|
||||
OpenPgpMetadata metadata = verifySignature(cert, BASE_CASE);
|
||||
MessageMetadata metadata = verifySignature(cert, BASE_CASE);
|
||||
|
||||
assertTrue(metadata.isVerified());
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -137,9 +137,9 @@ public class IgnoreUnknownSignatureVersionsTest {
|
|||
"ou1uiXJaDzZ6wQfB\n" +
|
||||
"=/JL1\n" +
|
||||
"-----END PGP SIGNATURE-----\n";
|
||||
OpenPgpMetadata metadata = verifySignature(cert, SIG4SIG23);
|
||||
MessageMetadata metadata = verifySignature(cert, SIG4SIG23);
|
||||
|
||||
assertTrue(metadata.isVerified());
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -170,12 +170,12 @@ public class IgnoreUnknownSignatureVersionsTest {
|
|||
"ou1uiXJaDzZ6wQfB\n" +
|
||||
"=Yc8d\n" +
|
||||
"-----END PGP SIGNATURE-----\n";
|
||||
OpenPgpMetadata metadata = verifySignature(cert, SIG23SIG4);
|
||||
MessageMetadata metadata = verifySignature(cert, SIG23SIG4);
|
||||
|
||||
assertTrue(metadata.isVerified());
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
}
|
||||
|
||||
private OpenPgpMetadata verifySignature(PGPPublicKeyRing cert, String BASE_CASE) throws PGPException, IOException {
|
||||
private MessageMetadata verifySignature(PGPPublicKeyRing cert, String BASE_CASE) throws PGPException, IOException {
|
||||
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify().onInputStream(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)))
|
||||
.withOptions(new ConsumerOptions()
|
||||
.addVerificationCert(cert)
|
||||
|
@ -184,6 +184,6 @@ public class IgnoreUnknownSignatureVersionsTest {
|
|||
Streams.drain(decryptionStream);
|
||||
decryptionStream.close();
|
||||
|
||||
return decryptionStream.getResult();
|
||||
return decryptionStream.getMetadata();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ public class PreventDecryptionUsingNonEncryptionKeyTest {
|
|||
|
||||
Streams.drain(decryptionStream);
|
||||
decryptionStream.close();
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
|
||||
assertEquals(new SubkeyIdentifier(secretKeys, secretKeys.getPublicKey().getKeyID()), metadata.getDecryptionKey());
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ public class PreventDecryptionUsingNonEncryptionKeyTest {
|
|||
|
||||
Streams.drain(decryptionStream);
|
||||
decryptionStream.close();
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
|
||||
assertEquals(new SubkeyIdentifier(secretKeys, secretKeys.getPublicKey().getKeyID()), metadata.getDecryptionKey());
|
||||
}
|
||||
|
|
|
@ -39,10 +39,10 @@ public class SignedMessageVerificationWithoutCertIsStillSignedTest {
|
|||
Streams.pipeAll(verificationStream, out);
|
||||
verificationStream.close();
|
||||
|
||||
OpenPgpMetadata metadata = verificationStream.getResult();
|
||||
MessageMetadata metadata = verificationStream.getMetadata();
|
||||
|
||||
assertFalse(metadata.isCleartextSigned());
|
||||
assertTrue(metadata.isSigned(), "Message is signed, even though we miss the verification cert.");
|
||||
assertFalse(metadata.isVerified(), "Message is not verified because we lack the verification cert.");
|
||||
assertFalse(metadata.isUsingCleartextSignatureFramework());
|
||||
assertTrue(metadata.hasRejectedSignatures(), "Message is signed, even though we miss the verification cert.");
|
||||
assertFalse(metadata.isVerifiedSigned(), "Message is not verified because we lack the verification cert.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,8 +65,8 @@ public class VerifyDetachedSignatureTest {
|
|||
|
||||
Streams.drain(verifier);
|
||||
verifier.close();
|
||||
OpenPgpMetadata metadata = verifier.getResult();
|
||||
assertTrue(metadata.isVerified());
|
||||
MessageMetadata metadata = verifier.getMetadata();
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -140,7 +140,7 @@ public class VerifyDetachedSignatureTest {
|
|||
|
||||
Streams.drain(verifier);
|
||||
verifier.close();
|
||||
OpenPgpMetadata metadata = verifier.getResult();
|
||||
assertTrue(metadata.isVerified());
|
||||
MessageMetadata metadata = verifier.getMetadata();
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,8 +68,8 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
.onInputStream(new ByteArrayInputStream(inlineSigned))
|
||||
.withOptions(options);
|
||||
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.getVerifiedSignatures().containsKey(new SubkeyIdentifier(certificate)));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.isVerifiedSignedBy(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -81,8 +81,8 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
.onInputStream(new ByteArrayInputStream(data))
|
||||
.withOptions(options);
|
||||
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.containsVerifiedSignatureFrom(certificate));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.isVerifiedSignedBy(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -93,8 +93,8 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(new ByteArrayInputStream(inlineSigned))
|
||||
.withOptions(options);
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.getVerifiedSignatures().containsKey(signingKey));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.isVerifiedSignedBy(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -106,8 +106,8 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(new ByteArrayInputStream(data))
|
||||
.withOptions(options);
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.getVerifiedSignatures().containsKey(signingKey));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.isVerifiedSignedBy(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -118,8 +118,8 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(new ByteArrayInputStream(inlineSigned))
|
||||
.withOptions(options);
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertFalse(metadata.getVerifiedSignatures().containsKey(signingKey));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertFalse(metadata.isVerifiedInlineSignedBy(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,8 +131,8 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(new ByteArrayInputStream(data))
|
||||
.withOptions(options);
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertFalse(metadata.getVerifiedSignatures().containsKey(signingKey));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertFalse(metadata.isVerifiedSignedBy(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -143,8 +143,8 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(new ByteArrayInputStream(inlineSigned))
|
||||
.withOptions(options);
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.getVerifiedSignatures().containsKey(signingKey));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.isVerifiedSignedBy(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -156,8 +156,8 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(new ByteArrayInputStream(data))
|
||||
.withOptions(options);
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.getVerifiedSignatures().containsKey(signingKey));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.isVerifiedSignedBy(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -168,8 +168,8 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(new ByteArrayInputStream(inlineSigned))
|
||||
.withOptions(options);
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertFalse(metadata.getVerifiedSignatures().containsKey(signingKey));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertFalse(metadata.isVerifiedSignedBy(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -181,13 +181,13 @@ public class VerifyNotBeforeNotAfterTest {
|
|||
DecryptionStream verifier = PGPainless.decryptAndOrVerify()
|
||||
.onInputStream(new ByteArrayInputStream(data))
|
||||
.withOptions(options);
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertFalse(metadata.getVerifiedSignatures().containsKey(signingKey));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertFalse(metadata.isVerifiedSignedBy(certificate));
|
||||
}
|
||||
|
||||
private OpenPgpMetadata processSignedData(DecryptionStream verifier) throws IOException {
|
||||
private MessageMetadata processSignedData(DecryptionStream verifier) throws IOException {
|
||||
Streams.drain(verifier);
|
||||
verifier.close();
|
||||
return verifier.getResult();
|
||||
return verifier.getMetadata();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ class VerifyVersion3SignaturePacketTest {
|
|||
.onInputStream(new ByteArrayInputStream(DATA))
|
||||
.withOptions(options);
|
||||
|
||||
OpenPgpMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.containsVerifiedSignatureFrom(TestKeys.getEmilPublicKeyRing()));
|
||||
MessageMetadata metadata = processSignedData(verifier);
|
||||
assertTrue(metadata.isVerifiedSignedBy(TestKeys.getEmilPublicKeyRing()));
|
||||
}
|
||||
|
||||
private static PGPSignature generateV3Signature() throws IOException, PGPException {
|
||||
|
@ -61,9 +61,9 @@ class VerifyVersion3SignaturePacketTest {
|
|||
return signatureGenerator.generate();
|
||||
}
|
||||
|
||||
private OpenPgpMetadata processSignedData(DecryptionStream verifier) throws IOException {
|
||||
private MessageMetadata processSignedData(DecryptionStream verifier) throws IOException {
|
||||
Streams.drain(verifier);
|
||||
verifier.close();
|
||||
return verifier.getResult();
|
||||
return verifier.getMetadata();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ public class VerifyWithMissingPublicKeyCallbackTest {
|
|||
verificationStream.close();
|
||||
|
||||
assertArrayEquals(msg.getBytes(StandardCharsets.UTF_8), plainOut.toByteArray());
|
||||
OpenPgpMetadata metadata = verificationStream.getResult();
|
||||
assertTrue(metadata.containsVerifiedSignatureFrom(signingPubKeys));
|
||||
MessageMetadata metadata = verificationStream.getMetadata();
|
||||
assertTrue(metadata.isVerifiedSignedBy(signingPubKeys));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,12 +102,12 @@ public class WrongSignerUserIdTest {
|
|||
Streams.pipeAll(decryptionStream, out);
|
||||
|
||||
decryptionStream.close();
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
|
||||
if (expectSuccessfulVerification) {
|
||||
assertTrue(metadata.isVerified());
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
} else {
|
||||
assertFalse(metadata.isVerified());
|
||||
assertFalse(metadata.isVerifiedSigned());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.pgpainless.algorithm.KeyFlag;
|
|||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
||||
import org.pgpainless.decryption_verification.MessageMetadata;
|
||||
import org.pgpainless.exception.KeyException;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
|
@ -185,11 +185,10 @@ public class EncryptDecryptTest {
|
|||
decryptor.close();
|
||||
|
||||
assertArrayEquals(secretMessage, decryptedSecretMessage.toByteArray());
|
||||
OpenPgpMetadata result = decryptor.getResult();
|
||||
assertTrue(result.containsVerifiedSignatureFrom(senderPub));
|
||||
assertTrue(result.isSigned());
|
||||
MessageMetadata result = decryptor.getMetadata();
|
||||
assertTrue(result.isVerifiedSignedBy(senderPub));
|
||||
assertTrue(result.isEncrypted());
|
||||
assertTrue(result.isVerified());
|
||||
assertTrue(result.isVerifiedSigned());
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
|
@ -233,7 +232,7 @@ public class EncryptDecryptTest {
|
|||
Streams.pipeAll(verifier, dummyOut);
|
||||
verifier.close();
|
||||
|
||||
OpenPgpMetadata decryptionResult = verifier.getResult();
|
||||
MessageMetadata decryptionResult = verifier.getMetadata();
|
||||
assertFalse(decryptionResult.getVerifiedSignatures().isEmpty());
|
||||
}
|
||||
|
||||
|
@ -263,7 +262,7 @@ public class EncryptDecryptTest {
|
|||
Streams.pipeAll(verifier, signOut);
|
||||
verifier.close();
|
||||
|
||||
OpenPgpMetadata metadata = verifier.getResult();
|
||||
MessageMetadata metadata = verifier.getMetadata();
|
||||
assertFalse(metadata.getVerifiedSignatures().isEmpty());
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
|
|||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
||||
import org.pgpainless.decryption_verification.MessageMetadata;
|
||||
import org.pgpainless.exception.KeyException;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
import org.pgpainless.key.TestKeys;
|
||||
|
@ -106,12 +106,11 @@ public class SigningTest {
|
|||
Streams.pipeAll(decryptionStream, plaintextOut);
|
||||
decryptionStream.close();
|
||||
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
assertTrue(metadata.isEncrypted());
|
||||
assertTrue(metadata.isSigned());
|
||||
assertTrue(metadata.isVerified());
|
||||
assertTrue(metadata.containsVerifiedSignatureFrom(KeyRingUtils.publicKeyRingFrom(cryptieKeys)));
|
||||
assertFalse(metadata.containsVerifiedSignatureFrom(julietKeys));
|
||||
assertTrue(metadata.isVerifiedSigned());
|
||||
assertTrue(metadata.isVerifiedSignedBy(KeyRingUtils.publicKeyRingFrom(cryptieKeys)));
|
||||
assertFalse(metadata.isVerifiedSignedBy(julietKeys));
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.pgpainless.PGPainless;
|
|||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
||||
import org.pgpainless.decryption_verification.MessageMetadata;
|
||||
import org.pgpainless.decryption_verification.SignatureVerification;
|
||||
import org.pgpainless.encryption_signing.EncryptionOptions;
|
||||
import org.pgpainless.encryption_signing.EncryptionResult;
|
||||
|
@ -88,10 +88,10 @@ public class GenerateKeyWithoutUserIdTest {
|
|||
Streams.pipeAll(decryptionStream, plaintextOut);
|
||||
decryptionStream.close();
|
||||
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
|
||||
assertTrue(metadata.containsVerifiedSignatureFrom(certificate),
|
||||
failuresToString(metadata.getInvalidInbandSignatures()));
|
||||
assertTrue(metadata.isVerifiedSignedBy(certificate),
|
||||
failuresToString(metadata.getRejectedInlineSignatures()));
|
||||
assertTrue(metadata.isEncrypted());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
||||
import org.pgpainless.decryption_verification.MessageMetadata;
|
||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||
import org.pgpainless.key.util.KeyRingUtils;
|
||||
|
||||
|
@ -154,8 +154,8 @@ public class IgnoreMarkerPacketsTest {
|
|||
Streams.pipeAll(decryptionStream, outputStream);
|
||||
|
||||
decryptionStream.close();
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
assertTrue(metadata.containsVerifiedSignatureFrom(new OpenPgpV4Fingerprint("D1A66E1A23B182C9980F788CFBFCC82A015E7330")));
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
assertTrue(metadata.isVerifiedSignedBy(new OpenPgpV4Fingerprint("D1A66E1A23B182C9980F788CFBFCC82A015E7330")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -204,8 +204,8 @@ public class IgnoreMarkerPacketsTest {
|
|||
|
||||
decryptionStream.close();
|
||||
assertArrayEquals(data.getBytes(StandardCharsets.UTF_8), outputStream.toByteArray());
|
||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||
assertTrue(metadata.containsVerifiedSignatureFrom(new OpenPgpV4Fingerprint("D1A66E1A23B182C9980F788CFBFCC82A015E7330")));
|
||||
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||
assertTrue(metadata.isVerifiedSignedBy(new OpenPgpV4Fingerprint("D1A66E1A23B182C9980F788CFBFCC82A015E7330")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue