-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add https support for version 3 of the controller, and moved dev to v…
…scode
- Loading branch information
Showing
18 changed files
with
138 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/dist | ||
/build | ||
/ihcsdk.egg-info | ||
/build.bat | ||
/upload.bat | ||
/nppBackup | ||
/.venv | ||
__pycache__/ | ||
.parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: Example file", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "example.py", | ||
"console": "integratedTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.pythonPath": "g:\\Dev\\python\\ihcsdk\\.venv\\Scripts\\python.exe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include readme.md | ||
include license.txt | ||
include ihcsdk/certs/*.crt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
rm -R dist | ||
python setup.py sdist | ||
rm -R build | ||
rm -R ihcsdk.egg-info | ||
python setup.py sdist bdist_wheel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDyzCCArOgAwIBAgIEapjIFzANBgkqhkiG9w0BAQsFADCBlTELMAkGA1UEBhMC | ||
RlIxDzANBgNVBAgTBkZyYW5jZTEeMBwGA1UEBxMVOTI1MDAgUnVlaWwgTWFsbWFp | ||
c29uMRswGQYDVQQKExJTY2huZWlkZXIgRWxlY3RyaWMxGzAZBgNVBAsTEkdsb2Jh | ||
bCBFbmdpbmVlcmluZzEbMBkGA1UEAxMSU2NobmVpZGVyIEVsZWN0cmljMB4XDTE2 | ||
MDMwMjExNTExMFoXDTI2MDEwOTExNTExMFowgZUxCzAJBgNVBAYTAkZSMQ8wDQYD | ||
VQQIEwZGcmFuY2UxHjAcBgNVBAcTFTkyNTAwIFJ1ZWlsIE1hbG1haXNvbjEbMBkG | ||
A1UEChMSU2NobmVpZGVyIEVsZWN0cmljMRswGQYDVQQLExJHbG9iYWwgRW5naW5l | ||
ZXJpbmcxGzAZBgNVBAMTElNjaG5laWRlciBFbGVjdHJpYzCCASIwDQYJKoZIhvcN | ||
AQEBBQADggEPADCCAQoCggEBAKBnGTVIWpV4yld9hFpkRFn0rT/jFMT9JUbMRvBx | ||
La0nZuOPAQh4xCpM6p+upjF91x+SRM+pGt1oMxptxmhK3fXeghinC1qF3EB3e7wE | ||
QUc/35ckVbDR7K/rlqRW/qSjB1mNSX8YWzxCTEbBhYJiQwSxVOjAZ1zyvNUq8Msq | ||
3yi19aER1Rn3Vpdma216ogXWHJe2hVgtnoM+l85vE8dd72wcVdya5qrMOI67gvnh | ||
DjoSbVeP5kUFgt9gU0cNC6HsSw0ayvxYlTb3hlzdO211zCJc1yADFzIb5eNa8LPp | ||
9NCTrG5qAhda+0GY2pJk+XqrpH6VryKLZIvV7CCa2VASlO0CAwEAAaMhMB8wHQYD | ||
VR0OBBYEFI2fPYY01dOInhlJEhJl3mMavE27MA0GCSqGSIb3DQEBCwUAA4IBAQB3 | ||
BdnEsqTv/f44b2cKsztQ9+3tq4RfO0FRtcpXGr5uNIRVcTLqaT1TrqEMOmB9v+9j | ||
99hVrm4T0gkchW51jYKNuwTP+4zYk+mx6BVuSWysmBg6meB3J8I7x5q/oWjylHOT | ||
LznoHPhB4kwA/TCh9DfOdcklhYMVesWm3XllYhY8Vy5JaT2g4AWE2PHZP6e/fPHc | ||
Vm4867n8P58ko+2uHb+noFBkNC/3BsSiGkMQZ+GSgkVxQAzvdj8vcndJEe/uvCh+ | ||
/OI9DdwFVF00zdP1CTaNI4YvDEfCHjRDyVNY1ygJ/cvNeK/Y1ohYKgGfrsunCZsJ | ||
Jit2KlT6WgvhepiYCrWP | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,46 @@ | ||
"""Implements soap reqeust using the "requests" module""" | ||
# pylint: disable=too-few-public-methods | ||
import ssl | ||
import xml.etree.ElementTree | ||
import os | ||
import requests | ||
from requests.packages.urllib3.util.ssl_ import create_urllib3_context | ||
|
||
from cryptography.x509 import load_pem_x509_certificate | ||
from cryptography.hazmat.backends import default_backend | ||
from cryptography.hazmat.primitives import hashes | ||
from requests.adapters import HTTPAdapter | ||
|
||
from ihcsdk.ihcconnection import IHCConnection | ||
|
||
|
||
class IHCSSLConnection(IHCConnection): | ||
"""description of class""" | ||
"""Implements a https connection to the controller""" | ||
|
||
def __init__(self, url: str): | ||
"""Initialize the IIHCSoapClient with a url for the controller""" | ||
"""Initialize the IHCSSLConnection with a url for the controller""" | ||
super(IHCSSLConnection, self).__init__(url) | ||
self.session = requests.Session() | ||
self.session.mount('https://', TLSv1Adapter()) | ||
self.cert_file = os.path.dirname( __file__) + "/certs/ihc3.crt" | ||
self.session.mount('https://', CertAdapter( self.get_fingerprint_from_cert())) | ||
|
||
def soap_action(self, service, action, payloadbody): | ||
"""Do a soap request""" | ||
payload = self.soapenvelope.format(body=payloadbody).encode('utf-8') | ||
headers = {"Host": self.url, | ||
"Content-Type": "text/xml; charset=UTF-8", | ||
"Cache-Control": "no-cache", | ||
"Content-Length": str(len(payload)), | ||
"SOAPAction": action} | ||
try: | ||
response = self.session.post( | ||
url=self.url + service, headers=headers, data=payload) | ||
except Exception as exp: | ||
return False | ||
if response.status_code != 200: | ||
return False | ||
try: | ||
xdoc = xml.etree.ElementTree.fromstring(response.text) | ||
if xdoc is None: | ||
return False | ||
except xml.etree.ElementTree.ParseError: | ||
return False | ||
return xdoc | ||
def get_fingerprint_from_cert( self): | ||
"""Get the fingerprint from the certificate""" | ||
pem = open( self.cert_file, "rb").read() | ||
cert = load_pem_x509_certificate(pem, default_backend()) | ||
f = cert.fingerprint( hashes.SHA1()) | ||
return ''.join('{:02x}'.format(x) for x in f) | ||
|
||
def cert_verify(self): | ||
return self.cert_file | ||
|
||
class TLSv1Adapter(HTTPAdapter): | ||
"""Force TLSv1""" | ||
|
||
CIPHERS = ('AES256-SHA') | ||
class CertAdapter(requests.adapters.HTTPAdapter): | ||
"""A adapter for a specific certificate""" | ||
|
||
def init_poolmanager(self, connections, maxsize, | ||
block=requests.adapters.DEFAULT_POOLBLOCK, | ||
**pool_kwargs): | ||
"""Initialize poolmanager with cipher and Tlsv1""" | ||
context = create_urllib3_context(ciphers=self.CIPHERS, | ||
ssl_version=ssl.PROTOCOL_TLSv1) | ||
pool_kwargs['ssl_context'] = context | ||
return super(TLSv1Adapter, self).init_poolmanager(connections, maxsize, | ||
block, **pool_kwargs) | ||
def __init__(self, fingerprint, **kwargs): | ||
"""Constructor. Store the fingerprint for use when creating the poolmanager.""" | ||
self.fingerprint = fingerprint | ||
super(CertAdapter, self).__init__(**kwargs) | ||
|
||
def proxy_manager_for(self, proxy, **proxy_kwargs): | ||
"""Ensure cipher and Tlsv1""" | ||
context = create_urllib3_context(ciphers=self.CIPHERS, | ||
ssl_version=ssl.PROTOCOL_TLSv1) | ||
proxy_kwargs['ssl_context'] = context | ||
return super(TLSv1Adapter, self).proxy_manager_for(proxy, | ||
**proxy_kwargs) | ||
def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs): | ||
"""Create a custom poolmanager""" | ||
pool_kwargs['assert_fingerprint'] = self.fingerprint | ||
return super(CertAdapter, self).init_poolmanager(connections, maxsize, | ||
block, **pool_kwargs) |
Oops, something went wrong.