X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fgovpn%2Fhandshake.go;h=cce621b48508fedd42cada1c957f901ae6e87591;hb=70e70dfded87dc2d737160444829c58ed8ed2fa0;hp=47fe4e9056f1131d8e2b3e7b361cee0d24c585c6;hpb=b779397ef0dba12ed2fb117e1a514bf0d5b598ef;p=govpn.git diff --git a/src/cypherpunks.ru/govpn/handshake.go b/src/cypherpunks.ru/govpn/handshake.go index 47fe4e9..cce621b 100644 --- a/src/cypherpunks.ru/govpn/handshake.go +++ b/src/cypherpunks.ru/govpn/handshake.go @@ -1,6 +1,6 @@ /* GoVPN -- simple secure free software virtual private network daemon -Copyright (C) 2014-2017 Sergey Matveev +Copyright (C) 2014-2018 Sergey Matveev 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 @@ -132,7 +132,7 @@ func NewHandshake(addr string, conn io.Writer, conf *PeerConf) *Handshake { } // Generate ID tag from client identification and data. -func idTag(id *PeerId, timeSync int, data []byte) []byte { +func idTag(id *PeerID, timeSync int, data []byte) []byte { enc := make([]byte, 8) copy(enc, data) AddTimeSync(timeSync, enc) @@ -141,8 +141,8 @@ func idTag(id *PeerId, timeSync int, data []byte) []byte { panic(err) } mac.Write(enc) - mac.Sum(enc[:0]) - return enc + sum := mac.Sum(nil) + return sum[len(sum)-8:] } // Start handshake's procedure from the client. It is the entry point @@ -174,7 +174,7 @@ func HandshakeStart(addr string, conn io.Writer, conf *PeerConf) *Handshake { chacha20.XORKeyStream(enc, enc, state.rNonce, state.dsaPubH) } data := append(state.rNonce[8:], enc...) - data = append(data, idTag(state.Conf.Id, state.Conf.TimeSync, state.rNonce[8:])...) + data = append(data, idTag(state.Conf.ID, state.Conf.TimeSync, state.rNonce[8:])...) state.conn.Write(data) return state } @@ -260,7 +260,7 @@ func (h *Handshake) Server(data []byte) *Peer { // Send that to client h.conn.Write(append(encPub, append( - encRs, idTag(h.Conf.Id, h.Conf.TimeSync, encPub)..., + encRs, idTag(h.Conf.ID, h.Conf.TimeSync, encPub)..., )...)) h.LastPing = time.Now() } else @@ -316,7 +316,7 @@ func (h *Handshake) Server(data []byte) *Peer { } else { chacha20.XORKeyStream(enc, enc, h.rNonceNext(2), h.key) } - h.conn.Write(append(enc, idTag(h.Conf.Id, h.Conf.TimeSync, enc)...)) + h.conn.Write(append(enc, idTag(h.Conf.ID, h.Conf.TimeSync, enc)...)) // Switch peer peer := newPeer( @@ -416,7 +416,7 @@ func (h *Handshake) Client(data []byte) *Peer { } // Send that to server - h.conn.Write(append(enc, idTag(h.Conf.Id, h.Conf.TimeSync, enc)...)) + h.conn.Write(append(enc, idTag(h.Conf.ID, h.Conf.TimeSync, enc)...)) h.LastPing = time.Now() } else // ENC(K, R+2, RC) + IDtag