Class EstablishBase

  • All Implemented Interfaces:
    EstablishState
    Direct Known Subclasses:
    InboundEstablishState, OutboundEstablishState

    abstract class EstablishBase
    extends Object
    implements EstablishState
    Inbound NTCP 1 or 2. Outbound NTCP 1 only. OutboundNTCP2State does not extend this. NTCP 1 establishement overview: Handle the 4-phase establishment, which is as follows:
    
     Alice                   contacts                      Bob
     =========================================================
    
     Message 1 (Session Request):
      X+(H(X) xor Bob.identHash)----------------------------->
    
     Message 2 (Session Created):
      <----------------------------------------Y+E(H(X+Y)+tsB, sk, Y[239:255])
    
     Message 3 (Session Confirm A):
      E(sz+Alice.identity+tsA+padding+S(X+Y+Bob.identHash+tsA+tsB), sk, hX_xor_Bob.identHash[16:31])--->
    
     Message 4 (Session Confirm B):
      <----------------------E(S(X+Y+Alice.identHash+tsA+tsB)+padding, sk, prev)
    
      Key:
    
        X, Y: 256 byte DH keys
        H(): 32 byte SHA256 Hash
        E(data, session key, IV): AES256 Encrypt
        S(): 40 byte DSA Signature, or length as implied by sig type
        tsA, tsB: timestamps (4 bytes, seconds since epoch)
        sk: 32 byte Session key
        sz: 2 byte size of Alice identity to follow
    
     
    Alternately, when Bob receives a connection, it could be a check connection (perhaps prompted by Bob asking for someone to verify his listener). check connections are formatted per isCheckInfo() NOTE: Check info is unused.
    Since:
    0.9.35 pulled out of EstablishState
    • Field Detail

      • VERIFIED

        public static final net.i2p.router.transport.ntcp.EstablishBase.VerifiedEstablishState VERIFIED
      • FAILED

        public static final net.i2p.router.transport.ntcp.EstablishBase.FailedEstablishState FAILED
      • _log

        protected final Log _log
      • _X

        protected final byte[] _X
      • _hX_xor_bobIdentHash

        protected final byte[] _hX_xor_bobIdentHash
      • _Y

        protected final byte[] _Y
      • _e_hXY_tsB

        protected final byte[] _e_hXY_tsB
      • _tsB

        protected transient long _tsB
        Bob's timestamp in seconds, this is in message #2, *before* _tsA
      • _tsA

        protected transient long _tsA
        Alice's timestamp in seconds, this is in message #3, *after* _tsB Only saved for outbound. For inbound, see verifyInbound().
      • _peerSkew

        protected transient long _peerSkew
        OUR clock minus HIS clock, in seconds Inbound: tsB - tsA - rtt/2 Outbound: tsA - tsB - rtt/2
      • _e_bobSig

        protected transient byte[] _e_bobSig
      • _prevEncrypted

        protected byte[] _prevEncrypted
        previously received encrypted block (or the IV)
      • _curDecrypted

        protected final byte[] _curDecrypted
        decryption buffer
      • _received

        protected int _received
        bytes received so far
      • _stateLock

        protected final Object _stateLock
    • Method Detail

      • receive

        public void receive​(ByteBuffer src)
        Parse the contents of the buffer as part of the handshake. All data must be copied out of the buffer as Reader.processRead() will return it to the pool. If there are additional data in the buffer after the handshake is complete, the EstablishState is responsible for passing it to NTCPConnection.
        Specified by:
        receive in interface EstablishState
      • prepareOutbound

        public void prepareOutbound()
        Does nothing. Outbound (Alice) must override. We are establishing an outbound connection, so prepare ourselves by queueing up the write of the first part of the handshake
        Specified by:
        prepareOutbound in interface EstablishState
      • isCorrupt

        public boolean isCorrupt()
        did the handshake fail for some reason?
        Specified by:
        isCorrupt in interface EstablishState
      • isComplete

        public boolean isComplete()
        If synchronized on this, fails with deadlocks from all over via CSFI.isEstablished(). Also CSFI.getFramedAveragePeerClockSkew().
        Specified by:
        isComplete in interface EstablishState
        Returns:
        is the handshake complete and valid?
      • getVersion

        public abstract int getVersion()
        Get the NTCP version
        Specified by:
        getVersion in interface EstablishState
        Returns:
        1, 2, or 0 if unknown
        Since:
        0.9.35
      • close

        public void close​(String reason,
                          Exception e)
        Release resources on timeout.
        Specified by:
        close in interface EstablishState
        Parameters:
        e - may be null
        Since:
        0.9.16
      • fail

        protected void fail​(String reason)
        Caller must synch.
      • fail

        protected void fail​(String reason,
                            Exception e)
        Caller must synch.
      • fail

        protected void fail​(String reason,
                            Exception e,
                            boolean bySkew)
        Caller must synch.
      • releaseBufs

        protected void releaseBufs​(boolean isVerified)
        Only call once. Caller must synch.
        Since:
        0.9.16
      • xor32

        protected static void xor32​(byte[] a,
                                    byte[] b)
        XOR a into b. Modifies b. a is unmodified.
        Parameters:
        a - 32 bytes
        b - 32 bytes
        Since:
        0.9.12
      • prefix

        protected String prefix()
      • _x

        protected static final String _x​(String s)
        Mark a string for extraction by xgettext and translation. Use this only in static initializers. It does not translate!
        Returns:
        s