Exemple #1
0
        public MFTestResults RSADesktop_Test()
        {
            Exception[] cryptoEx = new Exception[] { new CryptographicException(), new CryptographicUnexpectedOperationException() };
            Exception[] notSupportedEx = new Exception[] { new NotSupportedException() };

            //TestGroup rsaExcept = new TestGroup("RSA Exception Tests", new TestCase[]
            //{
            //    new ExceptionTestCase("FromXmlString null", new ExceptionTestCaseImpl(RsaFromXmlStringNull), ExceptionTestCase.ArgumentExceptions),
            //    new ExceptionTestCase("FromXmlString no modulus", new ExceptionTestCaseImpl(RsaFromXmlStringNoMod), cryptoEx),
            //    new ExceptionTestCase("FromXmlString no exponent", new ExceptionTestCaseImpl(RsaFromXmlStringNoExp), cryptoEx)
            //});

            TestGroup cspApi = new TestGroup("RSA CSP API Tests", new TestCase[]
		{
			//new TestCase("Check KeyExchangeAlgorithm", new TestCaseImpl(CspCheckKeyExchange)),
			//new TestCase("Check SignatureAlgorithm", new TestCaseImpl(CspCheckSignatureAlgorithm)),
			//new TestCase("Check UseMachineStore", new TestCaseImpl(CspCheckUseMachineStore)),
			//new TestCase("Check PersistKeys, then set true", new TestCaseImpl(CspCheckPersistKeys)),
			new TestCase("Sign bytes", new TestCaseImpl(CspSignBytes)),
			//new TestCase("IsPublic on bad key", new TestCaseImpl(IsPublicBadKey)),
			new TestCase("Sign with MD5", new TestCaseImpl(SignMD5))
		});

            TestGroup cspExcept = new TestGroup("RSA CSP Exception Tests", new TestCase[]
		{
			new ExceptionTestCase("Create negative key size", new ExceptionTestCaseImpl(CspNegativeKey), ExceptionTestCase.ArgumentExceptions),
			new ExceptionTestCase("Sign null hash", new ExceptionTestCaseImpl(CspSignNullHash), ExceptionTestCase.NullExceptions),
			new ExceptionTestCase("Sign with only public key", new ExceptionTestCaseImpl(CspSignPublic), cryptoEx),
			new ExceptionTestCase("Verify null hash", new ExceptionTestCaseImpl(CspVerifyNullHash), ExceptionTestCase.NullExceptions),
			new ExceptionTestCase("Verify null signature", new ExceptionTestCaseImpl(CspVerifyNullSig), ExceptionTestCase.NullExceptions),
			new ExceptionTestCase("Decrypt null bytes", new ExceptionTestCaseImpl(CspDecryptNullBytes), ExceptionTestCase.NullExceptions),
			new ExceptionTestCase("Decrypt wrong sized bytes", new ExceptionTestCaseImpl(CspDecryptWrongSizeBytes), cryptoEx),
			//new ExceptionTestCase("Decrypt value", new ExceptionTestCaseImpl(CspDecryptValue), notSupportedEx),
			//new ExceptionTestCase("Encrypt value", new ExceptionTestCaseImpl(CspEncryptValue), notSupportedEx),
			//new ExceptionTestCase("IsPublic on null key", new ExceptionTestCaseImpl(IsPublicNullKey), ExceptionTestCase.NullExceptions)
		});

        //    TestGroup oaepKeyApi = new TestGroup("OAEP Key Formatting API Tests", new TestCase[]
        //{
        //    new TestCase("Check Parameters", new TestCaseImpl(OaepKeyParams)),
        //    new TestCase("Round trip, RSA CSP", new TestCaseImpl(OaepKeyCSPRT)),
        //    new TestCase("Round trip, non-CSP", new TestCaseImpl(OaepKeyNotCSPRT)),
        //    new TestCase("Set parameter null", new TestCaseImpl(OaepKeyParameterNull)),
        //    new TestCase("Set parameters not-null", new TestCaseImpl(OaepKeyParameterNotNull)),
        //    new TestCase("Set RNG", new TestCaseImpl(OaepKeySetRng))
        //});

        //    TestGroup oaepKeyExcept = new TestGroup("OAEP Key Formatting Exception Tests", new TestCase[]
        //{
        //    new ExceptionTestCase("Deformat null", new ExceptionTestCaseImpl(OaepKeyDeformatNull), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Deformat bad key", new ExceptionTestCaseImpl(OaepKeyDeformatBad), cryptoEx),
        //    new ExceptionTestCase("Deformat null key", new ExceptionTestCaseImpl(OaepKeyDeformatSetNull), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Format set null key", new ExceptionTestCaseImpl(OaepKeyFormatSetNull), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Format null key", new ExceptionTestCaseImpl(OaepKeyFormatNull), ExceptionTestCase.NullExceptions)
        //});

        //    TestGroup pkcsKeyApi = new TestGroup("PKCS1 Key Formatting API Tests", new TestCase[]
        //{
        //    new TestCase("Set RNG", new TestCaseImpl(PkcsKeySetRng)),
        //    new TestCase("Set Parameters", new TestCaseImpl(PkcsKeySetParams)),
        //    new TestCase("Round trip, RSA CSP", new TestCaseImpl(PkcsKeyCSPRT)),
        //    new TestCase("Round trip, non-CSP", new TestCaseImpl(PkcsKeyNotCSPRT)),
        //    new TestCase("Check formatter parameters", new TestCaseImpl(PkcsKeyCheckFormatParams))
        //});

        //    TestGroup pkcsKeyExcept = new TestGroup("PKCS1 Key Formatting Exception Tests", new TestCase[]
        //{
        //    new ExceptionTestCase("Deformat null", new ExceptionTestCaseImpl(PkcsKeyDeformatNull), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Deformat set null key", new ExceptionTestCaseImpl(PkcsKeySetNullKey), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Format null key", new ExceptionTestCaseImpl(PkcsKeyFormatNull), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Format set null key", new ExceptionTestCaseImpl(PkcsKeyFormatSetNullKey), ExceptionTestCase.NullExceptions)
        //});

        //    TestGroup pkcsSigApi = new TestGroup("PKCS1 Signature Formatting API Tests", new TestCase[]
        //{
        //    new TestCase("Round trip, RSA CSP", new TestCaseImpl(PkcsSigCSPRT)),
        //    new TestCase("Round trip, non-CSP", new TestCaseImpl(PkcsSigNotCSPRT))
        //});

        //    TestGroup pkcsSigExcept = new TestGroup("PKCS1 Signature Formatting Exception Tests", new TestCase[]
        //{
        //    new ExceptionTestCase("Deformat set null key", new ExceptionTestCaseImpl(PkcsSigDeformatSetNullKey), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Verify null key", new ExceptionTestCaseImpl(PkcsSigVerifyNullKey), cryptoEx),
        //    new ExceptionTestCase("Verify null oid", new ExceptionTestCaseImpl(PkcsSigVerifyNullOid), cryptoEx),
        //    new ExceptionTestCase("Verify null hash", new ExceptionTestCaseImpl(PkcsSigVerifyNullHash), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Verify null signature", new ExceptionTestCaseImpl(PkcsSigVerifyNullSig), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Format set null key", new ExceptionTestCaseImpl(PkcsSigFormatSetNullKey), ExceptionTestCase.NullExceptions),
        //    new ExceptionTestCase("Sign null oid", new ExceptionTestCaseImpl(PkcsSigSignNullOid), cryptoEx),
        //    new ExceptionTestCase("Sign null key", new ExceptionTestCaseImpl(PkcsSigSignNullKey), cryptoEx),
        //    new ExceptionTestCase("Sign null hash", new ExceptionTestCaseImpl(PkcsSigSignNullHash), ExceptionTestCase.NullExceptions)
        //});

            TestRunner runner = new TestRunner(new TestGroup[] { /*rsaExcept,*/ cspApi, cspExcept /*, oaepKeyApi, oaepKeyExcept, pkcsKeyApi, pkcsKeyExcept, pkcsSigApi, pkcsSigExcept*/ });

            // test should only run on XP+
            return runner.Run() ? MFTestResults.Pass : MFTestResults.Fail;
        }
Exemple #2
0
        public MFTestResults DSA_Test()
        {
            Exception[] cryptoEx = new Exception[] { new CryptographicException(), new CryptographicUnexpectedOperationException() };

            //TestGroup dsaExcept = new TestGroup("DSA Exception Tests", new TestCase[] {
            //    new ExceptionTestCase("FromXml null", new ExceptionTestCaseImpl(FromXmlNull), ExceptionTestCase.ArgumentExceptions),
            //    new ExceptionTestCase("FromXml no P", new ExceptionTestCaseImpl(FromXmlNoP), cryptoEx),
            //    new ExceptionTestCase("FromXml no Q", new ExceptionTestCaseImpl(FromXmlNoQ), cryptoEx),
            //    new ExceptionTestCase("FromXml no G", new ExceptionTestCaseImpl(FromXmlNoG), cryptoEx),
            //    new ExceptionTestCase("FromXml no Y", new ExceptionTestCaseImpl(FromXmlNoY), cryptoEx),
            //    new ExceptionTestCase("FromXml seed, no pgencounter", new ExceptionTestCaseImpl(FromXmlSeedNoPgenCounter), cryptoEx),
            //    new ExceptionTestCase("FromXml pgencounter, no seed", new ExceptionTestCaseImpl(FromXmlNoSeedPgenCounter), cryptoEx)
            //});

            TestGroup dsaCspApi = new TestGroup("DSA CSP API Tests", new TestCase[] {
                //new TestCase("Create with CspParameters", new TestCaseImpl(CSPParameters)),
                //new TestCase("Check KeyExchangeAlgorithm", new TestCaseImpl(CSPCheckKeyExchangeAlg)),
                //new TestCase("Check SignatureAlgorithm", new TestCaseImpl(CSPCheckSignatureAlg)),
                //new TestCase("Check MachineStore", new TestCaseImpl(CSPCheckMachineStore)),
			    new TestCase("Sign stream", new TestCaseImpl(CSPSignStream)),
			    new TestCase("Sign buffer", new TestCaseImpl(CSPSignBuffer)),
			    //new TestCase("IsPublic for incorrectly formatted key", new TestCaseImpl(CSPIsPublicBadKey)),

		    });

            TestGroup dsaCspExcept = new TestGroup("DSA CSP Exception Tests", new TestCase[] {
			    new ExceptionTestCase("Create with negative keysize", new ExceptionTestCaseImpl(CSPNegativeKeySize), ExceptionTestCase.ArgumentExceptions),
			    new ExceptionTestCase("Clear, then try to use", new ExceptionTestCaseImpl(CSPClearUse), new Exception[] { new ObjectDisposedException("a") }),
			    new ExceptionTestCase("Sign null hash", new ExceptionTestCaseImpl(CSPSignNullHash), ExceptionTestCase.ArgumentExceptions),
			    new ExceptionTestCase("Sign without private key", new ExceptionTestCaseImpl(CSPSignNoPrivate), cryptoEx),
			    new ExceptionTestCase("Sign with wrong hash count", new ExceptionTestCaseImpl(CSPSignBadHashCount), cryptoEx),
			    new ExceptionTestCase("Verify null hash", new ExceptionTestCaseImpl(CSPVerifyNullHash), ExceptionTestCase.NullExceptions),
			    new ExceptionTestCase("Verify null signature", new ExceptionTestCaseImpl(CSPVerifyNullSig), ExceptionTestCase.NullExceptions),
			    new ExceptionTestCase("Verify signature of bad hash", new ExceptionTestCaseImpl(CSPVerifyBadHash), cryptoEx),
			    //new ExceptionTestCase("Check to see if the null key is public", new ExceptionTestCaseImpl(IsPublicNull), ExceptionTestCase.NullExceptions)
		    });

            //TestGroup dsaFormatExcept = new TestGroup("DSA Signature Formatter Exception Tests", new TestCase[]
            //{
            //    new ExceptionTestCase("Set null key", new ExceptionTestCaseImpl(FormatterSetKeyNull), ExceptionTestCase.NullExceptions),
            //    new ExceptionTestCase("Set non SHA1 algorithm", new ExceptionTestCaseImpl(FormatterNonSHA1), cryptoEx),
            //    new ExceptionTestCase("Sign null key", new ExceptionTestCaseImpl(FormatterSignNullKey), cryptoEx),
            //    new ExceptionTestCase("Sign null data", new ExceptionTestCaseImpl(FormatterSignNullHash), ExceptionTestCase.NullExceptions)
            //});

            //TestGroup dsaDeformatExcept = new TestGroup("DSA Signature Deformatter Exception Tests", new TestCase[]
            //{
            //    new ExceptionTestCase("Set null key", new ExceptionTestCaseImpl(DeformatterSetKeyNull), ExceptionTestCase.NullExceptions),
            //    new ExceptionTestCase("Set non SHA1 algorithm", new ExceptionTestCaseImpl(DeformatterNonSHA1), cryptoEx),
            //    new ExceptionTestCase("Verify null key", new ExceptionTestCaseImpl(DeformatterVerifyNullKey), cryptoEx),
            //    new ExceptionTestCase("Verify null hash", new ExceptionTestCaseImpl(DeformatterVerifyNullHash), ExceptionTestCase.NullExceptions),
            //    new ExceptionTestCase("Verify null signature", new ExceptionTestCaseImpl(DeformatterVerifyNullSig), ExceptionTestCase.NullExceptions)
            //});

            TestRunner runner = new TestRunner(new TestGroup[] { /*dsaExcept,*/ dsaCspApi, dsaCspExcept /*, dsaFormatExcept, dsaDeformatExcept*/ });
            return runner.Run() ? MFTestResults.Pass : MFTestResults.Fail;
        }