Closed SalusaSecondus closed 1 year ago
I'm not sure if it's a good idea to support or advocate this. Java's serialization mechanism is not the most suitable approach for serialization and it's best for customers to use more standard crypto formats like ASN1 encodings for such requirements. Also, not all providers need to implement a meaningful implementation for serialization; for example, SunPKCS11 provider that allows applications use keys backed by HSM does not (and cannot provide) meaningful implementation.
The problem with supporting this is it's maintenance can be become a hassle in future and it's best to push customers to avoid using this and rely on more standard formats.
@amirhosv I completely agree that people shouldn't serialize keys in this way. However, it is a way in which ACCP differs from the providers bundled with the JDK. The JDK's tests assume that keys are serializable (and so fail for meaningless reasons). Because this solution is built off of existing standardized encodings, the ongoing maintenance cost should be minimal.
So, fixing this makes it so that ACCP is even more of a transparent drop in replacement than it was before.
@amirhosv I completely agree that people shouldn't serialize keys in this way. However, it is a way in which ACCP differs from the providers bundled with the JDK. The JDK's tests assume that keys are serializable (and so fail for meaningless reasons). Because this solution is built off of existing standardized encodings, the ongoing maintenance cost should be minimal.
So, fixing this makes it so that ACCP is even more of a transparent drop in replacement than it was before.
Could you share the tests that are failing in JDK?
Hey @SalusaSecondus, just wanted to give a little more context here. We're trying to get a better understanding of what the use case is for this. We aren't necessarily opposed to bringing it in; as you noted, it shouldn't add a lot of ongoing maintenance. However, a tenet of ACCP is that it is opinionated and I see from the correspondence that both you and @amirhosv are of the opinion that people should not serialize keys in this way. As such, I would expect that the justification for this should outweigh the enablement of what both of you describe as an anti-pattern (my paraphrasing). So, we're just wondering if you could share more about the motivation and use case so we can better understand what the problem is with the current solution.
The failing test is here: https://github.com/openjdk/jdk/blob/master/test/jdk/javax/xml/crypto/dsig/GenerationTests.java#L464-L468
While this is a minor issue, getting patches into the JDK is orders of magnitude harder than getting them into ACCP. Neither do I believe that making keys serializable in ACCP will encourage the anti-pattern. If people are already doing the bad thing, they'll just blame ACCP for not being correct and thus won't use ACCP (rather than fixing things). If they aren't doing the bad thing, then better matching the JCA specification won't break things either.
Supporting serialization makes it easier and more reliable for ACCP to be a drop-in transparent replacement. Every friction point makes it harder to get people to adopt ACCP.
It sounds like merging this PR would unblock execution of JDK's JCE tests against ACCP, which would provide useful data on where we stand in terms of compatibility with the default JCE provider(s). Assuming that the maintenance cost of EvpKey's serialization format through time is low (which I agree that it is very likely to be given PKCS8/x509 formats' stability), I'm OK with merging this change.
Description of changes:
Java specifies that implementations of Key are Serializable. Currently ACCP does not allow its keys to be serialized due to the difficulties in handling pointers into native memory and fixing them up while still letting them be
final
. This change safely serializes and deserializes instances ofEvpKey
by using a secondary helper class. A code comment explaining how this works is duplicated below.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.