-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.py
More file actions
38 lines (26 loc) · 1.58 KB
/
Main.py
File metadata and controls
38 lines (26 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import winreg
from OpenSSL import crypto
from selenium import webdriver
def UpdateStringValue(strigValueName,newValueOfStrinValue, stringValuePath):
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, stringValuePath, 0, winreg.KEY_ALL_ACCESS)
winreg.SetValueEx(key, strigValueName, 0, winreg.REG_SZ, newValueOfStrinValue)
winreg.CloseKey(key)
def GetCertificate(pathOfCertificate, passwordOfCertifcate):
pkcs12 = crypto.load_pkcs12(open(pathOfCertificate, 'rb').read(), passwordOfCertifcate)
return pkcs12.get_certificate()
if __name__ == "__main__":
pathOfstringValue = 'SOFTWARE\Policies\Google\Chrome\AutoSelectCertificateForUrls'
stringValueName = '1'
certificate = GetCertificate("C:\Certificados\\45985371000108_000001010131997.pfx", 'br018726')
subject = certificate.get_subject()
issuer = certificate.get_issuer()
url_where_certificate_will_be_send = "https://notacarioca.rio.gov.br/"
url = 'https://notacarioca.rio.gov.br/senhaweb/login.aspx'
json = '{"pattern":"' + url_where_certificate_will_be_send + '","filter":{"ISSUER":{"CN":"' + issuer.CN + '","C":"' + issuer.C + '","O":"' + issuer.O + '"},"SUBJECT":{"CN":"' + subject.CN + '","C":"' + subject.C + '","O":"' + subject.O + '"}}}'
UpdateStringValue(stringValueName, json, pathOfstringValue)
path = 'C:\\Users\\rodrigo.peres\Downloads\chromedriver_win32\\'
driver = webdriver.Chrome()
driver.get(url)
btn_certificate_login = driver.find_element_by_id('ctl00_cphCabMenu_imgLoginICP')
btn_certificate_login.click()
driver.quit()