-
Notifications
You must be signed in to change notification settings - Fork 14.3k
KAFKA-17014: ScramFormatter should not use String for password #19082
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: trunk
Are you sure you want to change the base?
Conversation
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.
@mingdaoy , thanks a lot for working on this! The change looks good. Just have a few questions/suggestions.
BTW, I am not a Kafka committer. We need to find a Kafka committer reviewing this.
@@ -190,7 +190,7 @@ private void setState(State state) { | |||
|
|||
private ClientFinalMessage handleServerFirstMessage(char[] password) throws SaslException { | |||
try { | |||
byte[] passwordBytes = ScramFormatter.normalize(new String(password)); | |||
byte[] passwordBytes = ScramFormatter.normalize(new String(password).toCharArray()); |
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.
Why not simply passing the password as below?
byte[] passwordBytes = ScramFormatter.normalize(password);
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.
@@ -106,7 +106,7 @@ class DelegationTokenManager(val config: KafkaConfig, | |||
val scramCredentialMap = mutable.Map[String, ScramCredential]() | |||
|
|||
def scramCredential(mechanism: ScramMechanism): ScramCredential = { | |||
new ScramFormatter(mechanism).generateCredential(hmacString, mechanism.minIterations) | |||
new ScramFormatter(mechanism).generateCredential(hmacString.toCharArray, mechanism.minIterations) |
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.
It would be better if we change hmacString
to not using String.
@@ -173,7 +173,9 @@ byte[] saltedPassword(byte[] salt, int iterations) throws Exception { | |||
return configuredSaltedPassword.get(); | |||
} | |||
return new ScramFormatter(mechanism).saltedPassword( | |||
configuredPasswordString.get(), | |||
configuredPasswordString |
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.
Similarly, it would be better if we change configuredPasswordString
to not using String.
@@ -173,7 +173,8 @@ byte[] saltedPassword(byte[] salt, int iterations) throws Exception { | |||
return configuredSaltedPassword.get(); | |||
} | |||
return new ScramFormatter(mechanism).saltedPassword( | |||
configuredPasswordString.get(), | |||
configuredPassword |
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.
@szetszwo Thanks for the review!
val scramCredentialMap = mutable.Map[String, ScramCredential]() | ||
|
||
def scramCredential(mechanism: ScramMechanism): ScramCredential = { | ||
new ScramFormatter(mechanism).generateCredential(hmacString, mechanism.minIterations) | ||
new ScramFormatter(mechanism).generateCredential(hmacChars, mechanism.minIterations) |
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.
See hmacChars
@@ -190,7 +190,7 @@ private void setState(State state) { | |||
|
|||
private ClientFinalMessage handleServerFirstMessage(char[] password) throws SaslException { | |||
try { | |||
byte[] passwordBytes = ScramFormatter.normalize(new String(password)); | |||
byte[] passwordBytes = ScramFormatter.normalize(password); |
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.
password
https://issues.apache.org/jira/browse/KAFKA-17014
Update
saltedPassword
,generateCredential
, andnormalize
to usechar[]
for password handlingScramParserTest:
