Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to initialize jenkins but get Error: unable to verify the first certificate #91

Open
aguskianto opened this issue Mar 24, 2020 · 2 comments

Comments

@aguskianto
Copy link

I am trying to connect to jenkins using:
var jenkins = require('jenkins')({ baseUrl: 'https://user:token@link', crumbIssuer: true });

But, I got:
Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1321:34)
at TLSSocket.emit (events.js:223:5)
at TLSSocket._finishInit (_tls_wrap.js:794:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:608:12) {
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
res: undefined
}

image

As you can see above. One thing for sure: jenkins server is using https. Is there a way to use token? And, does node-jenkins support https?

@silas
Copy link
Owner

silas commented Mar 25, 2020

node-jenkins uses the global https agent by default, so it will validate any certificate that the default node installation does.

You can 1) ensure that your installation has validate certificates for your node.js installation, 2) add your custom certificate using NODE_EXTRA_CA_CERTS, or 3) add a custom certificate using the https.request options or disable verification (not recommend): see #13 (comment)

I don't know how your certificates were generated or what version of node you're using, but updating to a later version of node might fix it as well.

@pro-sumer
Copy link

I have the same issue with a self-signed certificate and want to use rejectUnauthorized as suggested in #13:

const https = require('https')
const agent = new https.Agent()
const jenkins = require('jenkins')({ baseUrl: process.env.JENKINS_BASE_URL, promisify: true, rejectUnauthorized: false, agent: agent })

However:

node:internal/process/promises:225
          triggerUncaughtException(err, true /* fromPromise */);
          ^

Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1498:34)
    at TLSSocket.emit (node:events:376:20)
    at TLSSocket._finishInit (node:_tls_wrap:933:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:707:12) {
  code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}

What am I doing wrong?

(I'm not the owner of this Jenkins installation; I cannot change the certificate)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants