filmov
tv
Java programmatically create truststore and import certificates into it
Показать описание
In this video we are going to setup truststore and then load certificates in it programmatically.
Up till now we were manually generating truststore and then loading certs in it, doing it using code means that, instead of opening a command prompt or git bash or a terminal window then using keytool to generate a truststore and then importing all certificates one by one, we will simply use code to generate a truststore and then load all certs using a loop.
truststore will be generated in-memory we will then we will write it to disk.
Once it is saved to a location, we will then set that location in java system properties and then use the saved truststore to connect to the URL that is giving us the PKIX or SSL Handshake exception.
Now I will be creating the truststore and then storing it in temp directory, as once the connection is complete, I will then use java File class to delete the file on exit.
This approach is helpful if you want to simply add certs to a location and want all certs to be auto loaded when program runs, this way when a cert expires you can simply update the cert and trigger a redeploy.
We will use java system property to get the temp folder, java separator to automatically apply the correct path separator like forward or backslash depending on the OS the program is running and auto closable logic to automatically close the file writers once the truststore is written.
Channel #Rahul Random Learnings #RahulRandomLearnings #RahulRandom Learnings Opinion Disclaimer:
The views and opinions expressed here are my own and not the views of my employer.
The content uploaded on my channel is not intended to malign any religion, ethic group, club, organization, company, individual or anyone or anything.
Up till now we were manually generating truststore and then loading certs in it, doing it using code means that, instead of opening a command prompt or git bash or a terminal window then using keytool to generate a truststore and then importing all certificates one by one, we will simply use code to generate a truststore and then load all certs using a loop.
truststore will be generated in-memory we will then we will write it to disk.
Once it is saved to a location, we will then set that location in java system properties and then use the saved truststore to connect to the URL that is giving us the PKIX or SSL Handshake exception.
Now I will be creating the truststore and then storing it in temp directory, as once the connection is complete, I will then use java File class to delete the file on exit.
This approach is helpful if you want to simply add certs to a location and want all certs to be auto loaded when program runs, this way when a cert expires you can simply update the cert and trigger a redeploy.
We will use java system property to get the temp folder, java separator to automatically apply the correct path separator like forward or backslash depending on the OS the program is running and auto closable logic to automatically close the file writers once the truststore is written.
Channel #Rahul Random Learnings #RahulRandomLearnings #RahulRandom Learnings Opinion Disclaimer:
The views and opinions expressed here are my own and not the views of my employer.
The content uploaded on my channel is not intended to malign any religion, ethic group, club, organization, company, individual or anyone or anything.
Комментарии