Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to create JWT key, Invalid keystore format

Brad59
Giga Guru

I have followed a variety of guides and knowledge articles and have created lots of different .jks and .keystore files. However, I always receive the below error when a attempting to create a JWT Key based off of the certificate that I upload.

The end goal is to authenticate via JWT to another system. This guide indicates that should be possible. Set up OAuth provider with JWT Bearer grant type | ServiceNow Docs

This KB shows it is as easy as just creating a generic keystore file but I need to incorporate the third party RSA key: oAuth JWT Bearer Grant Type Integration Setup - Support and Troubleshooting (servicenow.com)

I was provided an RSA private key by the other system and have to jump through hoops with openssl and keytool to incorporate the RSA key I was provided into the keystore/jks file. I am nearly certain that the hoops I am jumping through have something to do with the error I am seeing in ServiceNow on JWT Key creation.

The general method I am following is:
1. Create keystore file to be overwritten:
keytool -keystore lmskeystore.keystore -genkey -alias lmsalias -keyalg RSA

2. Generate a public certificate from the key you have:
openssl req -new -x509 -key lmsKey.pem -out publicCert.cer -days 365

3. Generate a pkcs12 key from the public and private certs
openssl pkcs12 -export -out publicprivate.p12 -inkey lmsKey.pem -in publicCert.cer

4. Import the pkcs12 certificate into the dumby keystore file from step 1
keytool -importkeystore -deststorepass <keystorepass> -destkeystore lmskeystore.keystore -srckeystore publicprivate.p12 -srcstoretype PKCS12 -srcstorepass <p12pass>

find_real_file.png

1 ACCEPTED SOLUTION

Brad59
Giga Guru

I fixed it by generating my jks file using the 3 commands listed in this blog post: Running a GitHub bot from SN (servicenow.com)

View solution in original post

3 REPLIES 3

Brad59
Giga Guru

 I disabled all the validation business rules on the JWT Provider table and I'm trying to force it to work currently. I plan to update this depending on how it goes. 

Brad59
Giga Guru

I fixed it by generating my jks file using the 3 commands listed in this blog post: Running a GitHub bot from SN (servicenow.com)

Luis R
Tera Contributor

did  you solve it? i was trying to solve it but it seems that my issue is due to i have a EC Private Key, can you help me ?