Esempio n. 1
0
        public Packet Auth(PublicKey remoteNodeId, EncryptionHandshake handshake)
        {
            handshake.RemoteNodeId        = remoteNodeId;
            handshake.InitiatorNonce      = _cryptoRandom.GenerateRandomBytes(32);
            handshake.EphemeralPrivateKey = _ephemeralGenerator.Generate();

            byte[] staticSharedSecret = Proxy.EcdhSerialized(remoteNodeId.Bytes, _privateKey.KeyBytes);
            byte[] forSigning         = staticSharedSecret.Xor(handshake.InitiatorNonce);

            AuthEip8Message authMessage = new AuthEip8Message();

            authMessage.Nonce     = handshake.InitiatorNonce;
            authMessage.PublicKey = _privateKey.PublicKey;
            authMessage.Signature = _ecdsa.Sign(handshake.EphemeralPrivateKey, new Keccak(forSigning));

            byte[] authData = _messageSerializationService.Serialize(authMessage);
            int    size     = authData.Length + 32 + 16 + 65; // data + MAC + IV + pub

            byte[] sizeBytes  = size.ToBigEndianByteArray().Slice(2, 2);
            byte[] packetData = _eciesCipher.Encrypt(
                remoteNodeId,
                authData,
                sizeBytes);

            handshake.AuthPacket = new Packet(Bytes.Concat(sizeBytes, packetData));
            return(handshake.AuthPacket);
        }
Esempio n. 2
0
 protected DiscoveryMsgSerializerBase(IEcdsa ecdsa,
                                      IPrivateKeyGenerator nodeKey,
                                      INodeIdResolver nodeIdResolver)
 {
     _ecdsa          = ecdsa ?? throw new ArgumentNullException(nameof(ecdsa));
     _privateKey     = nodeKey.Generate();
     _nodeIdResolver = nodeIdResolver ?? throw new ArgumentNullException(nameof(nodeIdResolver));
 }
Esempio n. 3
0
 protected DiscoveryMessageSerializerBase(
     IEcdsa ecdsa,
     IPrivateKeyGenerator privateKeyGenerator,
     IDiscoveryMessageFactory messageFactory,
     INodeIdResolver nodeIdResolver)
 {
     _ecdsa          = ecdsa ?? throw new ArgumentNullException(nameof(ecdsa));
     _privateKey     = privateKeyGenerator.Generate();
     _messageFactory = messageFactory ?? throw new ArgumentNullException(nameof(messageFactory));
     _nodeIdResolver = nodeIdResolver ?? throw new ArgumentNullException(nameof(nodeIdResolver));
 }
Esempio n. 4
0
 protected DiscoveryMessageSerializerBase(
     ISigner signer,
     IPrivateKeyGenerator privateKeyGenerator,
     IDiscoveryMessageFactory messageFactory,
     INodeIdResolver nodeIdResolver)
 {
     _signer        = signer ?? throw new ArgumentNullException(nameof(signer));
     _privateKey    = privateKeyGenerator.Generate() ?? throw new ArgumentNullException(nameof(_privateKey));
     MessageFactory = messageFactory ?? throw new ArgumentNullException(nameof(messageFactory));
     NodeIdResolver = nodeIdResolver ?? throw new ArgumentNullException(nameof(nodeIdResolver));
 }
        public async Task <ActionResult> Transfer()
        {
            using (var ms = new MemoryStream())
            {
                await Request.Body.CopyToAsync(ms);

                var authRequest  = ms.ToArray();
                var authResponse = await _privateKeyGenerator.Generate(authRequest);

                var res = new FileContentResult(authResponse, "application/octet-stream");
                return(res);
            }
        }
 public EnrResponseMsgSerializer(IEcdsa ecdsa, IPrivateKeyGenerator nodeKey, INodeIdResolver nodeIdResolver)
     : base(ecdsa, nodeKey, nodeIdResolver)
 {
     _nodeRecordSigner = new NodeRecordSigner(ecdsa, nodeKey.Generate());
 }