feat: awg 2.0 (#91)

* feat: ranged H1-H4
* feat: S3, S4 support
* chore: updated awg-tools version

---------

Co-authored-by: Yaroslav Gurov <ygurov@proton.me>
This commit is contained in:
Mark Puha 2025-09-01 14:04:52 +02:00 committed by GitHub
parent 1abd24b5b9
commit f6542209f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 1352 additions and 603 deletions

View file

@ -205,12 +205,22 @@ func (device *Device) CreateMessageInitiation(peer *Peer) (*MessageInitiation, e
handshake.mixHash(handshake.remoteStatic[:])
device.awg.ASecMux.RLock()
msgType := DefaultMessageInitiationType
if device.isAWG() {
device.awg.Mux.RLock()
msgType, err = device.awg.GetMsgType(DefaultMessageInitiationType)
if err != nil {
device.awg.Mux.RUnlock()
return nil, fmt.Errorf("get message type: %w", err)
}
device.awg.Mux.RUnlock()
}
msg := MessageInitiation{
Type: MessageInitiationType,
Type: msgType,
Ephemeral: handshake.localEphemeral.publicKey(),
}
device.awg.ASecMux.RUnlock()
handshake.mixKey(msg.Ephemeral[:])
handshake.mixHash(msg.Ephemeral[:])
@ -264,12 +274,13 @@ func (device *Device) ConsumeMessageInitiation(msg *MessageInitiation) *Peer {
chainKey [blake2s.Size]byte
)
device.awg.ASecMux.RLock()
device.awg.Mux.RLock()
if msg.Type != MessageInitiationType {
device.awg.ASecMux.RUnlock()
device.awg.Mux.RUnlock()
return nil
}
device.awg.ASecMux.RUnlock()
device.awg.Mux.RUnlock()
device.staticIdentity.RLock()
defer device.staticIdentity.RUnlock()
@ -384,9 +395,19 @@ func (device *Device) CreateMessageResponse(peer *Peer) (*MessageResponse, error
}
var msg MessageResponse
device.awg.ASecMux.RLock()
msg.Type = MessageResponseType
device.awg.ASecMux.RUnlock()
if device.isAWG() {
device.awg.Mux.RLock()
msg.Type, err = device.awg.GetMsgType(DefaultMessageResponseType)
if err != nil {
device.awg.Mux.RUnlock()
return nil, fmt.Errorf("get message type: %w", err)
}
device.awg.Mux.RUnlock()
} else {
msg.Type = DefaultMessageResponseType
}
msg.Sender = handshake.localIndex
msg.Receiver = handshake.remoteIndex
@ -436,12 +457,13 @@ func (device *Device) CreateMessageResponse(peer *Peer) (*MessageResponse, error
}
func (device *Device) ConsumeMessageResponse(msg *MessageResponse) *Peer {
device.awg.ASecMux.RLock()
device.awg.Mux.RLock()
if msg.Type != MessageResponseType {
device.awg.ASecMux.RUnlock()
device.awg.Mux.RUnlock()
return nil
}
device.awg.ASecMux.RUnlock()
device.awg.Mux.RUnlock()
// lookup handshake by receiver