Refactor: move HandshakeState to own struct in preparation for NTCP2 mods
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
test-crypto-aes-all: test-crypto-aes-core test-crypto-aes-validation test-crypto-aes-padding
|
test-crypto-aes-all: test-crypto-aes-core test-crypto-aes-validation test-crypto-aes-padding
|
||||||
|
|
||||||
test-crypto-aes-core:
|
test-crypto-aes-core:
|
||||||
go test -v ./lib/crypto -run TestAESEncryptDecrypt
|
$(GO) test -v ./lib/crypto -run TestAESEncryptDecrypt
|
||||||
|
|
||||||
test-crypto-aes-validation:
|
test-crypto-aes-validation:
|
||||||
go test -v ./lib/crypto -run TestAESEncryptInvalidKey
|
$(GO) test -v ./lib/crypto -run TestAESEncryptInvalidKey
|
||||||
go test -v ./lib/crypto -run TestAESDecryptInvalidInput
|
$(GO) test -v ./lib/crypto -run TestAESDecryptInvalidInput
|
||||||
|
|
||||||
test-crypto-aes-padding:
|
test-crypto-aes-padding:
|
||||||
go test -v ./lib/crypto -run TestPKCS7PadUnpad
|
$(GO) test -v ./lib/crypto -run TestPKCS7PadUnpad
|
||||||
go test -v ./lib/crypto -run TestPKCS7UnpadInvalidInput
|
$(GO) test -v ./lib/crypto -run TestPKCS7UnpadInvalidInput
|
||||||
|
|
||||||
.PHONY: test-crypto-aes-all \
|
.PHONY: test-crypto-aes-all \
|
||||||
test-crypto-aes-core \
|
test-crypto-aes-core \
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
test-base32-encode-decode-not-mangled:
|
test-base32-encode-decode-not-mangled:
|
||||||
go test -v ./lib/common/base32 -run TestEncodeDecodeNotMangled
|
$(GO) test -v ./lib/common/base32 -run TestEncodeDecodeNotMangled
|
||||||
|
|
||||||
.PHONY: test-base32-encode-decode-not-mangled
|
.PHONY: test-base32-encode-decode-not-mangled
|
@@ -1,4 +1,4 @@
|
|||||||
test-base64-encode-decode-not-mangled:
|
test-base64-encode-decode-not-mangled:
|
||||||
go test -v ./lib/common/base64 -run TestEncodeDecodeNotMangled
|
$(GO) test -v ./lib/common/base64 -run TestEncodeDecodeNotMangled
|
||||||
|
|
||||||
.PHONY: test-base64-encode-decode-not-mangled
|
.PHONY: test-base64-encode-decode-not-mangled
|
@@ -1,22 +1,22 @@
|
|||||||
test-build-request-all: test-build-request-receive test-build-request-ident test-build-request-components
|
test-build-request-all: test-build-request-receive test-build-request-ident test-build-request-components
|
||||||
|
|
||||||
test-build-request-receive:
|
test-build-request-receive:
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordReceiveTunnel
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordReceiveTunnel
|
||||||
|
|
||||||
test-build-request-ident:
|
test-build-request-ident:
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordOurIdent
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordOurIdent
|
||||||
|
|
||||||
test-build-request-components:
|
test-build-request-components:
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordNextTunnel
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordNextTunnel
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordNextIdent
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordNextIdent
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordLayerKey
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordLayerKey
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordIVKey
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordIVKey
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordReplyKey
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordReplyKey
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordReplyIV
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordReplyIV
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordFlag
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordFlag
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordRequestTime
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordRequestTime
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordSendMessageID
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordSendMessageID
|
||||||
go test -v ./lib/i2np -run TestReadBuildRequestRecordPadding
|
$(GO) test -v ./lib/i2np -run TestReadBuildRequestRecordPadding
|
||||||
|
|
||||||
.PHONY: test-build-request-all \
|
.PHONY: test-build-request-all \
|
||||||
test-build-request-receive \
|
test-build-request-receive \
|
||||||
|
@@ -2,46 +2,46 @@
|
|||||||
test-cert-all: test-cert-type test-cert-length test-cert-data test-cert-read test-cert-length-correct test-cert-length-too-short test-cert-length-data-short test-cert-data-correct test-cert-data-too-long test-cert-data-too-short test-cert-read-correct test-cert-read-short test-cert-read-remainder test-cert-read-invalid
|
test-cert-all: test-cert-type test-cert-length test-cert-data test-cert-read test-cert-length-correct test-cert-length-too-short test-cert-length-data-short test-cert-data-correct test-cert-data-too-long test-cert-data-too-short test-cert-read-correct test-cert-read-short test-cert-read-remainder test-cert-read-invalid
|
||||||
|
|
||||||
test-cert-type:
|
test-cert-type:
|
||||||
go test -v ./lib/common/certificate -run TestCertificateTypeIsFirstByte
|
$(GO) test -v ./lib/common/certificate -run TestCertificateTypeIsFirstByte
|
||||||
|
|
||||||
test-cert-length:
|
test-cert-length:
|
||||||
go test -v ./lib/common/certificate -run TestCertificateLength
|
$(GO) test -v ./lib/common/certificate -run TestCertificateLength
|
||||||
|
|
||||||
test-cert-data:
|
test-cert-data:
|
||||||
go test -v ./lib/common/certificate -run TestCertificateData
|
$(GO) test -v ./lib/common/certificate -run TestCertificateData
|
||||||
|
|
||||||
test-cert-read:
|
test-cert-read:
|
||||||
go test -v ./lib/common/certificate -run TestReadCertificate
|
$(GO) test -v ./lib/common/certificate -run TestReadCertificate
|
||||||
|
|
||||||
test-cert-length-correct:
|
test-cert-length-correct:
|
||||||
go test -v ./lib/common/certificate -run TestCertificateLengthCorrect
|
$(GO) test -v ./lib/common/certificate -run TestCertificateLengthCorrect
|
||||||
|
|
||||||
test-cert-length-too-short:
|
test-cert-length-too-short:
|
||||||
go test -v ./lib/common/certificate -run TestCertificateLengthErrWhenTooShort
|
$(GO) test -v ./lib/common/certificate -run TestCertificateLengthErrWhenTooShort
|
||||||
|
|
||||||
test-cert-length-data-short:
|
test-cert-length-data-short:
|
||||||
go test -v ./lib/common/certificate -run TestCertificateLengthErrWhenDataTooShort
|
$(GO) test -v ./lib/common/certificate -run TestCertificateLengthErrWhenDataTooShort
|
||||||
|
|
||||||
test-cert-data-correct:
|
test-cert-data-correct:
|
||||||
go test -v ./lib/common/certificate -run TestCertificateDataWhenCorrectSize
|
$(GO) test -v ./lib/common/certificate -run TestCertificateDataWhenCorrectSize
|
||||||
|
|
||||||
test-cert-data-too-long:
|
test-cert-data-too-long:
|
||||||
go test -v ./lib/common/certificate -run TestCertificateDataWhenTooLong
|
$(GO) test -v ./lib/common/certificate -run TestCertificateDataWhenTooLong
|
||||||
|
|
||||||
test-cert-data-too-short:
|
test-cert-data-too-short:
|
||||||
go test -v ./lib/common/certificate -run TestCertificateDataWhenTooShort
|
$(GO) test -v ./lib/common/certificate -run TestCertificateDataWhenTooShort
|
||||||
|
|
||||||
test-cert-read-correct:
|
test-cert-read-correct:
|
||||||
go test -v ./lib/common/certificate -run TestReadCertificateWithCorrectData
|
$(GO) test -v ./lib/common/certificate -run TestReadCertificateWithCorrectData
|
||||||
|
|
||||||
test-cert-read-short:
|
test-cert-read-short:
|
||||||
go test -v ./lib/common/certificate -run TestReadCertificateWithDataTooShort
|
$(GO) test -v ./lib/common/certificate -run TestReadCertificateWithDataTooShort
|
||||||
|
|
||||||
test-cert-read-remainder:
|
test-cert-read-remainder:
|
||||||
go test -v ./lib/common/certificate -run TestReadCertificateWithRemainder
|
$(GO) test -v ./lib/common/certificate -run TestReadCertificateWithRemainder
|
||||||
|
|
||||||
test-cert-read-invalid:
|
test-cert-read-invalid:
|
||||||
go test -v ./lib/common/certificate -run TestReadCertificateWithInvalidLength
|
$(GO) test -v ./lib/common/certificate -run TestReadCertificateWithInvalidLength
|
||||||
|
|
||||||
# Declare all targets as PHONY
|
# Declare all targets as PHONY
|
||||||
.PHONY: test-cert-all \
|
.PHONY: test-cert-all \
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
test-date-time-from-milliseconds:
|
test-date-time-from-milliseconds:
|
||||||
go test -v ./lib/common/data -run TestTimeFromMilliseconds
|
$(GO) test -v ./lib/common/data -run TestTimeFromMilliseconds
|
@@ -1,17 +1,17 @@
|
|||||||
test-crypto-dsa-all: test-crypto-dsa test-crypto-dsa-benchmarks
|
test-crypto-dsa-all: test-crypto-dsa test-crypto-dsa-benchmarks
|
||||||
|
|
||||||
test-crypto-dsa:
|
test-crypto-dsa:
|
||||||
go test -v ./lib/crypto -run TestDSA
|
$(GO) test -v ./lib/crypto -run TestDSA
|
||||||
|
|
||||||
test-crypto-dsa-benchmarks:
|
test-crypto-dsa-benchmarks:
|
||||||
go test -v ./lib/crypto -bench=DSA -run=^$
|
$(GO) test -v ./lib/crypto -bench=DSA -run=^$
|
||||||
|
|
||||||
# Individual benchmarks
|
# Individual benchmarks
|
||||||
test-crypto-dsa-bench-generate:
|
test-crypto-dsa-bench-generate:
|
||||||
go test -v ./lib/crypto -bench=DSAGenerate -run=^$
|
$(GO) test -v ./lib/crypto -bench=DSAGenerate -run=^$
|
||||||
|
|
||||||
test-crypto-dsa-bench-sign-verify:
|
test-crypto-dsa-bench-sign-verify:
|
||||||
go test -v ./lib/crypto -bench=DSASignVerify -run=^$
|
$(GO) test -v ./lib/crypto -bench=DSASignVerify -run=^$
|
||||||
|
|
||||||
.PHONY: test-crypto-dsa-all \
|
.PHONY: test-crypto-dsa-all \
|
||||||
test-crypto-dsa \
|
test-crypto-dsa \
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
test-crypto-ed25519-all: test-crypto-ed25519
|
test-crypto-ed25519-all: test-crypto-ed25519
|
||||||
|
|
||||||
test-crypto-ed25519:
|
test-crypto-ed25519:
|
||||||
go test -v ./lib/crypto -run TestEd25519
|
$(GO) test -v ./lib/crypto -run TestEd25519
|
||||||
|
|
||||||
.PHONY: test-crypto-ed25519-all \
|
.PHONY: test-crypto-ed25519-all \
|
||||||
test-crypto-ed25519
|
test-crypto-ed25519
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
test-crypto-elg-all: test-crypto-elg test-crypto-elg-benchmarks
|
test-crypto-elg-all: test-crypto-elg test-crypto-elg-benchmarks
|
||||||
|
|
||||||
test-crypto-elg:
|
test-crypto-elg:
|
||||||
go test -v ./lib/crypto -run TestElg
|
$(GO) test -v ./lib/crypto -run TestElg
|
||||||
|
|
||||||
test-crypto-elg-benchmarks:
|
test-crypto-elg-benchmarks:
|
||||||
go test -v ./lib/crypto -bench=Elg -run=^$
|
$(GO) test -v ./lib/crypto -bench=Elg -run=^$
|
||||||
|
|
||||||
# Individual benchmarks
|
# Individual benchmarks
|
||||||
test-crypto-elg-bench-generate:
|
test-crypto-elg-bench-generate:
|
||||||
go test -v ./lib/crypto -bench=ElgGenerate -run=^$
|
$(GO) test -v ./lib/crypto -bench=ElgGenerate -run=^$
|
||||||
|
|
||||||
test-crypto-elg-bench-encrypt:
|
test-crypto-elg-bench-encrypt:
|
||||||
go test -v ./lib/crypto -bench=ElgEncrypt -run=^$
|
$(GO) test -v ./lib/crypto -bench=ElgEncrypt -run=^$
|
||||||
|
|
||||||
test-crypto-elg-bench-decrypt:
|
test-crypto-elg-bench-decrypt:
|
||||||
go test -v ./lib/crypto -bench=ElgDecrypt -run=^$
|
$(GO) test -v ./lib/crypto -bench=ElgDecrypt -run=^$
|
||||||
|
|
||||||
.PHONY: test-crypto-elg-all \
|
.PHONY: test-crypto-elg-all \
|
||||||
test-crypto-elg \
|
test-crypto-elg \
|
||||||
|
@@ -2,24 +2,24 @@
|
|||||||
test-i2np-header-all: test-i2np-type test-i2np-message test-i2np-expiration test-i2np-ntcp-components test-i2np-data test-i2np-regression
|
test-i2np-header-all: test-i2np-type test-i2np-message test-i2np-expiration test-i2np-ntcp-components test-i2np-data test-i2np-regression
|
||||||
|
|
||||||
test-i2np-type:
|
test-i2np-type:
|
||||||
go test -v ./lib/i2np -run TestReadI2NPTypeWith
|
$(GO) test -v ./lib/i2np -run TestReadI2NPTypeWith
|
||||||
|
|
||||||
test-i2np-message:
|
test-i2np-message:
|
||||||
go test -v ./lib/i2np -run TestReadI2NPNTCPMessageID
|
$(GO) test -v ./lib/i2np -run TestReadI2NPNTCPMessageID
|
||||||
|
|
||||||
test-i2np-expiration:
|
test-i2np-expiration:
|
||||||
go test -v ./lib/i2np -run TestReadI2NPNTCPMessageExpiration
|
$(GO) test -v ./lib/i2np -run TestReadI2NPNTCPMessageExpiration
|
||||||
go test -v ./lib/i2np -run TestReadI2NPSSUMessageExpiration
|
$(GO) test -v ./lib/i2np -run TestReadI2NPSSUMessageExpiration
|
||||||
|
|
||||||
test-i2np-ntcp-components:
|
test-i2np-ntcp-components:
|
||||||
go test -v ./lib/i2np -run TestReadI2NPNTCPMessageSize
|
$(GO) test -v ./lib/i2np -run TestReadI2NPNTCPMessageSize
|
||||||
go test -v ./lib/i2np -run TestReadI2NPNTCPMessageChecksum
|
$(GO) test -v ./lib/i2np -run TestReadI2NPNTCPMessageChecksum
|
||||||
|
|
||||||
test-i2np-data:
|
test-i2np-data:
|
||||||
go test -v ./lib/i2np -run TestReadI2NPNTCPData
|
$(GO) test -v ./lib/i2np -run TestReadI2NPNTCPData
|
||||||
|
|
||||||
test-i2np-regression:
|
test-i2np-regression:
|
||||||
go test -v ./lib/i2np -run TestCrasherRegression123781
|
$(GO) test -v ./lib/i2np -run TestCrasherRegression123781
|
||||||
|
|
||||||
.PHONY: test-i2np-header-all \
|
.PHONY: test-i2np-header-all \
|
||||||
test-i2np-type \
|
test-i2np-type \
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
test-crypto-hmac-all: test-crypto-hmac
|
test-crypto-hmac-all: test-crypto-hmac
|
||||||
|
|
||||||
test-crypto-hmac:
|
test-crypto-hmac:
|
||||||
go test -v ./lib/crypto -run Test_I2PHMAC
|
$(GO) test -v ./lib/crypto -run Test_I2PHMAC
|
||||||
|
|
||||||
.PHONY: test-crypto-hmac-all \
|
.PHONY: test-crypto-hmac-all \
|
||||||
test-crypto-hmac
|
test-crypto-hmac
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
test-integer-all: test-integer-big-endian test-integer-one-byte test-integer-zero
|
test-integer-all: test-integer-big-endian test-integer-one-byte test-integer-zero
|
||||||
|
|
||||||
test-integer-big-endian:
|
test-integer-big-endian:
|
||||||
go test -v ./lib/common/integer -run TestIntegerBigEndian
|
$(GO) test -v ./lib/common/integer -run TestIntegerBigEndian
|
||||||
|
|
||||||
test-integer-one-byte:
|
test-integer-one-byte:
|
||||||
go test -v ./lib/common/integer -run TestWorksWithOneByte
|
$(GO) test -v ./lib/common/integer -run TestWorksWithOneByte
|
||||||
|
|
||||||
test-integer-zero:
|
test-integer-zero:
|
||||||
go test -v ./lib/common/integer -run TestIsZeroWithNoData
|
$(GO) test -v ./lib/common/integer -run TestIsZeroWithNoData
|
||||||
|
|
||||||
.PHONY: test-integer-all \
|
.PHONY: test-integer-all \
|
||||||
test-integer-big-endian \
|
test-integer-big-endian \
|
||||||
|
@@ -1,21 +1,21 @@
|
|||||||
test-key-cert-all: test-key-cert-signing test-key-cert-public test-key-cert-construct
|
test-key-cert-all: test-key-cert-signing test-key-cert-public test-key-cert-construct
|
||||||
|
|
||||||
test-key-cert-signing:
|
test-key-cert-signing:
|
||||||
go test -v ./lib/common/key_certificate -run TestSingingPublicKeyTypeReturnsCorrectInteger
|
$(GO) test -v ./lib/common/key_certificate -run TestSingingPublicKeyTypeReturnsCorrectInteger
|
||||||
go test -v ./lib/common/key_certificate -run TestSingingPublicKeyTypeReportsWhenDataTooSmall
|
$(GO) test -v ./lib/common/key_certificate -run TestSingingPublicKeyTypeReportsWhenDataTooSmall
|
||||||
go test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyReportsWhenDataTooSmall
|
$(GO) test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyReportsWhenDataTooSmall
|
||||||
go test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyWithDSASHA1
|
$(GO) test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyWithDSASHA1
|
||||||
go test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyWithP256
|
$(GO) test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyWithP256
|
||||||
go test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyWithP384
|
$(GO) test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyWithP384
|
||||||
go test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyWithP521
|
$(GO) test -v ./lib/common/key_certificate -run TestConstructSigningPublicKeyWithP521
|
||||||
|
|
||||||
test-key-cert-public:
|
test-key-cert-public:
|
||||||
go test -v ./lib/common/key_certificate -run TestPublicKeyTypeReturnsCorrectInteger
|
$(GO) test -v ./lib/common/key_certificate -run TestPublicKeyTypeReturnsCorrectInteger
|
||||||
go test -v ./lib/common/key_certificate -run TestPublicKeyTypeReportsWhenDataTooSmall
|
$(GO) test -v ./lib/common/key_certificate -run TestPublicKeyTypeReportsWhenDataTooSmall
|
||||||
|
|
||||||
test-key-cert-construct:
|
test-key-cert-construct:
|
||||||
go test -v ./lib/common/key_certificate -run TestConstructPublicKeyReportsWhenDataTooSmall
|
$(GO) test -v ./lib/common/key_certificate -run TestConstructPublicKeyReportsWhenDataTooSmall
|
||||||
go test -v ./lib/common/key_certificate -run TestConstructPublicKeyReturnsCorrectDataWithElg
|
$(GO) test -v ./lib/common/key_certificate -run TestConstructPublicKeyReturnsCorrectDataWithElg
|
||||||
|
|
||||||
.PHONY: test-key-cert-all \
|
.PHONY: test-key-cert-all \
|
||||||
test-key-cert-signing \
|
test-key-cert-signing \
|
||||||
|
@@ -1,27 +1,27 @@
|
|||||||
test-keys-cert-all: test-keys-cert-certificate test-keys-cert-public test-keys-cert-signing test-keys-cert-creation
|
test-keys-cert-all: test-keys-cert-certificate test-keys-cert-public test-keys-cert-signing test-keys-cert-creation
|
||||||
|
|
||||||
test-keys-cert-certificate:
|
test-keys-cert-certificate:
|
||||||
go test -v ./lib/common/keys_and_cert -run TestCertificateWithValidData
|
$(GO) test -v ./lib/common/keys_and_cert -run TestCertificateWithValidData
|
||||||
|
|
||||||
test-keys-cert-public:
|
test-keys-cert-public:
|
||||||
go test -v ./lib/common/keys_and_cert -run TestPublicKeyWithBadData
|
$(GO) test -v ./lib/common/keys_and_cert -run TestPublicKeyWithBadData
|
||||||
go test -v ./lib/common/keys_and_cert -run TestPublicKeyWithBadCertificate
|
$(GO) test -v ./lib/common/keys_and_cert -run TestPublicKeyWithBadCertificate
|
||||||
go test -v ./lib/common/keys_and_cert -run TestPublicKeyWithNullCertificate
|
$(GO) test -v ./lib/common/keys_and_cert -run TestPublicKeyWithNullCertificate
|
||||||
go test -v ./lib/common/keys_and_cert -run TestPublicKeyWithKeyCertificate
|
$(GO) test -v ./lib/common/keys_and_cert -run TestPublicKeyWithKeyCertificate
|
||||||
|
|
||||||
test-keys-cert-signing:
|
test-keys-cert-signing:
|
||||||
go test -v ./lib/common/keys_and_cert -run TestSigningPublicKeyWithBadData
|
$(GO) test -v ./lib/common/keys_and_cert -run TestSigningPublicKeyWithBadData
|
||||||
go test -v ./lib/common/keys_and_cert -run TestSigningPublicKeyWithBadCertificate
|
$(GO) test -v ./lib/common/keys_and_cert -run TestSigningPublicKeyWithBadCertificate
|
||||||
go test -v ./lib/common/keys_and_cert -run TestSigningPublicKeyWithNullCertificate
|
$(GO) test -v ./lib/common/keys_and_cert -run TestSigningPublicKeyWithNullCertificate
|
||||||
go test -v ./lib/common/keys_and_cert -run TestSigningPublicKeyWithKeyCertificate
|
$(GO) test -v ./lib/common/keys_and_cert -run TestSigningPublicKeyWithKeyCertificate
|
||||||
|
|
||||||
test-keys-cert-creation:
|
test-keys-cert-creation:
|
||||||
go test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithMissingData
|
$(GO) test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithMissingData
|
||||||
go test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithMissingCertData
|
$(GO) test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithMissingCertData
|
||||||
go test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithValidDataWithCertificate
|
$(GO) test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithValidDataWithCertificate
|
||||||
go test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithValidDataWithoutCertificate
|
$(GO) test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithValidDataWithoutCertificate
|
||||||
go test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithValidDataWithCertificateAndRemainder
|
$(GO) test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithValidDataWithCertificateAndRemainder
|
||||||
go test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithValidDataWithoutCertificateAndRemainder
|
$(GO) test -v ./lib/common/keys_and_cert -run TestNewKeysAndCertWithValidDataWithoutCertificateAndRemainder
|
||||||
|
|
||||||
.PHONY: test-keys-cert-all \
|
.PHONY: test-keys-cert-all \
|
||||||
test-keys-cert-certificate \
|
test-keys-cert-certificate \
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
test-lease-set-all: test-lease-set-basic test-lease-set-leases test-lease-set-expiration
|
test-lease-set-all: test-lease-set-basic test-lease-set-leases test-lease-set-expiration
|
||||||
|
|
||||||
test-lease-set-basic:
|
test-lease-set-basic:
|
||||||
go test -v ./lib/common/lease_set -run TestDestinationIsCorrect
|
$(GO) test -v ./lib/common/lease_set -run TestDestinationIsCorrect
|
||||||
go test -v ./lib/common/lease_set -run TestPublicKeyIsCorrect
|
$(GO) test -v ./lib/common/lease_set -run TestPublicKeyIsCorrect
|
||||||
go test -v ./lib/common/lease_set -run TestSigningKeyIsCorrect
|
$(GO) test -v ./lib/common/lease_set -run TestSigningKeyIsCorrect
|
||||||
go test -v ./lib/common/lease_set -run TestSignatureIsCorrect
|
$(GO) test -v ./lib/common/lease_set -run TestSignatureIsCorrect
|
||||||
|
|
||||||
test-lease-set-leases:
|
test-lease-set-leases:
|
||||||
go test -v ./lib/common/lease_set -run TestLeaseCountCorrect
|
$(GO) test -v ./lib/common/lease_set -run TestLeaseCountCorrect
|
||||||
go test -v ./lib/common/lease_set -run TestLeaseCountCorrectWithMultiple
|
$(GO) test -v ./lib/common/lease_set -run TestLeaseCountCorrectWithMultiple
|
||||||
go test -v ./lib/common/lease_set -run TestLeaseCountErrorWithTooMany
|
$(GO) test -v ./lib/common/lease_set -run TestLeaseCountErrorWithTooMany
|
||||||
go test -v ./lib/common/lease_set -run TestLeasesHaveCorrectData
|
$(GO) test -v ./lib/common/lease_set -run TestLeasesHaveCorrectData
|
||||||
|
|
||||||
test-lease-set-expiration:
|
test-lease-set-expiration:
|
||||||
go test -v ./lib/common/lease_set -run TestNewestExpirationIsCorrect
|
$(GO) test -v ./lib/common/lease_set -run TestNewestExpirationIsCorrect
|
||||||
go test -v ./lib/common/lease_set -run TestOldestExpirationIsCorrect
|
$(GO) test -v ./lib/common/lease_set -run TestOldestExpirationIsCorrect
|
||||||
|
|
||||||
.PHONY: test-lease-set-all \
|
.PHONY: test-lease-set-all \
|
||||||
test-lease-set-basic \
|
test-lease-set-basic \
|
||||||
|
@@ -1,25 +1,25 @@
|
|||||||
test-mapping-all: test-mapping-values test-mapping-duplicates test-mapping-conversion test-mapping-utils
|
test-mapping-all: test-mapping-values test-mapping-duplicates test-mapping-conversion test-mapping-utils
|
||||||
|
|
||||||
test-mapping-values:
|
test-mapping-values:
|
||||||
go test -v ./lib/common/data -run TestValuesExclusesPairWithBadData
|
$(GO) test -v ./lib/common/data -run TestValuesExclusesPairWithBadData
|
||||||
go test -v ./lib/common/data -run TestValuesWarnsMissingData
|
$(GO) test -v ./lib/common/data -run TestValuesWarnsMissingData
|
||||||
go test -v ./lib/common/data -run TestValuesWarnsExtraData
|
$(GO) test -v ./lib/common/data -run TestValuesWarnsExtraData
|
||||||
go test -v ./lib/common/data -run TestValuesEnforcesEqualDelimitor
|
$(GO) test -v ./lib/common/data -run TestValuesEnforcesEqualDelimitor
|
||||||
go test -v ./lib/common/data -run TestValuesEnforcedSemicolonDelimitor
|
$(GO) test -v ./lib/common/data -run TestValuesEnforcedSemicolonDelimitor
|
||||||
go test -v ./lib/common/data -run TestValuesReturnsValues
|
$(GO) test -v ./lib/common/data -run TestValuesReturnsValues
|
||||||
|
|
||||||
test-mapping-duplicates:
|
test-mapping-duplicates:
|
||||||
go test -v ./lib/common/data -run TestHasDuplicateKeysTrueWhenDuplicates
|
$(GO) test -v ./lib/common/data -run TestHasDuplicateKeysTrueWhenDuplicates
|
||||||
go test -v ./lib/common/data -run TestHasDuplicateKeysFalseWithoutDuplicates
|
$(GO) test -v ./lib/common/data -run TestHasDuplicateKeysFalseWithoutDuplicates
|
||||||
go test -v ./lib/common/data -run TestReadMappingHasDuplicateKeys
|
$(GO) test -v ./lib/common/data -run TestReadMappingHasDuplicateKeys
|
||||||
|
|
||||||
test-mapping-conversion:
|
test-mapping-conversion:
|
||||||
go test -v ./lib/common/data -run TestGoMapToMappingProducesCorrectMapping
|
$(GO) test -v ./lib/common/data -run TestGoMapToMappingProducesCorrectMapping
|
||||||
go test -v ./lib/common/data -run TestFullGoMapToMappingProducesCorrectMapping
|
$(GO) test -v ./lib/common/data -run TestFullGoMapToMappingProducesCorrectMapping
|
||||||
|
|
||||||
test-mapping-utils:
|
test-mapping-utils:
|
||||||
go test -v ./lib/common/data -run TestStopValueRead
|
$(GO) test -v ./lib/common/data -run TestStopValueRead
|
||||||
go test -v ./lib/common/data -run TestBeginsWith
|
$(GO) test -v ./lib/common/data -run TestBeginsWith
|
||||||
|
|
||||||
.PHONY: test-mapping-all \
|
.PHONY: test-mapping-all \
|
||||||
test-mapping-values \
|
test-mapping-values \
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
test-mapping-values-order:
|
test-mapping-values-order:
|
||||||
go test -v ./lib/common/data -run TestMappingOrderSortsValuesThenKeys
|
$(GO) test -v ./lib/common/data -run TestMappingOrderSortsValuesThenKeys
|
@@ -1,16 +1,16 @@
|
|||||||
test-noise-transport-all: test-noise-packet-encryption test-noise-transport-connection test-noise-packet-obfuscation test-noise-packet-obfuscation-func
|
test-noise-transport-all: test-noise-packet-encryption test-noise-transport-connection test-noise-packet-obfuscation test-noise-packet-obfuscation-func
|
||||||
|
|
||||||
test-noise-packet-encryption:
|
test-noise-packet-encryption:
|
||||||
go test -v ./lib/transport/noise -run TestEncryptDecryptPacketOffline
|
$(GO) test -v ./lib/transport/noise -run TestEncryptDecryptPacketOffline
|
||||||
|
|
||||||
test-noise-transport-connection:
|
test-noise-transport-connection:
|
||||||
go test -v ./lib/transport/noise -run TestTransport
|
$(GO) test -v ./lib/transport/noise -run TestTransport
|
||||||
|
|
||||||
test-noise-packet-obfuscation:
|
test-noise-packet-obfuscation:
|
||||||
go test -v ./lib/transport/noise -run TestEncryptDecryptPacketObfsOffline
|
$(GO) test -v ./lib/transport/noise -run TestEncryptDecryptPacketObfsOffline
|
||||||
|
|
||||||
test-noise-packet-obfuscation-func:
|
test-noise-packet-obfuscation-func:
|
||||||
go test -v ./lib/transport/noise -run TestEncryptDecryptPacketObfsOfflineWithFunc
|
$(GO) test -v ./lib/transport/noise -run TestEncryptDecryptPacketObfsOfflineWithFunc
|
||||||
|
|
||||||
.PHONY: test-noise-transport-all \
|
.PHONY: test-noise-transport-all \
|
||||||
test-noise-packet-encryption \
|
test-noise-packet-encryption \
|
||||||
|
@@ -1,17 +1,17 @@
|
|||||||
test-router-address-all: test-router-address-validation test-router-address-functionality test-router-address-fuzz
|
test-router-address-all: test-router-address-validation test-router-address-functionality test-router-address-fuzz
|
||||||
|
|
||||||
test-router-address-validation:
|
test-router-address-validation:
|
||||||
go test -v ./lib/common/router_address -run TestCheckValidReportsEmptySlice
|
$(GO) test -v ./lib/common/router_address -run TestCheckValidReportsEmptySlice
|
||||||
go test -v ./lib/common/router_address -run TestCheckRouterAddressValidReportsDataMissing
|
$(GO) test -v ./lib/common/router_address -run TestCheckRouterAddressValidReportsDataMissing
|
||||||
go test -v ./lib/common/router_address -run TestCheckRouterAddressValidNoErrWithValidData
|
$(GO) test -v ./lib/common/router_address -run TestCheckRouterAddressValidNoErrWithValidData
|
||||||
|
|
||||||
test-router-address-functionality:
|
test-router-address-functionality:
|
||||||
go test -v ./lib/common/router_address -run TestRouterAddressCostReturnsFirstByte
|
$(GO) test -v ./lib/common/router_address -run TestRouterAddressCostReturnsFirstByte
|
||||||
go test -v ./lib/common/router_address -run TestRouterAddressExpirationReturnsCorrectData
|
$(GO) test -v ./lib/common/router_address -run TestRouterAddressExpirationReturnsCorrectData
|
||||||
go test -v ./lib/common/router_address -run TestReadRouterAddressReturnsCorrectRemainderWithoutError
|
$(GO) test -v ./lib/common/router_address -run TestReadRouterAddressReturnsCorrectRemainderWithoutError
|
||||||
|
|
||||||
test-router-address-fuzz:
|
test-router-address-fuzz:
|
||||||
go test -v ./lib/common/router_address -run TestCorrectsFuzzCrasher1
|
$(GO) test -v ./lib/common/router_address -run TestCorrectsFuzzCrasher1
|
||||||
|
|
||||||
.PHONY: test-router-address-all \
|
.PHONY: test-router-address-all \
|
||||||
test-router-address-validation \
|
test-router-address-validation \
|
||||||
|
@@ -1,23 +1,23 @@
|
|||||||
test-router-info-all: test-router-info-published test-router-info-addresses test-router-info-identity test-router-info-misc
|
test-router-info-all: test-router-info-published test-router-info-addresses test-router-info-identity test-router-info-misc
|
||||||
|
|
||||||
test-router-info-published:
|
test-router-info-published:
|
||||||
go test -v ./lib/common/router_info -run TestPublishedReturnsCorrectDate
|
$(GO) test -v ./lib/common/router_info -run TestPublishedReturnsCorrectDate
|
||||||
go test -v ./lib/common/router_info -run TestPublishedReturnsCorrectErrorWithPartialDate
|
$(GO) test -v ./lib/common/router_info -run TestPublishedReturnsCorrectErrorWithPartialDate
|
||||||
go test -v ./lib/common/router_info -run TestPublishedReturnsCorrectErrorWithInvalidData
|
$(GO) test -v ./lib/common/router_info -run TestPublishedReturnsCorrectErrorWithInvalidData
|
||||||
|
|
||||||
test-router-info-addresses:
|
test-router-info-addresses:
|
||||||
go test -v ./lib/common/router_info -run TestRouterAddressCountReturnsCorrectCount
|
$(GO) test -v ./lib/common/router_info -run TestRouterAddressCountReturnsCorrectCount
|
||||||
go test -v ./lib/common/router_info -run TestRouterAddressCountReturnsCorrectErrorWithInvalidData
|
$(GO) test -v ./lib/common/router_info -run TestRouterAddressCountReturnsCorrectErrorWithInvalidData
|
||||||
go test -v ./lib/common/router_info -run TestRouterAddressesReturnsAddresses
|
$(GO) test -v ./lib/common/router_info -run TestRouterAddressesReturnsAddresses
|
||||||
go test -v ./lib/common/router_info -run TestRouterAddressesReturnsAddressesWithMultiple
|
$(GO) test -v ./lib/common/router_info -run TestRouterAddressesReturnsAddressesWithMultiple
|
||||||
|
|
||||||
test-router-info-identity:
|
test-router-info-identity:
|
||||||
go test -v ./lib/common/router_info -run TestRouterIdentityIsCorrect
|
$(GO) test -v ./lib/common/router_info -run TestRouterIdentityIsCorrect
|
||||||
|
|
||||||
test-router-info-misc:
|
test-router-info-misc:
|
||||||
go test -v ./lib/common/router_info -run TestPeerSizeIsZero
|
$(GO) test -v ./lib/common/router_info -run TestPeerSizeIsZero
|
||||||
go test -v ./lib/common/router_info -run TestOptionsAreCorrect
|
$(GO) test -v ./lib/common/router_info -run TestOptionsAreCorrect
|
||||||
go test -v ./lib/common/router_info -run TestSignatureIsCorrectSize
|
$(GO) test -v ./lib/common/router_info -run TestSignatureIsCorrectSize
|
||||||
|
|
||||||
.PHONY: test-router-info-all \
|
.PHONY: test-router-info-all \
|
||||||
test-router-info-published \
|
test-router-info-published \
|
||||||
|
@@ -1,24 +1,24 @@
|
|||||||
test-string-all: test-string-length test-string-data test-string-conversion test-string-read
|
test-string-all: test-string-length test-string-data test-string-conversion test-string-read
|
||||||
|
|
||||||
test-string-length:
|
test-string-length:
|
||||||
go test -v ./lib/common/data -run TestStringReportsCorrectLength
|
$(GO) test -v ./lib/common/data -run TestStringReportsCorrectLength
|
||||||
go test -v ./lib/common/data -run TestI2PStringReportsLengthZeroError
|
$(GO) test -v ./lib/common/data -run TestI2PStringReportsLengthZeroError
|
||||||
go test -v ./lib/common/data -run TestI2PStringReportsExtraDataError
|
$(GO) test -v ./lib/common/data -run TestI2PStringReportsExtraDataError
|
||||||
go test -v ./lib/common/data -run TestI2PStringDataReportsLengthZeroError
|
$(GO) test -v ./lib/common/data -run TestI2PStringDataReportsLengthZeroError
|
||||||
|
|
||||||
test-string-data:
|
test-string-data:
|
||||||
go test -v ./lib/common/data -run TestI2PStringDataReportsExtraDataError
|
$(GO) test -v ./lib/common/data -run TestI2PStringDataReportsExtraDataError
|
||||||
go test -v ./lib/common/data -run TestI2PStringDataEmptyWhenZeroLength
|
$(GO) test -v ./lib/common/data -run TestI2PStringDataEmptyWhenZeroLength
|
||||||
go test -v ./lib/common/data -run TestI2PStringDataErrorWhenNonZeroLengthOnly
|
$(GO) test -v ./lib/common/data -run TestI2PStringDataErrorWhenNonZeroLengthOnly
|
||||||
|
|
||||||
test-string-conversion:
|
test-string-conversion:
|
||||||
go test -v ./lib/common/data -run TestToI2PI2PStringFormatsCorrectly
|
$(GO) test -v ./lib/common/data -run TestToI2PI2PStringFormatsCorrectly
|
||||||
go test -v ./lib/common/data -run TestToI2PStringReportsOverflows
|
$(GO) test -v ./lib/common/data -run TestToI2PStringReportsOverflows
|
||||||
|
|
||||||
test-string-read:
|
test-string-read:
|
||||||
go test -v ./lib/common/data -run TestReadStringReadsLength
|
$(GO) test -v ./lib/common/data -run TestReadStringReadsLength
|
||||||
go test -v ./lib/common/data -run TestReadI2PStringErrWhenEmptySlice
|
$(GO) test -v ./lib/common/data -run TestReadI2PStringErrWhenEmptySlice
|
||||||
go test -v ./lib/common/data -run TestReadI2PStringErrWhenDataTooShort
|
$(GO) test -v ./lib/common/data -run TestReadI2PStringErrWhenDataTooShort
|
||||||
|
|
||||||
.PHONY: test-string-all \
|
.PHONY: test-string-all \
|
||||||
test-string-length \
|
test-string-length \
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
test-su3-all: test-su3-read test-su3-signature
|
test-su3-all: test-su3-read test-su3-signature
|
||||||
|
|
||||||
test-su3-read:
|
test-su3-read:
|
||||||
go test -v ./lib/su3 -run TestRead
|
$(GO) test -v ./lib/su3 -run TestRead
|
||||||
|
|
||||||
test-su3-signature:
|
test-su3-signature:
|
||||||
go test -v ./lib/su3 -run TestReadSignatureFirst
|
$(GO) test -v ./lib/su3 -run TestReadSignatureFirst
|
||||||
|
|
||||||
.PHONY: test-su3-all \
|
.PHONY: test-su3-all \
|
||||||
test-su3-read \
|
test-su3-read \
|
||||||
|
@@ -2,18 +2,18 @@ test-tunnel-all: test-tunnel-delivery-instructions test-tunnel-message
|
|||||||
|
|
||||||
# Tests from delivery_test.go
|
# Tests from delivery_test.go
|
||||||
test-tunnel-delivery-instructions:
|
test-tunnel-delivery-instructions:
|
||||||
go test -v ./lib/tunnel -run TestReadDeliveryInstructions
|
$(GO) test -v ./lib/tunnel -run TestReadDeliveryInstructions
|
||||||
|
|
||||||
# Tests from message_test.go
|
# Tests from message_test.go
|
||||||
test-tunnel-message: test-tunnel-message-padding test-tunnel-message-fragments
|
test-tunnel-message: test-tunnel-message-padding test-tunnel-message-fragments
|
||||||
|
|
||||||
test-tunnel-message-padding:
|
test-tunnel-message-padding:
|
||||||
go test -v ./lib/tunnel -run TestDeliveryInstructionDataWithNoPadding
|
$(GO) test -v ./lib/tunnel -run TestDeliveryInstructionDataWithNoPadding
|
||||||
go test -v ./lib/tunnel -run TestDeliveryInstructionDataWithSomePadding
|
$(GO) test -v ./lib/tunnel -run TestDeliveryInstructionDataWithSomePadding
|
||||||
go test -v ./lib/tunnel -run TestDeliveryInstructionDataWithOnlyPadding
|
$(GO) test -v ./lib/tunnel -run TestDeliveryInstructionDataWithOnlyPadding
|
||||||
|
|
||||||
test-tunnel-message-fragments:
|
test-tunnel-message-fragments:
|
||||||
go test -v ./lib/tunnel -run TestDeliveryInstructionsWithFragments
|
$(GO) test -v ./lib/tunnel -run TestDeliveryInstructionsWithFragments
|
||||||
|
|
||||||
.PHONY: test-tunnel-all \
|
.PHONY: test-tunnel-all \
|
||||||
test-tunnel-delivery-instructions \
|
test-tunnel-delivery-instructions \
|
||||||
|
@@ -3,13 +3,110 @@ package noise
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||||
"github.com/go-i2p/go-i2p/lib/util/logger"
|
"github.com/go-i2p/go-i2p/lib/util/logger"
|
||||||
|
|
||||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
"github.com/flynn/noise"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type HandshakeState struct {
|
||||||
|
mutex sync.Mutex
|
||||||
|
protocol *noise.HandshakeState
|
||||||
|
ephemeral *noise.DHKey
|
||||||
|
pattern noise.HandshakePattern
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHandshakeState(s noise.DHKey, isInitiator bool) (*HandshakeState, error) {
|
||||||
|
hs := &HandshakeState{
|
||||||
|
pattern: noise.HandshakeXK,
|
||||||
|
}
|
||||||
|
|
||||||
|
config := noise.Config{
|
||||||
|
CipherSuite: noise.NewCipherSuite(noise.DH25519, noise.CipherAESGCM, noise.HashSHA256),
|
||||||
|
Pattern: hs.pattern,
|
||||||
|
Initiator: isInitiator,
|
||||||
|
StaticKeypair: s,
|
||||||
|
}
|
||||||
|
|
||||||
|
protocol, err := noise.NewHandshakeState(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
hs.protocol = protocol
|
||||||
|
return hs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateEphemeral creates the ephemeral keypair that will be used in handshake
|
||||||
|
// This needs to be separate so NTCP2 can obfuscate it
|
||||||
|
func (h *HandshakeState) GenerateEphemeral() (*noise.DHKey, error) {
|
||||||
|
h.mutex.Lock()
|
||||||
|
defer h.mutex.Unlock()
|
||||||
|
|
||||||
|
dhKey, err := noise.DH25519.GenerateKeypair(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
h.ephemeral = &dhKey
|
||||||
|
return &dhKey, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEphemeral allows setting a potentially modified ephemeral key
|
||||||
|
// This is needed for NTCP2's obfuscation layer
|
||||||
|
func (h *HandshakeState) SetEphemeral(key *noise.DHKey) error {
|
||||||
|
h.mutex.Lock()
|
||||||
|
defer h.mutex.Unlock()
|
||||||
|
h.ephemeral = key
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *HandshakeState) WriteMessage(payload []byte) ([]byte, *noise.CipherState, *noise.CipherState, error) {
|
||||||
|
h.mutex.Lock()
|
||||||
|
defer h.mutex.Unlock()
|
||||||
|
|
||||||
|
return h.protocol.WriteMessage(nil, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *HandshakeState) ReadMessage(message []byte) ([]byte, *noise.CipherState, *noise.CipherState, error) {
|
||||||
|
h.mutex.Lock()
|
||||||
|
defer h.mutex.Unlock()
|
||||||
|
|
||||||
|
return h.protocol.ReadMessage(nil, message)
|
||||||
|
}
|
||||||
|
|
||||||
var log = logger.GetGoI2PLogger()
|
var log = logger.GetGoI2PLogger()
|
||||||
|
|
||||||
|
/*
|
||||||
|
func (c *NoiseTransport) Handshake(routerInfo router_info.RouterInfo) error {
|
||||||
|
log.WithField("router_info", routerInfo.IdentHash()).Debug("Starting Noise handshake")
|
||||||
|
c.Mutex.Lock()
|
||||||
|
defer c.Mutex.Unlock()
|
||||||
|
session, err := c.getSession(routerInfo)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("Failed to get session for handshake")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debug("Session obtained for handshake")
|
||||||
|
// Set handshakeCond to indicate that this goroutine is committing to
|
||||||
|
// running the handshake.
|
||||||
|
session.(*NoiseSession).Cond = sync.NewCond(&c.Mutex)
|
||||||
|
c.Mutex.Unlock()
|
||||||
|
session.(*NoiseSession).Mutex.Lock()
|
||||||
|
defer session.(*NoiseSession).Mutex.Unlock()
|
||||||
|
c.Mutex.Lock()
|
||||||
|
log.Debug("Running outgoing handshake")
|
||||||
|
if err := session.(*NoiseSession).RunOutgoingHandshake(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debug("Outgoing handshake completed successfully")
|
||||||
|
// Wake any other goroutines that are waiting for this handshake to
|
||||||
|
// complete.
|
||||||
|
session.(*NoiseSession).Cond.Broadcast()
|
||||||
|
session.(*NoiseSession).Cond = nil
|
||||||
|
log.Debug("Noise handshake completed successfully")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
*/
|
||||||
func (c *NoiseTransport) Handshake(routerInfo router_info.RouterInfo) error {
|
func (c *NoiseTransport) Handshake(routerInfo router_info.RouterInfo) error {
|
||||||
log.WithField("router_info", routerInfo.IdentHash()).Debug("Starting Noise handshake")
|
log.WithField("router_info", routerInfo.IdentHash()).Debug("Starting Noise handshake")
|
||||||
c.Mutex.Lock()
|
c.Mutex.Lock()
|
||||||
|
@@ -3,61 +3,13 @@ package noise
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/flynn/noise"
|
"github.com/flynn/noise"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ComposeReceiverHandshakeMessage(s noise.DHKey, rs []byte, payload []byte, ePrivate []byte) (negData, msg []byte, state *noise.HandshakeState, err error) {
|
|
||||||
log.Debug("Starting ComposeReceiverHandshakeMessage")
|
|
||||||
|
|
||||||
if len(rs) != 0 && len(rs) != noise.DH25519.DHLen() {
|
|
||||||
log.WithField("rs_length", len(rs)).Error("Invalid remote static key length")
|
|
||||||
return nil, nil, nil, errors.New("only 32 byte curve25519 public keys are supported")
|
|
||||||
}
|
|
||||||
negData = make([]byte, 6)
|
|
||||||
copy(negData, initNegotiationData(nil))
|
|
||||||
pattern := noise.HandshakeXK
|
|
||||||
negData[5] = NOISE_PATTERN_XK
|
|
||||||
log.WithField("pattern", "XK").Debug("Noise pattern set")
|
|
||||||
var random io.Reader
|
|
||||||
if len(ePrivate) == 0 {
|
|
||||||
random = rand.Reader
|
|
||||||
log.Debug("Using crypto/rand as random source")
|
|
||||||
} else {
|
|
||||||
random = bytes.NewBuffer(ePrivate)
|
|
||||||
log.Debug("Using provided ePrivate as random source")
|
|
||||||
}
|
|
||||||
prologue := make([]byte, 2, uint16Size+len(negData))
|
|
||||||
binary.BigEndian.PutUint16(prologue, uint16(len(negData)))
|
|
||||||
prologue = append(prologue, negData...)
|
|
||||||
log.WithField("prologue_length", len(prologue)).Debug("Prologue created")
|
|
||||||
// prologue = append(initString, prologue...)
|
|
||||||
state, err = noise.NewHandshakeState(noise.Config{
|
|
||||||
StaticKeypair: s,
|
|
||||||
Initiator: false,
|
|
||||||
Pattern: pattern,
|
|
||||||
CipherSuite: noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, noise.HashSHA256),
|
|
||||||
PeerStatic: rs,
|
|
||||||
Prologue: prologue,
|
|
||||||
Random: random,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Error("Failed to create new handshake state")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.WithField("message_length", len(msg)).Debug("Handshake message composed successfully")
|
|
||||||
// log.Debug("Handshake state created successfully")
|
|
||||||
padBuf := make([]byte, 2+len(payload))
|
|
||||||
copy(padBuf[2:], payload)
|
|
||||||
msg, _, _, err = state.WriteMessage(msg, padBuf)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *NoiseSession) RunIncomingHandshake() error {
|
func (c *NoiseSession) RunIncomingHandshake() error {
|
||||||
log.Debug("Starting incoming handshake")
|
log.Debug("Starting incoming handshake")
|
||||||
|
|
||||||
@@ -66,6 +18,9 @@ func (c *NoiseSession) RunIncomingHandshake() error {
|
|||||||
log.WithError(err).Error("Failed to compose receiver handshake message")
|
log.WithError(err).Error("Failed to compose receiver handshake message")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
c.HandshakeState = &HandshakeState{
|
||||||
|
protocol: state,
|
||||||
|
}
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"negData_length": len(negData),
|
"negData_length": len(negData),
|
||||||
"msg_length": len(msg),
|
"msg_length": len(msg),
|
||||||
@@ -86,3 +41,51 @@ func (c *NoiseSession) RunIncomingHandshake() error {
|
|||||||
log.Debug("Incoming handshake completed successfully")
|
log.Debug("Incoming handshake completed successfully")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ComposeReceiverHandshakeMessage(s noise.DHKey, rs []byte, payload []byte, ePrivate []byte) (negData, msg []byte, state *noise.HandshakeState, err error) {
|
||||||
|
log.Debug("Starting ComposeReceiverHandshakeMessage")
|
||||||
|
|
||||||
|
if len(rs) != 0 && len(rs) != noise.DH25519.DHLen() {
|
||||||
|
log.WithField("rs_length", len(rs)).Error("Invalid remote static key length")
|
||||||
|
return nil, nil, nil, errors.New("only 32 byte curve25519 public keys are supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
negData = make([]byte, 6)
|
||||||
|
copy(negData, initNegotiationData(nil))
|
||||||
|
pattern := noise.HandshakeXK
|
||||||
|
negData[5] = NOISE_PATTERN_XK
|
||||||
|
|
||||||
|
var random io.Reader
|
||||||
|
if len(ePrivate) == 0 {
|
||||||
|
random = rand.Reader
|
||||||
|
log.Debug("Using crypto/rand as random source")
|
||||||
|
} else {
|
||||||
|
random = bytes.NewBuffer(ePrivate)
|
||||||
|
}
|
||||||
|
|
||||||
|
config := noise.Config{
|
||||||
|
CipherSuite: noise.NewCipherSuite(noise.DH25519, noise.CipherAESGCM, noise.HashSHA256),
|
||||||
|
Pattern: pattern,
|
||||||
|
Initiator: false,
|
||||||
|
StaticKeypair: s,
|
||||||
|
Random: random,
|
||||||
|
}
|
||||||
|
|
||||||
|
state, err = noise.NewHandshakeState(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write message 2, expecting no CipherStates yet
|
||||||
|
msg, cs0, cs1, err := state.WriteMessage(nil, payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify no CipherStates are returned yet
|
||||||
|
if cs0 != nil || cs1 != nil {
|
||||||
|
return nil, nil, nil, errors.New("unexpected cipher states in message 2")
|
||||||
|
}
|
||||||
|
|
||||||
|
return negData, msg, state, nil
|
||||||
|
}
|
||||||
|
@@ -3,7 +3,6 @@ package noise
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@@ -12,56 +11,6 @@ import (
|
|||||||
"github.com/flynn/noise"
|
"github.com/flynn/noise"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ComposeInitiatorHandshakeMessage(s noise.DHKey, rs []byte, payload []byte, ePrivate []byte) (negData, msg []byte, state *noise.HandshakeState, err error) {
|
|
||||||
log.Debug("Starting ComposeInitiatorHandshakeMessage")
|
|
||||||
if len(rs) != 0 && len(rs) != noise.DH25519.DHLen() {
|
|
||||||
log.WithField("rs_length", len(rs)).Error("Invalid remote static key length")
|
|
||||||
return nil, nil, nil, errors.New("only 32 byte curve25519 public keys are supported")
|
|
||||||
}
|
|
||||||
negData = make([]byte, 6)
|
|
||||||
copy(negData, initNegotiationData(nil))
|
|
||||||
pattern := noise.HandshakeXK
|
|
||||||
negData[5] = NOISE_PATTERN_XK
|
|
||||||
log.WithField("pattern", "XK").Debug("Noise pattern set")
|
|
||||||
var random io.Reader
|
|
||||||
if len(ePrivate) == 0 {
|
|
||||||
random = rand.Reader
|
|
||||||
log.Debug("Using crypto/rand as random source")
|
|
||||||
} else {
|
|
||||||
random = bytes.NewBuffer(ePrivate)
|
|
||||||
log.Debug("Using provided ePrivate as random source")
|
|
||||||
}
|
|
||||||
prologue := make([]byte, 2, uint16Size+len(negData))
|
|
||||||
binary.BigEndian.PutUint16(prologue, uint16(len(negData)))
|
|
||||||
prologue = append(prologue, negData...)
|
|
||||||
log.WithField("prologue_length", len(prologue)).Debug("Prologue created")
|
|
||||||
// prologue = append(initString, prologue...)
|
|
||||||
state, err = noise.NewHandshakeState(noise.Config{
|
|
||||||
StaticKeypair: s,
|
|
||||||
Initiator: true,
|
|
||||||
Pattern: pattern,
|
|
||||||
CipherSuite: noise.NewCipherSuite(noise.DH25519, noise.CipherChaChaPoly, noise.HashSHA256),
|
|
||||||
PeerStatic: rs,
|
|
||||||
Prologue: prologue,
|
|
||||||
Random: random,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Error("Failed to create new handshake state")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Debug("Handshake state created successfully")
|
|
||||||
padBuf := make([]byte, 2+len(payload))
|
|
||||||
copy(padBuf[2:], payload)
|
|
||||||
msg, _, _, err = state.WriteMessage(msg, padBuf)
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Error("Failed to write handshake message")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.WithField("message_length", len(msg)).Debug("Handshake message composed successfully")
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *NoiseSession) RunOutgoingHandshake() error {
|
func (c *NoiseSession) RunOutgoingHandshake() error {
|
||||||
log.Debug("Starting outgoing handshake")
|
log.Debug("Starting outgoing handshake")
|
||||||
|
|
||||||
@@ -74,6 +23,9 @@ func (c *NoiseSession) RunOutgoingHandshake() error {
|
|||||||
"negData_length": len(negData),
|
"negData_length": len(negData),
|
||||||
"msg_length": len(msg),
|
"msg_length": len(msg),
|
||||||
}).Debug("Initiator handshake message composed")
|
}).Debug("Initiator handshake message composed")
|
||||||
|
c.HandshakeState = &HandshakeState{
|
||||||
|
protocol: state,
|
||||||
|
}
|
||||||
|
|
||||||
if _, err = c.Write(negData); err != nil {
|
if _, err = c.Write(negData); err != nil {
|
||||||
log.WithError(err).Error("Failed to write negotiation data")
|
log.WithError(err).Error("Failed to write negotiation data")
|
||||||
@@ -92,3 +44,49 @@ func (c *NoiseSession) RunOutgoingHandshake() error {
|
|||||||
log.Debug("Outgoing handshake completed successfully")
|
log.Debug("Outgoing handshake completed successfully")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ComposeInitiatorHandshakeMessage(s noise.DHKey, rs []byte, payload []byte, ePrivate []byte) (negData, msg []byte, state *noise.HandshakeState, err error) {
|
||||||
|
log.Debug("Starting ComposeInitiatorHandshakeMessage")
|
||||||
|
|
||||||
|
if len(rs) != 0 && len(rs) != noise.DH25519.DHLen() {
|
||||||
|
return nil, nil, nil, errors.New("only 32 byte curve25519 public keys are supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
negData = make([]byte, 6)
|
||||||
|
copy(negData, initNegotiationData(nil))
|
||||||
|
pattern := noise.HandshakeXK
|
||||||
|
negData[5] = NOISE_PATTERN_XK
|
||||||
|
|
||||||
|
var random io.Reader
|
||||||
|
if len(ePrivate) == 0 {
|
||||||
|
random = rand.Reader
|
||||||
|
} else {
|
||||||
|
random = bytes.NewBuffer(ePrivate)
|
||||||
|
}
|
||||||
|
|
||||||
|
config := noise.Config{
|
||||||
|
CipherSuite: noise.NewCipherSuite(noise.DH25519, noise.CipherAESGCM, noise.HashSHA256),
|
||||||
|
Pattern: pattern,
|
||||||
|
Initiator: true,
|
||||||
|
StaticKeypair: s,
|
||||||
|
Random: random,
|
||||||
|
}
|
||||||
|
|
||||||
|
state, err = noise.NewHandshakeState(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write message, expecting no CipherStates yet since this is message 1 [[1]](https://poe.com/citation?message_id=283961551087&citation=1)
|
||||||
|
msg, cs0, cs1, err := state.WriteMessage(nil, payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify no CipherStates are returned yet
|
||||||
|
if cs0 != nil || cs1 != nil {
|
||||||
|
return nil, nil, nil, errors.New("unexpected cipher states in message 1")
|
||||||
|
}
|
||||||
|
|
||||||
|
return negData, msg, state, nil
|
||||||
|
}
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package noise
|
package noise
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -28,10 +27,10 @@ type NoiseSession struct {
|
|||||||
RecvKey noise.DHKey
|
RecvKey noise.DHKey
|
||||||
HandKey noise.DHKey
|
HandKey noise.DHKey
|
||||||
VerifyCallback VerifyCallbackFunc
|
VerifyCallback VerifyCallbackFunc
|
||||||
handshakeBuffer bytes.Buffer
|
|
||||||
activeCall int32
|
activeCall int32
|
||||||
handshakeComplete bool
|
handshakeComplete bool
|
||||||
Conn net.Conn
|
Conn net.Conn
|
||||||
|
*HandshakeState
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteAddr implements net.Conn
|
// RemoteAddr implements net.Conn
|
||||||
|
@@ -7,4 +7,4 @@ package ssu
|
|||||||
If we've done our jobs correctly when we get to this point, we will be implementing a net.Conn interface
|
If we've done our jobs correctly when we get to this point, we will be implementing a net.Conn interface
|
||||||
that can do the peer-testing and session management stuff, and we will **layer** it with our Noise protocol
|
that can do the peer-testing and session management stuff, and we will **layer** it with our Noise protocol
|
||||||
implementation and the SSU2 modifications.
|
implementation and the SSU2 modifications.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user