-
Notifications
You must be signed in to change notification settings - Fork 157
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
Implement "Extended Master Secret" extension (RFC7626) #93
Implement "Extended Master Secret" extension (RFC7626) #93
Conversation
08225b9
to
b2589d1
Compare
Codecov Report
@@ Coverage Diff @@
## master #93 +/- ##
=========================================
+ Coverage 71.51% 72.31% +0.8%
=========================================
Files 52 53 +1
Lines 2952 3056 +104
=========================================
+ Hits 2111 2210 +99
+ Misses 597 594 -3
- Partials 244 252 +8
Continue to review full report at Codecov.
|
b2589d1
to
5299f36
Compare
55c3b65
to
eb351ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage is really great!
No issue from me, just a few minor nits just so we have a little less state if possible
@RyanGordon So not using In the future we may export these, and would be great if we can just upcase them all when we get to that point. I think that could be a huge advantage over OpenSSL, actually let people really understand what happened and why. |
state.go
Outdated
@@ -19,6 +19,10 @@ type State struct { | |||
remoteCertificate *x509.Certificate | |||
|
|||
isClient bool | |||
|
|||
serverKeyExchange *handshakeMessageServerKeyExchange |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you ever read anything about what may/may be kept in memory? I thought when writing things originally I read somewhere that certain things should be zero'ed out even (maybe reading OpenSSL)
crypto/tls
itself only keeps the masterSecret []byte
so I think we should push back on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So two problems that I ran into:
- In order to calculate the
extendedMasterSecret
hash, you have to keep a binary "log" of the handshakes, until you calculate the hash - For the client, the last part of the handshake is sending out the
clientKeyExchange
so we have to wait for theinitalizeCipherSuite
to run at that point which then calculates theextendedMasterSecret
and uses the serverKeyExchange (specificallypublicKey
,namedCurve
,signature
andhashAlgorithm
from it) to validate the key signature (if not disabled)
I'm happy to see if there are ways to more directly scrub it from memory but I am struggling to see how I (or another library?) could not keep it around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pull the *handshakeMessageServerKeyExchange
from the *handshakeCache
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even the handshake cache would still be an unprotected memory region right?
We could consider introducing a dependency on https://godoc.org/github.com/awnumar/memguard, for creating a secure enclave where we store sensitive information. It's a little more extreme than just zeroing out a buffer but it goes to fairly great lengths to help you keep a memory area protected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sean-Der Yes, we could pull it from the handshake cache but I would have to unmarshal it again which would be a bit extra computation. I don't have a strong preference either way
@daenney Yes, I think it's definitely worthwhile to have a discussion on how we could better protect memory in these cases. I opened up an issue here so we can have a fuller discussion on it: #97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference is double computation. Until we measure we don’t know how expensive something is.
But the more state we have the more difficult things become to keep in your head/and we have to guard and more nil checks (that’s just like my opinion though man)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daenney that’s super interesting I had no idea about memguard.
I will play with it/understand the trade offs! I don’t have a security background/I am pretty unaware of what the community is doing :/
return &alert{alertLevelFatal, alertInternalError}, err | ||
if c.state.extendedMasterSecret { | ||
var sessionHash []byte | ||
sessionHash, err = c.handshakeCache.sessionHash(c.state.cipherSuite.hashFunc()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sessionHash, err := c.handshakeCache.sessionHash(c.state.cipherSuite.hashFunc())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually lint fails with it this way:
client_handlers.go:19:16: declaration of "err" shadows declaration at client_handlers.go:9 (govet)
sessionHash, err := c.handshakeCache.sessionHash(c.state.cipherSuite.hashFunc())
^
server_handlers.go:131:18: declaration of "err" shadows declaration at server_handlers.go:106 (govet)
sessionHash, err := c.handshakeCache.sessionHash(c.state.cipherSuite.hashFunc())
69e8f74
to
131d7d1
Compare
Sorry I realize a lot of issues I have with code... is actually mine -_- If we can bring down the stored state to the absolute minimum (less bugs and random things changing the world) this is an approve from me! I will go back and send PRs your way to make things better. |
5102206
to
4717c1b
Compare
5d14817
to
a0d67a3
Compare
@RyanGordon this LGTM! free to merge w/e you are happy with it and all the tests pass! After it lands I am going to do do a cleanup pass (I will submit it!). When reading the code during the review I saw a lot of things that I didn't like. Then I realized it was code I had written and never come back to fix up. |
a0d67a3
to
1852733
Compare
This change implements RFC7627 "Extended Master Secret" extension with optional enforcement by default (Fixes pion#86).
1852733
to
2f74fec
Compare
Description
This change implements RFC7627 "Extended Master Secret" extension with
optional enforcement by default
Reference issue
Fixes #86