-
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
Open
mingdaoy
wants to merge
12
commits into
apache:trunk
Choose a base branch
from
mingdaoy:KAFKA-17014-ScramFormatter
base: trunk
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
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e5823b7
KAFKA-17014: ScramFormatter to use char[] for password handling
mingdaoy e602d28
Merge branch 'apache:trunk' into KAFKA-17014-ScramFormatter
mingdaoy 8ebde57
Merge branch 'apache:trunk' into KAFKA-17014-ScramFormatter
mingdaoy 4581b72
MINOR: Optimize password handling in ScramSaslClient
mingdaoy 4838862
MINOR: Update prepareScramCredentials to use hmacChars for HMAC handling
mingdaoy 1dc9d9a
MINOR: Update ScramParser to use char[] for password handling
mingdaoy e82c3ce
Merge branch 'trunk' into KAFKA-17014-ScramFormatter
mingdaoy 9b3ca17
Merge branch 'apache:trunk' into KAFKA-17014-ScramFormatter
mingdaoy 27c9753
Merge branch 'apache:trunk' into KAFKA-17014-ScramFormatter
mingdaoy cb482d0
Merge branch 'apache:trunk' into KAFKA-17014-ScramFormatter
mingdaoy fda74a7
Merge branch 'apache:trunk' into KAFKA-17014-ScramFormatter
mingdaoy 9e3b916
Merge branch 'apache:trunk' into KAFKA-17014-ScramFormatter
mingdaoy 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
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
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
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
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
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
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 |
---|---|---|
|
@@ -100,13 +100,13 @@ class DelegationTokenManager(val config: KafkaConfig, | |
} | ||
|
||
/** | ||
* @param hmacString | ||
* @param hmacChars | ||
*/ | ||
private def prepareScramCredentials(hmacString: String) : Map[String, ScramCredential] = { | ||
private def prepareScramCredentials(hmacChars: Array[Char]) : Map[String, ScramCredential] = { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. See |
||
} | ||
|
||
for (mechanism <- ScramMechanism.values) | ||
|
@@ -119,8 +119,8 @@ class DelegationTokenManager(val config: KafkaConfig, | |
* @param token | ||
*/ | ||
def updateToken(token: DelegationToken): Unit = { | ||
val hmacString = token.hmacAsBase64String | ||
val scramCredentialMap = prepareScramCredentials(hmacString) | ||
val hmacChars = token.hmacAsBase64String.toCharArray | ||
val scramCredentialMap = prepareScramCredentials(hmacChars) | ||
tokenCache.updateCache(token, scramCredentialMap.asJava) | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -74,22 +74,22 @@ static final class PerMechanismData { | |
private final String configuredName; | ||
private final Optional<byte[]> configuredSalt; | ||
private final OptionalInt configuredIterations; | ||
private final Optional<String> configuredPasswordString; | ||
private final Optional<char[]> configuredPassword; | ||
private final Optional<byte[]> configuredSaltedPassword; | ||
|
||
PerMechanismData( | ||
ScramMechanism mechanism, | ||
String configuredName, | ||
Optional<byte[]> configuredSalt, | ||
OptionalInt configuredIterations, | ||
Optional<String> configuredPasswordString, | ||
Optional<char[]> configuredPassword, | ||
Optional<byte[]> configuredSaltedPassword | ||
) { | ||
this.mechanism = mechanism; | ||
this.configuredName = configuredName; | ||
this.configuredSalt = configuredSalt; | ||
this.configuredIterations = configuredIterations; | ||
this.configuredPasswordString = configuredPasswordString; | ||
this.configuredPassword = configuredPassword; | ||
this.configuredSaltedPassword = configuredSaltedPassword; | ||
} | ||
|
||
|
@@ -139,14 +139,14 @@ static final class PerMechanismData { | |
throw new FormatterException("You must supply 'salt' with 'saltedpassword' to add-scram"); | ||
} | ||
try { | ||
this.configuredPasswordString = Optional.empty(); | ||
this.configuredPassword = Optional.empty(); | ||
this.configuredSaltedPassword = Optional.of(Base64.getDecoder().decode(saltedPasswordString)); | ||
} catch (IllegalArgumentException e) { | ||
throw new FormatterException("Failed to decode given saltedPassword: " + | ||
saltedPasswordString, e); | ||
} | ||
} else { | ||
this.configuredPasswordString = Optional.of(passwordString); | ||
this.configuredPassword = Optional.of(passwordString.toCharArray()); | ||
this.configuredSaltedPassword = Optional.empty(); | ||
} | ||
if (!components.isEmpty()) { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. @szetszwo Thanks for the review! |
||
.orElseThrow(() -> new IllegalStateException("configuredPassword is missing")), | ||
salt, | ||
iterations); | ||
} | ||
|
@@ -209,7 +210,8 @@ public boolean equals(Object o) { | |
Arrays.equals(configuredSalt.orElse(null), | ||
other.configuredSalt.orElse(null)) && | ||
configuredIterations.equals(other.configuredIterations) && | ||
configuredPasswordString.equals(other.configuredPasswordString) && | ||
Arrays.equals(configuredPassword.orElse(null), | ||
other.configuredPassword.orElse(null)) && | ||
Arrays.equals(configuredSaltedPassword.orElse(null), | ||
other.configuredSaltedPassword.orElse(null)); | ||
} | ||
|
@@ -220,7 +222,7 @@ public int hashCode() { | |
configuredName, | ||
configuredSalt, | ||
configuredIterations, | ||
configuredPasswordString, | ||
configuredPassword, | ||
configuredSaltedPassword); | ||
} | ||
|
||
|
@@ -231,7 +233,7 @@ public String toString() { | |
", configuredName=" + configuredName + | ||
", configuredSalt=" + configuredSalt.map(Arrays::toString) + | ||
", configuredIterations=" + configuredIterations + | ||
", configuredPasswordString=" + configuredPasswordString + | ||
", configuredPassword=" + configuredPassword + | ||
", configuredSaltedPassword=" + configuredSaltedPassword.map(Arrays::toString) + | ||
")"; | ||
} | ||
|
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
Oops, something went wrong.
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.
password