wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 254 forks source link

Issue loading SSL cert #262

Open Qwerty3210 opened 3 years ago

Qwerty3210 commented 3 years ago

Open initiating a browser on certain devices with the following code:

from seleniumwire import webdriver  # Import from seleniumwire

# Create a new instance of the Chrome driver
driver = webdriver.Chrome()

# Go to the Google home page
driver.get('https://www.google.com')

I receive the following error:

Traceback (most recent call last):
  File "browser_test.py", line 4, in <module>
    driver = webdriver.Chrome()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\seleniumwire\webdriver.py", line 87, in __init__
    options=seleniumwire_options
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\seleniumwire\backend.py", line 35, in create
    proxy = MitmProxy(addr, port, options)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\seleniumwire\server.py", line 52, in __init__
    self._master.server = ProxyServer(ProxyConfig(mitmproxy_opts))
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\seleniumwire\thirdparty\mitmproxy\server\config.py", line 40, in __init__
    self.configure(options, set(options.keys()))
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\seleniumwire\thirdparty\mitmproxy\server\config.py", line 69, in configure
    passphrase
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\seleniumwire\thirdparty\mitmproxy\certs.py", line 208, in from_store
    raw)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\OpenSSL\crypto.py", line 1951, in load_certificate
    _raise_current_error()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\OpenSSL\_util.py", line 57, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.crypto.Error: [('PEM routines', 'get_header_and_data', 'bad end line')]

I have checked the endlines of both the cert and the private key they seem to be valid:

-----END CERTIFICATE-----
-----END PRIVATE KEY-----

I have also packaged the module with pyinstaller on a device which the module works on however I still get the issue on other devices thus I don't believe it to be an environment error. The issue is currently occurring on all Windows 2019 data centre servers that I have tried.

wkeeling commented 3 years ago

Thanks for raising this.

Did you package the app on the same type of OS that you're deploying on? i.e. you're seeing the error on Windows 2019, but did you package the app on Windows? I'm just wondering whether the error could be line ending related.

Qwerty3210 commented 3 years ago

Thanks for raising this.

Did you package the app on the same type of OS that you're deploying on? i.e. you're seeing the error on Windows 2019, but did you package the app on Windows? I'm just wondering whether the error could be line ending related.

Yeah, they're both the same OS version (Windows 10 latest), the issue also occurs running the script unpackaged.

wkeeling commented 3 years ago

Thanks. Can you let me know what version of pyOpenSSL is being used? You can find that with:

pip show pyOpenSSL
Qwerty3210 commented 3 years ago

Thanks. Can you let me know what version of pyOpenSSL is being used? You can find that with:

pip show pyOpenSSL

Version: 20.0.1

wkeeling commented 3 years ago

I've not been able to reproduce this locally yet on Windows 10. My steps to reproduce were:

driver = webdriver.Chrome() driver.get('https://google.com/')

for request in driver.requests: print(request)

driver.quit()


I'm still wondering whether the error you're seeing is due to some kind of dependency version issue. My virtual environment looks like this:

blinker==1.4 certifi==2020.12.5 cffi==1.14.5 cryptography==3.4.7 h11==0.12.0 h2==4.0.0 hpack==4.0.0 hyperframe==6.0.0 kaitaistruct==0.9 pyasn1==0.4.8 pycparser==2.20 pydivert==2.1.0 pyOpenSSL==20.0.1 pyparsing==2.4.7 PySocks==1.7.1 selenium==3.141.0 selenium-wire==4.2.3 six==1.15.0 urllib3==1.26.4 wsproto==1.0.0



Are you able to confirm whether your versions of the above dependencies are the same (pyOpenSSL obviously already confirmed)?
Qwerty3210 commented 3 years ago

I've not been able to reproduce this locally yet on Windows 10. My steps to reproduce were:

  • Create a fresh virtual environment
  • pip install selenium-wire
  • Delete the existing .seleniumwire folder from my home directory
  • Run the following script
import logging
logging.basicConfig(level=logging.INFO)
from seleniumwire import webdriver

driver = webdriver.Chrome()
driver.get('https://google.com/')

for request in driver.requests:
    print(request)

driver.quit()

I'm still wondering whether the error you're seeing is due to some kind of dependency version issue. My virtual environment looks like this:

blinker==1.4
certifi==2020.12.5
cffi==1.14.5
cryptography==3.4.7
h11==0.12.0
h2==4.0.0
hpack==4.0.0
hyperframe==6.0.0
kaitaistruct==0.9
pyasn1==0.4.8
pycparser==2.20
pydivert==2.1.0
pyOpenSSL==20.0.1
pyparsing==2.4.7
PySocks==1.7.1
selenium==3.141.0
selenium-wire==4.2.3
six==1.15.0
urllib3==1.26.4
wsproto==1.0.0

Are you able to confirm whether your versions of the above dependencies are the same (pyOpenSSL obviously already confirmed)?

The only difference I have is that six is not the same version (six==1.10.0)

vasiliy1708 commented 3 years ago

I had the same mistake too. Deleting the folder '.seleniumwire' solved.

Vinyzu commented 2 years ago

Ah, i have the same issuey but i dont get what ".seleniumwire" folder you mean? In the site-packages directory where selenium-wire is installed?