]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/govpn/cmd/govpn-client/tcp.go
Initial encryptionless mode support
[govpn.git] / src / govpn / cmd / govpn-client / tcp.go
index 6265eeb6087e8f8b80dedf4f2450ede422ea5726..7f3c172105ce0bf709ff15cbee4e549c55a4bca0 100644 (file)
@@ -1,6 +1,6 @@
 /*
 GoVPN -- simple secure free software virtual private network daemon
-Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -20,7 +20,6 @@ package main
 
 import (
        "bytes"
-       "encoding/binary"
        "log"
        "net"
        "sync/atomic"
@@ -44,7 +43,7 @@ func startTCP(timeouted, rehandshaking, termination chan struct{}) {
 
 func handleTCP(conn *net.TCPConn, timeouted, rehandshaking, termination chan struct{}) {
        hs := govpn.HandshakeStart(*remoteAddr, conn, conf)
-       buf := make([]byte, govpn.MTU)
+       buf := make([]byte, 2*(govpn.EncLessEnlargeSize+govpn.MTU)+govpn.MTU)
        var n int
        var err error
        var prev int
@@ -57,7 +56,7 @@ HandshakeCycle:
                        break HandshakeCycle
                default:
                }
-               if prev == govpn.MTU {
+               if prev == len(buf) {
                        log.Println("Timeouted waiting for the packet")
                        timeouted <- struct{}{}
                        break HandshakeCycle
@@ -116,8 +115,7 @@ HandshakeCycle:
        }
 
        nonceExpectation := make([]byte, govpn.NonceSize)
-       binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
-       peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+       peer.NonceExpectation(nonceExpectation)
        prev = 0
        var i int
 TransportCycle:
@@ -127,7 +125,7 @@ TransportCycle:
                        break TransportCycle
                default:
                }
-               if prev == govpn.MTU {
+               if prev == len(buf) {
                        log.Println("Timeouted waiting for the packet")
                        timeouted <- struct{}{}
                        break TransportCycle
@@ -158,8 +156,7 @@ TransportCycle:
                        rehandshaking <- struct{}{}
                        break TransportCycle
                }
-               binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
-               peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+               peer.NonceExpectation(nonceExpectation)
                copy(buf, buf[i+govpn.NonceSize:prev])
                prev = prev - i - govpn.NonceSize
                goto CheckMore