2021-10-07 15:48:52 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-01-09 20:40:10 +01:00
|
|
|
package org.pgpainless.weird_keys;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
|
|
|
import java.security.InvalidAlgorithmParameterException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
import org.bouncycastle.openpgp.PGPException;
|
|
|
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|
|
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.pgpainless.PGPainless;
|
|
|
|
import org.pgpainless.algorithm.KeyFlag;
|
2021-06-16 15:38:02 +02:00
|
|
|
import org.pgpainless.encryption_signing.EncryptionOptions;
|
2021-01-09 20:40:10 +01:00
|
|
|
import org.pgpainless.key.generation.KeySpec;
|
|
|
|
import org.pgpainless.key.generation.type.KeyType;
|
|
|
|
import org.pgpainless.key.generation.type.rsa.RsaLength;
|
|
|
|
import org.pgpainless.key.util.KeyRingUtils;
|
|
|
|
|
|
|
|
public class TestEncryptCommsStorageFlagsDifferentiated {
|
|
|
|
|
|
|
|
@Test
|
2021-12-28 13:32:50 +01:00
|
|
|
public void testThatEncryptionDifferentiatesBetweenPurposeKeyFlags()
|
|
|
|
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
|
2021-11-02 12:23:05 +01:00
|
|
|
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
|
2021-09-20 12:30:03 +02:00
|
|
|
.setPrimaryKey(KeySpec.getBuilder(
|
2021-09-13 19:20:19 +02:00
|
|
|
KeyType.RSA(RsaLength._3072),
|
|
|
|
KeyFlag.CERTIFY_OTHER,
|
2021-01-09 20:40:10 +01:00
|
|
|
KeyFlag.SIGN_DATA,
|
|
|
|
KeyFlag.ENCRYPT_STORAGE // no ENCRYPT_COMMS
|
2021-09-20 12:30:03 +02:00
|
|
|
))
|
|
|
|
.addUserId("cannot@encrypt.comms")
|
2021-01-09 20:40:10 +01:00
|
|
|
.build();
|
|
|
|
|
2021-06-16 15:38:02 +02:00
|
|
|
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
2021-01-09 20:40:10 +01:00
|
|
|
|
2021-06-16 15:38:02 +02:00
|
|
|
assertThrows(IllegalArgumentException.class, () -> EncryptionOptions.encryptCommunications()
|
|
|
|
.addRecipient(publicKeys));
|
2021-01-09 20:40:10 +01:00
|
|
|
}
|
|
|
|
}
|