Self signed certificate in certificate chain ошибка

I can run the selenium server with fresh rebooting of my Windows 7. However if I kill the server and start it again, I will get this error. Sometimes doing webdriver-manager update--ignore_ssl may fix the problem, but most of time it won’t fix. Any idea?

I am running it on Windows 7 x64.

C:\Users\...> webdriver-manager start --ignore_ssl
events.js:163
      throw er; // Unhandled 'error' event
      ^

Error: self signed certificate in certificate chain
    at TLSSocket.<anonymous> (_tls_wrap.js:1084:38)
    at emitNone (events.js:86:13)
    at TLSSocket.emit (events.js:188:7)
    at TLSSocket._finishInit (_tls_wrap.js:606:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:436:38)

asked Apr 3, 2017 at 21:24

zs2020's user avatar

Most of the time clearing cache and ignoring ssl during webdriver-manager update would solve the problem

npm cache clean
webdriver-manager update --ignore_ssl

In my case I resolved by updating webdriver manage locally in the project and starting standalone server

package.json

"scripts": {
    "webdrivermanager:update": "node node_modules/protractor/bin/webdriver-manager update --versions.standalone=3.2.0 --ignore_ssl",
    "webdrivermanager:clean": "node node_modules/protractor/bin/webdriver-manager clean",
    "install": "npm run webdrivermanager:clean && npm run webdrivermanager:update"
  }

protractor configuration file

seleniumServerJar: 'node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.2.0.jar',

npm install update your webdriver-manager first time and everytime you need just issue the command protractor protractor.conf.js

answered Apr 4, 2017 at 14:52

Surendra Jnawali's user avatar

Surendra JnawaliSurendra Jnawali

3,1905 gold badges28 silver badges44 bronze badges

we are running a remote Seleniumbox and want to run our test on it. The Certificate of the address of remote selenium is self signed by the company. I have the root certificates, but no idea to include them. I already tried to use options like npm ca, —ignore-ssl-strict, etc. also set capabilities, but nothing works. It looks like all these settings are for the connection between seleniumbox and test site. But I have the certificate problem earlier, when the build server want to connect to seleniumbox.

[08:59:28] I/update - chromedriver: chromedriver_88.0.4324.96.exe up to date
[08:59:28] I/launcher - Running 1 instances of WebDriver
[08:59:28] I/hosted - Using the selenium server at https://seleniumbox.xxxxxxxx.xx/wd/hub
[08:59:28] E/launcher - SELF_SIGNED_CERT_IN_CHAIN self signed certificate in certificate chain
[08:59:28] E/launcher - Error: SELF_SIGNED_CERT_IN_CHAIN self signed certificate in certificate chain
    at ClientRequest.<anonymous> (XXX\node_modules\selenium-webdriver\http\index.js:238:15)
    at ClientRequest.emit (events.js:223:5)
    at TLSSocket.socketErrorListener (_http_client.js:406:9)
    at TLSSocket.emit (events.js:223:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
From: Task: WebDriver.createSession()
    at Function.createSession (XXX\node_modules\selenium-webdriver\lib\webdriver.js:769:24)
    at Function.createSession (XXX\node_modules\selenium-webdriver\chrome.js:761:15)
    at createDriver (XXX\node_modules\selenium-webdriver\index.js:170:33)
    at Builder.build (XXX\node_modules\selenium-webdriver\index.js:626:16)
    at Hosted.getNewDriver (XXX\node_modules\protractor\built\driverProviders\driverProvider.js:53:33)
    at Runner.createBrowser (XXX\node_modules\protractor\built\runner.js:195:43)
    at XXX\node_modules\protractor\built\runner.js:339:29
    at _fulfilled (XXX\node_modules\protractor\node_modules\q\q.js:834:54)
    at XXX\node_modules\protractor\node_modules\q\q.js:863:30
    at Promise.promise.promiseDispatch (XXX\node_modules\protractor\node_modules\q\q.js:796:13)
[08:59:28] E/launcher - Process exited with error code 199

Anybody has an idea?

Thanks & Regards

asked Feb 16, 2021 at 8:09

NiBurhe's user avatar

8

you can turn off ssl validation as

npm config set strict-ssl false

But this is not recommended , instead add the root certificate to the certificate chain . To do so follow the below steps. When ever you want to add a different root create the corresponding cer file of that root and copy the content and add it at the end of your crt file.

Steps:

Save certificate:

open https://seleniumbox.xxxxxxxx.xx/wd/hub in chrome

click lock icon > click view certificate

click certification path > click root > Click view certificate

CLick details ,> Click copy to file > select base 64 cert.cer

save it as cert.cer

Npm config:

npm config set cafile «C:<pathto>\cert.cer»

Update:

Try using :

SET NODE_EXTRA_CA_CERTS="C:\<pathto>\cert.cer"

or

dissable tls all together (not recommended)

SET NODE_TLS_REJECT_UNAUTHORIZED=0

This will stop unauthorized tls from being rejected

answered Feb 16, 2021 at 8:34

PDHide's user avatar

PDHidePDHide

18.2k2 gold badges32 silver badges46 bronze badges

6

502 Bad Gateway
Certificate verification error for update.googleapis.com: self signed certificate in certificate chain (errno: 19, depth: 1)

The certificate is displayed as valid. There is an error in the code
127.0.0.1:1038: Invalid certificate, closing connection. Pass —ssl-insecure to disable validation.
127.0.0.1:1038: Certificate verification error for update.googleapis.com: self signed certificate in certificate chain (errno: 19, depth: 1)

seleniumwire_options = {
‘connection_timeout’: None,
‘proxy’: {
‘http’: ‘http://127.0.0.1:8080’,
‘https’: ‘http://127.0.0.1:8080’,
‘no_proxy’: ‘localhost, 127.0.0.1’
},
‘verify_ssl’: False
}

options = webdriver.ChromeOptions ()
options.add_argument (‘- ignore-certificate-errors’)

chrome = webdriver.Chrome (r ‘./ chromedriver.exe’, chrome_options = options, seleniumwire_options = seleniumwire_options)

I use burp for proxying.

My .npmrc looks like this:

registry=http://registry.npmjs.org/
strict-ssl=false
python=python2.7
ca=

It shouldn’t even try to open a SSL connection because I’m using HTTP for the registry.

npm install protractor gives an error when running node-gyp «Error: self signed certificate in certificate chain»:

> utf-8-validate@1.1.0 install .\node_modules\protractor\node_modules\selenium-webd
river\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild


.\node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modu
les\utf-8-validate>if not defined npm_config_node_gyp (node "C:\Program Files\iojs\node_modules\npm\bin\node-gyp-bin\\..
\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: self signed certificate in certificate chain
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1010:38)
gyp ERR! stack     at emitNone (events.js:67:13)
gyp ERR! stack     at TLSSocket.emit (events.js:166:7)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:566:8)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\iojs\\node.exe" "C:\\Program Files\\iojs\\node_modules\\npm\\node_modules\\node-gyp
\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd .\node_modules\protractor\node_modules\selenium-webdriver\node_modules
\ws\node_modules\utf-8-validate
gyp ERR! node -v v3.0.0
gyp ERR! node-gyp -v v2.0.2
gyp ERR! not ok

> bufferutil@1.1.0 install .\node_modules\protractor\node_modules\selenium-webdrive
r\node_modules\ws\node_modules\bufferutil
> node-gyp rebuild


.\node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modu
les\bufferutil>if not defined npm_config_node_gyp (node "C:\Program Files\iojs\node_modules\npm\bin\node-gyp-bin\\..\..\
node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: self signed certificate in certificate chain
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1010:38)
gyp ERR! stack     at emitNone (events.js:67:13)
gyp ERR! stack     at TLSSocket.emit (events.js:166:7)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:566:8)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\iojs\\node.exe" "C:\\Program Files\\iojs\\node_modules\\npm\\node_modules\\node-gyp
\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd .\node_modules\protractor\node_modules\selenium-webdriver\node_modules
\ws\node_modules\bufferutil
gyp ERR! node -v v3.0.0
gyp ERR! node-gyp -v v2.0.2
gyp ERR! not ok
npm WARN optional dep failed, continuing utf-8-validate@1.1.0
npm WARN optional dep failed, continuing bufferutil@1.1.0
protractor@2.1.0 node_modules\protractor
├── jasminewd@1.1.0
├── jasminewd2@0.0.5
├── html-entities@1.1.3
├── saucelabs@0.1.1
├── q@1.0.0
├── minijasminenode@1.1.1
├── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)
├── adm-zip@0.4.4
├── glob@3.2.11 (inherits@2.0.1, minimatch@0.3.0)
├── jasmine@2.3.1 (exit@0.1.2, jasmine-core@2.3.4)
├── source-map-support@0.2.10 (source-map@0.1.32)
├── accessibility-developer-tools@2.6.0
├── request@2.36.0 (qs@0.6.6, forever-agent@0.5.2, aws-sign2@0.5.0, oauth-sign@0.3.0, tunnel-agent@0.4.1, json-stringify
-safe@5.0.1, mime@1.2.11, node-uuid@1.4.3, form-data@0.1.4, http-signature@0.10.1, tough-cookie@2.0.0, hawk@1.0.0)
├── lodash@2.4.2
└── selenium-webdriver@2.45.1 (tmp@0.0.24, rimraf@2.4.2, xml2js@0.4.4, ws@0.7.2)
. > npm install protractor
-


> bufferutil@1.1.0 install .\node_modules\protractor\node_modules\selenium-webdrive
r\node_modules\ws\node_modules\bufferutil
> node-gyp rebuild


.\node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modu
les\bufferutil>if not defined npm_config_node_gyp (node "C:\Program Files\iojs\node_modules\npm\bin\node-gyp-bin\\..\..\
node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: self signed certificate in certificate chain
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1010:38)
gyp ERR! stack     at emitNone (events.js:67:13)
gyp ERR! stack     at TLSSocket.emit (events.js:166:7)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:566:8)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\iojs\\node.exe" "C:\\Program Files\\iojs\\node_modules\\npm\\node_modules\\node-gyp
\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd .\node_modules\protractor\node_modules\selenium-webdriver\node_modules
\ws\node_modules\bufferutil
gyp ERR! node -v v3.0.0
gyp ERR! node-gyp -v v2.0.2
gyp ERR! not ok

> utf-8-validate@1.1.0 install .\node_modules\protractor\node_modules\selenium-webd
river\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild


.\node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modu
les\utf-8-validate>if not defined npm_config_node_gyp (node "C:\Program Files\iojs\node_modules\npm\bin\node-gyp-bin\\..
\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: self signed certificate in certificate chain
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1010:38)
gyp ERR! stack     at emitNone (events.js:67:13)
gyp ERR! stack     at TLSSocket.emit (events.js:166:7)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:566:8)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\iojs\\node.exe" "C:\\Program Files\\iojs\\node_modules\\npm\\node_modules\\node-gyp
\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd .\node_modules\protractor\node_modules\selenium-webdriver\node_modules
\ws\node_modules\utf-8-validate
gyp ERR! node -v v3.0.0
gyp ERR! node-gyp -v v2.0.2
gyp ERR! not ok
npm WARN optional dep failed, continuing bufferutil@1.1.0
npm WARN optional dep failed, continuing utf-8-validate@1.1.0
protractor@2.1.0 node_modules\protractor
├── jasminewd@1.1.0
├── jasminewd2@0.0.5
├── html-entities@1.1.3
├── saucelabs@0.1.1
├── q@1.0.0
├── minijasminenode@1.1.1
├── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)
├── adm-zip@0.4.4
├── glob@3.2.11 (inherits@2.0.1, minimatch@0.3.0)
├── jasmine@2.3.1 (exit@0.1.2, jasmine-core@2.3.4)
├── accessibility-developer-tools@2.6.0
├── source-map-support@0.2.10 (source-map@0.1.32)
├── lodash@2.4.2
├── request@2.36.0 (forever-agent@0.5.2, aws-sign2@0.5.0, qs@0.6.6, oauth-sign@0.3.0, tunnel-agent@0.4.1, json-stringify
-safe@5.0.1, mime@1.2.11, node-uuid@1.4.3, form-data@0.1.4, http-signature@0.10.1, tough-cookie@2.0.0, hawk@1.0.0)
└── selenium-webdriver@2.45.1 (tmp@0.0.24, rimraf@2.4.2, xml2js@0.4.4, ws@0.7.2)
. > npm install protractornpm config set ca ""
. > npm config set ca ""
. > npm install protractor
|
> utf-8-validate@1.1.0 install .\node_modules\protractor\node_modules\selenium-webd
river\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild


.\node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modu
les\utf-8-validate>if not defined npm_config_node_gyp (node "C:\Program Files\iojs\node_modules\npm\bin\node-gyp-bin\\..
\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: self signed certificate in certificate chain
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1010:38)
gyp ERR! stack     at emitNone (events.js:67:13)
gyp ERR! stack     at TLSSocket.emit (events.js:166:7)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:566:8)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\iojs\\node.exe" "C:\\Program Files\\iojs\\node_modules\\npm\\node_modules\\node-gyp
\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd .\node_modules\protractor\node_modules\selenium-webdriver\node_modules
\ws\node_modules\utf-8-validate
gyp ERR! node -v v3.0.0
gyp ERR! node-gyp -v v2.0.2
gyp ERR! not ok

> bufferutil@1.1.0 install .\node_modules\protractor\node_modules\selenium-webdrive
r\node_modules\ws\node_modules\bufferutil
> node-gyp rebuild


.\node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modu
les\bufferutil>if not defined npm_config_node_gyp (node "C:\Program Files\iojs\node_modules\npm\bin\node-gyp-bin\\..\..\
node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node  rebuild )
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: self signed certificate in certificate chain
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1010:38)
gyp ERR! stack     at emitNone (events.js:67:13)
gyp ERR! stack     at TLSSocket.emit (events.js:166:7)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:566:8)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\iojs\\node.exe" "C:\\Program Files\\iojs\\node_modules\\npm\\node_modules\\node-gyp
\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd .\node_modules\protractor\node_modules\selenium-webdriver\node_modules
\ws\node_modules\bufferutil
gyp ERR! node -v v3.0.0
gyp ERR! node-gyp -v v2.0.2
gyp ERR! not ok
npm WARN optional dep failed, continuing utf-8-validate@1.1.0
npm WARN optional dep failed, continuing bufferutil@1.1.0
protractor@2.1.0 node_modules\protractor
├── jasminewd@1.1.0
├── jasminewd2@0.0.5
├── saucelabs@0.1.1
├── html-entities@1.1.3
├── q@1.0.0
├── minijasminenode@1.1.1
├── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)
├── adm-zip@0.4.4
├── jasmine@2.3.1 (exit@0.1.2, jasmine-core@2.3.4)
├── source-map-support@0.2.10 (source-map@0.1.32)
├── accessibility-developer-tools@2.6.0
├── lodash@2.4.2
├── glob@3.2.11 (inherits@2.0.1, minimatch@0.3.0)
├── request@2.36.0 (aws-sign2@0.5.0, qs@0.6.6, forever-agent@0.5.2, oauth-sign@0.3.0, tunnel-agent@0.4.1, json-stringify
-safe@5.0.1, mime@1.2.11, node-uuid@1.4.3, form-data@0.1.4, http-signature@0.10.1, tough-cookie@2.0.0, hawk@1.0.0)
└── selenium-webdriver@2.45.1 (tmp@0.0.24, rimraf@2.4.2, xml2js@0.4.4, ws@0.7.2)

How can I deal with the web application for which HTTPS is enabled with self-signed certificates? – This is a common scenario we face as testers in our test execution. A self-signed certificate is enough to establish a secure HTTPS connection, although browsers will complain that the certificate is self-signed and not trusted. However it is great for development and testing purposes. In this article, we are going to experiment working with ‘HTTPS’ web application.

What is Certificate?

When you visit a website whose web address starts with https, your browser communication with the site is encrypted to help ensure data privacy. Before starting the encrypted communication, the website will present browser with a certificate to identify itself. Browser will validate the website’s certificate by checking that the certificate that signed it is valid, and checking that the certificate that signed the parent certificate is valid and so forth up to a root certificate that is known to be valid( Usually called Certificate Hierarchy ).

Why there is going to be a Certificate Error?

If the certificate presented by server cannot be validated or if the encryption is not strong enough, browsers will stop the connection to the website and show you an error page with the message “Your connection is not secure”

This can happen in many scenarios,

  • Certificate does not come from a trusted source
  • The certificate will not be valid until date
  • The certificate expired on date
  • The issuer certificate is unknown and hence it is not trusted
  • The certificate is not trusted because it is self-signed
  • Given certificate is only valid for particular site name
  • Corrupted certificate store

Why we get this error in our Test Environment?

Certificates are costly and may not be used for test environments. Most of the times, to test web applications over https, self-signed certificates are used. And due to the fact that ‘self signed certificates are not trusted’ by browsers, we get the error in our test environment while executing test scripts.

How to handle this error in Selenium?

There are many different ways we can solve this problem and the solution depends on the browser.

Firefox Browser – Method 1:

You can set ‘accept_untrusted_certs‘ value in FirefoxProfile() option to True.

from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True

driver = webdriver.Firefox(firefox_profile=profile)
driver.get('https://url')
print(driver.title)
driver.close()

Firefox Browser – Method 2:

You could use DesiredCapabilities to set ‘acceptInsecureCerts‘ capability to True (Note: This should work for all browsers since it is a generic read/write capability)

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_capabilities = DesiredCapabilities.FIREFOX.copy()
desired_capabilities['acceptInsecureCerts'] = True

driver = webdriver.Firefox(capabilities=desired_capabilities)
driver.get('https://url')
print(driver.title)
driver.close()

Chrome Browser – Method 1:

You can add ‘–ignore-certificate-errors‘ and ‘–allow-running-insecure-content‘ arguments to Chrome Options().

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--allow-running-insecure-content')
options.add_argument('--ignore-certificate-errors')

driver = webdriver.Chrome(chrome_options=options)
driver.get('https://url')
print(driver.title)
driver.close()

Chrome Browser – Method 2:

You could use DesiredCapabilities to set ‘acceptInsecureCerts‘ capability to True (Note: This should work for all browsers since it is a generic read/write capability)

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_capabilities = DesiredCapabilities.CHROME.copy()
desired_capabilities['acceptInsecureCerts'] = True
driver = webdriver.Chrome(desired_capabilities=desired_capabilities)
driver.get('https://url')
print(driver.title)
driver.close()

Chrome Browser – Method 3:

This is also using DesiredCapabilities again; But we are going to use Options -> set_capability() method to set ‘acceptInsecureCerts‘ to True.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.set_capability("acceptInsecureCerts", True)

driver = webdriver.Chrome(chrome_options=options)
driver.get('https://url')
print(driver.title)
driver.close()

Please let us know your thoughts in comment section. Stay tuned for more knowledge sharing articles!!!

Понравилась статья? Поделить с друзьями:
  • Select action ошибка
  • Seiko ошибка e en 2031
  • Segway ошибка e027
  • Segway ninebot ошибка сетевого запроса
  • Sdi ошибка 422