summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2021-05-23 19:27:59 +1000
committerDavid Hook <dgh@bouncycastle.org>2021-05-23 19:27:59 +1000
commit8ebe171819966753072c65743fd9b1c9e7f090a5 (patch)
treea5a9a3e907a7b5c096b0d59e17a1481140ba718e /crypto/test
parentgithub #250 lookup table error (diff)
downloadBouncyCastle.NET-ed25519-8ebe171819966753072c65743fd9b1c9e7f090a5.tar.xz
github #23 added method for handling signing subkey
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/openpgp/test/PgpKeyRingTest.cs42
1 files changed, 38 insertions, 4 deletions
diff --git a/crypto/test/src/openpgp/test/PgpKeyRingTest.cs b/crypto/test/src/openpgp/test/PgpKeyRingTest.cs
index 5f1d83459..aed750318 100644
--- a/crypto/test/src/openpgp/test/PgpKeyRingTest.cs
+++ b/crypto/test/src/openpgp/test/PgpKeyRingTest.cs
@@ -2261,7 +2261,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
         }
 
         [Test]
-        public void GenerateSha1Test()
+        public void GenerateSha256Test()
         {
             char[] passPhrase = "hello".ToCharArray();
 
@@ -2296,11 +2296,14 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
 
             PgpKeyPair dsaKeyPair = new PgpKeyPair(PublicKeyAlgorithmTag.Dsa, dsaKp, DateTime.UtcNow);
             PgpKeyPair elgKeyPair = new PgpKeyPair(PublicKeyAlgorithmTag.ElGamalEncrypt, elgKp, DateTime.UtcNow);
+            PgpKeyPair dsaSubKeyPair = new PgpKeyPair(PublicKeyAlgorithmTag.Dsa, dsaKpg.GenerateKeyPair(), DateTime.UtcNow);
 
             PgpKeyRingGenerator keyRingGen = new PgpKeyRingGenerator(PgpSignature.PositiveCertification, dsaKeyPair,
                 "test", SymmetricKeyAlgorithmTag.Aes256, passPhrase, true, null, null, Random);
 
-            keyRingGen.AddSubKey(elgKeyPair);
+            keyRingGen.AddSubKey(elgKeyPair, HashAlgorithmTag.Sha256);
+
+            keyRingGen.AddSubKey(dsaSubKeyPair, HashAlgorithmTag.Sha256, HashAlgorithmTag.Sha256);
 
             PgpSecretKeyRing keyRing = keyRingGen.GenerateSecretKeyRing();
 
@@ -2310,6 +2313,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
 
             PgpPublicKey vKey = null;
             PgpPublicKey sKey = null;
+            PgpPublicKey sdKey = null;
 
             foreach (PgpPublicKey pk in pubRing.GetPublicKeys())
             {
@@ -2319,7 +2323,14 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
                 }
                 else
                 {
-                    sKey = pk;
+                    if (pk.IsEncryptionKey)
+                    {
+                        sKey = pk;
+                    }
+                    else
+                    {
+                        sdKey = pk;
+                    }
                 }
             }
 
@@ -2336,6 +2347,29 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
                     }
                 }
             }
+
+            foreach (PgpSignature sig in sdKey.GetSignatures())
+            {
+                if (sig.KeyId == vKey.KeyId
+                    && sig.SignatureType == PgpSignature.SubkeyBinding)
+                {
+                    sig.InitVerify(vKey);
+
+                    if (!sig.VerifyCertification(vKey, sdKey))
+                    {
+                        Fail("failed to verify dsa sub-key signature.");
+                    }
+
+                    PgpSignature bindSig = sig.GetHashedSubPackets().GetEmbeddedSignatures()[0];
+
+                    bindSig.InitVerify(sdKey);
+
+                    if (!bindSig.VerifyCertification(vKey, sdKey))
+                    {
+                        Fail("failed to verify dsa sub-key primary binding signature.");
+                    }
+                }
+            }
         }
 
         [Test]
@@ -2574,7 +2608,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
             PerformTest11();
 
             GenerateTest();
-            GenerateSha1Test();
+            GenerateSha256Test();
             RewrapTest();
             PublicKeyRingWithX509Test();
             SecretKeyRingWithPersonalCertificateTest();