Repository navigation
auth: pass auth switch data to plugins unmodified #1825
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,7 +54,10 @@ func init() { | |||||||||
| // 3. XOR(SHA256(password), SHA256(SHA256(SHA256(password)), scramble)) | ||||||||||
| func (p *cachingSha2PasswordPlugin) InitAuth(ctx context.Context, authData []byte, auth *AuthContext) ([]byte, error) { | ||||||||||
| p.state = cachingSha2Initial | ||||||||||
| return scrambleSHA256Password(authData, auth.Password()), nil | ||||||||||
| if len(authData) < 20 { | ||||||||||
|
Member
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.
Suggested change
|
||||||||||
| return nil, ErrMalformPkt | ||||||||||
| } | ||||||||||
| return scrambleSHA256Password(authData[:20], auth.Password()), nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // ContinuationAuth processes the server's response to our authentication attempt. | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,9 @@ import ( | |
| // while a method is running. Plugins should use it to cancel blocking work. | ||
| type AuthPlugin interface { | ||
| // InitAuth initializes the authentication process and returns the initial response. | ||
| // authData is the challenge data from the server. It must not be modified | ||
| // and must be copied if retained after the call. | ||
| // authData is the challenge data exactly as sent by the server, including | ||
| // any trailing NUL. It must not be modified and must be copied if retained | ||
| // after the call. | ||
|
Comment on lines
-22
to
+24
Member
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. Explaining the NUL byte here won't make sense to readers who aren't already aware of this issue. Please revert this change. |
||
| // auth is the snapshot for this exchange, shared with ContinuationAuth. | ||
| // A nil or empty response sends an empty authentication response. | ||
| // Plugins must check any transport requirements here before returning credentials. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -117,17 +117,18 @@ func (p *sha256PasswordPlugin) ContinuationAuth(ctx context.Context, packet, aut | |||||||||
| // encryptPassword encrypts the password using RSA-OAEP with SHA1 hash. | ||||||||||
| // | ||||||||||
| // The process: | ||||||||||
| // 1. XORs the password with the auth seed to prevent replay attacks | ||||||||||
| // 1. XORs the password with the 20-byte scramble to prevent replay attacks | ||||||||||
| // 2. Encrypts the XORed password using RSA-OAEP with SHA1 | ||||||||||
| // | ||||||||||
| // The encryption uses OAEP padding which is more secure than PKCS#1 v1.5 padding. | ||||||||||
| func encryptPassword(password string, seed []byte, pub *rsa.PublicKey) ([]byte, error) { | ||||||||||
| if pub == nil { | ||||||||||
| return nil, fmt.Errorf("public key is nil") | ||||||||||
| } | ||||||||||
| if len(seed) == 0 { | ||||||||||
| return nil, fmt.Errorf("%w: empty auth seed", ErrMalformPkt) | ||||||||||
| if len(seed) < 20 { | ||||||||||
|
Member
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.
Suggested change
|
||||||||||
| return nil, ErrMalformPkt | ||||||||||
| } | ||||||||||
| seed = seed[:20] | ||||||||||
|
|
||||||||||
| // Create the plaintext by XORing password with seed | ||||||||||
| plain := make([]byte, len(password)+1) | ||||||||||
|
|
||||||||||
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.
remove this too.