Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/pg/src
diff options
context:
space:
mode:
Diffstat (limited to 'pg/src')
-rw-r--r--pg/src/main/j2me/org/bouncycastle/openpgp/PGPSignature.java6
-rw-r--r--pg/src/main/j2me/org/bouncycastle/openpgp/PGPUtil.java10
-rw-r--r--pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java10
-rw-r--r--pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPPBETest.java100
4 files changed, 113 insertions, 13 deletions
diff --git a/pg/src/main/j2me/org/bouncycastle/openpgp/PGPSignature.java b/pg/src/main/j2me/org/bouncycastle/openpgp/PGPSignature.java
index 7f20fdc9..e345167a 100644
--- a/pg/src/main/j2me/org/bouncycastle/openpgp/PGPSignature.java
+++ b/pg/src/main/j2me/org/bouncycastle/openpgp/PGPSignature.java
@@ -6,7 +6,7 @@ import java.io.OutputStream;
import java.util.Date;
import org.bouncycastle.asn1.ASN1EncodableVector;
-import org.bouncycastle.asn1.DERInteger;
+import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.bcpg.BCPGInputStream;
import org.bouncycastle.bcpg.BCPGOutputStream;
@@ -463,8 +463,8 @@ public class PGPSignature
try
{
ASN1EncodableVector v = new ASN1EncodableVector();
- v.add(new DERInteger(sigValues[0].getValue()));
- v.add(new DERInteger(sigValues[1].getValue()));
+ v.add(new ASN1Integer(sigValues[0].getValue()));
+ v.add(new ASN1Integer(sigValues[1].getValue()));
signature = new DERSequence(v).getEncoded();
}
diff --git a/pg/src/main/j2me/org/bouncycastle/openpgp/PGPUtil.java b/pg/src/main/j2me/org/bouncycastle/openpgp/PGPUtil.java
index 2bae0cee..fc5dab65 100644
--- a/pg/src/main/j2me/org/bouncycastle/openpgp/PGPUtil.java
+++ b/pg/src/main/j2me/org/bouncycastle/openpgp/PGPUtil.java
@@ -5,7 +5,7 @@ import java.security.SecureRandom;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Sequence;
-import org.bouncycastle.asn1.DERInteger;
+import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.bcpg.HashAlgorithmTags;
import org.bouncycastle.bcpg.MPInteger;
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
@@ -23,15 +23,15 @@ public class PGPUtil
{
ASN1InputStream aIn = new ASN1InputStream(encoding);
- DERInteger i1;
- DERInteger i2;
+ ASN1Integer i1;
+ ASN1Integer i2;
try
{
ASN1Sequence s = (ASN1Sequence)aIn.readObject();
- i1 = (DERInteger)s.getObjectAt(0);
- i2 = (DERInteger)s.getObjectAt(1);
+ i1 = (ASN1Integer)s.getObjectAt(0);
+ i2 = (ASN1Integer)s.getObjectAt(1);
}
catch (IOException e)
{
diff --git a/pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java b/pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java
index ecb3b778..e3e9c438 100644
--- a/pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java
+++ b/pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java
@@ -13,8 +13,8 @@ import java.security.Security;
import java.util.Date;
import org.bouncycastle.asn1.ASN1InputStream;
+import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Sequence;
-import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.bcpg.HashAlgorithmTags;
import org.bouncycastle.bcpg.MPInteger;
@@ -59,15 +59,15 @@ public class PGPUtil
{
ASN1InputStream aIn = new ASN1InputStream(encoding);
- DERInteger i1;
- DERInteger i2;
+ ASN1Integer i1;
+ ASN1Integer i2;
try
{
ASN1Sequence s = (ASN1Sequence)aIn.readObject();
- i1 = (DERInteger)s.getObjectAt(0);
- i2 = (DERInteger)s.getObjectAt(1);
+ i1 = (ASN1Integer)s.getObjectAt(0);
+ i2 = (ASN1Integer)s.getObjectAt(1);
}
catch (IOException e)
{
diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPPBETest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPPBETest.java
index 80ca57a0..97fd07e0 100644
--- a/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPPBETest.java
+++ b/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPPBETest.java
@@ -106,6 +106,60 @@ public class BcPGPPBETest
return bOut.toByteArray();
}
+ /**
+ * decrypt the passed in message stream, verifying the algorithm used.
+ */
+ private byte[] decryptMessageCheck(
+ int algorithm,
+ byte[] message,
+ Date date)
+ throws Exception
+ {
+ PGPObjectFactory pgpF = new PGPObjectFactory(message);
+ PGPEncryptedDataList enc = (PGPEncryptedDataList)pgpF.nextObject();
+ PGPPBEEncryptedData pbe = (PGPPBEEncryptedData)enc.get(0);
+
+ if (algorithm != pbe.getSymmetricAlgorithm(new BcPBEDataDecryptorFactory(pass, new BcPGPDigestCalculatorProvider())))
+ {
+ fail("algorithm mismatch");
+ }
+
+ InputStream clear = pbe.getDataStream(new BcPBEDataDecryptorFactory(pass, new BcPGPDigestCalculatorProvider()));
+
+ PGPObjectFactory pgpFact = new PGPObjectFactory(clear);
+ PGPCompressedData cData = (PGPCompressedData)pgpFact.nextObject();
+
+ pgpFact = new PGPObjectFactory(cData.getDataStream());
+
+ PGPLiteralData ld = (PGPLiteralData)pgpFact.nextObject();
+
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ if (!ld.getFileName().equals("test.txt")
+ && !ld.getFileName().equals("_CONSOLE"))
+ {
+ fail("wrong filename in packet");
+ }
+ if (!ld.getModificationTime().equals(date))
+ {
+ fail("wrong modification time in packet: " + ld.getModificationTime().getTime() + " " + date.getTime());
+ }
+
+ InputStream unc = ld.getInputStream();
+ int ch;
+
+ while ((ch = unc.read()) >= 0)
+ {
+ bOut.write(ch);
+ }
+
+ if (pbe.isIntegrityProtected() && !pbe.verify())
+ {
+ fail("integrity check failed");
+ }
+
+ return bOut.toByteArray();
+ }
+
private byte[] decryptMessageBuffered(
byte[] message,
Date date)
@@ -383,6 +437,52 @@ public class BcPGPPBETest
{
fail("wrong plain text in buffer generated packet");
}
+
+ tryAlgorithm(PGPEncryptedData.AES_128, text);
+ //tryAlgorithm(PGPEncryptedData.CAMELLIA_128, text);
+ }
+
+ private void tryAlgorithm(int algorithm, byte[] text)
+ throws Exception
+ {
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(
+ PGPCompressedData.ZIP);
+
+ Date cDate = new Date((System.currentTimeMillis() / 1000) * 1000);
+ PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
+ OutputStream comOut = comData.open(new UncloseableOutputStream(bOut));
+ OutputStream ldOut = lData.open(
+ new UncloseableOutputStream(comOut),
+ PGPLiteralData.BINARY,
+ PGPLiteralData.CONSOLE,
+ text.length,
+ cDate);
+
+ ldOut.write(text);
+
+ ldOut.close();
+
+ comOut.close();
+
+ ByteArrayOutputStream cbOut = new ByteArrayOutputStream();
+ PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new BcPGPDataEncryptorBuilder(algorithm).setSecureRandom(new SecureRandom()));
+
+ cPk.addMethod(new BcPBEKeyEncryptionMethodGenerator(pass));
+
+ OutputStream cOut = cPk.open(new UncloseableOutputStream(cbOut), bOut.toByteArray().length);
+
+ cOut.write(bOut.toByteArray());
+
+ cOut.close();
+
+ byte[] out = decryptMessageCheck(algorithm, cbOut.toByteArray(), cDate);
+
+ if (!areEqual(out, text))
+ {
+ fail("wrong plain text in generated packet");
+ }
}
public String getName()