Ticket #20348: 0001-num_frame-cypherpunk-kludge.patch

File 0001-num_frame-cypherpunk-kludge.patch, 3.4 KB (added by dcf, 2 years ago)

Implementation of idea from comment:61.

  • transports/obfs4/obfs4.go

    From b21d91d0b0307f88b61f4f0df63f1ac2e7aab60d Mon Sep 17 00:00:00 2001
    From: David Fifield <david@bamsoftware.com>
    Date: Sat, 26 Nov 2016 19:13:47 -0800
    Subject: [PATCH] num_frame cypherpunk kludge.
    
    https://bugs.torproject.org/20348#comment:61
    ---
     transports/obfs4/obfs4.go | 38 ++++++++++++++++++++++----------------
     1 file changed, 22 insertions(+), 16 deletions(-)
    
    diff --git a/transports/obfs4/obfs4.go b/transports/obfs4/obfs4.go
    index 304097e..380ae93 100644
    a b func (t *Transport) ServerFactory(stateDir string, args *pt.Args) (base.ServerFa 
    111111        }
    112112
    113113        var iatSeed *drbg.Seed
    114         if st.iatMode != iatNone {
    115                 iatSeedSrc := sha256.Sum256(st.drbgSeed.Bytes()[:])
    116                 var err error
    117                 iatSeed, err = drbg.SeedFromBytes(iatSeedSrc[:])
    118                 if err != nil {
    119                         return nil, err
    120                 }
     114        iatSeedSrc := sha256.Sum256(st.drbgSeed.Bytes()[:])
     115        iatSeed, err = drbg.SeedFromBytes(iatSeedSrc[:])
     116        if err != nil {
     117                return nil, err
    121118        }
    122119
    123120        // Store the arguments that should appear in our descriptor for the clients.
    func (sf *obfs4ServerFactory) WrapConn(conn net.Conn) (net.Conn, error) { 
    265262                iatDist = probdist.New(sf.iatSeed, 0, maxIATDelay, biasedDist)
    266263        }
    267264
    268         c := &obfs4Conn{conn, true, lenDist, iatDist, sf.iatMode, bytes.NewBuffer(nil), bytes.NewBuffer(nil), make([]byte, consumeReadSize), nil, nil}
     265        c := &obfs4Conn{conn, true, lenDist, iatDist, sf.iatMode, 0, bytes.NewBuffer(nil), bytes.NewBuffer(nil), make([]byte, consumeReadSize), nil, nil}
    269266
    270267        startTime := time.Now()
    271268
    type obfs4Conn struct { 
    286283        iatDist *probdist.WeightedDist
    287284        iatMode int
    288285
     286        // https://bugs.torproject.org/20348#comment:61
     287        num_frame uint64
     288
    289289        receiveBuffer        *bytes.Buffer
    290290        receiveDecodedBuffer *bytes.Buffer
    291291        readBuffer           []byte
    func newObfs4ClientConn(conn net.Conn, args *obfs4ClientArgs) (c *obfs4Conn, err 
    302302        }
    303303        lenDist := probdist.New(seed, 0, framing.MaximumSegmentLength, biasedDist)
    304304        var iatDist *probdist.WeightedDist
    305         if args.iatMode != iatNone {
    306                 var iatSeed *drbg.Seed
    307                 iatSeedSrc := sha256.Sum256(seed.Bytes()[:])
    308                 if iatSeed, err = drbg.SeedFromBytes(iatSeedSrc[:]); err != nil {
    309                         return
    310                 }
    311                 iatDist = probdist.New(iatSeed, 0, maxIATDelay, biasedDist)
     305
     306        var iatSeed *drbg.Seed
     307        iatSeedSrc := sha256.Sum256(seed.Bytes()[:])
     308        if iatSeed, err = drbg.SeedFromBytes(iatSeedSrc[:]); err != nil {
     309                return
    312310        }
     311        iatDist = probdist.New(iatSeed, 0, maxIATDelay, biasedDist)
    313312
    314313        // Allocate the client structure.
    315         c = &obfs4Conn{conn, false, lenDist, iatDist, args.iatMode, bytes.NewBuffer(nil), bytes.NewBuffer(nil), make([]byte, consumeReadSize), nil, nil}
     314        c = &obfs4Conn{conn, false, lenDist, iatDist, args.iatMode, 0, bytes.NewBuffer(nil), bytes.NewBuffer(nil), make([]byte, consumeReadSize), nil, nil}
    316315
    317316        // Start the handshake timeout.
    318317        deadline := time.Now().Add(clientHandshakeTimeout)
    func (conn *obfs4Conn) Write(b []byte) (n int, err error) { 
    483482        var payload [maxPacketPayloadLength]byte
    484483        var frameBuf bytes.Buffer
    485484
     485        // https://bugs.torproject.org/20348#comment:61
     486        if conn.isServer && conn.num_frame < 7 {
     487                iatDelay := time.Duration(10) + time.Duration(conn.iatDist.Sample())
     488                time.Sleep(iatDelay * time.Millisecond)
     489                conn.num_frame++
     490        }
     491
    486492        // Chop the pending data into payload frames.
    487493        for chopBuf.Len() > 0 {
    488494                // Send maximum sized frames.