Esempio n. 1
0
 public void SecretKeyRingWithPersonalCertificateTest()
 {
     checkSecretKeyRingWithPersonalCertificate(secWithPersonalCertificate);
     PgpSecretKeyRingBundle secRing = new PgpSecretKeyRingBundle(secWithPersonalCertificate);
     checkSecretKeyRingWithPersonalCertificate(secRing.GetEncoded());
 }
Esempio n. 2
0
        public void PerformTest9()
        {
            PgpSecretKeyRingBundle secretRings1 = new PgpSecretKeyRingBundle(sec9);

            int count = 0;

            byte[] encRing = secretRings1.GetEncoded();

            PgpSecretKeyRingBundle secretRings2 = new PgpSecretKeyRingBundle(encRing);

            foreach (PgpSecretKeyRing pgpSec1 in secretRings1.GetKeyRings())
            {
                count++;

                int keyCount = 0;

                byte[] bytes = pgpSec1.GetEncoded();

                PgpSecretKeyRing pgpSec2 = new PgpSecretKeyRing(bytes);

                foreach (PgpSecretKey k in pgpSec2.GetSecretKeys())
                {
                    keyCount++;

                    PgpPrivateKey pKey = k.ExtractPrivateKey(sec9pass);
                    if (keyCount == 1 && pKey != null)
                    {
                        Fail("primary secret key found, null expected");
                    }
                }

                if (keyCount != 3)
                {
                    Fail("wrong number of secret keys");
                }
            }

            if (count != 1)
            {
                Fail("wrong number of secret keyrings");
            }
        }
Esempio n. 3
0
        public void PerformTest8()
        {
            PgpPublicKeyRingBundle pubRings = new PgpPublicKeyRingBundle(pub8);

            int count = 0;

            byte[] encRing = pubRings.GetEncoded();

            pubRings = new PgpPublicKeyRingBundle(encRing);

            foreach (PgpPublicKeyRing pgpPub1 in pubRings.GetKeyRings())
            {
                count++;

                int keyCount = 0;

                byte[] bytes = pgpPub1.GetEncoded();

                PgpPublicKeyRing pgpPub2 = new PgpPublicKeyRing(bytes);

                foreach (PgpPublicKey o in pgpPub2.GetPublicKeys())
                {
                    if (o == null)
                        Fail("null key found");

                    keyCount++;
                }

                if (keyCount != 2)
                {
                    Fail("wrong number of public keys");
                }
            }

            if (count != 2)
            {
                Fail("wrong number of public keyrings");
            }

            PgpSecretKeyRingBundle secretRings1 = new PgpSecretKeyRingBundle(sec8);

            count = 0;

            encRing = secretRings1.GetEncoded();

            PgpSecretKeyRingBundle secretRings2 = new PgpSecretKeyRingBundle(encRing);

            foreach (PgpSecretKeyRing pgpSec1 in secretRings1.GetKeyRings())
            {
                count++;

                int keyCount = 0;

                byte[] bytes = pgpSec1.GetEncoded();

                PgpSecretKeyRing pgpSec2 = new PgpSecretKeyRing(bytes);

                foreach (PgpSecretKey k in pgpSec2.GetSecretKeys())
                {
                    keyCount++;
                    k.ExtractPrivateKey(sec8pass);
                }

                if (keyCount != 2)
                {
                    Fail("wrong number of secret keys");
                }
            }

            if (count != 1)
            {
                Fail("wrong number of secret keyrings");
            }
        }
Esempio n. 4
0
        public void PerformTest4()
        {
            PgpSecretKeyRingBundle secretRings1 = new PgpSecretKeyRingBundle(sec4);
            int count = 0;

            byte[] encRing = secretRings1.GetEncoded();

            PgpSecretKeyRingBundle secretRings2 = new PgpSecretKeyRingBundle(encRing);

            foreach (PgpSecretKeyRing pgpSec1 in secretRings1.GetKeyRings())
            {
                count++;

                int keyCount = 0;

                byte[] bytes = pgpSec1.GetEncoded();

                PgpSecretKeyRing pgpSec2 = new PgpSecretKeyRing(bytes);

                foreach (PgpSecretKey k in pgpSec2.GetSecretKeys())
                {
                    keyCount++;
                    k.ExtractPrivateKey(sec3pass1);
                }

                if (keyCount != 2)
                {
                    Fail("wrong number of secret keys");
                }
            }

            if (count != 1)
            {
                Fail("wrong number of secret keyrings");
            }
        }
Esempio n. 5
0
        public void PerformTest3()
        {
            PgpPublicKeyRingBundle pubRings = new PgpPublicKeyRingBundle(pub3);

            int count = 0;

            byte[] encRing = pubRings.GetEncoded();

            pubRings = new PgpPublicKeyRingBundle(encRing);

            foreach (PgpPublicKeyRing pgpPub1 in pubRings.GetKeyRings())
            {
                count++;

                int keyCount = 0;

                byte[] bytes = pgpPub1.GetEncoded();

                PgpPublicKeyRing pgpPub2 = new PgpPublicKeyRing(bytes);

                foreach (PgpPublicKey pubK in pgpPub2.GetPublicKeys())
                {
                    keyCount++;
                    pubK.GetSignatures();
                }

                if (keyCount != 2)
                {
                    Fail("wrong number of public keys");
                }
            }

            if (count != 1)
            {
                Fail("wrong number of public keyrings");
            }

            PgpSecretKeyRingBundle secretRings2 = new PgpSecretKeyRingBundle(sec3);

            count = 0;

            encRing = secretRings2.GetEncoded();

            PgpSecretKeyRingBundle secretRings = new PgpSecretKeyRingBundle(encRing);

            foreach (PgpSecretKeyRing pgpSec1 in secretRings2.GetKeyRings())
            {
                count++;

                int keyCount = 0;

                byte[] bytes = pgpSec1.GetEncoded();

                PgpSecretKeyRing pgpSec2 = new PgpSecretKeyRing(bytes);

                foreach (PgpSecretKey k in pgpSec2.GetSecretKeys())
                {
                    keyCount++;
                    k.ExtractPrivateKey(sec3pass1);
                }

                if (keyCount != 2)
                {
                    Fail("wrong number of secret keys");
                }
            }

            if (count != 1)
            {
                Fail("wrong number of secret keyrings");
            }
        }
Esempio n. 6
0
        public void PerformTest2()
        {
            PgpPublicKeyRingBundle pubRings = new PgpPublicKeyRingBundle(pub2);

            int count = 0;

            byte[] encRing = pubRings.GetEncoded();

            pubRings = new PgpPublicKeyRingBundle(encRing);

            foreach (PgpPublicKeyRing pgpPub1 in pubRings.GetKeyRings())
            {
                count++;

                int keyCount = 0;

                byte[] bytes = pgpPub1.GetEncoded();

                PgpPublicKeyRing pgpPub2 = new PgpPublicKeyRing(bytes);

                foreach (PgpPublicKey pk in pgpPub2.GetPublicKeys())
                {
                    byte[] pkBytes = pk.GetEncoded();

                    PgpPublicKeyRing pkR = new PgpPublicKeyRing(pkBytes);

                    keyCount++;
                }

                if (keyCount != 2)
                {
                    Fail("wrong number of public keys");
                }
            }

            if (count != 2)
            {
                Fail("wrong number of public keyrings");
            }

            PgpSecretKeyRingBundle secretRings2 = new PgpSecretKeyRingBundle(sec2);

            count = 0;

            encRing = secretRings2.GetEncoded();
            PgpSecretKeyRingBundle secretRings = new PgpSecretKeyRingBundle(encRing);

            foreach (PgpSecretKeyRing pgpSec1 in secretRings2.GetKeyRings())
            {
                count++;

                int keyCount = 0;

                byte[] bytes = pgpSec1.GetEncoded();

                PgpSecretKeyRing pgpSec2 = new PgpSecretKeyRing(bytes);

                foreach (PgpSecretKey k in pgpSec2.GetSecretKeys())
                {
                    keyCount++;
                    PgpPublicKey pk = k.PublicKey;

                    if (pk.KeyId == -1413891222336124627L)
                    {
                        int sCount = 0;

                        foreach (PgpSignature pgpSignature in pk.GetSignaturesOfType(PgpSignature.SubkeyBinding))
                        {
                            int type = pgpSignature.SignatureType;
                            if (type != PgpSignature.SubkeyBinding)
                            {
                                Fail("failed to return correct signature type");
                            }
                            sCount++;
                        }

                        if (sCount != 1)
                        {
                            Fail("failed to find binding signature");
                        }
                    }

                    pk.GetSignatures();

                    if (k.KeyId == -4049084404703773049L
                        || k.KeyId == -1413891222336124627L)
                    {
                        k.ExtractPrivateKey(sec2pass1);
                    }
                    else if (k.KeyId == -6498553574938125416L
                        || k.KeyId == 59034765524361024L)
                    {
                        k.ExtractPrivateKey(sec2pass2);
                    }
                }

                if (keyCount != 2)
                {
                    Fail("wrong number of secret keys");
                }
            }

            if (count != 2)
            {
                Fail("wrong number of secret keyrings");
            }
        }