mirror of
https://codeberg.org/PGPainless/bc-sop.git
synced 2025-09-09 19:29:41 +02:00
Adjust to latest changes (fa281a744d537f9d369b92ee02c7f7cb61c2ee6f)
This commit is contained in:
parent
994ba47b30
commit
ec4bb0c5db
4 changed files with 31 additions and 7 deletions
|
@ -3,9 +3,12 @@ package org.pgpainless.bouncycastle.sop.operation;
|
||||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||||
import org.bouncycastle.bcpg.BCPGOutputStream;
|
import org.bouncycastle.bcpg.BCPGOutputStream;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPApi;
|
import org.bouncycastle.openpgp.api.OpenPGPApi;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPDetachedSignatureGenerator;
|
import org.bouncycastle.openpgp.api.OpenPGPDetachedSignatureGenerator;
|
||||||
|
import org.bouncycastle.openpgp.api.OpenPGPKey;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPSignature;
|
import org.bouncycastle.openpgp.api.OpenPGPSignature;
|
||||||
|
import org.bouncycastle.openpgp.api.SignatureParameters;
|
||||||
import org.bouncycastle.openpgp.api.exception.InvalidSigningKeyException;
|
import org.bouncycastle.openpgp.api.exception.InvalidSigningKeyException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import sop.MicAlg;
|
import sop.MicAlg;
|
||||||
|
@ -28,6 +31,8 @@ public class BCDetachedSign
|
||||||
private boolean armored = true;
|
private boolean armored = true;
|
||||||
private char[] keyPassword = null;
|
private char[] keyPassword = null;
|
||||||
|
|
||||||
|
private int signatureMode = PGPSignature.BINARY_DOCUMENT;
|
||||||
|
|
||||||
public BCDetachedSign(OpenPGPApi api) {
|
public BCDetachedSign(OpenPGPApi api) {
|
||||||
super(api);
|
super(api);
|
||||||
sigGen = api.createDetachedSignature();
|
sigGen = api.createDetachedSignature();
|
||||||
|
@ -83,10 +88,10 @@ public class BCDetachedSign
|
||||||
switch (signAs)
|
switch (signAs)
|
||||||
{
|
{
|
||||||
case text:
|
case text:
|
||||||
sigGen.setCanonicalTextDocument();
|
signatureMode = PGPSignature.CANONICAL_TEXT_DOCUMENT;
|
||||||
break;
|
break;
|
||||||
case binary:
|
case binary:
|
||||||
sigGen.setBinarySignature();
|
signatureMode = PGPSignature.BINARY_DOCUMENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -102,7 +107,16 @@ public class BCDetachedSign
|
||||||
public DetachedSign key(@NotNull InputStream inputStream) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
|
public DetachedSign key(@NotNull InputStream inputStream) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
sigGen.addSigningKey(parseKey(inputStream), keyPassword);
|
OpenPGPKey key = parseKey(inputStream);
|
||||||
|
OpenPGPKey.OpenPGPSecretKey signingKey = key.getSecretKey(key.getSigningKeys().get(0));
|
||||||
|
sigGen.addSigningKey(signingKey,
|
||||||
|
k -> keyPassword,
|
||||||
|
new SignatureParameters.Callback() {
|
||||||
|
@Override
|
||||||
|
public SignatureParameters apply(SignatureParameters parameters) {
|
||||||
|
return parameters.setSignatureType(signatureMode);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (InvalidSigningKeyException e)
|
catch (InvalidSigningKeyException e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.bouncycastle.openpgp.api.OpenPGPApi;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
|
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPMessageOutputStream;
|
import org.bouncycastle.openpgp.api.OpenPGPMessageOutputStream;
|
||||||
import org.bouncycastle.openpgp.api.exception.InvalidEncryptionKeyException;
|
import org.bouncycastle.openpgp.api.exception.InvalidEncryptionKeyException;
|
||||||
|
import org.bouncycastle.openpgp.api.exception.InvalidSigningKeyException;
|
||||||
import org.bouncycastle.util.io.Streams;
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import sop.EncryptionResult;
|
import sop.EncryptionResult;
|
||||||
|
@ -46,7 +47,11 @@ public class BCEncrypt
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Encrypt signWith(@NotNull InputStream inputStream) throws SOPGPException.KeyCannotSign, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData, IOException {
|
public Encrypt signWith(@NotNull InputStream inputStream) throws SOPGPException.KeyCannotSign, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData, IOException {
|
||||||
mGen.addSigningKey(parseKey(inputStream), k -> keyPassword);
|
try {
|
||||||
|
mGen.addSigningKey(parseKey(inputStream), k -> keyPassword);
|
||||||
|
} catch (InvalidSigningKeyException e) {
|
||||||
|
throw new SOPGPException.KeyCannotSign("Key cannot sign", e);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,11 +46,11 @@ public class BCGenerateKey
|
||||||
{
|
{
|
||||||
if (signOnly)
|
if (signOnly)
|
||||||
{
|
{
|
||||||
key = generator.signOnlyKey(passphrase);
|
key = generator.signOnlyKey().build(passphrase);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
key = generator.ed25519x25519Key(userId, passphrase);
|
key = generator.ed25519x25519Key(userId).build(passphrase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (PGPException e)
|
catch (PGPException e)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPApi;
|
import org.bouncycastle.openpgp.api.OpenPGPApi;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
|
import org.bouncycastle.openpgp.api.OpenPGPMessageGenerator;
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPMessageOutputStream;
|
import org.bouncycastle.openpgp.api.OpenPGPMessageOutputStream;
|
||||||
|
import org.bouncycastle.openpgp.api.exception.InvalidSigningKeyException;
|
||||||
import org.bouncycastle.util.io.Streams;
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import sop.Ready;
|
import sop.Ready;
|
||||||
|
@ -59,7 +60,11 @@ public class BCInlineSign
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InlineSign key(@NotNull InputStream inputStream) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
|
public InlineSign key(@NotNull InputStream inputStream) throws SOPGPException.KeyCannotSign, SOPGPException.BadData, SOPGPException.UnsupportedAsymmetricAlgo, IOException {
|
||||||
mGen.addSigningKey(api.readKeyOrCertificate().parseKey(inputStream), k -> keyPassword);
|
try {
|
||||||
|
mGen.addSigningKey(api.readKeyOrCertificate().parseKey(inputStream), k -> keyPassword);
|
||||||
|
} catch (InvalidSigningKeyException e) {
|
||||||
|
throw new SOPGPException.KeyCannotSign("Key cannot sign.", e);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue