mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 03:17:58 +01:00
Cleartext Signaure Framework: Support for multiple Hash: headers
This commit is contained in:
parent
a19fc9ebda
commit
e4560ac5b5
1 changed files with 24 additions and 3 deletions
|
@ -8,7 +8,10 @@ import java.io.BufferedOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||||
|
@ -22,6 +25,7 @@ import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||||
import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder;
|
import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder;
|
||||||
import org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator;
|
import org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator;
|
||||||
import org.pgpainless.algorithm.CompressionAlgorithm;
|
import org.pgpainless.algorithm.CompressionAlgorithm;
|
||||||
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
import org.pgpainless.algorithm.StreamEncoding;
|
import org.pgpainless.algorithm.StreamEncoding;
|
||||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||||
import org.pgpainless.implementation.ImplementationFactory;
|
import org.pgpainless.implementation.ImplementationFactory;
|
||||||
|
@ -165,9 +169,8 @@ public final class EncryptionStream extends OutputStream {
|
||||||
|
|
||||||
private void prepareLiteralDataProcessing() throws IOException {
|
private void prepareLiteralDataProcessing() throws IOException {
|
||||||
if (options.isCleartextSigned()) {
|
if (options.isCleartextSigned()) {
|
||||||
// Begin cleartext with hash algorithm of first signing method
|
int[] algorithmIds = collectHashAlgorithmsForCleartextSigning();
|
||||||
SigningOptions.SigningMethod firstMethod = options.getSigningOptions().getSigningMethods().values().iterator().next();
|
armorOutputStream.beginClearText(algorithmIds);
|
||||||
armorOutputStream.beginClearText(firstMethod.getHashAlgorithm().getAlgorithmId());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +198,24 @@ public final class EncryptionStream extends OutputStream {
|
||||||
outermostStream = crlfGeneratorStream;
|
outermostStream = crlfGeneratorStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int[] collectHashAlgorithmsForCleartextSigning() {
|
||||||
|
SigningOptions signOpts = options.getSigningOptions();
|
||||||
|
Set<HashAlgorithm> hashAlgorithms = new HashSet<>();
|
||||||
|
if (signOpts != null) {
|
||||||
|
for (SigningOptions.SigningMethod method : signOpts.getSigningMethods().values()) {
|
||||||
|
hashAlgorithms.add(method.getHashAlgorithm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] algorithmIds = new int[hashAlgorithms.size()];
|
||||||
|
Iterator<HashAlgorithm> iterator = hashAlgorithms.iterator();
|
||||||
|
for (int i = 0; i < algorithmIds.length; i++) {
|
||||||
|
algorithmIds[i] = iterator.next().getAlgorithmId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return algorithmIds;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(int data) throws IOException {
|
public void write(int data) throws IOException {
|
||||||
outermostStream.write(data);
|
outermostStream.write(data);
|
||||||
|
|
Loading…
Reference in a new issue