示例#1
0
 public static void VerifyDuplicateKey_DistinctHandles()
 {
     using (DSAOpenSsl first = new DSAOpenSsl())
     using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle())
     using (SafeEvpPKeyHandle firstHandle2 = first.DuplicateKeyHandle())
     {
         Assert.NotSame(firstHandle, firstHandle2);
     }
 }
示例#2
0
 public static void VerifyDuplicateKey_DistinctHandles()
 {
     using (DSAOpenSsl first = new DSAOpenSsl())
         using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle())
             using (SafeEvpPKeyHandle firstHandle2 = first.DuplicateKeyHandle())
             {
                 Assert.NotSame(firstHandle, firstHandle2);
             }
 }
示例#3
0
        public static void VerifyDuplicateKey_InvalidHandle()
        {
            using (DSAOpenSsl dsa = new DSAOpenSsl())
            {
                SafeEvpPKeyHandle pkey = dsa.DuplicateKeyHandle();

                using (pkey)
                {
                }

                AssertExtensions.Throws <ArgumentException>("pkeyHandle", () => new DSAOpenSsl(pkey));
            }
        }
示例#4
0
        public static void VerifyDuplicateKey_InvalidHandle()
        {
            using (DSAOpenSsl dsa = new DSAOpenSsl())
            {
                SafeEvpPKeyHandle pkey = dsa.DuplicateKeyHandle();

                using (pkey)
                {
                }

                Assert.Throws<ArgumentException>(() => new DSAOpenSsl(pkey));
            }
        }
示例#5
0
        public static void VerifyDuplicateKey_ValidHandle()
        {
            byte[] data = ByteUtils.RepeatByte(0x71, 11);

            using (DSAOpenSsl first = new DSAOpenSsl())
                using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle())
                {
                    using (DSA second = new DSAOpenSsl(firstHandle))
                    {
                        byte[] signed = second.SignData(data, HashAlgorithmName.SHA512);
                        Assert.True(first.VerifyData(data, signed, HashAlgorithmName.SHA512));
                    }
                }
        }
示例#6
0
        public static void VerifyDuplicateKey_ValidHandle()
        {
            byte[] data = ByteUtils.RepeatByte(0x71, 11);

            using (DSAOpenSsl first = new DSAOpenSsl())
            using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle())
            {
                using (DSA second = new DSAOpenSsl(firstHandle))
                {
                    byte[] signed = second.SignData(data, HashAlgorithmName.SHA512);
                    Assert.True(first.VerifyData(data, signed, HashAlgorithmName.SHA512));
                }
            }
        }
示例#7
0
        public ICertificatePal CopyWithPrivateKey(DSA privateKey)
        {
            DSAOpenSsl typedKey = privateKey as DSAOpenSsl;

            if (typedKey != null)
            {
                return(CopyWithPrivateKey((SafeEvpPKeyHandle)typedKey.DuplicateKeyHandle()));
            }

            DSAParameters dsaParameters = privateKey.ExportParameters(true);

            using (PinAndClear.Track(dsaParameters.X))
                using (typedKey = new DSAOpenSsl(dsaParameters))
                {
                    return(CopyWithPrivateKey((SafeEvpPKeyHandle)typedKey.DuplicateKeyHandle()));
                }
        }
示例#8
0
        public static void VerifyDuplicateKey_RefCounts()
        {
            byte[] data = ByteUtils.RepeatByte(0x74, 11);
            byte[] signature;
            DSA    second;

            using (DSAOpenSsl first = new DSAOpenSsl())
                using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle())
                {
                    signature = first.SignData(data, HashAlgorithmName.SHA384);
                    second    = new DSAOpenSsl(firstHandle);
                }

            // Now show that second still works, despite first and firstHandle being Disposed.
            using (second)
            {
                Assert.True(second.VerifyData(data, signature, HashAlgorithmName.SHA384));
            }
        }
示例#9
0
        public static void VerifyDuplicateKey_RefCounts()
        {
            byte[] data = ByteUtils.RepeatByte(0x74, 11);
            byte[] signature;
            DSA second;

            using (DSAOpenSsl first = new DSAOpenSsl())
            using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle())
            {
                signature = first.SignData(data, HashAlgorithmName.SHA384);
                second = new DSAOpenSsl(firstHandle);
            }

            // Now show that second still works, despite first and firstHandle being Disposed.
            using (second)
            {
                Assert.True(second.VerifyData(data, signature, HashAlgorithmName.SHA384));
            }
        }