I am trying to configure Jenkins on Windows with a SLL certificate following these instructions. Instead of using a Digicert certificate, our IT administrator would like to generate a certificate using the Windows AD CS using the certificate snap-in of mmc. However we cannot figure out how to import the keytool generated csr certificate request into the certificate snap-in. If I use a certificate with a recreated certificate request in the mmc certificate store, the certificate is rejected with the following message:
keytool -importcert -alias jenkins -file "D:\Temp\jenkins\jenkins.pem" -keystore "D:\Temp\jenkins\jenkins.jks"
Enter keystore password:
keytool error: java.lang.Exception: Certificate reply does not contain public key for <jenkins>
Does anyone know how to create an SSL certificate from the Windows certificate store based on a java keytool created csr certificate request?
I was able to get Jenkins running with SSL and this is what I did.
On the Jenkins Master
In the Certificate Snap-in of mmc, navigate to Certificates (Local Computer) / Personal.
Right click Personal Folder and select All Tasks / Request New Certificate...
Confirm the next two Enrollment pages by clicking on Next.
Check a Webserver Active Directory Enrollment Policy.
A Warning Message shows below the Enrollment Policy
More information is required to enroll for this certificate. Click here to configure settings.
Click on it.
Fill out the Certificate Properties:
Subject name: Common name:
[the name of your jenkins server]
Alternative name: DNS: [the
name of your jenkins server]
Alternative name: DNS: [the full
name of your jenkins server including your domain]
Confirm the
page with OK and the following two pages.
Export the Certificate as PFX format
Right click on
certificate
All Tasks / Export...
Check: Yes, export the private key
Check Include all
certificates in the certification path if possible
Check:
Export all extended properties
Since we are exporting the
private key, we must provide a password
Check: Password and
enter your password and password confirmation
Pick a path for your PFX certificate and finish the export.
Rename the resulting .CER file into .PEM.
Create a java key store on the Jenkins server with
keytool -genkeypair -keysize 2048 -keyalg RSA -alias jenkins -keystore jenkins.jks
Answer the questions appropriate for your company and organisation.
Import the PFX certificate into the java keystore with
keytool -importkeystore -srckeystore jenkins.pfx -srcstoretype pkcs12 -destkeystore jenkins.jks -deststoretype JKS
Copy the jenkins.jks
to secrets directory where Jenkins is
installed (in my case C:\Program Files (x86)\Jenkins\secrets
).
Add the certificate to the Jenkins startup parameters:
-Djavax.net.ssl.trustStore=%JENKINS_HOME%\secrets\jenkins.jks
-Djavax.net.ssl.trustStorePassword=[your password for the java key store]
Restart the jenkins service
On the Jenkins Agent
Import the PEM certificate from above into the java keystore from the command line with administrator priviliges:
keytool -import -alias jenkins -keystore "C:\Program Files (x86)\Java\jre1.8.0_161\lib\security\cacerts" -file [your pem file]
Enter the password of the keystore (by
default changeit)
Trust this certificate? [no]: yes
Make sure your jenkins-slave.xml
in %JENKINS_HOME%
does not contain
-noCheckCertificate
in the arguments.
Restart the service jenkinsslave-D__Jenkins
.