-
Notifications
You must be signed in to change notification settings - Fork 3
crypto/tls: make checkForResumption side-effect free #3
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
Open
SparrowLii
wants to merge
1
commit into
MabinGo:master
Choose a base branch
from
SparrowLii:0727-tls
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -357,26 +357,26 @@ func (hs *serverHandshakeState) checkForResumption() bool { | |
| if plaintext == nil { | ||
| return false | ||
| } | ||
| hs.sessionState = &sessionState{usedOldKey: usedOldKey} | ||
| ok := hs.sessionState.unmarshal(plaintext) | ||
| clientSessionState := &sessionState{usedOldKey: usedOldKey} | ||
| ok := clientSessionState.unmarshal(plaintext) | ||
| if !ok { | ||
| return false | ||
| } | ||
|
|
||
| createdAt := time.Unix(int64(hs.sessionState.createdAt), 0) | ||
| createdAt := time.Unix(int64(clientSessionState.createdAt), 0) | ||
| if c.config.time().Sub(createdAt) > maxSessionTicketLifetime { | ||
| return false | ||
| } | ||
|
|
||
| // Never resume a session for a different TLS version. | ||
| if c.vers != hs.sessionState.vers { | ||
| if c.vers != clientSessionState.vers { | ||
| return false | ||
| } | ||
|
|
||
| cipherSuiteOk := false | ||
| // Check that the client is still offering the ciphersuite in the session. | ||
| for _, id := range hs.clientHello.cipherSuites { | ||
| if id == hs.sessionState.cipherSuite { | ||
| if id == clientSessionState.cipherSuite { | ||
| cipherSuiteOk = true | ||
| break | ||
| } | ||
|
|
@@ -385,14 +385,7 @@ func (hs *serverHandshakeState) checkForResumption() bool { | |
| return false | ||
| } | ||
|
|
||
| // Check that we also support the ciphersuite from the session. | ||
| hs.suite = selectCipherSuite([]uint16{hs.sessionState.cipherSuite}, | ||
| c.config.cipherSuites(), hs.cipherSuiteOk) | ||
| if hs.suite == nil { | ||
| return false | ||
| } | ||
|
|
||
| sessionHasClientCerts := len(hs.sessionState.certificates) != 0 | ||
| sessionHasClientCerts := len(clientSessionState.certificates) != 0 | ||
| needClientCerts := requiresClientCert(c.config.ClientAuth) | ||
| if needClientCerts && !sessionHasClientCerts { | ||
| return false | ||
|
|
@@ -401,6 +394,15 @@ func (hs *serverHandshakeState) checkForResumption() bool { | |
| return false | ||
| } | ||
|
|
||
| // Check that we also support the ciphersuite from the session. | ||
| hs.suite = selectCipherSuite([]uint16{clientSessionState.cipherSuite}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 看起来似乎还是存在hs.suite被赋值,但是最终返回false的情况
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这种情况下只可能是suite==nil,然后返回false,表示没有找到合适的加解密工具版本。suite之前就是nil,没有变化 |
||
| c.config.cipherSuites(), hs.cipherSuiteOk) | ||
| if hs.suite == nil { | ||
| return false | ||
| } | ||
|
|
||
| hs.sessionState = clientSessionState | ||
|
|
||
| return true | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这里改动代码顺序有影响吗?
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.
有影响,这样做避免了给hs.suite赋值以后,之后的函数语句又返回了false结果,导致suite维护了一个无用的值。保持了函数的side-effect free。