Exemple #1
0
        // Session to introducer
        internal SSUSession(SSUHost owner, IPEndPoint remoteep, IntroducerInfo ii, IMTUProvider mtup, RouterContext rc)
        {
            Host            = owner;
            RemoteEP        = remoteep;
            MTUProvider     = mtup;
            MyRouterContext = rc;

            RemoteAddr = new I2PRouterAddress(ii.Host, ii.Port, 0, "SSU");

            // TODO: This is what PurpleI2P does. Seems strange... But there is no RouterInfo available for introducer sessions.
            RemoteRouter = MyRouterContext.MyRouterIdentity;

            TransportInstance = Interlocked.Increment(ref NTCPClient.TransportInstanceCounter);

#if LOG_ALL_TRANSPORT
            DebugUtils.LogDebug("SSUSession: " + DebugId + " Introducer instance created.");
#endif

            Fragmenter = new DataFragmenter();

            if (RemoteAddr == null)
            {
                throw new NullReferenceException("SSUSession needs an address");
            }

            IntroKey = ii.IntroKey;

            MTU = MTUProvider.GetMTU(remoteep);
        }
Exemple #2
0
        internal static void Receive(DHHandshakeContext context, I2PKeysAndCert ri)
        {
            var responselength = ri.Certificate.SignatureLength;

            responselength += BufUtils.Get16BytePadding(responselength);

            var data = context.Client.BlockReceive(responselength);

            context.Dectryptor.ProcessBytes(data);

            var signature = new I2PSignature(new BufRefLen(data), context.RemoteRI.Certificate);

            if (!I2PSignature.SupportedSignatureType(context.RemoteRI.Certificate.SignatureType))
            {
                throw new SignatureCheckFailureException("NTCP SessionConfirmB recv not supported signature type: " +
                                                         context.RemoteRI.Certificate.SignatureType.ToString());
            }

            var ok = I2PSignature.DoVerify(context.RemoteRI.SigningPublicKey, signature,
                                           context.X.Key,
                                           context.Y.Key,
                                           RouterContext.Inst.MyRouterIdentity.IdentHash.Hash,
                                           BufUtils.Flip32BL(context.TimestampA),
                                           BufUtils.Flip32BL(context.TimestampB));

#if LOG_ALL_TRANSPORT
            DebugUtils.Log("SessionConfirmB: " + context.RemoteRI.Certificate.SignatureType.ToString() + " signature check: " + ok.ToString());
#endif
            if (!ok)
            {
                throw new SignatureCheckFailureException("NTCP SessionConfirmB recv sig check failure");
            }
        }
Exemple #3
0
        // We are client
        public SSUSession(SSUHost owner, IPEndPoint remoteep, I2PRouterAddress remoteaddr, I2PKeysAndCert rri, IMTUProvider mtup, RouterContext rc)
        {
            Host              = owner;
            RemoteEP          = remoteep;
            RemoteAddr        = remoteaddr;
            RemoteRouter      = rri;
            MTUProvider       = mtup;
            MyRouterContext   = rc;
            TransportInstance = Interlocked.Increment(ref NTCPClient.TransportInstanceCounter);

#if LOG_ALL_TRANSPORT
            DebugUtils.LogDebug("SSUSession: " + DebugId + " Client instance created.");
#endif

            Fragmenter = new DataFragmenter();

            if (RemoteAddr == null)
            {
                throw new NullReferenceException("SSUSession needs an address");
            }

            IntroKey = new BufLen(FreenetBase64.Decode(RemoteAddr.Options["key"]));

            MTU = MTUProvider.GetMTU(remoteep);
        }
Exemple #4
0
        private PeerTestState(SSUHost host, I2PRouterAddress addr, I2PKeysAndCert dest)
        {
            Host = host;
            Addr = addr;
            Dest = dest;

            Session = (SSUSession)Host.AddSession(addr, dest);
            //Session.StartPeerTest( this );
        }
Exemple #5
0
        public NTCPClientOutgoing(I2PRouterAddress addr, I2PKeysAndCert dest)
            : base()
        {
            Address = addr;
            NTCPContext.RemoteRouterIdentity = dest;

            RemoteDescription = Address.Options["host"];
            OutgoingAddress   = addr.Host;
            OutgoingPort      = int.Parse(Address.Options["port"]);
        }
Exemple #6
0
 public DestinationSession this[I2PKeysAndCert dest]
 {
     get
     {
         lock ( Sessions )
         {
             DestinationSession result;
             if (!Sessions.TryGetValue(dest.IdentHash, out result))
             {
                 result = new DestinationSession(dest, OutTunnelSelector, InTunnelSelector);
                 Sessions[dest.IdentHash] = result;
             }
             return(result);
         }
     }
 }
Exemple #7
0
        public ITransport AddSession(I2PRouterAddress addr, I2PKeysAndCert dest)
        {
            IPEndPoint remoteep = null;
            IPEndPoint key      = null;

            if (addr.HaveHostAndPort)
            {
                remoteep = new IPEndPoint(addr.Host, addr.Port);

                if (!AllowConnectToSelf && IsOurIP(remoteep.Address))
                {
                    Logging.LogTransport($"SSU AddSession: [{dest.IdentHash.Id32}]:{key} - {addr}. Dropped. Not connecting to ourselves.");
                    return(null);
                }

                key = remoteep;

                Logging.LogDebugData($"SSU AddSession: [{dest.IdentHash.Id32}]:{key} - {addr}");

                lock ( Sessions )
                {
                    if (Sessions.ContainsKey(key))
                    {
                        var sess = Sessions[key];
                        return(sess);
                    }
                }
            }

            var newsess = new SSUSession(
                this,
                Send,
                remoteep,
                addr,
                dest,
                MTUProvider,
                MyRouterContext);

            if (key != null)
            {
                lock ( Sessions )
                {
                    Sessions[key] = newsess;
                }
            }
            return(newsess);
        }
Exemple #8
0
        public ITransport AddSession(I2PRouterAddress addr, I2PKeysAndCert dest)
        {
            IPEndPoint remoteep = null;
            IPEndPoint key      = null;

            if (addr.HaveHostAndPort)
            {
                remoteep = new IPEndPoint(addr.Host, addr.Port);

                if (!AllowConnectToSelf && IsOurIP(remoteep.Address))
                {
                    Logging.LogTransport(string.Format("SSU AddSession: [{0}]:{1} - {2}. Dropped. Not connecting to ourselves.", dest.IdentHash.Id32, key, addr));
                    return(null);
                }

                key = remoteep;

#if LOG_ALL_TRANSPORT
                Logging.LogTransport(string.Format("SSU AddSession: [{0}]:{1} - {2}", dest.IdentHash.Id32, key, addr));
#endif

                lock ( Sessions )
                {
                    if (Sessions.ContainsKey(key))
                    {
                        var sess = Sessions[key];
                        return(sess);
                    }
                }
            }

            var newsess = new SSUSession(this, remoteep, addr, dest, MTUProvider, MyRouterContext);
            if (key != null)
            {
                lock ( Sessions )
                {
                    Sessions[key] = newsess;
                }
            }
            return(newsess);
        }
Exemple #9
0
 public HopInfo(I2PKeysAndCert dest, I2PTunnelId id)
 {
     Peer     = dest;
     TunnelId = id;
 }
Exemple #10
0
 public DestinationSession(I2PKeysAndCert dest, OutboundTunnelSelector tunnelsel, InboundTunnelSelector intunnelsel)
 {
     TagsValiditySlidingWindow = new TagsTransferWindow(this, tunnelsel);
     Destination      = dest;
     SelInboundTunnel = intunnelsel;
 }
Exemple #11
0
        /*
         * public GarlicCreationInfo GenerateGarlicMessage( I2PKeysAndCert dest, Garlic msg )
         * {
         *  DestinationSession session;
         *
         *  lock ( Sessions )
         *  {
         *      if ( !Sessions.TryGetValue( dest, out session ) )
         *      {
         *          session = new DestinationSession( dest, OutTunnelSelector, InTunnelSelector );
         *          Sessions[dest] = session;
         *      }
         *  }
         *
         *  return session.Encrypt( msg, I2NPHeader.GenerateMessageId() );
         * }
         *
         * public GarlicCreationInfo CreateMessage( I2PKeysAndCert dest, params GarlicCloveDelivery[] messages )
         * {
         *  return GenerateGarlicMessage( dest, Garlic.Create( messages ) );
         * }
         *
         * public GarlicCreationInfo CreateMessage( I2PKeysAndCert dest, I2PDate expiration, params GarlicCloveDelivery[] messages )
         * {
         *  return GenerateGarlicMessage( dest, Garlic.Create( expiration, messages ) );
         * }
         */

        internal GarlicCreationInfo Send(I2PKeysAndCert dest, bool explack, params GarlicCloveDelivery[] messages)
        {
            DestinationSession session = this[dest];

            return(session.Send(explack, messages));
        }