[JAVA] What to do if you go offline due to SSL certificate error when running Jenkins on Mac

A note on what to do if you get an untrusted SSL certificate error (javax.net.ssl.SSLHandshakeException) in Java when trying to install Jenkins on MacOSX using homebrew

After the installation was completed, when I started it and tried to perform the initial settings, I was offline and could not install the plug-in at all, so when I looked at the log, I got an error like this.

Apr 28, 2018 12:40:10 AM hudson.model.UpdateCenter updateDefaultSite
warning: Upgrading Jenkins. Failed to update the default Update Site 'default'. Plugin upgrades may fail.
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
	at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509)
	at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
	at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
	at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
	at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
	at hudson.model.DownloadService.loadJSON(DownloadService.java:167)
	at hudson.model.UpdateSite.updateDirectlyNow(UpdateSite.java:190)
	at hudson.model.UpdateCenter.updateDefaultSite(UpdateCenter.java:2194)
	at jenkins.install.SetupWizard.init(SetupWizard.java:174)
	at jenkins.install.InstallState$InitialSecuritySetup.initializeState(InstallState.java:142)
	at jenkins.model.Jenkins.setInstallState(Jenkins.java:1033)
	at jenkins.install.InstallUtil.proceedToNextStateFrom(InstallUtil.java:97)
	at jenkins.install.InstallState$Unknown.initializeState(InstallState.java:75)
	at jenkins.model.Jenkins$17.run(Jenkins.java:3149)
	at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
	at jenkins.model.Jenkins$5.runTask(Jenkins.java:1062)
	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
	at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
	at sun.security.validator.Validator.validate(Validator.java:260)
	at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491)
	... 29 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
	at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
	at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
	... 35 more

The cause is that when the certificate is verified with java, it cannot be trusted, so it is said that the certificate should be added directly to the trusted certificate information of java, so add it according to the following flow.

1. Get a certificate

As of April 28, 2018, https://updates.jenkins.io/update-center.json It was okay if I put the certificate of, so access the site with chrome etc., display the certificate and download it.
(For the DL of the certificate, display the site in chrome, press "Protected communication" in the URL field and select "Certificate", then "Image part" of the displayed certificate Drag & Drop to a suitable folder and you should get "updates.jenkins.io.cer" etc.)

2. Register the certificate with keytool
cd `/usr/libexec/java_home`/jre/lib/security

sudo keytool -importcert -file [DL path of cert]/updates.jenkins.io.cer -keystore cacerts

At this time, you will be asked for the keystore password, so enter "change it". (Since it is the default setting, it is better to search for "java default keystore password")

3. Start jenkins

You should probably be able to access it now.

Recommended Posts

What to do if you go offline due to SSL certificate error when running Jenkins on Mac
What to do if you get a port error when docker-compose up on Mac
What to do if you get an error when you hit Heroku logs
What to do if you get an error on heroku rake db: migrate
What to do if you get an "A server is already running." Error when you try to start the rails server
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
What to do if you get a DISPLAY error in gym.render ()
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if you install Ubuntu
What to do if you get an error during rails db: reset
[Composer] [Laravel] What to do if you cannot install due to insufficient memory
What to do if you get an uninitialized constant Likes Controller error
What to do if an error occurs when nokogiri enters when bundle install
no space left on device What to do if an error occurs
What to do if you get a MiniMagick vulnerability alert on GitHub
What to do if you get the error Too long with no output (exceeded 10m0s) on CircleCI
What to do if you push incorrect information
What do you use when converting to String?
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do if you get the error message unrecognized selector send to instance "***"
[Grails] Error occurred running What to do when the Grails CLI does not start
What to do if you have installed Java for OS X on macOS
[Ubuntu] What to do when MongoDB cannot be started due to a SocketException error
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
What to do if you get a wrong number of arguments error in binding.pry
What to do if TextToSpeech doesn't work on Android 11
What to do if you accidentally create a model
What to do when a null byte error occurs
What to do if an ActionController :: UnknownFormat error occurs
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
What to see when IntelliJ doesn't start on Mac
What to do if you get the error Couldn't find Item without an ID
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
What to do if you enable UFW on Ubuntu VM on GCP and you can't connect to SSH
What to do if you don't see the test code error message in the terminal console
[Rails] What to do if you can't get an error message with the errors method
What to do if you get a "302" error in your controller unit test code in Rails
What to do if you get an error in Basic authentication during Rails test code
What to do when you launch an application with rails
What to do if audio is not available on discordrb
# What to do if you accidentally do rails db: migrate: drop
What to do if mysql2 gets a bundle install error
What to do if you can't use the rails command
Notes on what to do if Ubuntu 20.04 installation on Virtual box 6.1 (Windows10) fails with "Error 5 Input / output error"
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if you get an [An HTTP request took too long to complete.] Error in Docker.
What to do if you get "Changes not staged for commit:" when you git status after git add.
What to do if an error occurs when doing npm install axios in React + Typescript project
How to uninstall if you have updated to Java 9 on your Mac
What to do if you get angry with OpenSSL with pyenv install
What to do when you become a Problem During Content Assist
What to do when you run into a docker-compose node_modules problem
What to do if you forget the root password in CentOS7
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
[Rails] What to do if you can't get parameters with form_with
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
What to do if you get Application with name appName is already registered. When you try to start GlassFish