Are you getting the most out of your AWS investment? Get your free AWS Well-Architected Assessment.

2021 Fillmore Street #1128

}

24/7 solutions

What do you do when your SSL Certificate expired?

I ran into this problem the other day. My SSL Certificate expired for my dev domain. I went to Network Solutions, snagged a new Certificate using my old Certificate Signing Request (CSR), and tried to import it into my keystore. In the past, I’ve always generated my private key and CSR, and then imported a […]

I ran into this problem the other day. My SSL Certificate expired for my dev domain. I went to Network Solutions, snagged a new Certificate using my old Certificate Signing Request (CSR), and tried to import it into my keystore.
In the past, I’ve always generated my private key and CSR, and then imported a new certificate along with the complete chain. Since the old expired certificate was still in the keystore, I thought it made sense to blow away the appropriate alias in the keystore with the following command.

1
%JAVA_HOME%/bin/keytool -delete -alias tomcat_ssl -keystore C:/Users/Joel/.keystore

Big mistake.
What I didn’t realize is when you blow away your alias in the keystore, it not only blows away the certificate, but the private key as well. Oops.
Luckily, I still had my private key. I was hopeful that I could just import this private key into my keystore. Strike 2!
The Java keytool does not allow you to import an existing private key. Crap. I didn’t want to go back to Network Solutions to generate a new certificate. That’s a pain. There has to be a way to get a private key into my keystore.
Luckily, there is. You can’t import a private key directly into your keystore, but you can merge a private-cert pair into an existing keystore if the private-cert pair is in PKCS12 format. How’s that for fun?
To start, you need to use openssl to generate a PKCS12 file from your pem file. The pem file needs to be a combination of first your private key followed by your crt file for the domain.

1
C:/cygwin/home/Joel/dev> cat openssl_dev.crt >> openssl_dev.pem

Next you need to run openssl with the -in parameter to generate the PKCS12 fle.

1
C:/cygwin/home/Joel/dev> openssl pkcs12 -export -in openssl_dev.pem  -out openssl_dev.p12

Now, with the PKCS12 file, you need to do a keystore merge with your existing keystore.

1
%JAVA_HOME%/bin/keytool -importkeystore -srckeystore openssl_dev.p12 -srcstoretype PKCS12 -destkeystore C:/Users/Joel/.keystore

After doing the merge, when you look into your keystore, you will see that this entry has been given an alias of 1.

1
%JAVA_HOME%/bin/keytool -list -v -keystore C:/Users/Joel/.keystore > dump.txt

You will want to change this alias to something usable,

1
%JAVA_HOME%/bin/keytool -changealias -alias 1 -destalias tomcat_ssl

Now, you will also want to import other portions of the certificate chain.

1
%JAVA_HOME%/bin/keytool -import -alias root -keystore C:/Users/Joel/.keystore -trustcacerts -file network_first_add_trust_second_carriage_return.pem

Now, when I start up my tomcat instance referencing my tomcat_ssl alias, I’m back in business!

Joel Garcia

Joel Garcia

Joel Garcia has been building AllCode since 2015. He’s an innovative, hands-on executive with a proven record of designing, developing, and operating Software-as-a-Service (SaaS), mobile, and desktop solutions. Joel has expertise in HealthTech, VoIP, and cloud-based solutions. Joel has experience scaling multiple start-ups for successful exits to IMS Health and Golden Gate Capital, as well as working at mature, industry-leading software companies. He’s held executive engineering positions in San Francisco at TidalWave, LittleCast, Self Health Network, LiveVox acquired by Golden Gate Capital, and Med-Vantage acquired by IMS Health.

Related Articles

How the AWS Well-Architected Tool Improves Your Environment

How the AWS Well-Architected Tool Improves Your Environment

The AWS Well-Architected Framework is a set of standards for best practices designed to maximize efficiency, stability, security, and resilience on the platform. These are some incredibly difficult standards to achieve and it is ideal to seek help from a third party to review the infrastructure. Amazon does provide additional tools for helping to verify that an environment does meet standards.

AWS Think Big for Small Business Program

AWS Think Big for Small Business Program

At the time of writing, AllCode recently entered AWS’ Think Big for Small Business Program, granting us better reach in the public sector. This article is meant to review what that means for our potential clients and how they can benefit from working with partners of the Think Big for Small Business Program.

AWS Financial Services

AWS Financial Services

While the Amazon Cloud at large is meant to be flexible in how it is applied, there are a number of services that are more directly tailored to specific industries. The financial industry for example has solutions set out to help them merge their usual operations with the benefits cloud technology can provide. It has provided many companies with the capability to adapt to new regulations and further optimize their existing services.While the Amazon Cloud at large is meant to be flexible in how it is applied, there are a number of services that are more directly tailored to specific industries. The financial industry for example has solutions set out to help them merge their usual operations with the benefits cloud technology can provide. It has provided many companies with the capability to adapt to new regulations and further optimize their existing services.