Compare commits

..

No commits in common. "e0952aaf6043bb69e2f8def67edf08a643fe29ae" and "43fdac4ac5e9a12eca577d3514e345e03f445ff8" have entirely different histories.

4 changed files with 9 additions and 45 deletions

View file

@ -1,8 +1,6 @@
package org.pgpainless.bouncycastle.sop.operation;
import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.api.OpenPGPApi;
import org.bouncycastle.util.io.Streams;
import org.jetbrains.annotations.NotNull;
@ -28,11 +26,10 @@ public class BCArmor
return new Ready() {
@Override
public void writeTo(@NotNull OutputStream outputStream) throws IOException {
InputStream decodeIn = PGPUtil.getDecoderStream(inputStream);
ArmoredOutputStream aOut = ArmoredOutputStream.builder()
.clearHeaders()
.build(outputStream);
Streams.pipeAll(decodeIn, aOut);
Streams.pipeAll(inputStream, aOut);
aOut.close();
}
};

View file

@ -1,6 +1,6 @@
package org.pgpainless.bouncycastle.sop.operation;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.openpgp.api.OpenPGPApi;
import org.bouncycastle.util.io.Streams;
import org.jetbrains.annotations.NotNull;
@ -26,9 +26,9 @@ public class BCDearmor
return new Ready() {
@Override
public void writeTo(@NotNull OutputStream outputStream) throws IOException {
InputStream decodeIn = PGPUtil.getDecoderStream(inputStream);
Streams.pipeAll(decodeIn, outputStream);
decodeIn.close();
ArmoredInputStream aIn = new ArmoredInputStream(inputStream);
Streams.pipeAll(aIn, outputStream);
aIn.close();
}
};
}

View file

@ -1,11 +1,8 @@
package org.pgpainless.bouncycastle.sop.operation;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.api.MessageEncryptionMechanism;
import org.bouncycastle.openpgp.api.OpenPGPApi;
import org.bouncycastle.openpgp.api.OpenPGPEncryptionNegotiator;
import org.bouncycastle.openpgp.api.OpenPGPKey;
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
import org.bouncycastle.openpgp.api.OpenPGPMessageOutputStream;
@ -15,7 +12,6 @@ import org.bouncycastle.openpgp.api.exception.InvalidSigningKeyException;
import org.bouncycastle.util.io.Streams;
import org.jetbrains.annotations.NotNull;
import sop.EncryptionResult;
import sop.Profile;
import sop.ReadyWithResult;
import sop.SessionKey;
import sop.enums.EncryptAs;
@ -27,25 +23,15 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class BCEncrypt
extends AbstractBCOperation
implements Encrypt {
public static final Profile RFC4880_PROFILE = new Profile("rfc4880", "Follow the packet format of rfc4880");
public static final Profile RFC9580_PROFILE = new Profile("rfc9580", "Follow the packet format of rfc9580");
public static final List<Profile> PROFILES = Arrays.asList(
RFC4880_PROFILE.withAliases("default", "compatibility"),
RFC9580_PROFILE.withAliases("security", "performance"));
private final OpenPGPMessageGenerator mGen;
private final List<OpenPGPKey> signingKeys = new ArrayList<>();
private int signatureMode = PGPSignature.BINARY_DOCUMENT;
private boolean hasEncryptionMethod = false;
private Profile profile = RFC9580_PROFILE;
public BCEncrypt(OpenPGPApi api) {
super(api);
@ -118,13 +104,8 @@ public class BCEncrypt
@NotNull
@Override
public Encrypt profile(@NotNull String s) {
for (Profile p : PROFILES) {
if (p.getName().equals(s) || p.getAliases().contains(s)) {
profile = p;
return this;
}
}
throw new SOPGPException.UnsupportedProfile("encrypt", s);
// TODO: Implement
return this;
}
@NotNull
@ -135,21 +116,6 @@ public class BCEncrypt
throw new SOPGPException.MissingArg("No encryption method provided.");
}
if (profile.getName().equals(RFC4880_PROFILE.getName())) {
mGen.setPublicKeyBasedEncryptionNegotiator(new OpenPGPEncryptionNegotiator() {
@Override
public MessageEncryptionMechanism negotiateEncryption(OpenPGPMessageGenerator configuration) {
return MessageEncryptionMechanism.integrityProtected(SymmetricKeyAlgorithmTags.AES_256);
}
});
mGen.setPasswordBasedEncryptionNegotiator(new OpenPGPEncryptionNegotiator() {
@Override
public MessageEncryptionMechanism negotiateEncryption(OpenPGPMessageGenerator configuration) {
return MessageEncryptionMechanism.integrityProtected(SymmetricKeyAlgorithmTags.AES_256);
}
});
}
for (OpenPGPKey key : signingKeys) {
try {
mGen.addSigningKey(key, new SignatureParameters.Callback() {

View file

@ -6,6 +6,7 @@ import sop.Profile;
import sop.exception.SOPGPException;
import sop.operation.ListProfiles;
import java.util.Collections;
import java.util.List;
public class BCListProfiles
@ -23,7 +24,7 @@ public class BCListProfiles
case "generate-key":
return BCGenerateKey.PROFILES;
case "encrypt":
return BCEncrypt.PROFILES;
return Collections.emptyList();
}
throw new SOPGPException.UnsupportedProfile(s);
}