phax / as2-lib

A generic Java AS2 library, servlet and server
107 stars 43 forks source link

Possibility to initialize CertificateFactory with keystore as InputStream or byte[] #110

Closed yaskovdev closed 3 years ago

yaskovdev commented 4 years ago

I am using your library with Spring Boot application. Everything works fine, but there is a small issue with the CertificateFactory initialization. Current implementation of CertificateFactory can only be initialized using the filename of my keystore (via passing the filename as the ATTR_FILENAME value to the CertificateFactory#initDynamicComponent method).

This causes issues when the keystore file resides not in the filesystem of the OS where I run my AS2 server, but is located inside the Spring Boot JAR file. This is because Spring cannot resolve the proper filename for a file located inside the JAR, it will try to find the file in the filesystem and fail (details here).

Please add possibility to initialize CertificateFactory not with the filename of the keystore, but with the InputStream (or byte[]) of the keystore. I can see that AS2Client already provides such possibility (see AS2ClientSettings#setKeyStore(IKeyStoreType, byte[], String) method). Unfortunately I was not able to find such possibility for AS2 server.

Thank you.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

phax commented 3 years ago

Sorry for the delay, but I think here's a solution for you (should work with 4.6.3):

  1. Create a custom base class of CertificateFactory
  2. On init, ensure that no filename is present
  3. After loading you have an empty keystore - now call load (new ByteArrayInputStream (bytes), "password".toCharArray ())

See e.g. the demo class in the previouse commit - untested but should work

yaskovdev commented 3 years ago

@phax, I have tried the approach you suggested, it works very well. Thank you for the great library.

Not sure what to do with the issue. It most likely can be just closed, cannot it?

phax commented 3 years ago

Thanks for verifying it :) Happy messaging