Skip to content

ARTEMIS-5902 optimize authn cache key creation#6258

Open
jbertram wants to merge 1 commit intoapache:mainfrom
jbertram:ARTEMIS-5902
Open

ARTEMIS-5902 optimize authn cache key creation#6258
jbertram wants to merge 1 commit intoapache:mainfrom
jbertram:ARTEMIS-5902

Conversation

@jbertram
Copy link
Contributor

Eliminate unnecessary calls to j.s.MessageDigest#getInstance(String) as well as unnecessary bytes in hash.

Existing tests should suffice for validation.

Eliminate unnecessary calls to j.s.MessageDigest#getInstance(String) as
well as unnecessary bytes in hash.

Existing tests should suffice for validation.
return ByteUtil.bytesToHex(MessageDigest.getInstance("SHA-256").digest((username + password + CertificateUtil.getCertSubjectDN(connection)).getBytes(StandardCharsets.UTF_8)));
} catch (NoSuchAlgorithmException e) {
return (MessageDigest) SHA256.clone();
} catch (CloneNotSupportedException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of throwing here would it not make sense to try and get an instance via something like return MessageDigest.getInstance(digest.getAlgorithm()); and only throw if that fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, and that's exactly what org.apache.activemq.artemis.protocol.amqp.sasl.scram.ScramServerFunctionalityImpl#getDigest does. I think that's fair, but this optimization is the whole point of this change so I think I'll add some code to log once if this fails so we know the optimization isn't working. I'll also make this method protected and add a test to ensure it works as expected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging is a good addition. Given users want it to work and it can regardless of the clone support falling back and maybe losing some performance is acceptable vs not working at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants