From d70ee864682e89c5d8f7fb9cd558647d4f90d83f Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 20 May 2021 12:40:38 +0200 Subject: [PATCH] Prevent plaintext encryption --- .../encryption_signing/EncryptionOptions.java | 3 +++ .../org/pgpainless/key/EvaluatedKeyRing.java | 19 +++++++++++++++---- .../bouncycastle/PGPPublicKeyRingTest.java | 1 - 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionOptions.java b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionOptions.java index f3428c45..e46aabaa 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionOptions.java +++ b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionOptions.java @@ -124,6 +124,9 @@ public class EncryptionOptions { } public void overrideEncryptionAlgorithm(SymmetricKeyAlgorithm encryptionAlgorithm) { + if (encryptionAlgorithm == SymmetricKeyAlgorithm.NULL) { + throw new IllegalArgumentException("Plaintext encryption can only be used to denote unencrypted secret keys."); + } this.encryptionAlgorithmOverride = encryptionAlgorithm; } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/EvaluatedKeyRing.java b/pgpainless-core/src/main/java/org/pgpainless/key/EvaluatedKeyRing.java index 393666d5..34d9314c 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/EvaluatedKeyRing.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/EvaluatedKeyRing.java @@ -1,3 +1,18 @@ +/* + * Copyright 2021 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. + */ package org.pgpainless.key; import java.util.List; @@ -29,8 +44,4 @@ public interface EvaluatedKeyRing { PGPSignature signature = getUserIdCertification(userId); return SignatureSubpacketsUtil.parseKeyFlags(signature); } - - - - } diff --git a/pgpainless-core/src/test/java/org/bouncycastle/PGPPublicKeyRingTest.java b/pgpainless-core/src/test/java/org/bouncycastle/PGPPublicKeyRingTest.java index 43fb135b..475a2516 100644 --- a/pgpainless-core/src/test/java/org/bouncycastle/PGPPublicKeyRingTest.java +++ b/pgpainless-core/src/test/java/org/bouncycastle/PGPPublicKeyRingTest.java @@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; -import java.util.Collections; import java.util.Iterator; import java.util.List;