Пример #1
0
        public void TestReceiveResponse()
        {
            TestWebServiceProxy testProxy = new TestWebServiceProxy();
            ITransportProxy     proxy     = testProxy;

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

            String sender = "stateKey";
            string result = transport.receive(encryptedMessage, signature,
                                              encryptedAesKey, encryptedIV, sender);

            // The result should be an XML document with an encrypted AES key
            // and
            // IV,
            // an AES-encrypted response string, and a signed hash of the
            // encrypted
            // response string.
            ResponseInfo objResponseInfo = ResponseInfo.decode(result);

            encryptorVerifier = new RSACipher(
                keyStore,
                "countyKey",
                false);
            signerDecryptor = new RSACipher(
                keyStore,
                "stateKey",
                true);

            byte[] sig  = Convert.FromBase64String(objResponseInfo.Signature);
            byte[] hash = encryptorVerifier.decrypt(sig);
            byte[] encryptedResponse = Convert.FromBase64String(objResponseInfo.Response);
            byte[] expectedHash      = Hash.getHash(encryptedResponse);

            Assert.AreEqual(hash, expectedHash);

            byte[]    key    = signerDecryptor.decrypt(Convert.FromBase64String(objResponseInfo.Key));
            byte[]    iv     = signerDecryptor.decrypt(Convert.FromBase64String(objResponseInfo.IV));
            AESCipher cipher = new AESCipher(key, iv);

            Assert.AreEqual(TestWebServiceProxy.THIS_IS_THE_RESPONSE, cipher
                            .decrypt(encryptedResponse));
        }
Пример #2
0
        public void TestReceiveCall()
        {
            TestWebServiceProxy testProxy = new TestWebServiceProxy();
            ITransportProxy     proxy     = testProxy;

            // This establishes the signature of the proxy's "receive"
            // method. We need to know if the signature was verified
            // and whether it came from an authorized sender.
            MethodInfo methodInfo     = new MethodInfo();
            bool       validSignature = true;
            String     sender         = "sender";
            String     reply          = proxy.receive(validSignature, methodInfo, sender);

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

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

            testProxy.m_validSignature = false;
            testProxy.m_message        = null;
            sender = "stateKey";
            String result = transport.receive(encryptedMessage, signature,
                                              encryptedAesKey, encryptedIV, sender);

            Assert.IsTrue(testProxy.m_validSignature);
            Assert.IsNotNull(testProxy.m_methodInfo);
            Assert.AreEqual(expectedMethodInfo.MethodName, testProxy.m_methodInfo.MethodName);
            Assert.AreEqual(sender, testProxy.m_senderAlias);
        }