Example #1
0
        /// <summary>
        /// Decrypt and parses a JSON-encoded HandshakeToken. Also verifies that the
        /// token was encrypted by the ID that issued the token.
        /// </summary>
        /// <param name="encryptedHandshakeToken">The JSON-encoded SYNACK</param>
        /// <returns>The HandshakeToken object</returns>
        protected async Task <T> DecryptAndInstantiateHandshakeToken <T>(string encryptedHandshakeToken, ID id = null) where T : HandshakeToken, new()
        {
            string decryptedToken = _tokenCryptoService.Decrypt(encryptedHandshakeToken, _accountService.GetPrivateKeyAsByteArray());
            HandshakeTokenFactory <T> handshakeTokenFactory = new HandshakeTokenFactory <T>(_idFacade, id);
            T handshakeToken = await handshakeTokenFactory.CreateHandshakeTokenAsync(decryptedToken);

            return(handshakeToken);
        }
Example #2
0
        public void Setup()
        {
            _account  = new AccountService("9e6a6bf412ce4e3a91a33c7c0f6d94b3127b8d4f5ed336210a672fe595bf1769");
            _idFacade = new DummyIDFacade(_account);

            SetupIDsAsync().Wait();

            _token = new Syn()
            {
                Encrypted      = false,
                PublicKey      = _account.PublicKey,
                NetworkAddress = "a8aa460b582f9dd543835d2388dd7b0b15fa0ddfbc5d386cf187df6720e3d95656789abcd56789abcd56789abcd",
                Id             = _id
            };

            _token.SignAndLock("sig");
            _restoredSyn    = null;
            _hsTokenFactory = new HandshakeTokenFactory <Syn>(_idFacade);
        }
Example #3
0
        public async Task ProcessSyn(string synString)
        {
            HandshakeTokenFactory <Syn> synFactory = new HandshakeTokenFactory <Syn>(_idFacade);
            Syn syn = await synFactory.CreateHandshakeTokenAsync(synString);

            byte[] pubK = Nethereum.Hex.HexConvertors.Extensions.HexByteConvertorExtensions.HexToByteArray(syn.PublicKey);

            VerifyHandshakeTokenIDOwnership(syn);

            if (_tokenCryptoService.VerifySignature(syn))
            {
                _syn = syn;
                Acknowledge(_syn);
            }
            else
            {
                throw new SignatureDoesntMatchException("The signature was not " +
                                                        "generated by the given " +
                                                        "public Key");
            }
        }