gevent.ssl – SSL wrapper for socket objects

For the documentation, refer to ssl module manual.

This module implements cooperative SSL socket wrappers. On Python 2.6 and newer it uses Python’s native ssl module. On Python 2.5 and 2.4 it requires ssl package to be installed.

class gevent.ssl.SSLSocket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=0, ssl_version=2, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None)
read(len=1024)

Read up to LEN bytes and return them. Return zero-length string on EOF.

write(data)

Write DATA to the underlying SSL channel. Returns number of bytes of DATA actually transmitted.

getpeercert(binary_form=False)

Returns a formatted version of the data in the certificate provided by the other end of the SSL channel. Return None if no certificate was provided, {} if a certificate was provided, but not validated.

cipher()
send(data, flags=0, timeout=<object object at 0x2b9f6d5e63d0>)
sendto(*args)
recv(buflen=1024, flags=0)
recv_into(buffer, nbytes=None, flags=0)
recvfrom(*args)
recvfrom_into(*args)
pending()
unwrap()
shutdown(how)
close()
do_handshake()

Perform a TLS/SSL handshake.

connect(addr)

Connects to remote ADDR, and then wraps the connection in an SSL channel.

accept()

Accepts a new connection from a remote client, and returns a tuple containing that new connection wrapped with a server-side SSL channel, and the address of the remote client.

makefile(mode='r', bufsize=-1)

Make and return a file-like object that works with the SSL connection. Just use the code from the socket module.

gevent.ssl.wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=0, ssl_version=2, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None)

Create a new SSLSocket instance.

gevent.ssl.get_server_certificate(addr, ssl_version=1, ca_certs=None)

Retrieve the certificate from the server at the specified address, and return it as a PEM-encoded string. If ‘ca_certs’ is specified, validate the server cert against it. If ‘ssl_version’ is specified, use it in the connection attempt.

gevent.ssl.sslwrap_simple(sock, keyfile=None, certfile=None)

A replacement for the old socket.ssl function. Designed for compability with Python 2.5 and earlier. Will disappear in Python 3.0.

exception gevent.ssl.SSLError
gevent.ssl.RAND_status() → 0 or 1

Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not. It is necessary to seed the PRNG with RAND_add() on some platforms before using the ssl() function.

gevent.ssl.RAND_egd(path) → bytes

Queries the entropy gather daemon (EGD) on the socket named by ‘path’. Returns number of bytes read. Raises SSLError if connection to EGD fails or if it does not provide enough data to seed PRNG.

gevent.ssl.RAND_add(string, entropy)

Mix string into the OpenSSL PRNG state. entropy (a float) is a lower bound on the entropy contained in string. See RFC 1750.

gevent.ssl.cert_time_to_seconds(cert_time)

Takes a date-time string in standard ASN1_print form (“MON DAY 24HOUR:MINUTE:SEC YEAR TIMEZONE”) and return a Python time value in seconds past the epoch.

gevent.ssl.get_protocol_name(protocol_code)
gevent.ssl.DER_cert_to_PEM_cert(der_cert_bytes)

Takes a certificate in binary DER format and returns the PEM version of it as a string.

gevent.ssl.PEM_cert_to_DER_cert(pem_cert_string)

Takes a certificate in ASCII PEM format and returns the DER-encoded version of it as a byte sequence

Next page: gevent.select