Start working on de-obfuscating ephemeral keys from remote peers

This commit is contained in:
eyedeekay
2024-08-28 18:32:42 -04:00
parent 310ef07d3c
commit cbc0de4e7e
2 changed files with 45 additions and 1 deletions

View File

@ -27,7 +27,7 @@ clean:
$(GO) clean -v
fmt:
find . -name '*.go' -exec gofmt -w -s {} \;
find . -name '*.go' -exec gofumpt -w {} \;
info:
echo "GOROOT: ${GOROOT}"

View File

@ -0,0 +1,44 @@
package noise
import (
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"github.com/flynn/noise"
"github.com/go-i2p/go-i2p/lib/common/router_address"
log "github.com/sirupsen/logrus"
)
// Noise obfuscation functions used in I2P NTCP2 and SSU2 Handshakes,
// including obfuscating the ephemeral keys with a known key and IV found
// in the netDb.
func AESDeObfuscateEphemeralKeys(cipherText string, config noise.Config, bob router_address.RouterAddress) (*noise.DHKey, error) {
bobsStaticKey, err := bob.StaticKey()
if err != nil {
return nil, err
}
bobsInitializatonVector, err := bob.InitializationVector()
if err != nil {
return nil, err
}
log.WithFields(
log.Fields{
"at": "(noise) AESObfuscateEphemeralKeys",
}).Debugf("getting ready to obfuscate our ephemeral keys with bob's static key %s and IV %s", bobsStaticKey, bobsInitializatonVector)
cipherTextDecoded, err := hex.DecodeString(cipherText)
if err != nil {
return nil, err
}
block, err := aes.NewCipher(bobsStaticKey[:])
if err != nil {
return nil, err
}
mode := cipher.NewCBCDecrypter(block, bobsInitializatonVector[:])
mode.CryptBlocks([]byte(cipherTextDecoded), []byte(cipherTextDecoded))
dhk := &noise.DHKey{
Private: cipherTextDecoded,
}
return dhk, nil
}