Ejemplo n.º 1
0
        public void TestSendDecryptResponse()
        {
            String methodName             = "methodOne";
            String arg0                   = "arg0";
            String arg1                   = "arg1";
            TestWebServiceProxy testProxy = new TestWebServiceProxy();
            ITransportProxy     proxy     = testProxy;

            FolaighKeyStore keyStore          = new FolaighKeyStore(KEYSTORE, "bird8top".ToCharArray());
            RSACipher       encryptorVerifier = new RSACipher(
                keyStore,
                "countyKey",
                false);
            RSACipher signerDecryptor = new RSACipher(
                keyStore,
                "stateKey",
                true);

            SecureTransport transport = new SecureTransport(proxy, encryptorVerifier,
                                                            signerDecryptor);

            String response = transport.send(methodName, new String[] { arg0, arg1 });

            Assert.AreEqual(TestWebServiceProxy.THIS_IS_THE_RESPONSE, response);
        }
Ejemplo n.º 2
0
        public void TestSecureTransport()
        {
            String methodName                     = "methodOne";
            String arg0                           = "arg0";
            String arg1                           = "arg1";
            TestWebServiceProxy testProxy         = new TestWebServiceProxy();
            ITransportProxy     proxy             = testProxy;
            FolaighKeyStore     keyStore          = new FolaighKeyStore(KEYSTORE, "bird8top".ToCharArray());
            RSACipher           encryptorVerifier = new RSACipher(
                keyStore,
                "countyKey",
                false);
            RSACipher signerDecryptor = new RSACipher(
                keyStore,
                "stateKey",
                true);
            SecureTransport transport = new SecureTransport(
                proxy,
                encryptorVerifier,
                signerDecryptor);

            // Test for the proxy method
            String message     = "message";
            String signature   = "signature";
            String aesKey      = "key";
            String iv          = "iv";
            String senderAlias = "alias";
            String retval      = proxy.send(message, signature, aesKey, iv, senderAlias);

            String returnVal = transport.send(methodName, new String[] { arg0, arg1 });

            // First, just check to see if something got to the proxy.
            Assert.IsNotNull(returnVal);
            Assert.IsNotNull(testProxy.m_aesKey);
            Assert.IsNotNull(testProxy.m_iv);
            Assert.IsNotNull(testProxy.m_message);
            Assert.IsNotNull(testProxy.m_senderAlias);
            Assert.IsNotNull(testProxy.m_signature);

            Console.WriteLine("Encrypted AES Key:" + testProxy.m_aesKey);
            Console.WriteLine("Encrypted IV:" + testProxy.m_iv);
            Console.WriteLine("Encrypted Message:" + testProxy.m_message);
            Console.WriteLine("Sender Alias:" + testProxy.m_senderAlias);
            Console.WriteLine("Signature:" + testProxy.m_signature);

            // Decrypt the AES Key
            RSACipher testDecryptor = new RSACipher(
                keyStore,
                "countyKey",
                true);

            byte[] testKey = testDecryptor.decrypt(Convert.FromBase64String(testProxy.m_aesKey));
            byte[] testIV  = testDecryptor.decrypt(Convert.FromBase64String(testProxy.m_iv));

            Console.WriteLine("Decrypted Key:" + Convert.ToBase64String(testKey));
            Console.WriteLine("Decrypted IV:" + Convert.ToBase64String(testIV));

            AESCipher cipher = new AESCipher(testKey, testIV);

            // Independently encrypt the message and make sure they're the same
            MethodInfo mInfo = new MethodInfo(methodName, new String[] { arg0, arg1 });
            String     xml   = mInfo.encode();

            String testEncryptedMessage = Convert.ToBase64String(cipher.encrypt(xml));

            Assert.AreEqual(xml, cipher.decrypt(Convert.FromBase64String(testEncryptedMessage)));
            Assert.AreEqual(testEncryptedMessage, testProxy.m_message);

            string decryptedMessage = cipher.decrypt(Convert.FromBase64String(testProxy.m_message));
            string expectedMessage  = expectedMethodInfo.encode();

            Assert.AreEqual(expectedMessage, decryptedMessage);
        }