public VerifyMessageRequestObserverTests()
        {
            _signingContext = new SigningContext
            {
                NetworkType   = NetworkType.Devnet,
                SignatureType = SignatureType.ProtocolRpc
            };

            _testPeerId = PeerIdHelper.GetPeerId("TestPeerIdentifier");

            var peerSettings = _testPeerId.ToSubstitutedPeerSettings();

            _keySigner = Substitute.For <FakeKeySigner>();
            _keySigner.CryptoContext.Returns(new FfiWrapper());

            var logger = Substitute.For <ILogger>();

            _fakeContext = Substitute.For <IChannelHandlerContext>();

            var fakeChannel = Substitute.For <IChannel>();

            _fakeContext.Channel.Returns(fakeChannel);
            _verifyMessageRequestObserver = new VerifyMessageRequestObserver(peerSettings, logger, _keySigner);

            _verifyMessageRequest = GetValidVerifyMessageRequest();
        }
Пример #2
0
        public async Task <bool> VerifyMessage(string msg, string signature)
        {
            var request = new VerifyMessageRequest()
            {
                Msg = ByteString.CopyFromUtf8(msg), Signature = signature
            };
            var response = await lndClient.VerifyMessageAsync(request);

            return(response.Valid);
        }
Пример #3
0
        public void Invalid_Message_Signature_Can_Return_False_Response()
        {
            var requestMessage = new VerifyMessageRequest
            {
                Message        = _testMessageToSign,
                PublicKey      = ByteString.CopyFrom(new byte[_keySigner.CryptoContext.PublicKeyLength]),
                Signature      = ByteString.CopyFrom(new byte[_keySigner.CryptoContext.SignatureLength]),
                SigningContext = new SigningContext()
            };

            _verifyMessageRequestObserver
            .OnNext(new ObserverDto(_fakeContext,
                                    requestMessage.ToProtocolMessage(_peerId)));
            AssertVerifyResponse(false);
        }
Пример #4
0
        public void Valid_Message_Signature_Can_Return_True_Response()
        {
            var privateKey = _keySigner.KeyStore.KeyStoreDecrypt(KeyRegistryTypes.DefaultKey);

            var signingContext = new SigningContext
            {
                NetworkType   = NetworkType.Devnet,
                SignatureType = SignatureType.TransactionPublic
            };

            var requestMessage = new VerifyMessageRequest
            {
                Message        = _testMessageToSign,
                PublicKey      = privateKey.GetPublicKey().Bytes.ToByteString(),
                Signature      = _keySigner.CryptoContext.Sign(privateKey, _testMessageToSign.ToByteArray(), signingContext.ToByteArray()).SignatureBytes.ToByteString(),
                SigningContext = signingContext
            };

            _verifyMessageRequestObserver
            .OnNext(new ObserverDto(_fakeContext,
                                    requestMessage.ToProtocolMessage(_peerId)));
            AssertVerifyResponse(true);
        }
        public JsonResult VerifyMessage([FromBody] VerifyMessageRequest request)
        {
            var result = _cryptoHelper.VerifyMessage(request.message, request.signature, request.publicKey);

            return(Json(new { message = result }));
        }