Browse Source

Can now use key/cert from memory in addition to from a file path.

pyserial_fix
Scott Petersen 11 years ago
parent
commit
613fa5de2f
2 changed files with 20 additions and 6 deletions
  1. +18
    -4
      pyad2usb/devices.py
  2. +2
    -2
      test.py

+ 18
- 4
pyad2usb/devices.py View File

@@ -11,7 +11,7 @@ import threading
import serial import serial
import serial.tools.list_ports import serial.tools.list_ports
import socket import socket
from OpenSSL import SSL
from OpenSSL import SSL, crypto
from pyftdi.pyftdi.ftdi import * from pyftdi.pyftdi.ftdi import *
from pyftdi.pyftdi.usbtools import * from pyftdi.pyftdi.usbtools import *
from . import util from . import util
@@ -742,9 +742,23 @@ class SocketDevice(Device):
if self._use_ssl: if self._use_ssl:
try: try:
ctx = SSL.Context(SSL.TLSv1_METHOD) ctx = SSL.Context(SSL.TLSv1_METHOD)
ctx.use_privatekey_file(self.ssl_key)
ctx.use_certificate_file(self.ssl_certificate)
ctx.load_verify_locations(self.ssl_ca, None)

if isinstance(self.ssl_key, crypto.PKey):
ctx.use_privatekey(self.ssl_key)
else:
ctx.use_privatekey_file(self.ssl_key)

if isinstance(self.ssl_certificate, crypto.X509):
ctx.use_certificate(self.ssl_certificate)
else:
ctx.use_certificate_file(self.ssl_certificate)

if isinstance(self.ssl_ca, crypto.X509):
store = ctx.get_cert_store()
store.add_cert(self.ssl_ca)
else:
ctx.load_verify_locations(self.ssl_ca, None)

ctx.set_verify(SSL.VERIFY_PEER, self._verify_ssl_callback) ctx.set_verify(SSL.VERIFY_PEER, self._verify_ssl_callback)


self._device = SSL.Connection(ctx, self._device) self._device = SSL.Connection(ctx, self._device)


+ 2
- 2
test.py View File

@@ -374,14 +374,14 @@ try:
#test_serial() #test_serial()
#upload_serial() #upload_serial()


#test_usb()
test_usb()
#test_usb_serial() #test_usb_serial()
#test_factory() #test_factory()
#test_factory_watcher() #test_factory_watcher()
#upload_usb() #upload_usb()
#upload_usb_serial() #upload_usb_serial()


test_socket()
#test_socket()
#upload_socket() #upload_socket()


#test_no_read_thread() #test_no_read_thread()


Loading…
Cancel
Save