SSL_write() extended to handle ctypes.Array as data
* dtls/openssl.py: SSL_write() can handle ctypes.Array data * dtls/sslconnection.py: Added missing import ERR_BOTH_KEY_CERT_FILES * dtls/test/simple_client.py: Added basic test client to use with dtls/test/echo_seq.pyincoming
parent
b4911f4949
commit
d601774e24
|
@ -1,3 +1,11 @@
|
||||||
|
2017-03-17 Björn Freise <mcfreis@gmx.net>
|
||||||
|
|
||||||
|
SSL_write() extended to handle ctypes.Array as data
|
||||||
|
|
||||||
|
* dtls/openssl.py: SSL_write() can handle ctypes.Array data
|
||||||
|
* dtls/sslconnection.py: Added missing import ERR_BOTH_KEY_CERT_FILES
|
||||||
|
* dtls/test/simple_client.py: Added basic test client to use with dtls/test/echo_seq.py
|
||||||
|
|
||||||
2017-03-17 Björn Freise <mcfreis@gmx.net>
|
2017-03-17 Björn Freise <mcfreis@gmx.net>
|
||||||
|
|
||||||
Beautified lists and maps, grouped imports for easy merges in the future - no changed functionality!
|
Beautified lists and maps, grouped imports for easy merges in the future - no changed functionality!
|
||||||
|
|
|
@ -772,6 +772,8 @@ def SSL_write(ssl, data):
|
||||||
str_data = data
|
str_data = data
|
||||||
elif hasattr(data, "tobytes") and callable(data.tobytes):
|
elif hasattr(data, "tobytes") and callable(data.tobytes):
|
||||||
str_data = data.tobytes()
|
str_data = data.tobytes()
|
||||||
|
elif isinstance(data, ctypes.Array):
|
||||||
|
str_data = data.raw
|
||||||
else:
|
else:
|
||||||
str_data = str(data)
|
str_data = str(data)
|
||||||
return _SSL_write(ssl, str_data, len(str_data))
|
return _SSL_write(ssl, str_data, len(str_data))
|
||||||
|
|
|
@ -55,7 +55,7 @@ from err import SSL_ERROR_WANT_READ, SSL_ERROR_SYSCALL
|
||||||
from err import ERR_COOKIE_MISMATCH, ERR_NO_CERTS
|
from err import ERR_COOKIE_MISMATCH, ERR_NO_CERTS
|
||||||
from err import ERR_NO_CIPHER, ERR_HANDSHAKE_TIMEOUT, ERR_PORT_UNREACHABLE
|
from err import ERR_NO_CIPHER, ERR_HANDSHAKE_TIMEOUT, ERR_PORT_UNREACHABLE
|
||||||
from err import ERR_READ_TIMEOUT, ERR_WRITE_TIMEOUT
|
from err import ERR_READ_TIMEOUT, ERR_WRITE_TIMEOUT
|
||||||
from err import ERR_BOTH_KEY_CERT_FILES_SVR
|
from err import ERR_BOTH_KEY_CERT_FILES, ERR_BOTH_KEY_CERT_FILES_SVR
|
||||||
from x509 import _X509, decode_cert
|
from x509 import _X509, decode_cert
|
||||||
from tlock import tlock_init
|
from tlock import tlock_init
|
||||||
from openssl import *
|
from openssl import *
|
||||||
|
|
|
@ -39,6 +39,7 @@ basicConfig(level=DEBUG) # set now for dtls import code
|
||||||
from dtls.sslconnection import SSLConnection
|
from dtls.sslconnection import SSLConnection
|
||||||
from dtls.err import SSLError, SSL_ERROR_WANT_READ, SSL_ERROR_ZERO_RETURN
|
from dtls.err import SSLError, SSL_ERROR_WANT_READ, SSL_ERROR_ZERO_RETURN
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
sck = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sck = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
sck.bind(("127.0.0.1", 28000))
|
sck.bind(("127.0.0.1", 28000))
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
from os import path
|
||||||
|
import ssl
|
||||||
|
from socket import socket, AF_INET, SOCK_DGRAM, SHUT_RDWR
|
||||||
|
from logging import basicConfig, DEBUG
|
||||||
|
basicConfig(level=DEBUG) # set now for dtls import code
|
||||||
|
from dtls import do_patch
|
||||||
|
do_patch()
|
||||||
|
|
||||||
|
cert_path = path.join(path.abspath(path.dirname(__file__)), "certs")
|
||||||
|
sock = ssl.wrap_socket(socket(AF_INET, SOCK_DGRAM), cert_reqs=ssl.CERT_REQUIRED, ca_certs=path.join(cert_path, "ca-cert.pem"))
|
||||||
|
sock.connect(('localhost', 28000))
|
||||||
|
sock.send('Hi there')
|
||||||
|
print sock.recv()
|
||||||
|
sock.unwrap()
|
||||||
|
sock.shutdown(SHUT_RDWR)
|
Loading…
Reference in New Issue