I am attempting to automate the push of a backup file from a (local) headless data server, to a (remote) secure backup server - which [for reasons] (currently) needs to be done via a web page.
I have written a Selenium/Python script which works well, but ignores ALL certificate errors - which, in this case, is NOT the desired behaviour.
- Platform: Raspberry Pi 3B / Raspbian 10
- Selenium: v3.141.0 (from Raspbian repo)
- Geckdriver: v0.29 (built from github release source with rust v1.50)
...Installed with:cp /path/to/geckodriver-0.29.0/target/debug/geckodriver /usr/local/bin - Firefox: v78.7.0esr (from Raspbian repo)
Most people (in my searches) seem to have the exact /opposite/ problem - IE. they want to DISable the security mechanism ...But inverting the (literally True/False) logic in those many different solutions has NOT led me to a solution which allows me to ENable cert checking.
Here is some (abbreviated and annotated) example code, with one of my (many) attempts:
#!/bin/python3
from selenium import webdriver # selenium instance
from selenium.webdriver.firefox.options import Options # headless
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # Reject bad SSL
# Set headless mode
opts = Options()
opts.headless = True
# Enforce certificate checking - [this fails]
caps = DesiredCapabilities.FIREFOX
print(caps) # {'browserName': 'firefox', 'marionette': True, 'acceptInsecureCerts': True}
caps['acceptInsecureCerts'] = False
print(caps) # {'browserName': 'firefox', 'marionette': True, 'acceptInsecureCerts': False}
driver = webdriver.Firefox(capabilities=caps, options=opts)
# LOG FILE ENTRY APPEARS in geckodriver.log:
# "Marionette WARN TLS certificate errors will be ignored for this session"
driver.get("https://wrong.host.badssl.com")
# <<perform upload here>>
driver.save_screenshot("test.png") # Page was NOT blocked! :(
driver.close()
My question is:
What modification(s) can be made to this code such that the <<upload>> will happen if (and only if) the SSL/TLS certificates are valid?
Extra kudos for an additional line of code to display a reason {"self-signed cert", "cert revoked", etc} if the <<upload>> is blocked.