-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add equals/hashcode for Destination #341
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.
My comments are also valid for resolveKeyStoreHashCode
.
} | ||
} | ||
catch( final Exception e ) { | ||
log.debug("Error while resolving certificates from KeyStore", e); |
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 will only throw when a keyStore is not initialized. The first thing in resolveCertificatesOnly
should be filtering for un-initialized keystores. Or maybe in the destination itself.
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 is no method on
KeyStore
to check for "is-loaded" unfortunately. - The existing API and behavior assumes the
KeyStore
inkeyStore
andtrustStore
fields are already loaded. There is no "lazy loading" or sth like that in already initializedDestination
/HttpClient
objects. - I want to avoid additional logic within
DefaultHttpDestination
class or its super classes as far as reasonably possible, this is why I put all potential logic into this helper comparator util class.
...rc/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationKeyStoreComparator.java
Show resolved
Hide resolved
if( !ks.isCertificateEntry(alias) ) { | ||
return new Certificate[0]; | ||
} | ||
out.add(ks.getCertificate(alias)); |
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.
What happens if a certificate is followed by "not a certificate"? Should "not a certificate" rather be ignored instead?
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.
I didn't want to mix behavior:
As soon as a non-certificate based entry occurs, the logic falls back to current main
behavior, i.e. ignore everything.
…code' into destination-keystore-equals-hashcode
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.
I hope those destinations are supposed to be equal:
final KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(null);
keyStore.setCertificateEntry("a", cert);
Destination dest = DefaultHttpDestination.builder("https://example.com").keyStore(keyStore).build();
final KeyStore keyStore2 = KeyStore.getInstance("JKS");
keyStore2.load(null);
keyStore2.setCertificateEntry("b", cert);
Destination dest2 = DefaultHttpDestination.builder("https://example.com").keyStore(keyStore2).build();
assertThat(dest).isEqualTo(dest2);
Otherwise LGTM
I think this is fine, currently the aliases don't matter AFAIK. I think it wouldn't hurt to also compare the aliases, they should always be equal as well in our usage, but not super required I guess.. |
Good find, @CharlesDuboisSAP. I haven't noticed that I removed the alias comparison :/ @MatKuhr is right, the aliases are not important at runtime. However not comparing them might be add to the confusion 🤔 On the other hand adding new logic now to compare Therefore I'll leave it as is. |
Backlog item: https://github.com/SAP/cloud-sdk-java-backlog/issues/403
Context
keyStore
andtrustStore
properties; both of Java typeKeyStore
. Useful in mTLS scenarios or when having a custom root certificate for TLS/SSL.KeyStore
API does not offer a custom implementation forequals
andhashCode
. This is why we exclude it from evaluation in theDefaultHttpDestination
class.hashCode
to isolate destination-related cache entries, e.g. for resolving storedHttpClient
instances.Currently on
main
.Destinations are evaluated as equal with same hash-code:
KeyStore
orTrustStore
KeyStore
mixedTrustStore
With this PR
Destinations are evaluated as equal with same hash-code:
AssignedKeyStore
orTrustStore
Destination1(name=foo, staticHeaders={sap-client:100}, keyStore={fizz})Destination2(name=foo, staticHeaders={sap-client:100})AssignedKeyStore
mixedTrustStore
Destination1(name=foo, staticHeaders={sap-client:100}, keyStore={fizz})Destination2(name=foo, staticHeaders={sap-client:100}, trustStore={buzz})Limitation
This behavior change only applies to
KeyStore
instances that have certificate based entries only.E.g. if a
KeyStore
with only a secret-key would be added - it will be ignored from equals/hashCode, i.e. the previous behavior ofmain
applies again.