Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NewGCMTLS (when using experiment boringcrypto) #803

Merged
merged 3 commits into from
Apr 5, 2023
Merged

Conversation

wadey
Copy link
Member

@wadey wadey commented Jan 10, 2023

This change only affects builds built using GOEXPERIMENT=boringcrypto. When built with this experiment, we use the NewGCMTLS() method exposed by goboring, which validates that the nonce is strictly monotonically increasing. This is the TLS 1.2 specification for nonce generation (which also matches the method used by the Noise Protocol)

@wadey wadey added this to the v1.7.0 milestone Jan 10, 2023
@wadey wadey added the slack label Jan 20, 2023
adamrothman
adamrothman previously approved these changes Feb 7, 2023
Copy link

@adamrothman adamrothman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


// Ensure NewGCMTLS validates the nonce is non-repeating
func TestNewGCMTLS(t *testing.T) {
// Test Case 16 from http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link is now a redirect to https://csrc.nist.gov/projects/block-cipher-techniques/bcm, which eventually links to https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf for GCM. But I didn't see any test cases listed therein – is there a way I see the case referenced here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, let me try to track it down. I actually cribbed this from the boringssl tests IIRC, so maybe I should just link there.

@wadey wadey added the needs-defined-net-review Review needed from a Defined Networking team member label Mar 13, 2023
//ci.writeLock.Lock()
if noiseutil.EncryptLockNeeded {
// NOTE: for goboring AESGCMTLS we need to lock because of the nonce check
ci.writeLock.Lock()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC the Lock guarantees that the ci.messageCounter.Add(1) line just below, which increments the message counter, is kept in lock step with the Seal() call on the actual encryption keys, called through EncryptDanger just before the lock is released.

If that's correct, then I think this lock is also required in the SendVia() implementation, which also calls EncryptDanger (and therefore Seal()) to authenticate a relayed packet.

SendVia() is the only other active invocation of EncryptDanger() that I see in Nebula code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 194e920

@wadey wadey merged commit e055382 into master Apr 5, 2023
@wadey wadey deleted the boring-gcmtls branch April 5, 2023 15:08
apeters1827 pushed a commit to oneclick-ag/nebula that referenced this pull request Jul 4, 2023
* Use NewGCMTLS (when using experiment boringcrypto)

This change only affects builds built using `GOEXPERIMENT=boringcrypto`.
When built with this experiment, we use the NewGCMTLS() method exposed by
goboring, which validates that the nonce is strictly monotonically increasing.
This is the TLS 1.2 specification for nonce generation (which also matches the
method used by the Noise Protocol)

- https://github.com/golang/go/blob/go1.19/src/crypto/tls/cipher_suites.go#L520-L522
- https://github.com/golang/go/blob/go1.19/src/crypto/internal/boring/aes.go#L235-L237
- https://github.com/golang/go/blob/go1.19/src/crypto/internal/boring/aes.go#L250
- https://github.com/google/boringssl/blob/ae223d6138807a13006342edfeef32e813246b39/include/openssl/aead.h#L379-L381
- https://github.com/google/boringssl/blob/ae223d6138807a13006342edfeef32e813246b39/crypto/fipsmodule/cipher/e_aes.c#L1082-L1093

* need to lock around EncryptDanger in SendVia

* fix link to test vector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-defined-net-review Review needed from a Defined Networking team member slack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants