From 044ae976a04e524ba001f63d437ecb866ebeff68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Tue, 8 Dec 2020 17:31:09 +0100 Subject: Administrative tasks to create release 0.37. --- CHANGES | 18 + M2Crypto/__init__.py | 2 +- doc/doctrees/M2Crypto.SSL.doctree | Bin 349315 -> 447469 bytes doc/doctrees/M2Crypto.doctree | Bin 963869 -> 1345083 bytes doc/doctrees/ZServerSSL-HOWTO.doctree | Bin 43570 -> 43612 bytes doc/doctrees/environment.pickle | Bin 535122 -> 542878 bytes doc/doctrees/howto.ca.doctree | Bin 49113 -> 49176 bytes doc/doctrees/howto.smime.doctree | Bin 88860 -> 88920 bytes doc/doctrees/howto.ssl.doctree | Bin 20890 -> 20957 bytes doc/doctrees/index.doctree | Bin 6360 -> 6497 bytes doc/html/M2Crypto.SSL.html | 904 +++- doc/html/M2Crypto.html | 4468 +++++++++++++++++--- doc/html/_modules/M2Crypto/ASN1.html | 64 +- doc/html/_modules/M2Crypto/AuthCookie.html | 42 +- doc/html/_modules/M2Crypto/BIO.html | 65 +- doc/html/_modules/M2Crypto/BN.html | 36 +- doc/html/_modules/M2Crypto/DH.html | 49 +- doc/html/_modules/M2Crypto/DSA.html | 47 +- doc/html/_modules/M2Crypto/EC.html | 46 +- doc/html/_modules/M2Crypto/EVP.html | 13 +- doc/html/_modules/M2Crypto/Engine.html | 41 +- doc/html/_modules/M2Crypto/RC4.html | 37 +- doc/html/_modules/M2Crypto/Rand.html | 36 +- doc/html/_modules/M2Crypto/SMIME.html | 43 +- doc/html/_modules/M2Crypto/SSL.html | 50 +- doc/html/_modules/M2Crypto/SSL/Checker.html | 42 +- doc/html/_modules/M2Crypto/SSL/Cipher.html | 2 + doc/html/_modules/M2Crypto/SSL/Context.html | 2 + doc/html/_modules/M2Crypto/SSL/SSLServer.html | 56 +- doc/html/_modules/M2Crypto/SSL/Session.html | 2 + .../M2Crypto/SSL/TwistedProtocolWrapper.html | 54 +- doc/html/_modules/M2Crypto/SSL/cb.html | 2 + doc/html/_modules/M2Crypto/SSL/ssl_dispatcher.html | 37 +- doc/html/_modules/M2Crypto/SSL/timeout.html | 31 +- doc/html/_modules/M2Crypto/X509.html | 140 +- doc/html/_modules/M2Crypto/ftpslib.html | 37 +- doc/html/_modules/M2Crypto/httpslib.html | 46 +- doc/html/_modules/M2Crypto/m2urllib.html | 46 +- doc/html/_modules/M2Crypto/m2urllib2.html | 48 +- doc/html/_modules/M2Crypto/m2xmlrpclib.html | 54 +- doc/html/_modules/M2Crypto/threading.html | 33 +- doc/html/_modules/M2Crypto/util.html | 5 +- doc/html/_modules/index.html | 30 +- doc/html/_modules/urllib/request.html | 295 +- doc/html/genindex.html | 1388 +++++- doc/html/index.html | 50 +- doc/html/objects.inv | Bin 4395 -> 4432 bytes doc/html/py-modindex.html | 135 + doc/html/searchindex.js | 2 +- 49 files changed, 7005 insertions(+), 1493 deletions(-) diff --git a/CHANGES b/CHANGES index d2fc378..10e6274 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,21 @@ +0.37.0 - 2020-12-08 +------------------- + +- Remove support for CentOS 6 and Python 2.6 (remove tests.vendor + module). +- Remodel CI: + - on GitHub switched from Travis-CI to GH Actions + - on GitLab-CI: stop testing 2.7 on Fedora, add centos7 + - update appveyor.yml +- Stop playing with swig in setup.py, we don't support swig 1.* anymore. +- Fix dereferencing of pointers (gl#m2crypto/m2crypto#281) +- Replace deprecated PyObject_AsReadBuffer with our own shim. +- Use parametrized to create parametrized tests (new external + dependency). +- Only use DigestSign() and DigestUpdate() with OpenSSL >= 1.1.1 +- Expose all the X509_V_FLAG +- Add support for DigestSign* and DigestVerify* + 0.36.0 - 2020-07-13 ------------------- diff --git a/M2Crypto/__init__.py b/M2Crypto/__init__.py index 06243c9..f0fd255 100644 --- a/M2Crypto/__init__.py +++ b/M2Crypto/__init__.py @@ -19,7 +19,7 @@ Copyright 2008-2011 Heikki Toivonen. All rights reserved. """ # noqa from distutils.version import StrictVersion -__version__ = '0.36.0' +__version__ = '0.37.0' version = __version__ # type: str version_info = StrictVersion(__version__).version diff --git a/doc/doctrees/M2Crypto.SSL.doctree b/doc/doctrees/M2Crypto.SSL.doctree index 7ea180d..4b24ab4 100644 Binary files a/doc/doctrees/M2Crypto.SSL.doctree and b/doc/doctrees/M2Crypto.SSL.doctree differ diff --git a/doc/doctrees/M2Crypto.doctree b/doc/doctrees/M2Crypto.doctree index 9a06cce..2e219e5 100644 Binary files a/doc/doctrees/M2Crypto.doctree and b/doc/doctrees/M2Crypto.doctree differ diff --git a/doc/doctrees/ZServerSSL-HOWTO.doctree b/doc/doctrees/ZServerSSL-HOWTO.doctree index 040bc3f..ec0d8c9 100644 Binary files a/doc/doctrees/ZServerSSL-HOWTO.doctree and b/doc/doctrees/ZServerSSL-HOWTO.doctree differ diff --git a/doc/doctrees/environment.pickle b/doc/doctrees/environment.pickle index 9a85a4e..880df37 100644 Binary files a/doc/doctrees/environment.pickle and b/doc/doctrees/environment.pickle differ diff --git a/doc/doctrees/howto.ca.doctree b/doc/doctrees/howto.ca.doctree index d86d193..f9ccf3e 100644 Binary files a/doc/doctrees/howto.ca.doctree and b/doc/doctrees/howto.ca.doctree differ diff --git a/doc/doctrees/howto.smime.doctree b/doc/doctrees/howto.smime.doctree index 4199adb..92317fa 100644 Binary files a/doc/doctrees/howto.smime.doctree and b/doc/doctrees/howto.smime.doctree differ diff --git a/doc/doctrees/howto.ssl.doctree b/doc/doctrees/howto.ssl.doctree index e90779b..4caf727 100644 Binary files a/doc/doctrees/howto.ssl.doctree and b/doc/doctrees/howto.ssl.doctree differ diff --git a/doc/doctrees/index.doctree b/doc/doctrees/index.doctree index cab8fd0..1d082e7 100644 Binary files a/doc/doctrees/index.doctree and b/doc/doctrees/index.doctree differ diff --git a/doc/html/M2Crypto.SSL.html b/doc/html/M2Crypto.SSL.html index a6b1cb3..19a257d 100644 --- a/doc/html/M2Crypto.SSL.html +++ b/doc/html/M2Crypto.SSL.html @@ -36,9 +36,60 @@

SSL Package

SSL Package

+
+
+exception M2Crypto.SSL.SSLError[source]
+

Bases: Exception

+
+ +
+
+exception M2Crypto.SSL.SSLTimeoutError[source]
+

Bases: M2Crypto.SSL.SSLError, socket.timeout

+
+
-
-

Checker Module

+
+

Checker Module

+

SSL peer certificate checking routines

+

Copyright (c) 2004-2007 Open Source Applications Foundation. +All rights reserved.

+

Copyright 2008 Heikki Toivonen. All rights reserved.

+
+
+class M2Crypto.SSL.Checker.Checker(host: Optional[str] = None, peerCertHash: Optional[bytes] = None, peerCertDigest: str = 'sha1')[source]
+

Bases: object

+
+
+numericIpMatch = re.compile('^[0-9]+(\\.[0-9]+)*$')
+
+ +
+ +
+
+exception M2Crypto.SSL.Checker.NoCertificate[source]
+

Bases: M2Crypto.SSL.Checker.SSLVerificationError

+
+ +
+
+exception M2Crypto.SSL.Checker.SSLVerificationError[source]
+

Bases: Exception

+
+ +
+
+exception M2Crypto.SSL.Checker.WrongCertificate[source]
+

Bases: M2Crypto.SSL.Checker.SSLVerificationError

+
+ +
+
+exception M2Crypto.SSL.Checker.WrongHost(expectedHost: str, actualHost: AnyStr, fieldName: str = 'commonName')[source]
+

Bases: M2Crypto.SSL.Checker.SSLVerificationError

+
+

Cipher Module

@@ -67,8 +118,588 @@
-
-

Connection Module

+
+

Connection Module

+
+
+class M2Crypto.SSL.Connection.Connection(ctx: Context, sock: socket.socket = None, family: int = <AddressFamily.AF_INET: 2>)
+

Bases: object

+

An SSL connection.

+
+
+accept() → Tuple[M2Crypto.SSL.Connection.Connection, Union[Tuple[str, int], str]]
+

Accept an SSL connection.

+

The return value is a pair (ssl, addr) where ssl is a new SSL +connection object and addr is the address bound to the other end +of the SSL connection.

+
+
Returns
+

tuple of Connection and addr. Address can take very +various forms (see socket documentation), for IPv4 it +is tuple(str, int), for IPv6 a tuple of four (host, +port, flowinfo, scopeid), where the last two are +optional ints.

+
+
+
+ +
+
+accept_ssl() → Optional[int]
+

Waits for a TLS/SSL client to initiate the TLS/SSL handshake.

+

The communication channel must already have been set and +assigned to the ssl by setting an underlying BIO.

+
+
Returns
+

+
0 The TLS/SSL handshake was not successful but was shut

down controlled and by the specifications of the +TLS/SSL protocol. Call get_error() with the return +value ret to find out the reason.

+
+
1 The TLS/SSL handshake was successfully completed,

a TLS/SSL connection has been established.

+
+
<0 The TLS/SSL handshake was not successful because

a fatal error occurred either at the protocol level +or a connection failure occurred. The shutdown was +not clean. It can also occur of action is need to +continue the operation for non-blocking BIOs. Call +get_error() with the return value ret to find +out the reason.

+
+
+

+
+
+
+ +
+
+bind(addr: Union[Tuple[str, int], str]) → None
+
+ +
+
+clear() → int
+

If there were errors in this connection, call clear() rather +than close() to end it, so that bad sessions will be cleared +from cache.

+
+ +
+
+close(freeBio=False)
+

if freeBio is true, call _free_bio

+
+ +
+
+connect(addr: Union[Tuple[str, int], str]) → int
+

Overloading socket.connect()

+
+
Parameters
+

addr – addresses have various depending on their type

+
+
+

:return:status of ssl_connect()

+
+ +
+
+connect_ssl() → Optional[int]
+
+ +
+
+fileno() → int
+
+ +
+
+get_cipher() → Optional[M2Crypto.SSL.Cipher.Cipher]
+

Return an M2Crypto.SSL.Cipher object for this connection; if the +connection has not been initialised with a cipher suite, return None.

+
+ +
+
+get_cipher_list(idx: int = 0) → str
+

Return the cipher suites for this connection as a string object.

+
+ +
+
+get_ciphers() → Optional[M2Crypto.SSL.Cipher.Cipher_Stack]
+

Return an M2Crypto.SSL.Cipher_Stack object for this +connection; if the connection has not been initialised with +cipher suites, return None.

+
+ +
+
+get_context() → Context
+

Return the Context object associated with this connection.

+
+ +
+
+get_default_session_timeout() → int
+
+ +
+
+get_peer_cert()M2Crypto.X509.X509
+

Return the peer certificate.

+

If the peer did not provide a certificate, return None.

+
+ +
+
+get_peer_cert_chain() → Optional[M2Crypto.X509.X509_Stack]
+

Return the peer certificate chain; if the peer did not provide +a certificate chain, return None.

+
+
Warning
+

The returned chain will be valid only for as long as the +connection object is alive. Once the connection object +gets freed, the chain will be freed as well.

+
+
+
+ +
+
+get_session()M2Crypto.SSL.Session.Session
+
+ +
+
+get_shutdown() → None
+

Get the current shutdown mode of the Connection.

+
+ +
+
+get_socket_read_timeout() → timeout
+
+ +
+
+get_socket_write_timeout() → timeout
+
+ +
+
+get_state() → bytes
+

Return the SSL state of this connection.

+

During its use, an SSL objects passes several states. The state +is internally maintained. Querying the state information is not +very informative before or when a connection has been +established. It however can be of significant interest during +the handshake.

+
+
Returns
+

6 letter string indicating the current state of the SSL +object ssl.

+
+
+
+ +
+
+get_verify_depth() → int
+

Return the peer certificate verification depth.

+
+ +
+
+get_verify_mode() → int
+

Return the peer certificate verification mode.

+
+ +
+
+get_verify_result() → int
+

Return the peer certificate verification result.

+
+ +
+
+get_version() → str
+

Return the TLS/SSL protocol version for this connection.

+
+ +
+
+getpeername() → Union[Tuple[str, int], str]
+

Return the remote address to which the socket is connected.

+

This is useful to find out the port number of a remote IPv4/v6 socket, +for instance. +On some systems this function is not supported.

+
+
Returns
+

+
+
+
+ +
+
+getsockname() → Union[Tuple[str, int], str]
+

Return the socket’s own address.

+

This is useful to find out the port number of an IPv4/v6 socket, +for instance. (The format of the address returned depends +on the address family – see above.)

+

:return:socket’s address as addr type

+
+ +
+
+getsockopt(level: int, optname: int, buflen: Optional[int] = None) → Union[int, bytes]
+

Get the value of the given socket option.

+
+
Parameters
+
    +
  • level – level at which the option resides. +To manipulate options at the sockets API level, level is +specified as socket.SOL_SOCKET. To manipulate options at +any other level the protocol number of the appropriate +protocol controlling the option is supplied. For example, +to indicate that an option is to be interpreted by the +TCP protocol, level should be set to the protocol number +of socket.SOL_TCP; see getprotoent(3).

  • +
  • optname – The value of the given socket option is +described in the Unix man page getsockopt(2)). The needed +symbolic constants (SO_* etc.) are defined in the socket +module.

  • +
  • buflen – If it is absent, an integer option is assumed +and its integer value is returned by the function. If +buflen is present, it specifies the maximum length of the +buffer used to receive the option in, and this buffer is +returned as a bytes object.

  • +
+
+
Returns
+

Either integer or bytes value of the option. It is up +to the caller to decode the contents of the buffer (see +the optional built-in module struct for a way to decode +C structures encoded as byte strings).

+
+
+
+ +
+
+listen(qlen: int = 5) → None
+
+ +
+
+m2_bio_free()
+
+ +
+
+m2_bio_noclose = 0
+
+ +
+
+m2_ssl_free()
+
+ +
+
+makefile(mode: AnyStr = 'rb', bufsize: int = - 1) → Union[_io.BufferedRWPair, _io.BufferedReader]
+
+ +
+
+pending() → int
+

Return the numbers of octets that can be read from the connection.

+
+ +
+
+read(size: int = 1024) → bytes
+
+ +
+
+recv(size: int = 1024) → bytes
+
+ +
+
+recv_into(buff: Union[bytearray, memoryview], nbytes: int = 0) → int
+

A version of recv() that stores its data into a buffer rather +than creating a new string. Receive up to buffersize bytes from +the socket. If buffersize is not specified (or 0), receive up +to the size available in the given buffer.

+

If buff is bytearray, it will have after return length of the +actually returned number of bytes. If buff is memoryview, then +the size of buff won’t change (it cannot), but all bytes after +the number of returned bytes will be NULL.

+
+
Parameters
+
    +
  • buffer – a buffer for the received bytes

  • +
  • nbytes – maximum number of bytes to read

  • +
+
+
Returns
+

number of bytes read

+
+
+

See recv() for documentation about the flags.

+
+ +
+
+renegotiate() → int
+

Renegotiate this connection’s SSL parameters.

+
+ +
+
+send(data: bytes) → int
+
+ +
+
+sendall(data: bytes) → int
+
+ +
+
+serverPostConnectionCheck(**kw: Any) → int
+
+ +
+
+set1_host(name: bytes) → None
+

Set the requested hostname to check in the server certificate.

+
+ +
+
+set_accept_state() → None
+

Sets Connection to work in the server mode.

+
+ +
+
+set_bio(readbio: M2Crypto.BIO.BIO, writebio: M2Crypto.BIO.BIO) → None
+

Explicitly set read and write bios

+

Connects the BIOs for the read and write operations of the +TLS/SSL (encrypted) side of ssl.

+

The SSL engine inherits the behaviour of both BIO objects, +respectively. If a BIO is non-blocking, the Connection will also +have non-blocking behaviour.

+

If there was already a BIO connected to Connection, BIO_free() +will be called (for both the reading and writing side, if +different).

+
+
Parameters
+
    +
  • readbio – BIO for reading

  • +
  • writebio – BIO for writing.

  • +
+
+
+
+ +
+
+set_cipher_list(cipher_list: str) → int
+

Set the cipher suites for this connection.

+
+ +
+
+set_client_CA_list_from_context() → None
+

Set the acceptable client CA list. If the client +returns a certificate, it must have been issued by +one of the CAs listed in context.

+

Makes sense only for servers.

+
+ +
+
+set_client_CA_list_from_file(cafile: AnyStr) → None
+

Set the acceptable client CA list.

+

If the client returns a certificate, it must have been issued by +one of the CAs listed in cafile.

+

Makes sense only for servers.

+
+
Parameters
+

cafile – Filename from which to load the CA list.

+
+
Returns
+

+
0 A failure while manipulating the STACK_OF(X509_NAME)

object occurred or the X509_NAME could not be +extracted from cacert. Check the error stack to find +out the reason.

+
+
+

1 The operation succeeded.

+

+
+
+
+ +
+
+set_connect_state() → None
+

Sets Connection to work in the client mode.

+
+ +
+
+set_post_connection_check_callback(postConnectionCheck: Callable) → None
+
+ +
+
+set_session(session: M2Crypto.SSL.Session.Session) → None
+
+ +
+
+set_session_id_ctx(id: bytes) → int
+
+ +
+
+set_shutdown(mode: int) → None
+

Sets the shutdown state of the Connection to mode.

+

The shutdown state of an ssl connection is a bitmask of (use +m2.SSL_* constants):

+

0 No shutdown setting, yet.

+
+
SSL_SENT_SHUTDOWN

A “close notify” shutdown alert was sent to the peer, the +connection is being considered closed and the session is +closed and correct.

+
+
SSL_RECEIVED_SHUTDOWN

A shutdown alert was received form the peer, either a normal +“close notify” or a fatal error.

+
+
+

SSL_SENT_SHUTDOWN and SSL_RECEIVED_SHUTDOWN can be set at the +same time.

+
+
Parameters
+

mode – set the mode bitmask.

+
+
+
+ +
+
+set_socket_read_timeout(timeo: timeout) → None
+
+ +
+
+set_socket_write_timeout(timeo: timeout) → None
+
+ +
+
+set_ssl_close_flag(flag: int) → None
+

By default, SSL struct will be freed in __del__. Call with +m2.bio_close to override this default.

+
+
Parameters
+

flag – either m2.bio_close or m2.bio_noclose

+
+
+
+ +
+
+set_tlsext_host_name(name: bytes) → None
+

Set the requested hostname for the SNI (Server Name Indication) +extension.

+
+ +
+
+setblocking(mode: int) → None
+

Set this connection’s underlying socket to _mode_.

+

Set blocking or non-blocking mode of the socket: if flag is 0, +the socket is set to non-blocking, else to blocking mode. +Initially all sockets are in blocking mode. In non-blocking mode, +if a recv() call doesn’t find any data, or if a send() call can’t +immediately dispose of the data, a error exception is raised; +in blocking mode, the calls block until they can proceed. +s.setblocking(0) is equivalent to s.settimeout(0.0); +s.setblocking(1) is equivalent to s.settimeout(None).

+
+
Parameters
+

mode – new mode to be set

+
+
+
+ +
+
+setsockopt(level: int, optname: int, value: Optional[Union[int, bytes]] = None) → Optional[bytes]
+

Set the value of the given socket option.

+
+
Parameters
+
    +
  • level – same as with getsockopt() above

  • +
  • optname – same as with getsockopt() above

  • +
  • value – an integer or a string representing a buffer. In +the latter case it is up to the caller to ensure +that the string contains the proper bits (see the +optional built-in module struct for a way to +encode C structures as strings).

  • +
+
+
Returns
+

None for success or the error handler for failure.

+
+
+
+ +
+
+settimeout(timeout: float) → None
+

Set this connection’s underlying socket’s timeout to _timeout_.

+
+ +
+
+setup_addr(addr: Union[Tuple[str, int], str]) → None
+
+ +
+
+setup_ssl() → None
+
+ +
+
+shutdown(how: int) → None
+
+ +
+
+ssl_get_error(ret: int) → int
+
+ +
+
+verify_ok() → bool
+
+ +
+
+write(data: bytes) → int
+
+ +
+

Context Module

@@ -111,7 +742,7 @@ certificate if the certificate’s CA is unknown.

-get_cert_store() → X509.X509[source]
+get_cert_store()M2Crypto.X509.X509[source]

Get the certificate store associated with this context.

Warning
@@ -548,8 +1179,40 @@ verification checks.

-
-

SSLServer Module

+
+

SSLServer Module

+
+
+class M2Crypto.SSL.SSLServer.ForkingSSLServer(server_address: Union[Tuple[str, int], str], RequestHandlerClass: socketserver.BaseRequestHandler, ssl_context: M2Crypto.SSL.Context.Context, bind_and_activate: bool = True)[source]
+

Bases: socketserver.ForkingMixIn, M2Crypto.SSL.SSLServer.SSLServer

+
+ +
+
+class M2Crypto.SSL.SSLServer.SSLServer(server_address: Union[Tuple[str, int], str], RequestHandlerClass: socketserver.BaseRequestHandler, ssl_context: M2Crypto.SSL.Context.Context, bind_and_activate: bool = True)[source]
+

Bases: socketserver.TCPServer

+
+
+handle_error(request: Union[socket.socket, M2Crypto.SSL.Connection.Connection], client_address: Union[Tuple[str, int], str]) → None[source]
+

Handle an error gracefully. May be overridden.

+

The default is to print a traceback and continue.

+
+ +
+
+handle_request() → None[source]
+

Handle one request, possibly blocking.

+

Respects self.timeout.

+
+ +
+ +
+
+class M2Crypto.SSL.SSLServer.ThreadingSSLServer(server_address: Union[Tuple[str, int], str], RequestHandlerClass: socketserver.BaseRequestHandler, ssl_context: M2Crypto.SSL.Context.Context, bind_and_activate: bool = True)[source]
+

Bases: socketserver.ThreadingMixIn, M2Crypto.SSL.SSLServer.SSLServer

+
+

Session Module

@@ -596,7 +1259,7 @@ verification checks.

-write_bio(bio: BIO.BIO) → int[source]
+write_bio(bio: M2Crypto.BIO.BIO) → int[source]
@@ -607,8 +1270,119 @@ verification checks.

-
-

TwistedProtocolWrapper Module

+
+

TwistedProtocolWrapper Module

+

Make Twisted use M2Crypto for SSL

+

Copyright (c) 2004-2007 Open Source Applications Foundation. +All rights reserved.

+

FIXME THIS HAS NOT BEEN FINISHED. NEITHER PEP484 NOR PORT PYTHON3 HAS +BEEN FINISHED. THE FURTHER WORK WILL BE DONE WHEN THE STATUS OF TWISTED +IN THE PYTHON 3 (AND ASYNCIO) WORLD WILL BE CLEAR.

+
+
+class M2Crypto.SSL.TwistedProtocolWrapper.TLSProtocolWrapper(factory: twisted.protocols.policies.WrappingFactory, wrappedProtocol: object, startPassThrough: int, client: int, contextFactory: object, postConnectionCheck: M2Crypto.SSL.Checker.Checker)[source]
+

Bases: twisted.protocols.policies.ProtocolWrapper

+

A SSL/TLS protocol wrapper to be used with Twisted. Typically +you would not use this class directly. Use connectTCP, +connectSSL, listenTCP, listenSSL functions defined above, +which will hook in this class.

+
+
+clear()[source]
+

Clear this instance, after which it is ready for reuse.

+
+ +
+
+connectionLost(reason: AnyStr) → None[source]
+

Called when the connection is shut down.

+

Clear any circular references here, and any external references +to this Protocol. The connection has been closed.

+

@type reason: L{twisted.python.failure.Failure}

+
+ +
+
+connectionMade()[source]
+

Called when a connection is made.

+

This may be considered the initializer of the protocol, because +it is called when the connection is completed. For clients, +this is called once the connection to the server has been +established; for servers, this is called after an accept() call +stops blocking and a socket has been received. If you need to +send any greeting or initial message, do it here.

+
+ +
+
+dataReceived(data: bytes) → None[source]
+

Called whenever data is received.

+

Use this method to translate to a higher-level message. Usually, some +callback will be made upon the receipt of each complete protocol +message.

+
+
@param data: a string of indeterminate length. Please keep in mind

that you will probably need to buffer some data, as partial +(or multiple) protocol messages may be received! I recommend +that unit tests for protocols call through to this method with +differing chunk sizes, down to one byte at a time.

+
+
+
+ +
+
+loseConnection()[source]
+
+ +
+
+startTLS(ctx)[source]
+

Start SSL/TLS. If this is not called, this instance just passes data +through untouched.

+
+ +
+
+write(data: bytes) → None[source]
+
+ +
+
+writeSequence(data: Iterable[bytes]) → None[source]
+
+ +
+ +
+
+M2Crypto.SSL.TwistedProtocolWrapper.connectSSL(host: str, port: int, factory: object, contextFactory: object, timeout: int = 30, bindAddress: Optional[str] = None, reactor: twisted.internet.reactor = <twisted.internet.epollreactor.EPollReactor object>, postConnectionCheck: Checker = <M2Crypto.SSL.Checker.Checker object>) → reactor.connectTCP[source]
+

A convenience function to start an SSL/TLS connection using Twisted.

+

See IReactorSSL interface in Twisted.

+
+ +
+
+M2Crypto.SSL.TwistedProtocolWrapper.connectTCP(host: str, port: int, factory: object, timeout: int = 30, bindAddress: Optional[Union[Tuple[str, int], str]] = None, reactor: object = <twisted.internet.epollreactor.EPollReactor object>, postConnectionCheck: Callable = <M2Crypto.SSL.Checker.Checker object>) → object[source]
+

A convenience function to start a TCP connection using Twisted.

+

NOTE: You must call startTLS(ctx) to go into SSL/TLS mode.

+

See IReactorTCP interface in Twisted.

+
+ +
+
+M2Crypto.SSL.TwistedProtocolWrapper.listenSSL(port, factory, contextFactory, backlog=5, interface='', reactor=<twisted.internet.epollreactor.EPollReactor object>, postConnectionCheck=<function _alwaysSucceedsPostConnectionCheck>)[source]
+

A convenience function to listen for SSL/TLS connections using Twisted.

+

See IReactorSSL interface in Twisted.

+
+ +
+
+M2Crypto.SSL.TwistedProtocolWrapper.listenTCP(port, factory, backlog=5, interface='', reactor=<twisted.internet.epollreactor.EPollReactor object>, postConnectionCheck=None)[source]
+

A convenience function to listen for TCP connections using Twisted.

+

NOTE: You must call startTLS(ctx) to go into SSL/TLS mode.

+

See IReactorTCP interface in Twisted.

+
+

cb Module

@@ -633,11 +1407,63 @@ verification checks.

-
-

ssl_dispatcher Module

+
+

ssl_dispatcher Module

+
+
+class M2Crypto.SSL.ssl_dispatcher.ssl_dispatcher(sock=None, map=None)[source]
+

Bases: asyncore.dispatcher

+
+
+connect(addr: Union[Tuple[str, int], str]) → None[source]
+
+ +
+
+create_socket(ssl_context: M2Crypto.SSL.Context.Context) → None[source]
+
+ +
+
+recv(buffer_size: int = 4096) → bytes[source]
+

Receive data over SSL.

+
+ +
+
+send(buffer: bytes) → int[source]
+

Send data over SSL.

+
+ +
+
-
-

timeout Module

+
+

timeout Module

+

Support for SSL socket timeouts.

+

Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved.

+

Copyright 2008 Heikki Toivonen. All rights reserved.

+
+
+M2Crypto.SSL.timeout.struct_size() → int[source]
+
+ +
+
+M2Crypto.SSL.timeout.struct_to_timeout(binstr: bytes)M2Crypto.SSL.timeout.timeout[source]
+
+ +
+
+class M2Crypto.SSL.timeout.timeout(sec: int = 600, microsec: int = 0)[source]
+

Bases: object

+
+
+pack()[source]
+
+ +
+
@@ -661,44 +1487,44 @@ verification checks.

  • M2Crypto Package
    • M2Crypto Package
    • -
    • ASN1 Module
    • -
    • AuthCookie Module
    • -
    • BIO Module
    • -
    • BN Module
    • -
    • DH Module
    • -
    • DSA Module
    • -
    • EC Module
    • +
    • ASN1 Module
    • +
    • AuthCookie Module
    • +
    • BIO Module
    • +
    • BN Module
    • +
    • DH Module
    • +
    • DSA Module
    • +
    • EC Module
    • EVP Module
    • -
    • Engine Module
    • +
    • Engine Module
    • Err Module
    • -
    • RC4 Module
    • +
    • RC4 Module
    • RSA Module
    • -
    • Rand Module
    • -
    • SMIME Module
    • -
    • X509 Module
    • -
    • callback Module
    • -
    • ftpslib Module
    • -
    • httpslib Module
    • +
    • Rand Module
    • +
    • SMIME Module
    • +
    • X509 Module
    • +
    • callback Module
    • +
    • ftpslib Module
    • +
    • httpslib Module
    • m2 Module
    • m2crypto Module
    • -
    • m2urllib Module
    • -
    • m2urllib2 Module
    • -
    • m2xmlrpclib Module
    • -
    • threading Module
    • +
    • m2urllib Module
    • +
    • m2urllib2 Module
    • +
    • m2xmlrpclib Module
    • +
    • threading Module
    • util Module
    • Subpackages diff --git a/doc/html/M2Crypto.html b/doc/html/M2Crypto.html index ff8cc46..04046ac 100644 --- a/doc/html/M2Crypto.html +++ b/doc/html/M2Crypto.html @@ -37,701 +37,1177 @@

      M2Crypto Package

      M2Crypto Package

      -
      -
      -

      ASN1 Module

      -
      -
      -

      AuthCookie Module

      -
      -
      -

      BIO Module

      -
      -
      -

      BN Module

      -
      -
      -

      DH Module

      -
      -
      -

      DSA Module

      -
      -
      -

      EC Module

      -
      -
      -

      EVP Module

      +
      +
      +

      ASN1 Module

      -
      -class M2Crypto.EVP.Cipher(alg: str, key: bytes, iv: bytes, op: object, key_as_bytes: int = 0, d: str = 'md5', salt: bytes = b'12345678', i: int = 1, padding: int = 1)[source]
      +
      +class M2Crypto.ASN1.ASN1_Integer(asn1int: M2Crypto.ASN1.ASN1_Integer, _pyfree: int = 0)[source]

      Bases: object

      -
      -final() → bytes[source]
      +
      +m2_asn1_integer_free()
      +
      + +
      +
      +class M2Crypto.ASN1.ASN1_Object(asn1obj: M2Crypto.ASN1.ASN1_Object, _pyfree: int = 0)[source]
      +

      Bases: object

      -
      -m2_cipher_ctx_free()
      +
      +m2_asn1_object_free()
      +
      + +
      +
      +class M2Crypto.ASN1.ASN1_String(asn1str: M2Crypto.ASN1.ASN1_String, _pyfree: int = 0)[source]
      +

      Bases: object

      -
      -set_padding(padding: int = 1) → int[source]
      -

      Actually always return 1

      +
      +as_text(flags: int = 0) → str[source]
      +

      Output an ASN1_STRING structure according to the set flags.

      +
      +
      Parameters
      +

      flags – determine the format of the output by using +predetermined constants, see ASN1_STRING_print_ex(3) +manpage for their meaning.

      +
      +
      Returns
      +

      output an ASN1_STRING structure.

      +
      +
      -
      -update(data: bytes) → bytes[source]
      +
      +m2_asn1_string_free()
      -
      -
      -exception M2Crypto.EVP.EVPError[source]
      -

      Bases: ValueError

      -
      -
      -
      -class M2Crypto.EVP.HMAC(key: bytes, algo: str = 'sha1')[source]
      +
      +class M2Crypto.ASN1.ASN1_TIME(asn1_time: Optional[M2Crypto.ASN1.ASN1_TIME] = None, _pyfree: Optional[int] = 0, asn1_utctime: Optional[M2Crypto.ASN1.ASN1_TIME] = None)[source]

      Bases: object

      -
      -digest() → bytes
      +
      +get_datetime()M2Crypto.ASN1.ASN1_TIME[source]
      -
      -final() → bytes[source]
      +
      +m2_asn1_time_free()
      -
      -m2_hmac_ctx_free()
      +
      +set_datetime(date: datetime.datetime)M2Crypto.ASN1.ASN1_TIME[source]
      -
      -reset(key: bytes) → None[source]
      -
      +
      +set_string(string: bytes) → int[source]
      +

      Set time from UTC string.

      +
      -
      -update(data: bytes) → None[source]
      -
      +
      +set_time(time: int)M2Crypto.ASN1.ASN1_TIME[source]
      +

      Set time from seconds since epoch (int).

      +
      + + +
      +
      +M2Crypto.ASN1.ASN1_UTCTIME
      +

      alias of M2Crypto.ASN1.ASN1_TIME

      -
      -class M2Crypto.EVP.MessageDigest(algo: str)[source]
      +
      +class M2Crypto.ASN1.LocalTimezone[source]
      +

      Bases: datetime.tzinfo

      +

      Localtimezone from datetime manual.

      +
      +
      +dst(dt: datetime.datetime) → datetime.timedelta[source]
      +

      datetime -> DST offset as timedelta positive east of UTC.

      +
      + +
      +
      +tzname(dt: datetime.datetime) → str[source]
      +

      datetime -> string name of time zone.

      +
      + +
      +
      +utcoffset(dt: datetime.datetime) → datetime.timedelta[source]
      +

      datetime -> timedelta showing offset from UTC, negative values indicating West of UTC

      +
      + +
      + +
      +
      +

      AuthCookie Module

      +
      +
      +class M2Crypto.AuthCookie.AuthCookie(expiry: float, data: str, dough: str, mac: str)[source]

      Bases: object

      -

      Message Digest

      -
      -digest()
      -
      +
      +data() → str[source]
      +

      Return the data portion of the cookie.

      +
      -
      -final()[source]
      +
      +expiry() → float[source]
      +

      Return the cookie’s expiry time.

      +
      + +
      +
      +headerValue() → str[source]
      -
      -m2_md_ctx_free()
      +
      +isExpired() → bool[source]
      +

      Return 1 if the cookie has expired, 0 otherwise.

      +
      + +
      +
      +mac() → str[source]
      +

      Return the cookie’s MAC.

      +
      + +
      +
      +name() → str[source]
      -
      -update(data: bytes) → int[source]
      -

      Add data to be digested.

      -
      -
      Returns
      -

      -1 for Python error, 1 for success, 0 for OpenSSL failure.

      -
      -
      +
      +output(header: Optional[str] = 'Set-Cookie:') → str[source]
      +

      Return the cookie’s output in “Set-Cookie” format.

      +
      + +
      +
      +value() → str[source]
      +

      Return the cookie’s output minus the “Set-Cookie: ” portion.

      -
      -class M2Crypto.EVP.PKey(pkey: Optional[bytes] = None, _pyfree: int = 0, md: str = 'sha1')[source]
      +
      +class M2Crypto.AuthCookie.AuthCookieJar[source]

      Bases: object

      -

      Public Key

      -
      -as_der() → bytes[source]
      -

      Return key in DER format in a string

      -
      +
      +isGoodCookie(cookie: M2Crypto.AuthCookie.AuthCookie) → Union[bool, int][source]
      +
      -
      -as_pem(cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → bytes[source]
      -

      Return key in PEM format in a string.

      -
      -
      Parameters
      -
        -
      • cipher – Symmetric cipher to protect the key. The default -cipher is 'aes_128_cbc'. If cipher is None, -then the key is saved in the clear.

      • -
      • callback – A Python callable object that is invoked -to acquire a passphrase with which to protect -the key. The default is -util.passphrase_callback.

      • -
      -
      -
      -
      +
      +isGoodCookieString(cookie_str: Union[dict, bytes], _debug: bool = False) → Union[bool, int][source]
      +
      -
      -assign_rsa(rsa: M2Crypto.RSA.RSA, capture: int = 1) → int[source]
      -

      Assign the RSA key pair to self.

      +
      +makeCookie(expiry: float, data: str)M2Crypto.AuthCookie.AuthCookie[source]
      +

      Make a cookie

      Parameters
        -
      • rsa – M2Crypto.RSA.RSA object to be assigned to self.

      • -
      • capture – If true (default), this PKey object will own the RSA -object, meaning that once the PKey object gets -deleted it is no longer safe to use the RSA object.

      • +
      • expiry – expiration time (float in seconds)

      • +
      • data – cookie content

      Returns
      -

      Return 1 for success and 0 for failure.

      +

      AuthCookie object

      + + +
      +
      +M2Crypto.AuthCookie.mix(expiry: float, data: AnyStr, format: str = 'exp=%f&data=%s&digest=') → AnyStr[source]
      +
      + +
      +
      +M2Crypto.AuthCookie.unmix(dough: AnyStr, regex: re = re.compile('exp=(\\d+\\.\\d+)&data=(.+)&digest=(\\S*)')) → object[source]
      +
      + +
      +
      +M2Crypto.AuthCookie.unmix3(dough: AnyStr, regex: type_re = re.compile('exp=(\\d+\\.\\d+)&data=(.+)&digest=(\\S*)')) → Optional[tuple[float, AnyStr, AnyStr]][source]
      +
      + +
      +
      +

      BIO Module

      +
      +
      +class M2Crypto.BIO.BIO(bio: Optional[M2Crypto.BIO.BIO] = None, _pyfree: int = 0, _close_cb: Optional[Callable] = None)[source]
      +

      Bases: object

      +

      Abstract object interface to the BIO API.

      -
      -digest_sign(data) → bytes[source]
      -

      Return signature.

      +
      +bio_ptr()
      +
      + +
      +
      +close() → None[source]
      +
      + +
      +
      +fileno() → int[source]
      +
      + +
      +
      +flush() → None[source]
      +

      Flush the buffers.

      Returns
      -

      The signature.

      +

      1 for success, and 0 or -1 for failure

      -
      -digest_sign_final() → bytes[source]
      -

      Return signature.

      +
      +m2_bio_free()
      +
      + +
      +
      +read(size: Optional[int] = None) → Union[bytes, bytearray][source]
      +
      + +
      +
      +readable() → bool[source]
      +
      + +
      +
      +readline(size: int = 4096) → bytes[source]
      +
      + +
      +
      +readlines(sizehint: Union[AnyStr, int] = 'ignored') → Iterable[bytes][source]
      +
      + +
      +
      +reset() → int[source]
      +

      Set the bio to its initial state.

      Returns
      -

      The signature.

      +

      1 for success, and 0 or -1 for failure

      -
      -digest_sign_init() → None[source]
      -

      Initialise digest signing operation with self.

      +
      +seek(off)[source]
      +

      Seek to the specified absolute offset.

      -
      -digest_sign_update(data: bytes) → None[source]
      -

      Feed data to digest signing operation.

      -
      -
      Parameters
      -

      data – Data to be signed.

      -
      -
      +
      +should_read() → int[source]
      +

      Should we read more data?

      -
      -digest_verify()[source]
      -

      Return result of verification.

      -
      -
      Parameters
      -
        -
      • sign – Signature to use for verification

      • -
      • data – Data to be verified.

      • -
      -
      -
      Returns
      -

      Result of verification: 1 for success, 0 for failure, -1 on -other error.

      -
      -
      +
      +should_retry() → int[source]
      +

      Can the call be attempted again, or was there an error +ie do_handshake

      -
      -digest_verify_final(sign: bytes) → int[source]
      -

      Feed data to digest verification operation.

      -
      -
      Parameters
      -

      sign – Signature to use for verification

      -
      -
      Returns
      -

      Result of verification: 1 for success, 0 for failure, -1 on -other error.

      -
      -
      +
      +should_write() → int[source]
      +

      Should we write more data?

      -
      -digest_verify_init() → None[source]
      -

      Initialise verification operation with self.

      +
      +tell()[source]
      +

      Return the current offset.

      -
      -digest_verify_update(data: bytes) → int[source]
      -

      Feed data to verification operation.

      +
      +write(data: AnyStr) → int[source]
      +

      Write data to BIO.

      -
      Parameters
      -

      data – Data to be verified.

      -
      -
      Returns
      -

      -1 on Python error, 1 for success, 0 for OpenSSL error

      +
      Returns
      +

      either data written, or [0, -1] for nothing written, +-2 not implemented

      -
      -final() → bytes
      -

      Return signature.

      -
      -
      Returns
      -

      The signature.

      -
      -
      -
      +
      +write_close() → None[source]
      +
      -
      -get_modulus() → Optional[bytes][source]
      -

      Return the modulus in hex format.

      +
      +writeable() → bool[source]
      +
      + -
      -
      -get_rsa()M2Crypto.RSA.RSA_pub[source]
      -

      Return the underlying RSA key if that is what the EVP -instance is holding.

      +
      +
      +exception M2Crypto.BIO.BIOError[source]
      +

      Bases: ValueError

      -
      -
      -m2_md_ctx_free()
      +
      +
      +class M2Crypto.BIO.CipherStream(obio: M2Crypto.BIO.BIO)[source]
      +

      Bases: M2Crypto.BIO.BIO

      +

      Object interface to BIO_f_cipher.

      +
      +
      +SALT_LEN = 8
      -
      -m2_pkey_free()
      +
      +close() → None[source]
      -
      -reset_context(md: str = 'sha1') → None[source]
      -

      Reset internal message digest context.

      -
      -
      Parameters
      -

      md – The message digest algorithm.

      -
      -
      -
      +
      +m2_bio_free()
      +
      -
      -save_key(file: AnyStr, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
      -

      Save the key pair to a file in PEM format.

      -
      -
      Parameters
      -
        -
      • file – Name of file to save key to.

      • -
      • cipher – Symmetric cipher to protect the key. The default -cipher is ‘aes_128_cbc’. If cipher is None, then -the key is saved in the clear.

      • -
      • callback – A Python callable object that is invoked -to acquire a passphrase with which to protect -the key. The default is -util.passphrase_callback.

      • -
      -
      -
      +
      +m2_bio_pop()
      +
      + +
      +
      +set_cipher(algo: str, key: AnyStr, iv: AnyStr, op: int) → None[source]
      +
      + +
      +
      +write_close() → None[source]
      +
      +
      +
      +
      +class M2Crypto.BIO.File(pyfile: Union[_io.BytesIO, AnyStr], close_pyfile: int = 1, mode: AnyStr = 'rb')[source]
      +

      Bases: M2Crypto.BIO.BIO

      +

      Object interface to BIO_s_pyfd.

      +

      This class interfaces Python to OpenSSL functions that expect BIO. For +general file manipulation in Python, use Python’s builtin file object.

      -
      -save_key_bio(bio: BIO.BIO, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
      -

      Save the key pair to the M2Crypto.BIO object ‘bio’ in PEM format.

      +
      +close() → None[source]
      +
      + +
      +
      +flush() → None[source]
      +

      Flush the buffers.

      -
      Parameters
      -
        -
      • bio – M2Crypto.BIO object to save key to.

      • -
      • cipher – Symmetric cipher to protect the key. The default -cipher is ‘aes_128_cbc’. If cipher is None, then -the key is saved in the clear.

      • -
      • callback – A Python callable object that is invoked -to acquire a passphrase with which to protect -the key. The default is -util.passphrase_callback.

      • -
      +
      Returns
      +

      1 for success, and 0 or -1 for failure

      -
      -sign_final() → bytes[source]
      -

      Return signature.

      +
      +reset() → int[source]
      +

      Set the bio to its initial state.

      Returns
      -

      The signature.

      +

      0 for success, and -1 for failure

      +
      + +
      +
      +class M2Crypto.BIO.IOBuffer(under_bio: M2Crypto.BIO.BIO, mode: str = 'rwb', _pyfree: int = 1)[source]
      +

      Bases: M2Crypto.BIO.BIO

      +

      Object interface to BIO_f_buffer.

      +

      Its principal function is to be BIO_push()’ed on top of a BIO_f_ssl, so +that makefile() of said underlying SSL socket works.

      -
      -sign_init() → None[source]
      -

      Initialise signing operation with self.

      +
      +close() → None[source]
      +
      + +
      +
      +m2_bio_free()
      +
      + +
      +
      +m2_bio_pop()
      +
      +
      +
      +
      +class M2Crypto.BIO.MemoryBuffer(data: Optional[bytes] = None)[source]
      +

      Bases: M2Crypto.BIO.BIO

      +

      Object interface to BIO_s_mem.

      +

      Empirical testing suggests that this class performs less well than +cStringIO, because cStringIO is implemented in C, whereas this class +is implemented in Python. Thus, the recommended practice is to use +cStringIO for regular work and convert said cStringIO object to +a MemoryBuffer object only when necessary.

      -
      -sign_update(data: bytes) → None[source]
      -

      Feed data to signing operation.

      -
      -
      Parameters
      -

      data – Data to be signed.

      -
      -
      +
      +close() → None
      +
      + +
      +
      +getvalue(size: int = 0) → bytes
      +
      + +
      +
      +read(size: int = 0) → bytes[source]
      +
      + +
      +
      +read_all(size: int = 0) → bytes
      +
      + +
      +
      +write_close() → None[source]
      +
      +
      +
      +
      +class M2Crypto.BIO.SSLBio(_pyfree: int = 1)[source]
      +

      Bases: M2Crypto.BIO.BIO

      +

      Object interface to BIO_f_ssl.

      -
      -size() → int[source]
      -

      Return the size of the key in bytes.

      +
      +do_handshake() → int[source]
      +

      Do the handshake.

      +

      Return 1 if the handshake completes +Return 0 or a negative number if there is a problem

      -
      -update(data: bytes) → None
      -

      Feed data to signing operation.

      +
      +set_ssl(conn, close_flag=0)[source]
      +

      Sets the bio to the SSL pointer which is +contained in the connection object.

      +
      + +
      + +
      +
      +M2Crypto.BIO.openfile(filename: AnyStr, mode: AnyStr = 'rb')M2Crypto.BIO.File[source]
      +
      + +
      +
      +

      BN Module

      +
      +
      +M2Crypto.BN.rand(bits: int, top: int = - 1, bottom: int = 0) → Optional[int][source]
      +

      Generate cryptographically strong random number.

      Parameters
      -

      data – Data to be signed.

      +
        +
      • bits – Length of random number in bits.

      • +
      • top – If -1, the most significant bit can be 0. If 0, the most +significant bit is 1, and if 1, the two most significant +bits will be 1.

      • +
      • bottom – If bottom is true, the number will be odd.

      • +
      -
      -
      -verify_final(sign: bytes) → int[source]
      -

      Return result of verification.

      +
      +
      +M2Crypto.BN.rand_range(range: int) → int[source]
      +

      Generate a random number in a range.

      Parameters
      -

      sign – Signature to use for verification

      +

      range – Upper limit for range.

      Returns
      -

      Result of verification: 1 for success, 0 for failure, -1 on -other error.

      +

      A random number in the range [0, range)

      -
      -
      -verify_init() → None[source]
      -

      Initialise signature verification operation with self.

      -
      - -
      -
      -verify_update(data: bytes) → int[source]
      -

      Feed data to verification operation.

      +
      +
      +M2Crypto.BN.randfname(length: int) → str[source]
      +

      Return a random filename, which is simply a string where all +the characters are from the set [a-zA-Z0-9].

      Parameters
      -

      data – Data to be verified.

      +

      length – Length of filename to return.

      Returns
      -

      -1 on Python error, 1 for success, 0 for OpenSSL error

      +

      random filename string

      +
      +
      +

      DH Module

      +
      +
      +class M2Crypto.DH.DH(dh: bytes, _pyfree: int = 0)[source]
      +

      Bases: object

      +

      Object interface to the Diffie-Hellman key exchange protocol.

      +
      +
      +check_params() → int[source]
      +
      + +
      +
      +compute_key(pubkey: bytes) → bytes[source]
      +
      + +
      +
      +gen_key() → None[source]
      +
      + +
      +
      +m2_dh_free()
      +
      + +
      +
      +print_params(bio: M2Crypto.BIO.BIO) → int[source]
      +
      + +
      + +
      +
      +exception M2Crypto.DH.DHError[source]
      +

      Bases: Exception

      -
      -M2Crypto.EVP.hmac(key: bytes, data: bytes, algo: str = 'sha1') → bytes[source]
      +
      +M2Crypto.DH.gen_params(plen: int, g: int, callback: Optional[Callable] = <function genparam_callback>)M2Crypto.DH.DH[source]
      -
      -M2Crypto.EVP.load_key(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
      -

      Load an M2Crypto.EVP.PKey from file.

      +
      +M2Crypto.DH.load_params(file: AnyStr)M2Crypto.DH.DH[source]
      +
      + +
      +
      +M2Crypto.DH.load_params_bio(bio: M2Crypto.BIO.BIO)M2Crypto.DH.DH[source]
      +
      + +
      +
      +M2Crypto.DH.set_params(p: bytes, g: bytes)M2Crypto.DH.DH[source]
      +
      + +
      +
      +

      DSA Module

      +
      +
      +class M2Crypto.DSA.DSA(dsa: bytes, _pyfree: int = 0)[source]
      +

      Bases: object

      +

      This class is a context supporting DSA key and parameter +values, signing and verifying.

      +

      Simple example:

      +
      from M2Crypto import EVP, DSA, util
      +
      +message = 'Kilroy was here!'
      +md = EVP.MessageDigest('sha1')
      +md.update(message)
      +digest = md.final()
      +
      +dsa = DSA.gen_params(1024)
      +dsa.gen_key()
      +r, s = dsa.sign(digest)
      +good = dsa.verify(digest, r, s)
      +if good:
      +    print('  ** success **')
      +else:
      +    print('  ** verification failed **')
      +
      +
      +
      +
      +check_key()[source]
      +

      Check to be sure the DSA object has a valid private key.

      +
      +
      Returns
      +

      1 (true) if a valid private key

      +
      +
      +
      + +
      +
      +gen_key() → None[source]
      +

      Generate a key pair.

      +
      + +
      +
      +m2_dsa_free()
      +
      + +
      +
      +save_key(filename: AnyStr, cipher: str = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
      +

      Save the DSA key pair to a file.

      Parameters
        -
      • file – Name of file containing the key in PEM format.

      • -
      • callback – A Python callable object that is invoked -to acquire a passphrase with which to protect the -key.

      • +
      • filename – Save the DSA key pair to this file.

      • +
      • cipher – name of symmetric key algorithm and mode +to encrypt the private key.

      Returns
      -

      M2Crypto.EVP.PKey object.

      +

      1 (true) if successful

      -
      -
      -M2Crypto.EVP.load_key_bio(bio: BIO.BIO, callback: Callable = <function passphrase_callback>)PKey[source]
      -

      Load an M2Crypto.EVP.PKey from an M2Crypto.BIO object.

      +
      +
      +save_key_bio(bio: M2Crypto.BIO.BIO, cipher: str = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
      +

      Save DSA key pair to a BIO object.

      Parameters
        -
      • bio – M2Crypto.BIO object containing the key in PEM format.

      • -
      • callback – A Python callable object that is invoked -to acquire a passphrase with which to protect the -key.

      • +
      • bio – Save DSA parameters to this object.

      • +
      • cipher – name of symmetric key algorithm and mode +to encrypt the private key.

      Returns
      -

      M2Crypto.EVP.PKey object.

      +

      1 (true) if successful

      -
      -
      -M2Crypto.EVP.load_key_bio_pubkey(bio: BIO.BIO, callback: Callable = <function passphrase_callback>)PKey[source]
      -

      Load an M2Crypto.EVP.PKey from a public key as a M2Crypto.BIO object.

      +
      +
      +save_params(filename: AnyStr) → int[source]
      +

      Save the DSA parameters to a file.

      Parameters
      -
        -
      • bio – M2Crypto.BIO object containing the key in PEM format.

      • -
      • callback – A Python callable object that is invoked -to acquire a passphrase with which to protect the -key.

      • -
      +

      filename – Save the DSA parameters to this file.

      Returns
      -

      M2Crypto.EVP.PKey object.

      +

      1 (true) if successful

      -
      -
      -M2Crypto.EVP.load_key_pubkey(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
      -

      Load an M2Crypto.EVP.PKey from a public key as a file.

      +
      +
      +save_params_bio(bio: M2Crypto.BIO.BIO) → int[source]
      +

      Save DSA parameters to a BIO object.

      Parameters
      -
        -
      • file – Name of file containing the key in PEM format.

      • -
      • callback – A Python callable object that is invoked -to acquire a passphrase with which to protect the -key.

      • -
      +

      bio – Save DSA parameters to this object.

      Returns
      -

      M2Crypto.EVP.PKey object.

      +

      1 (true) if successful

      -
      -
      -M2Crypto.EVP.load_key_string(string: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
      -

      Load an M2Crypto.EVP.PKey from a string.

      +
      +
      +save_pub_key(filename: AnyStr) → int[source]
      +

      Save the DSA public key (with parameters) to a file.

      Parameters
      -
        -
      • string – String containing the key in PEM format.

      • -
      • callback – A Python callable object that is invoked -to acquire a passphrase with which to protect the -key.

      • -
      +

      filename – Save DSA public key (with parameters) +to this file.

      Returns
      -

      M2Crypto.EVP.PKey object.

      +

      1 (true) if successful

      -
      -
      -M2Crypto.EVP.load_key_string_pubkey(string: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
      -

      Load an M2Crypto.EVP.PKey from a public key as a string.

      +
      +
      +save_pub_key_bio(bio: M2Crypto.BIO.BIO) → int[source]
      +

      Save DSA public key (with parameters) to a BIO object.

      Parameters
      -
        -
      • string – String containing the key in PEM format.

      • -
      • callback – A Python callable object that is invoked -to acquire a passphrase with which to protect the -key.

      • -
      +

      bio – Save DSA public key (with parameters) +to this object.

      Returns
      -

      M2Crypto.EVP.PKey object.

      +

      1 (true) if successful

      -
      -
      -M2Crypto.EVP.pbkdf2(password: bytes, salt: bytes, iter: int, keylen: int) → bytes[source]
      -

      Derive a key from password using PBKDF2 algorithm specified in RFC 2898.

      +
      +
      +set_params(p: bytes, q: bytes, g: bytes) → None[source]
      +

      Set new parameters.

      Parameters
        -
      • password – Derive the key from this password.

      • -
      • salt – Salt.

      • -
      • iter – Number of iterations to perform.

      • -
      • keylen – Length of key to produce.

      • +
      • p – MPI binary representation … format that consists of +the number’s length in bytes represented as a 4-byte +big-endian number, and the number itself in big-endian +format, where the most significant bit signals +a negative number (the representation of numbers with +the MSB set is prefixed with null byte).

      • +
      • q – ditto

      • +
      • g – ditto

      +
      +
      +
      @warning: This does not change the private key, so it may be

      unsafe to use this method. It is better to use +gen_params function to create a new DSA object.

      +
      +
      +
      + +
      +
      +sign(digest: bytes) → Tuple[bytes, bytes][source]
      +

      Sign the digest.

      +
      +
      Parameters
      +

      digest – SHA-1 hash of message (same as output +from MessageDigest, a “byte string”)

      +
      Returns
      -

      Key.

      +

      DSA signature, a tuple of two values, r and s, +both “byte strings”.

      -
      -
      -

      Engine Module

      -
      -
      -

      Err Module

      -
      -
      -exception M2Crypto.Err.M2CryptoError[source]
      -

      Bases: Exception

      +
      +
      +sign_asn1(digest)[source]
      +
      + +
      +
      +verify(digest: bytes, r: bytes, s: bytes) → int[source]
      +

      Verify a newly calculated digest against the signature +values r and s.

      +
      +
      Parameters
      +
        +
      • digest – SHA-1 hash of message (same as output +from MessageDigest, a “byte string”)

      • +
      • r – r value of the signature, a “byte string”

      • +
      • s – s value of the signature, a “byte string”

      • +
      +
      +
      Returns
      +

      1 (true) if verify succeeded, 0 if failed

      +
      +
      +
      + +
      +
      +verify_asn1(digest, blob)[source]
      +
      +
      -
      -exception M2Crypto.Err.SSLError(err: int, client_addr: Union[Tuple[str, int], str])[source]
      +
      +exception M2Crypto.DSA.DSAError[source]

      Bases: Exception

      -
      -
      -M2Crypto.Err.get_error() → Optional[str][source]
      -
      +
      +
      +class M2Crypto.DSA.DSA_pub(dsa: bytes, _pyfree: int = 0)[source]
      +

      Bases: M2Crypto.DSA.DSA

      +

      This class is a DSA context that only supports a public key +and verification. It does NOT support a private key or +signing.

      +
      +
      +check_key() → int[source]
      +
      +
      Returns
      +

      does DSA_pub contain a pub key?

      +
      +
      +
      + +
      +
      +save_key(filename: AnyStr) → int
      +

      Save the DSA public key (with parameters) to a file.

      +
      +
      Parameters
      +

      filename – Save DSA public key (with parameters) +to this file.

      +
      +
      Returns
      +

      1 (true) if successful

      +
      +
      +
      + +
      +
      +save_key_bio(bio: M2Crypto.BIO.BIO) → int
      +

      Save DSA public key (with parameters) to a BIO object.

      +
      +
      Parameters
      +

      bio – Save DSA public key (with parameters) +to this object.

      +
      +
      Returns
      +

      1 (true) if successful

      +
      +
      +
      + +
      +
      +sign(*argv: Any) → None[source]
      +

      Sign the digest.

      +
      +
      Parameters
      +

      digest – SHA-1 hash of message (same as output +from MessageDigest, a “byte string”)

      +
      +
      Returns
      +

      DSA signature, a tuple of two values, r and s, +both “byte strings”.

      +
      +
      +
      + +
      +
      +sign_asn1(*argv: Any) → None
      +

      Sign the digest.

      +
      +
      Parameters
      +

      digest – SHA-1 hash of message (same as output +from MessageDigest, a “byte string”)

      +
      +
      Returns
      +

      DSA signature, a tuple of two values, r and s, +both “byte strings”.

      +
      +
      +
      + +
      -
      -M2Crypto.Err.get_error_code() → int[source]
      -
      +
      +M2Crypto.DSA.gen_params(bits: int, callback: Callable = <function genparam_callback>)M2Crypto.DSA.DSA[source]
      +

      Factory function that generates DSA parameters and +instantiates a DSA object from the output.

      +
      +
      Parameters
      +
        +
      • bits – The length of the prime to be generated. If +‘bits’ < 512, it is set to 512.

      • +
      • callback – A Python callback object that will be +invoked during parameter generation; it usual +purpose is to provide visual feedback.

      • +
      +
      +
      Returns
      +

      instance of DSA.

      +
      +
      +
      -
      -M2Crypto.Err.get_error_func(err: Optional[int]) → str[source]
      -
      +
      +M2Crypto.DSA.load_key(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.DSA.DSA[source]
      +

      Factory function that instantiates a DSA object from a +PEM encoded DSA key pair.

      +
      +
      Parameters
      +
        +
      • file – Names the file (a path) that contains the PEM +representation of the DSA key pair.

      • +
      • callback – A Python callback object that will be +invoked if the DSA key pair is +passphrase-protected.

      • +
      +
      +
      Returns
      +

      instance of DSA.

      +
      +
      +
      -
      -M2Crypto.Err.get_error_lib(err: Optional[int]) → str[source]
      -
      +
      +M2Crypto.DSA.load_key_bio(bio: M2Crypto.BIO.BIO, callback: Callable = <function passphrase_callback>)M2Crypto.DSA.DSA[source]
      +

      Factory function that instantiates a DSA object from a +PEM encoded DSA key pair.

      +
      +
      Parameters
      +
        +
      • bio – Contains the PEM representation of the DSA +key pair.

      • +
      • callback – A Python callback object that will be +invoked if the DSA key pair is +passphrase-protected.

      • +
      +
      +
      Returns
      +

      instance of DSA.

      +
      +
      +
      -
      -M2Crypto.Err.get_error_message() → str[source]
      -
      +
      +M2Crypto.DSA.load_params(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.DSA.DSA[source]
      +

      Factory function that instantiates a DSA object with DSA +parameters from a file.

      +
      +
      Parameters
      +
        +
      • file – Names the file (a path) that contains the PEM +representation of the DSA parameters.

      • +
      • callback – A Python callback object that will be +invoked if the DSA parameters file is +passphrase-protected.

      • +
      +
      +
      Returns
      +

      instance of DSA.

      +
      +
      +
      -
      -M2Crypto.Err.get_error_reason(err: Optional[int]) → str[source]
      -
      +
      +M2Crypto.DSA.load_params_bio(bio: M2Crypto.BIO.BIO, callback: Callable = <function passphrase_callback>)M2Crypto.DSA.DSA[source]
      +

      Factory function that instantiates a DSA object with DSA +parameters from a M2Crypto.BIO object.

      +
      +
      Parameters
      +
        +
      • bio – Contains the PEM representation of the DSA +parameters.

      • +
      • callback – A Python callback object that will be +invoked if the DSA parameters file is +passphrase-protected.

      • +
      +
      +
      Returns
      +

      instance of DSA.

      +
      +
      +
      -
      -M2Crypto.Err.get_x509_verify_error(err: Optional[int]) → str[source]
      -
      +
      +M2Crypto.DSA.load_pub_key(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.DSA.DSA_pub[source]
      +

      Factory function that instantiates a DSA_pub object using +a DSA public key contained in PEM file. The PEM file +must contain the parameters in addition to the public key.

      +
      +
      Parameters
      +
        +
      • file – Names the file (a path) that contains the PEM +representation of the DSA public key.

      • +
      • callback – A Python callback object that will be +invoked should the DSA public key be +passphrase-protected.

      • +
      +
      +
      Returns
      +

      instance of DSA_pub.

      +
      +
      +
      -
      -M2Crypto.Err.peek_error_code() → int[source]
      -
      +
      +M2Crypto.DSA.load_pub_key_bio(bio: M2Crypto.BIO.BIO, callback: Callable = <function passphrase_callback>)M2Crypto.DSA.DSA_pub[source]
      +

      Factory function that instantiates a DSA_pub object using +a DSA public key contained in PEM format. The PEM +must contain the parameters in addition to the public key.

      +
      +
      Parameters
      +
        +
      • bio – Contains the PEM representation of the DSA +public key (with params).

      • +
      • callback – A Python callback object that will be +invoked should the DSA public key be +passphrase-protected.

      • +
      +
      +
      Returns
      +

      instance of DSA_pub.

      +
      +
      +
      -
      -
      -

      RC4 Module

      -
      -
      -

      RSA Module

      -
      -
      -class M2Crypto.RSA.RSA(rsa: bytes, _pyfree: int = 0)[source]
      -

      Bases: object

      -

      RSA Key Pair.

      -
      -
      -as_pem(cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → bytes[source]
      -

      Returns the key(pair) as a string in PEM format.

      +
      +
      +M2Crypto.DSA.pub_key_from_params(p: bytes, q: bytes, g: bytes, pub: bytes)M2Crypto.DSA.DSA_pub[source]
      +

      Factory function that instantiates a DSA_pub object using +the parameters and public key specified.

      +
      +
      Parameters
      +
        +
      • p – value of p

      • +
      • q – value of q

      • +
      • g – value of g

      • +
      • pub – value of the public key

      • +
      +
      +
      Returns
      +

      instance of DSA_pub.

      +
      +
      -
      -
      -check_key() → int[source]
      -

      Validate RSA keys.

      -

      It checks that p and q are in fact prime, and that n = p*q.

      +
      +
      +M2Crypto.DSA.set_params(p: bytes, q: bytes, g: bytes)M2Crypto.DSA.DSA[source]
      +

      Factory function that instantiates a DSA object with DSA +parameters.

      -
      Returns
      -

      returns 1 if rsa is a valid RSA key, and 0 otherwise. --1 is returned if an error occurs while checking the key. -If the key is invalid or an error occurred, the reason -code can be obtained using ERR_get_error(3).

      +
      Parameters
      +
        +
      • p – value of p, a “byte string”

      • +
      • q – value of q, a “byte string”

      • +
      • g – value of g, a “byte string”

      • +
      +
      +
      Returns
      +

      instance of DSA.

      +
      +
      +

      EC Module

      +
      +
      +class M2Crypto.EC.EC(ec: M2Crypto.EC.EC, _pyfree: int = 0)[source]
      +

      Bases: object

      +

      Object interface to a EC key pair.

      -
      -m2_rsa_free()
      -
      +
      +as_pem(cipher='aes_128_cbc', callback=<function passphrase_callback>)[source]
      +

      Returns the key(pair) as a string in PEM format. +If no password is passed and the cipher is set +it exits with error

      +
      -
      -private_decrypt(data: bytes, padding: int) → bytes[source]
      +
      +check_key() → int[source]
      -
      -private_encrypt(data: bytes, padding: int) → bytes[source]
      -
      +
      +compute_dh_key(pub_key: M2Crypto.EC.EC) → Optional[bytes][source]
      +

      Compute the ECDH shared key of this key pair and the given public +key object. They must both use the same curve. Returns the +shared key in binary as a buffer object. No Key Derivation Function is +applied.

      +
      -
      -pub() → Tuple[bytes, bytes][source]
      -
      +
      +gen_key() → int[source]
      +

      Generates the key pair from its parameters. Use:

      +
      keypair = EC.gen_params(curve)
      +keypair.gen_key()
      +
      +
      +

      to create an EC key pair.

      +
      -
      -public_decrypt(data: bytes, padding: int) → bytes[source]
      +
      +m2_ec_key_free()
      -
      -public_encrypt(data: bytes, padding: int) → bytes[source]
      +
      +pub()M2Crypto.EC.EC_pub[source]
      -
      -save_key(file: AnyStr, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
      +
      +save_key(file: AnyStr, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]

      Save the key pair to a file in PEM format.

      Parameters
        -
      • file – Name of file to save key to.

      • +
      • file – Name of filename to save key to.

      • cipher – Symmetric cipher to protect the key. The default cipher is ‘aes_128_cbc’. If cipher is None, then the key is saved in the clear.

      • @@ -745,8 +1221,8 @@ util.passphrase_callback.

      -
      -save_key_bio(bio: BIO.BIO, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
      +
      +save_key_bio(bio: M2Crypto.BIO.BIO, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]

      Save the key pair to an M2Crypto.BIO.BIO object in PEM format.

      Parameters
      @@ -757,7 +1233,7 @@ cipher is ‘aes_128_cbc’. If cipher is None, then the key is saved in the clear.

    • callback – A Python callable object that is invoked to acquire a passphrase with which to protect -the key. The default is +the key. The default is util.passphrase_callback.

    @@ -765,20 +1241,20 @@ util.passphrase_callback.

  • -
    -save_key_der(file: AnyStr) → int[source]
    -

    Save the key pair to a file in DER format.

    +
    +save_pub_key(file: AnyStr) → int[source]
    +

    Save the public key to a filename in PEM format.

    Parameters
    -

    file – Filename to save key to

    +

    file – Name of filename to save key to.

    -
    -save_key_der_bio(bio: BIO.BIO) → int[source]
    -

    Save the key pair to an M2Crypto.BIO.BIO object in DER format.

    +
    +save_pub_key_bio(bio: M2Crypto.BIO.BIO) → int[source]
    +

    Save the public key to an M2Crypto.BIO.BIO object in PEM format.

    Parameters

    bio – M2Crypto.BIO.BIO object to save key to.

    @@ -787,19 +1263,337 @@ util.passphrase_callback.

    -
    -save_pem(file: AnyStr, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int
    -

    Save the key pair to a file in PEM format.

    -
    -
    Parameters
    -
      -
    • file – Name of file to save key to.

    • -
    • cipher – Symmetric cipher to protect the key. The default -cipher is ‘aes_128_cbc’. If cipher is None, then -the key is saved in the clear.

    • +
      +sign_dsa(digest: bytes) → Tuple[bytes, bytes][source]
      +

      Sign the given digest using ECDSA. Returns a tuple (r,s), the two +ECDSA signature parameters.

      +
    + +
    +
    +sign_dsa_asn1(digest: bytes) → bytes[source]
    +
    + +
    +
    +verify_dsa(digest: bytes, r: bytes, s: bytes) → int[source]
    +

    Verify the given digest using ECDSA. r and s are the ECDSA +signature parameters.

    +
    + +
    +
    +verify_dsa_asn1(digest, blob)[source]
    +
    + +
    + +
    +
    +exception M2Crypto.EC.ECError[source]
    +

    Bases: Exception

    +
    + +
    +
    +class M2Crypto.EC.EC_pub(ec: M2Crypto.EC.EC, _pyfree: int = 0)[source]
    +

    Bases: M2Crypto.EC.EC

    +

    Object interface to an EC public key. +((don’t like this implementation inheritance))

    +
    +
    +get_der() → bytes[source]
    +

    Returns the public key in DER format as a buffer object.

    +
    + +
    +
    +get_key() → bytes[source]
    +

    Returns the public key as a byte string.

    +
    + +
    +
    +save_key(file: AnyStr) → int
    +

    Save the public key to a filename in PEM format.

    +
    +
    Parameters
    +

    file – Name of filename to save key to.

    +
    +
    +
    + +
    +
    +save_key_bio(bio: M2Crypto.BIO.BIO) → int
    +

    Save the public key to an M2Crypto.BIO.BIO object in PEM format.

    +
    +
    Parameters
    +

    bio – M2Crypto.BIO.BIO object to save key to.

    +
    +
    +
    + +
    + +
    +
    +M2Crypto.EC.ec_error()M2Crypto.EC.ECError[source]
    +
    + +
    +
    +M2Crypto.EC.gen_params(curve: int)M2Crypto.EC.EC[source]
    +

    Factory function that generates EC parameters and +instantiates a EC object from the output.

    +
    +
    Parameters
    +

    curve – This is the OpenSSL nid of the curve to use.

    +
    +
    +
    + +
    +
    +M2Crypto.EC.get_builtin_curves() → Tuple[Dict[str, Union[int, str]]][source]
    +
    + +
    +
    +M2Crypto.EC.load_key(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.EC.EC[source]
    +

    Factory function that instantiates a EC object.

    +
    +
    Parameters
    +
      +
    • file – Names the filename that contains the PEM representation +of the EC key pair.

    • +
    • callback – Python callback object that will be invoked +if the EC key pair is passphrase-protected.

    • +
    +
    +
    +
    + +
    +
    +M2Crypto.EC.load_key_bio(bio: M2Crypto.BIO.BIO, callback: Callable = <function passphrase_callback>)M2Crypto.EC.EC[source]
    +

    Factory function that instantiates a EC object.

    +
    +
    Parameters
    +
      +
    • bio – M2Crypto.BIO object that contains the PEM +representation of the EC key pair.

    • +
    • callback – Python callback object that will be invoked +if the EC key pair is passphrase-protected.

    • +
    +
    +
    +
    + +
    +
    +M2Crypto.EC.load_key_string(string: str, callback: Callable = <function passphrase_callback>)M2Crypto.EC.EC[source]
    +

    Load an EC key pair from a string.

    +
    +
    Parameters
    +
      +
    • string – String containing EC key pair in PEM format.

    • +
    • callback – A Python callable object that is invoked +to acquire a passphrase with which to unlock the +key. The default is util.passphrase_callback.

    • +
    +
    +
    Returns
    +

    M2Crypto.EC.EC object.

    +
    +
    +
    + +
    +
    +M2Crypto.EC.load_key_string_pubkey(string: str, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
    +

    Load an M2Crypto.EC.PKey from a public key as a string.

    +
    +
    Parameters
    +
      +
    • string – String containing the key in PEM format.

    • +
    • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect the +key.

    • +
    +
    +
    Returns
    +

    M2Crypto.EC.PKey object.

    +
    +
    +
    + +
    +
    +M2Crypto.EC.load_pub_key(file: AnyStr)M2Crypto.EC.EC_pub[source]
    +

    Load an EC public key from filename.

    +
    +
    Parameters
    +

    file – Name of filename containing EC public key in PEM +format.

    +
    +
    Returns
    +

    M2Crypto.EC.EC_pub object.

    +
    +
    +
    + +
    +
    +M2Crypto.EC.load_pub_key_bio(bio: M2Crypto.BIO.BIO)M2Crypto.EC.EC_pub[source]
    +

    Load an EC public key from an M2Crypto.BIO.BIO object.

    +
    +
    Parameters
    +

    bio – M2Crypto.BIO.BIO object containing EC public key in PEM +format.

    +
    +
    Returns
    +

    M2Crypto.EC.EC_pub object.

    +
    +
    +
    + +
    +
    +M2Crypto.EC.pub_key_from_der(der: bytes)M2Crypto.EC.EC_pub[source]
    +

    Create EC_pub from DER.

    +
    + +
    +
    +M2Crypto.EC.pub_key_from_params(curve: bytes, bytes: bytes)M2Crypto.EC.EC_pub[source]
    +

    Create EC_pub from curve name and octet string.

    +
    + +
+
+

EVP Module

+
+
+class M2Crypto.EVP.Cipher(alg: str, key: bytes, iv: bytes, op: object, key_as_bytes: int = 0, d: str = 'md5', salt: bytes = b'12345678', i: int = 1, padding: int = 1)[source]
+

Bases: object

+
+
+final() → bytes[source]
+
+ +
+
+m2_cipher_ctx_free()
+
+ +
+
+set_padding(padding: int = 1) → int[source]
+

Actually always return 1

+
+ +
+
+update(data: bytes) → bytes[source]
+
+ +
+ +
+
+exception M2Crypto.EVP.EVPError[source]
+

Bases: ValueError

+
+ +
+
+class M2Crypto.EVP.HMAC(key: bytes, algo: str = 'sha1')[source]
+

Bases: object

+
+
+digest() → bytes
+
+ +
+
+final() → bytes[source]
+
+ +
+
+m2_hmac_ctx_free()
+
+ +
+
+reset(key: bytes) → None[source]
+
+ +
+
+update(data: bytes) → None[source]
+
+ +
+ +
+
+class M2Crypto.EVP.MessageDigest(algo: str)[source]
+

Bases: object

+

Message Digest

+
+
+digest()
+
+ +
+
+final()[source]
+
+ +
+
+m2_md_ctx_free()
+
+ +
+
+update(data: bytes) → int[source]
+

Add data to be digested.

+
+
Returns
+

-1 for Python error, 1 for success, 0 for OpenSSL failure.

+
+
+
+ +
+ +
+
+class M2Crypto.EVP.PKey(pkey: Optional[bytes] = None, _pyfree: int = 0, md: str = 'sha1')[source]
+

Bases: object

+

Public Key

+
+
+as_der() → bytes[source]
+

Return key in DER format in a string

+
+ +
+
+as_pem(cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → bytes[source]
+

Return key in PEM format in a string.

+
+
Parameters
+
    +
  • cipher – Symmetric cipher to protect the key. The default +cipher is 'aes_128_cbc'. If cipher is None, +then the key is saved in the clear.

  • callback – A Python callable object that is invoked to acquire a passphrase with which to protect -the key. The default is +the key. The default is util.passphrase_callback.

@@ -807,319 +1601,2648 @@ util.passphrase_callback.

-
-save_pub_key(file: AnyStr) → int[source]
-

Save the public key to a file in PEM format.

+
+assign_rsa(rsa: M2Crypto.RSA.RSA, capture: int = 1) → int[source]
+

Assign the RSA key pair to self.

+
+
Parameters
+
    +
  • rsa – M2Crypto.RSA.RSA object to be assigned to self.

  • +
  • capture – If true (default), this PKey object will own the RSA +object, meaning that once the PKey object gets +deleted it is no longer safe to use the RSA object.

  • +
+
+
Returns
+

Return 1 for success and 0 for failure.

+
+
+
+ +
+
+digest_sign(data) → bytes[source]
+

Return signature.

+
+
Returns
+

The signature.

+
+
+
+ +
+
+digest_sign_final() → bytes[source]
+

Return signature.

+
+
Returns
+

The signature.

+
+
+
+ +
+
+digest_sign_init() → None[source]
+

Initialise digest signing operation with self.

+
+ +
+
+digest_sign_update(data: bytes) → None[source]
+

Feed data to digest signing operation.

+
+
Parameters
+

data – Data to be signed.

+
+
+
+ +
+
+digest_verify()[source]
+

Return result of verification.

+
+
Parameters
+
    +
  • sign – Signature to use for verification

  • +
  • data – Data to be verified.

  • +
+
+
Returns
+

Result of verification: 1 for success, 0 for failure, -1 on +other error.

+
+
+
+ +
+
+digest_verify_final(sign: bytes) → int[source]
+

Feed data to digest verification operation.

+
+
Parameters
+

sign – Signature to use for verification

+
+
Returns
+

Result of verification: 1 for success, 0 for failure, -1 on +other error.

+
+
+
+ +
+
+digest_verify_init() → None[source]
+

Initialise verification operation with self.

+
+ +
+
+digest_verify_update(data: bytes) → int[source]
+

Feed data to verification operation.

+
+
Parameters
+

data – Data to be verified.

+
+
Returns
+

-1 on Python error, 1 for success, 0 for OpenSSL error

+
+
+
+ +
+
+final() → bytes
+

Return signature.

+
+
Returns
+

The signature.

+
+
+
+ +
+
+get_modulus() → Optional[bytes][source]
+

Return the modulus in hex format.

+
+ +
+
+get_rsa()M2Crypto.RSA.RSA_pub[source]
+

Return the underlying RSA key if that is what the EVP +instance is holding.

+
+ +
+
+m2_md_ctx_free()
+
+ +
+
+m2_pkey_free()
+
+ +
+
+reset_context(md: str = 'sha1') → None[source]
+

Reset internal message digest context.

+
+
Parameters
+

md – The message digest algorithm.

+
+
+
+ +
+
+save_key(file: AnyStr, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
+

Save the key pair to a file in PEM format.

+
+
Parameters
+
    +
  • file – Name of file to save key to.

  • +
  • cipher – Symmetric cipher to protect the key. The default +cipher is ‘aes_128_cbc’. If cipher is None, then +the key is saved in the clear.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect +the key. The default is +util.passphrase_callback.

  • +
+
+
+
+ +
+
+save_key_bio(bio: M2Crypto.BIO.BIO, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
+

Save the key pair to the M2Crypto.BIO object ‘bio’ in PEM format.

+
+
Parameters
+
    +
  • bio – M2Crypto.BIO object to save key to.

  • +
  • cipher – Symmetric cipher to protect the key. The default +cipher is ‘aes_128_cbc’. If cipher is None, then +the key is saved in the clear.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect +the key. The default is +util.passphrase_callback.

  • +
+
+
+
+ +
+
+sign_final() → bytes[source]
+

Return signature.

+
+
Returns
+

The signature.

+
+
+
+ +
+
+sign_init() → None[source]
+

Initialise signing operation with self.

+
+ +
+
+sign_update(data: bytes) → None[source]
+

Feed data to signing operation.

+
+
Parameters
+

data – Data to be signed.

+
+
+
+ +
+
+size() → int[source]
+

Return the size of the key in bytes.

+
+ +
+
+update(data: bytes) → None
+

Feed data to signing operation.

+
+
Parameters
+

data – Data to be signed.

+
+
+
+ +
+
+verify_final(sign: bytes) → int[source]
+

Return result of verification.

+
+
Parameters
+

sign – Signature to use for verification

+
+
Returns
+

Result of verification: 1 for success, 0 for failure, -1 on +other error.

+
+
+
+ +
+
+verify_init() → None[source]
+

Initialise signature verification operation with self.

+
+ +
+
+verify_update(data: bytes) → int[source]
+

Feed data to verification operation.

+
+
Parameters
+

data – Data to be verified.

+
+
Returns
+

-1 on Python error, 1 for success, 0 for OpenSSL error

+
+
+
+ +
+ +
+
+M2Crypto.EVP.hmac(key: bytes, data: bytes, algo: str = 'sha1') → bytes[source]
+
+ +
+
+M2Crypto.EVP.load_key(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
+

Load an M2Crypto.EVP.PKey from file.

+
+
Parameters
+
    +
  • file – Name of file containing the key in PEM format.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect the +key.

  • +
+
+
Returns
+

M2Crypto.EVP.PKey object.

+
+
+
+ +
+
+M2Crypto.EVP.load_key_bio(bio: M2Crypto.BIO.BIO, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
+

Load an M2Crypto.EVP.PKey from an M2Crypto.BIO object.

+
+
Parameters
+
    +
  • bio – M2Crypto.BIO object containing the key in PEM format.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect the +key.

  • +
+
+
Returns
+

M2Crypto.EVP.PKey object.

+
+
+
+ +
+
+M2Crypto.EVP.load_key_bio_pubkey(bio: M2Crypto.BIO.BIO, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
+

Load an M2Crypto.EVP.PKey from a public key as a M2Crypto.BIO object.

+
+
Parameters
+
    +
  • bio – M2Crypto.BIO object containing the key in PEM format.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect the +key.

  • +
+
+
Returns
+

M2Crypto.EVP.PKey object.

+
+
+
+ +
+
+M2Crypto.EVP.load_key_pubkey(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
+

Load an M2Crypto.EVP.PKey from a public key as a file.

+
+
Parameters
+
    +
  • file – Name of file containing the key in PEM format.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect the +key.

  • +
+
+
Returns
+

M2Crypto.EVP.PKey object.

+
+
+
+ +
+
+M2Crypto.EVP.load_key_string(string: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
+

Load an M2Crypto.EVP.PKey from a string.

+
+
Parameters
+
    +
  • string – String containing the key in PEM format.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect the +key.

  • +
+
+
Returns
+

M2Crypto.EVP.PKey object.

+
+
+
+ +
+
+M2Crypto.EVP.load_key_string_pubkey(string: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.EVP.PKey[source]
+

Load an M2Crypto.EVP.PKey from a public key as a string.

+
+
Parameters
+
    +
  • string – String containing the key in PEM format.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect the +key.

  • +
+
+
Returns
+

M2Crypto.EVP.PKey object.

+
+
+
+ +
+
+M2Crypto.EVP.pbkdf2(password: bytes, salt: bytes, iter: int, keylen: int) → bytes[source]
+

Derive a key from password using PBKDF2 algorithm specified in RFC 2898.

+
+
Parameters
+
    +
  • password – Derive the key from this password.

  • +
  • salt – Salt.

  • +
  • iter – Number of iterations to perform.

  • +
  • keylen – Length of key to produce.

  • +
+
+
Returns
+

Key.

+
+
+
+ +
+
+

Engine Module

+
+
+class M2Crypto.Engine.Engine(id: Optional[bytes] = None, _ptr: Optional[bytes] = None, _pyfree: int = 1)[source]
+

Bases: object

+

Wrapper for ENGINE object.

+
+
+ctrl_cmd_string(cmd: AnyStr, arg: Optional[AnyStr], optional: int = 0) → None[source]
+

Call ENGINE_ctrl_cmd_string

+
+ +
+
+finish() → int[source]
+

Release a functional and structural reference to the engine.

+
+ +
+
+get_id() → bytes[source]
+

Return engine id

+
+ +
+
+get_name() → bytes[source]
+

Return engine name

+
+ +
+
+init() → int[source]
+

Obtain a functional reference to the engine.

+
+
Returns
+

0 on error, non-zero on success.

+
+
+
+ +
+
+load_certificate(name: bytes)M2Crypto.X509.X509[source]
+

Load certificate from engine (e.g from smartcard). +NOTE: This function may be not implemented by engine!

+
+ +
+
+load_private_key(name: bytes, pin: Optional[bytes] = None)M2Crypto.X509.X509[source]
+

Load private key with engine methods (e.g from smartcard). +If pin is not set it will be asked

+
+ +
+
+load_public_key(name: bytes, pin: Optional[bytes] = None)M2Crypto.EVP.PKey[source]
+

Load public key with engine methods (e.g from smartcard).

+
+ +
+
+m2_engine_free()
+
+ +
+
+set_default(methods: int = 65535) → int[source]
+

Use this engine as default for methods specified in argument

+
+
Parameters
+

methods – Possible values are bitwise OR of m2.ENGINE_METHOD_*

+
+
+
+ +
+ +
+
+exception M2Crypto.Engine.EngineError[source]
+

Bases: Exception

+
+ +
+
+M2Crypto.Engine.cleanup() → None[source]
+

If you load any engines, you need to clean up after your application +is finished with the engines.

+
+ +
+
+M2Crypto.Engine.load_dynamic() → None[source]
+

Load dynamic engine

+
+ +
+
+M2Crypto.Engine.load_dynamic_engine(id: bytes, sopath: AnyStr)M2Crypto.Engine.Engine[source]
+

Load and return dymanic engine from sopath and assign id to it

+
+ +
+
+M2Crypto.Engine.load_openssl() → None[source]
+

Load openssl engine

+
+ +
+
+

Err Module

+
+
+exception M2Crypto.Err.M2CryptoError[source]
+

Bases: Exception

+
+ +
+
+exception M2Crypto.Err.SSLError(err: int, client_addr: Union[Tuple[str, int], str])[source]
+

Bases: Exception

+
+ +
+
+M2Crypto.Err.get_error() → Optional[str][source]
+
+ +
+
+M2Crypto.Err.get_error_code() → int[source]
+
+ +
+
+M2Crypto.Err.get_error_func(err: Optional[int]) → str[source]
+
+ +
+
+M2Crypto.Err.get_error_lib(err: Optional[int]) → str[source]
+
+ +
+
+M2Crypto.Err.get_error_message() → str[source]
+
+ +
+
+M2Crypto.Err.get_error_reason(err: Optional[int]) → str[source]
+
+ +
+
+M2Crypto.Err.get_x509_verify_error(err: Optional[int]) → str[source]
+
+ +
+
+M2Crypto.Err.peek_error_code() → int[source]
+
+ +
+
+

RC4 Module

+
+
+class M2Crypto.RC4.RC4(key: Optional[bytes] = None)[source]
+

Bases: object

+

Object interface to the stream cipher RC4.

+
+
+final() → str[source]
+
+ +
+
+rc4_free()
+
+ +
+
+set_key(key: bytes) → None[source]
+
+ +
+
+update(data: bytes) → bytes[source]
+
+ +
+ +
+
+

RSA Module

+
+
+class M2Crypto.RSA.RSA(rsa: bytes, _pyfree: int = 0)[source]
+

Bases: object

+

RSA Key Pair.

+
+
+as_pem(cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → bytes[source]
+

Returns the key(pair) as a string in PEM format.

+
+ +
+
+check_key() → int[source]
+

Validate RSA keys.

+

It checks that p and q are in fact prime, and that n = p*q.

+
+
Returns
+

returns 1 if rsa is a valid RSA key, and 0 otherwise. +-1 is returned if an error occurs while checking the key. +If the key is invalid or an error occurred, the reason +code can be obtained using ERR_get_error(3).

+
+
+
+ +
+
+m2_rsa_free()
+
+ +
+
+private_decrypt(data: bytes, padding: int) → bytes[source]
+
+ +
+
+private_encrypt(data: bytes, padding: int) → bytes[source]
+
+ +
+
+pub() → Tuple[bytes, bytes][source]
+
+ +
+
+public_decrypt(data: bytes, padding: int) → bytes[source]
+
+ +
+
+public_encrypt(data: bytes, padding: int) → bytes[source]
+
+ +
+
+save_key(file: AnyStr, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
+

Save the key pair to a file in PEM format.

+
+
Parameters
+
    +
  • file – Name of file to save key to.

  • +
  • cipher – Symmetric cipher to protect the key. The default +cipher is ‘aes_128_cbc’. If cipher is None, then +the key is saved in the clear.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect +the key. The default is +util.passphrase_callback.

  • +
+
+
+
+ +
+
+save_key_bio(bio: M2Crypto.BIO.BIO, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int[source]
+

Save the key pair to an M2Crypto.BIO.BIO object in PEM format.

+
+
Parameters
+
    +
  • bio – M2Crypto.BIO.BIO object to save key to.

  • +
  • cipher – Symmetric cipher to protect the key. The default +cipher is ‘aes_128_cbc’. If cipher is None, then +the key is saved in the clear.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect +the key. The default is +util.passphrase_callback.

  • +
+
+
+
+ +
+
+save_key_der(file: AnyStr) → int[source]
+

Save the key pair to a file in DER format.

+
+
Parameters
+

file – Filename to save key to

+
+
+
+ +
+
+save_key_der_bio(bio: M2Crypto.BIO.BIO) → int[source]
+

Save the key pair to an M2Crypto.BIO.BIO object in DER format.

+
+
Parameters
+

bio – M2Crypto.BIO.BIO object to save key to.

+
+
+
+ +
+
+save_pem(file: AnyStr, cipher: Optional[str] = 'aes_128_cbc', callback: Callable = <function passphrase_callback>) → int
+

Save the key pair to a file in PEM format.

+
+
Parameters
+
    +
  • file – Name of file to save key to.

  • +
  • cipher – Symmetric cipher to protect the key. The default +cipher is ‘aes_128_cbc’. If cipher is None, then +the key is saved in the clear.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to protect +the key. The default is +util.passphrase_callback.

  • +
+
+
+
+ +
+
+save_pub_key(file: AnyStr) → int[source]
+

Save the public key to a file in PEM format.

+
+
Parameters
+

file – Name of file to save key to.

+
+
+
+ +
+
+save_pub_key_bio(bio: M2Crypto.BIO.BIO) → int[source]
+

Save the public key to an M2Crypto.BIO.BIO object in PEM format.

+
+
Parameters
+

bio – M2Crypto.BIO.BIO object to save key to.

+
+
+
+ +
+
+sign(digest: bytes, algo: str = 'sha1') → bytes[source]
+

Signs a digest with the private key

+
+
Parameters
+
    +
  • digest – A digest created by using the digest method

  • +
  • algo – The method that created the digest. +Legal values like ‘sha1’,’sha224’, ‘sha256’, +‘ripemd160’, and ‘md5’.

  • +
+
+
Returns
+

a string which is the signature

+
+
+
+ +
+
+sign_rsassa_pss(digest: bytes, algo: str = 'sha1', salt_length: int = 20) → bytes[source]
+

Signs a digest with the private key using RSASSA-PSS

+
+
Parameters
+
    +
  • digest – A digest created by using the digest method

  • +
  • salt_length – The length of the salt to use

  • +
  • algo – The hash algorithm to use +Legal values like ‘sha1’,’sha224’, ‘sha256’, +‘ripemd160’, and ‘md5’.

  • +
+
+
Returns
+

a string which is the signature

+
+
+
+ +
+
+verify(data: bytes, signature: bytes, algo: str = 'sha1') → int[source]
+

Verifies the signature with the public key

+
+
Parameters
+
    +
  • data – Data that has been signed

  • +
  • signature – The signature signed with the private key

  • +
  • algo – The method use to create digest from the data +before it was signed. Legal values like +‘sha1’,’sha224’, ‘sha256’, ‘ripemd160’, and ‘md5’.

  • +
+
+
Returns
+

1 or 0, depending on whether the signature was +verified or not.

+
+
+
+ +
+
+verify_rsassa_pss(data: bytes, signature: bytes, algo: str = 'sha1', salt_length: int = 20) → int[source]
+

Verifies the signature RSASSA-PSS

+
+
Parameters
+
    +
  • data – Data that has been signed

  • +
  • signature – The signature signed with RSASSA-PSS

  • +
  • salt_length – The length of the salt that was used

  • +
  • algo – The hash algorithm to use +Legal values are for example ‘sha1’,’sha224’, +‘sha256’, ‘ripemd160’, and ‘md5’.

  • +
+
+
Returns
+

1 or 0, depending on whether the signature was +verified or not.

+
+
+
+ +
+ +
+
+exception M2Crypto.RSA.RSAError[source]
+

Bases: Exception

+
+ +
+
+class M2Crypto.RSA.RSA_pub(rsa: bytes, _pyfree: int = 0)[source]
+

Bases: M2Crypto.RSA.RSA

+

Object interface to an RSA public key.

+
+
+check_key() → int[source]
+

Validate RSA keys.

+

It checks that p and q are in fact prime, and that n = p*q.

+
+
Returns
+

returns 1 if rsa is a valid RSA key, and 0 otherwise. +-1 is returned if an error occurs while checking the key. +If the key is invalid or an error occurred, the reason +code can be obtained using ERR_get_error(3).

+
+
+
+ +
+
+private_decrypt(*argv: Any) → None[source]
+
+ +
+
+private_encrypt(*argv: Any) → None[source]
+
+ +
+
+save_key(file: AnyStr, *args: Any, **kw: Any) → int[source]
+

Save public key to file.

+
+ +
+
+save_key_bio(bio: M2Crypto.BIO.BIO, *args: Any, **kw: Any) → int[source]
+

Save public key to BIO.

+
+ +
+ +
+
+M2Crypto.RSA.gen_key(bits: int, e: int, callback: Callable = <function keygen_callback>)M2Crypto.RSA.RSA[source]
+

Generate an RSA key pair.

+
+
Parameters
+
    +
  • bits – Key length, in bits.

  • +
  • e – The RSA public exponent.

  • +
  • callback – A Python callable object that is invoked +during key generation; its usual purpose is to +provide visual feedback. The default callback is +keygen_callback.

  • +
+
+
Returns
+

M2Crypto.RSA.RSA object.

+
+
+
+ +
+
+M2Crypto.RSA.keygen_callback(p: int, n: Any, out: IO[str] = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) → None[source]
+

Default callback for gen_key().

+
+ +
+
+M2Crypto.RSA.load_key(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.RSA.RSA[source]
+

Load an RSA key pair from file.

+
+
Parameters
+
    +
  • file – Name of file containing RSA public key in PEM format.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to unlock the +key. The default is util.passphrase_callback.

  • +
+
+
Returns
+

M2Crypto.RSA.RSA object.

+
+
+
+ +
+
+M2Crypto.RSA.load_key_bio(bio: M2Crypto.BIO.BIO, callback: Callable = <function passphrase_callback>)M2Crypto.RSA.RSA[source]
+

Load an RSA key pair from an M2Crypto.BIO.BIO object.

+
+
Parameters
+
    +
  • bio – M2Crypto.BIO.BIO object containing RSA key pair in PEM +format.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to unlock the +key. The default is util.passphrase_callback.

  • +
+
+
Returns
+

M2Crypto.RSA.RSA object.

+
+
+
+ +
+
+M2Crypto.RSA.load_key_string(string: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.RSA.RSA[source]
+

Load an RSA key pair from a string.

+
+
Parameters
+
    +
  • string – String containing RSA key pair in PEM format.

  • +
  • callback – A Python callable object that is invoked +to acquire a passphrase with which to unlock the +key. The default is util.passphrase_callback.

  • +
+
+
Returns
+

M2Crypto.RSA.RSA object.

+
+
+
+ +
+
+M2Crypto.RSA.load_pub_key(file: AnyStr)M2Crypto.RSA.RSA_pub[source]
+

Load an RSA public key from file.

+
+
Parameters
+

file – Name of file containing RSA public key in PEM format.

+
+
Returns
+

M2Crypto.RSA.RSA_pub object.

+
+
+
+ +
+
+M2Crypto.RSA.load_pub_key_bio(bio: M2Crypto.BIO.BIO)M2Crypto.RSA.RSA_pub[source]
+

Load an RSA public key from an M2Crypto.BIO.BIO object.

+
+
Parameters
+

bio – M2Crypto.BIO.BIO object containing RSA public key in PEM +format.

+
+
Returns
+

M2Crypto.RSA.RSA_pub object.

+
+
+
+ +
+
+M2Crypto.RSA.new_pub_key(e_n: Tuple[bytes, bytes])M2Crypto.RSA.RSA_pub[source]
+

Instantiate an RSA_pub object from an (e, n) tuple.

+
+
Parameters
+
    +
  • e – The RSA public exponent; it is a string in OpenSSL’s MPINT +format - 4-byte big-endian bit-count followed by the +appropriate number of bits.

  • +
  • n – The RSA composite of primes; it is a string in OpenSSL’s +MPINT format - 4-byte big-endian bit-count followed by the +appropriate number of bits.

  • +
+
+
Returns
+

M2Crypto.RSA.RSA_pub object.

+
+
+
+ +
+
+M2Crypto.RSA.rsa_error() → None[source]
+
+ +
+
+

Rand Module

+

M2Crypto wrapper for OpenSSL PRNG. Requires OpenSSL 0.9.5 and above.

+

Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved. +Copyright (c) 2014-2017 Matej Cepl. All rights reserved.

+

See LICENCE for the license information.

+
+
+M2Crypto.Rand.load_file(filename: AnyStr, max_bytes: int) → int[source]
+

Read a number of bytes from file filename and adds them to the PRNG.

+

If max_bytes is non-negative, up to to max_bytes are read; starting with +OpenSSL 0.9.5, if max_bytes is -1, the complete file is read.

+
+
Parameters
+
    +
  • filename

  • +
  • max_bytes

  • +
+
+
Returns
+

the number of bytes read.

+
+
+
+ +
+
+M2Crypto.Rand.rand_add(blob: bytes, entropy: float) → None[source]
+

Mixes blob into the PRNG state.

+
+
Parameters
+
    +
  • blob – added data

  • +
  • entropy – (the lower bound of) an estimate of how much randomness +is contained in blob, measured in bytes.

  • +
+
+
+

Thus, if the data at buf are unpredictable to an adversary, this +increases the uncertainty about the state and makes the PRNG output less +predictable. Suitable input comes from user interaction (random key +presses, mouse movements) and certain hardware events.

+

Details about sources of randomness and how to estimate their entropy +can be found in the literature, e.g. RFC 1750.

+
+ +
+
+M2Crypto.Rand.rand_bytes(num: int) → bytes[source]
+

Return n cryptographically strong pseudo-random bytes.

+

An error occurs if the PRNG has not been seeded with enough randomness +to ensure an unpredictable byte sequence.

+
+
Parameters
+

num – number of bytes to be returned

+
+
Returns
+

random bytes

+
+
+
+ +
+
+M2Crypto.Rand.rand_file_name() → str[source]
+

Generate a default path for the random seed file.

+
+
Returns
+

string with the filename. +The seed file is $RANDFILE if that environment variable +is set, $HOME/.rnd otherwise. If $HOME is not set either, +an error occurs.

+
+
+
+ +
+
+M2Crypto.Rand.rand_pseudo_bytes(num: int) → Tuple[bytes, int][source]
+

Return num pseudo-random bytes into buf.

+

Pseudo-random byte sequences generated by this method will be unique +if they are of sufficient length, but are not necessarily +unpredictable. They can be used for non-cryptographic purposes and for +certain purposes in cryptographic protocols, but usually not for key +generation etc.

+

Output of the function is mixed into the entropy pool before +retrieving the new pseudo-random bytes unless disabled at compile +time (see FAQ).

+
+
Parameters
+

num – number of bytes to be returned

+
+
Returns
+

random bytes

+
+
+
+ +
+
+M2Crypto.Rand.rand_seed(seed: bytes) → None[source]
+

Equivalent to rand_add() when len(seed) == entropy.

+
+
Parameters
+

seed – added data (see description at rand_add)

+
+
+
+ +
+
+M2Crypto.Rand.rand_status() → int[source]
+

Check whether there is enough entropy in PRNG.

+
+
Returns
+

1 if the PRNG has been seeded with enough +data, 0 otherwise.

+
+
+
+ +
+
+M2Crypto.Rand.save_file(filename: AnyStr) → int[source]
+

Write a number of random bytes (currently 1024) to file.

+

The file then can be used to initialize the PRNG by calling load_file() in +a later session.

+
+
Parameters
+

filename

+
+
Returns
+

returns the number of bytes written, and -1 if the bytes +written were generated without appropriate seed.

+
+
+
+ +
+
+

SMIME Module

+
+
+class M2Crypto.SMIME.Cipher(algo: str)[source]
+

Bases: object

+

Object interface to EVP_CIPHER without all the frills of +M2Crypto.EVP.Cipher.

+
+ +
+
+class M2Crypto.SMIME.PKCS7(pkcs7: Optional[bytes] = None, _pyfree: int = 0)[source]
+

Bases: object

+
+
+get0_signers(certs: M2Crypto.X509.X509_Stack, flags: int = 0)M2Crypto.X509.X509_Stack[source]
+
+ +
+
+m2_pkcs7_free()
+
+ +
+
+type(text_name: int = 0) → int[source]
+
+ +
+
+write(bio: M2Crypto.BIO.BIO) → int[source]
+
+ +
+
+write_der(bio: M2Crypto.BIO.BIO) → int[source]
+
+ +
+ +
+
+exception M2Crypto.SMIME.PKCS7_Error[source]
+

Bases: Exception

+
+ +
+
+class M2Crypto.SMIME.SMIME[source]
+

Bases: object

+
+
+decrypt(pkcs7: M2Crypto.SMIME.PKCS7, flags: int = 0) → Optional[bytes][source]
+
+ +
+
+encrypt(data_bio: M2Crypto.BIO.BIO, flags: int = 0)M2Crypto.SMIME.PKCS7[source]
+
+ +
+
+load_key(keyfile: AnyStr, certfile: Optional[AnyStr] = None, callback: Callable = <function passphrase_callback>) → None[source]
+
+ +
+
+load_key_bio(keybio: M2Crypto.BIO.BIO, certbio: Optional[M2Crypto.BIO.BIO] = None, callback: Callable = <function passphrase_callback>) → None[source]
+
+ +
+
+set_cipher(cipher: M2Crypto.SMIME.Cipher) → None[source]
+
+ +
+
+set_x509_stack(stack: M2Crypto.X509.X509_Stack) → None[source]
+
+ +
+
+set_x509_store(store: M2Crypto.X509.X509_Store) → None[source]
+
+ +
+
+sign(data_bio: M2Crypto.BIO.BIO, flags: int = 0, algo: Optional[str] = 'sha1')M2Crypto.SMIME.PKCS7[source]
+
+ +
+
+unset_cipher() → None[source]
+
+ +
+
+unset_key() → None[source]
+
+ +
+
+unset_x509_stack() → None[source]
+
+ +
+
+unset_x509_store() → None[source]
+
+ +
+
+verify(pkcs7: M2Crypto.SMIME.PKCS7, data_bio: Optional[M2Crypto.BIO.BIO] = None, flags: int = 0) → Optional[bytes][source]
+
+ +
+
+write(out_bio: M2Crypto.BIO.BIO, pkcs7: M2Crypto.SMIME.PKCS7, data_bio: Optional[M2Crypto.BIO.BIO] = None, flags: int = 0) → int[source]
+
+ +
+ +
+
+exception M2Crypto.SMIME.SMIME_Error[source]
+

Bases: Exception

+
+ +
+
+M2Crypto.SMIME.load_pkcs7(p7file: AnyStr)M2Crypto.SMIME.PKCS7[source]
+
+ +
+
+M2Crypto.SMIME.load_pkcs7_bio(p7_bio: M2Crypto.BIO.BIO)M2Crypto.SMIME.PKCS7[source]
+
+ +
+
+M2Crypto.SMIME.load_pkcs7_bio_der(p7_bio: M2Crypto.BIO.BIO)M2Crypto.SMIME.PKCS7[source]
+
+ +
+
+M2Crypto.SMIME.load_pkcs7_der(p7file: AnyStr)M2Crypto.SMIME.PKCS7[source]
+
+ +
+
+M2Crypto.SMIME.smime_load_pkcs7(p7file: AnyStr)M2Crypto.SMIME.PKCS7[source]
+
+ +
+
+M2Crypto.SMIME.smime_load_pkcs7_bio(p7_bio: M2Crypto.BIO.BIO)M2Crypto.SMIME.PKCS7[source]
+
+ +
+
+M2Crypto.SMIME.text_crlf(text: bytes) → bytes[source]
+
+ +
+
+M2Crypto.SMIME.text_crlf_bio(bio_in: M2Crypto.BIO.BIO)M2Crypto.BIO.BIO[source]
+
+ +
+
+

X509 Module

+
+
+class M2Crypto.X509.CRL(crl: Optional[bytes] = None, _pyfree: int = 0)[source]
+

Bases: object

+

X509 Certificate Revocation List

+
+
+as_text() → str[source]
+

Return CRL in PEM format in a string.

+
+
Returns
+

String containing the CRL in PEM format.

+
+
+
+ +
+
+m2_x509_crl_free()
+
+ +
+ +
+
+class M2Crypto.X509.Request(req: Optional[int] = None, _pyfree: int = 0)[source]
+

Bases: object

+

X509 Certificate Request.

+
+
+add_extensions(ext_stack: M2Crypto.X509.X509_Extension_Stack) → int[source]
+

Add X509 extensions to this request.

+
+
Parameters
+

ext_stack – Stack of extensions to add.

+
+
Returns
+

1 for success and 0 for failure

+
+
+
+ +
+
+as_der() → bytes[source]
+
+ +
+
+as_pem() → bytes[source]
+
+ +
+
+as_text() → str[source]
+
+ +
+
+get_pubkey()M2Crypto.EVP.PKey[source]
+

Get the public key for the request.

+
+
Returns
+

Public key from the request.

+
+
+
+ +
+
+get_subject()M2Crypto.X509.X509_Name[source]
+
+ +
+
+get_version() → int[source]
+

Get version.

+
+
Returns
+

Returns version.

+
+
+
+ +
+
+m2_x509_req_free()
+
+ +
+
+save(filename: AnyStr, format: int = 1) → int[source]
+

Saves X.509 certificate request to a file. Default output +format is PEM.

+
+
Parameters
+
    +
  • filename – Name of the file the request will be saved to.

  • +
  • format – Controls what output format is used to save the +request. Either FORMAT_PEM or FORMAT_DER to save +in PEM or DER format. Raises ValueError if an +unknown format is used.

  • +
+
+
Returns
+

1 for success, 0 for failure. +The error code can be obtained by ERR_get_error.

+
+
+
+ +
+
+save_pem(filename: AnyStr) → int[source]
+
+ +
+
+set_pubkey(pkey: M2Crypto.EVP.PKey) → int[source]
+

Set the public key for the request.

+
+
Parameters
+

pkey – Public key

+
+
Returns
+

Return 1 for success and 0 for failure.

+
+
+
+ +
+
+set_subject(name: M2Crypto.X509.X509_Name) → int
+

Set subject name.

+
+
Parameters
+

name – subjectName field.

+
+
Returns
+

1 for success and 0 for failure

+
+
+
+ +
+
+set_subject_name(name: M2Crypto.X509.X509_Name) → int[source]
+

Set subject name.

+
+
Parameters
+

name – subjectName field.

+
+
Returns
+

1 for success and 0 for failure

+
+
+
+ +
+
+set_version(version: int) → int[source]
+

Set version.

+
+
Parameters
+

version – Version number.

+
+
Returns
+

Returns 0 on failure.

+
+
+
+ +
+
+sign(pkey: M2Crypto.EVP.PKey, md: str) → int[source]
+
+
Parameters
+
    +
  • pkey – PKey to be signed

  • +
  • md – used algorigthm

  • +
+
+
Returns
+

1 for success and 0 for failure

+
+
+
+ +
+
+verify(pkey: M2Crypto.EVP.PKey) → int[source]
+
+
Parameters
+

pkey – PKey to be verified

+
+
Returns
+

1 for success and 0 for failure

+
+
+
+ +
+ +
+
+class M2Crypto.X509.X509(x509: Optional[bytes] = None, _pyfree: int = 0)[source]
+

Bases: object

+

X.509 Certificate

+
+
+add_ext(ext: M2Crypto.X509.X509_Extension) → int[source]
+

Add X509 extension to this certificate.

+
+
Parameters
+

ext – Extension

+
+
+

:return 1 for success and 0 for failure

+
+ +
+
+as_der() → bytes[source]
+
+ +
+
+as_pem() → bytes[source]
+
+ +
+
+as_text() → str[source]
+
+ +
+
+check_ca() → int[source]
+

Check if the certificate is a Certificate Authority (CA) certificate.

+
+
Returns
+

0 if the certificate is not CA, nonzero otherwise.

+
+
Requires
+

OpenSSL 0.9.8 or newer

+
+
+
+ +
+
+check_purpose(id: int, ca: int) → int[source]
+

Check if the certificate’s purpose matches the asked purpose.

+
+
Parameters
+
    +
  • id – Purpose id. See X509_PURPOSE_* constants.

  • +
  • ca – 1 if the certificate should be CA, 0 otherwise.

  • +
+
+
Returns
+

0 if the certificate purpose does not match, nonzero +otherwise.

+
+
+
+ +
+
+get_ext(name: str)M2Crypto.X509.X509_Extension[source]
+

Get X509 extension by name.

+
+
Parameters
+

name – Name of the extension

+
+
Returns
+

X509_Extension

+
+
+
+ +
+
+get_ext_at(index: int)M2Crypto.X509.X509_Extension[source]
+

Get X509 extension by index.

+
+
Parameters
+

index – Name of the extension

+
+
Returns
+

X509_Extension

+
+
+
+ +
+
+get_ext_count() → int[source]
+

Get X509 extension count.

+
+ +
+
+get_fingerprint(md: str = 'md5') → str[source]
+

Get the fingerprint of the certificate.

+
+
Parameters
+

md – Message digest algorithm to use.

+
+
Returns
+

String containing the fingerprint in hex format.

+
+
+
+ +
+
+get_issuer()M2Crypto.X509.X509_Name[source]
+
+ +
+
+get_not_after()M2Crypto.ASN1.ASN1_TIME[source]
+
+ +
+
+get_not_before()M2Crypto.ASN1.ASN1_TIME[source]
+
+ +
+
+get_pubkey()M2Crypto.EVP.PKey[source]
+
+ +
+
+get_serial_number()M2Crypto.ASN1.ASN1_Integer[source]
+
+ +
+
+get_subject()M2Crypto.X509.X509_Name[source]
+
+ +
+
+get_version() → int[source]
+
+ +
+
+m2_x509_free()
+
+ +
+
+save(filename: AnyStr, format: int = 1) → int[source]
+

Saves X.509 certificate to a file. Default output +format is PEM.

+
+
Parameters
+
    +
  • filename – Name of the file the cert will be saved to.

  • +
  • format – Controls what output format is used to save the cert. +Either FORMAT_PEM or FORMAT_DER to save in PEM or +DER format. Raises a ValueError if an unknow +format is used.

  • +
+
+
Returns
+

1 for success or 0 for failure

+
+
+
+ +
+
+save_pem(filename: AnyStr) → int[source]
+
+
Parameters
+

filename – name of the file to be loaded

+
+
Returns
+

1 for success or 0 for failure

+
+
+
+ +
+
+set_issuer(name: M2Crypto.X509.X509_Name) → int[source]
+

Set issuer name.

+
+
Parameters
+

name – subjectName field.

+
+
+

:return 1 for success and 0 for failure

+
+ +
+
+set_issuer_name(name: M2Crypto.X509.X509_Name) → int[source]
+
+
Returns
+

1 on success, 0 on failure

+
+
+
+ +
+
+set_not_after(asn1_time: M2Crypto.ASN1.ASN1_TIME) → int[source]
+
+
Returns
+

1 on success, 0 on failure

+
+
+
+ +
+
+set_not_before(asn1_time: M2Crypto.ASN1.ASN1_TIME) → int[source]
+
+
Returns
+

1 on success, 0 on failure

+
+
+
+ +
+
+set_pubkey(pkey: M2Crypto.EVP.PKey) → int[source]
+

Set the public key for the certificate

+
+
Parameters
+

pkey – Public key

+
+
+

:return 1 for success and 0 for failure

+
+ +
+
+set_serial_number(serial: M2Crypto.ASN1.ASN1_Integer) → int[source]
+

Set serial number.

+
+
Parameters
+

serial – Serial number.

+
+
+

:return 1 for success and 0 for failure.

+
+ +
+
+set_subject(name: M2Crypto.X509.X509_Name) → int[source]
+

Set subject name.

+
+
Parameters
+

name – subjectName field.

+
+
+

:return 1 for success and 0 for failure

+
+ +
+
+set_subject_name(name: M2Crypto.X509.X509_Name) → int[source]
+
+
Returns
+

1 on success, 0 on failure

+
+
+
+ +
+
+set_version(version: int) → int[source]
+

Set version of the certificate.

+
+
Parameters
+

version – Version number.

+
+
Returns
+

Returns 0 on failure.

+
+
+
+ +
+
+sign(pkey: M2Crypto.EVP.PKey, md: str) → int[source]
+

Sign the certificate.

+
+
Parameters
+
    +
  • pkey – Public key

  • +
  • md – Message digest algorithm to use for signing, +for example ‘sha1’.

  • +
+
+
+

:return int

+
+ +
+
+verify(pkey: Optional[M2Crypto.EVP.PKey] = None) → int[source]
+
+ +
+ +
+
+exception M2Crypto.X509.X509Error[source]
+

Bases: ValueError

+
+ +
+
+class M2Crypto.X509.X509_Extension(x509_ext_ptr: Optional[bytes] = None, _pyfree: int = 1)[source]
+

Bases: object

+

X509 Extension

+
+
+get_critical() → int[source]
+

Return whether or not this is a critical extension.

+
+
Returns
+

Nonzero if this is a critical extension.

+
+
+
+ +
+
+get_name() → str[source]
+

Get the extension name, for example ‘subjectAltName’.

+
+ +
+
+get_value(flag: int = 0, indent: int = 0) → str[source]
+

Get the extension value, for example ‘DNS:www.example.com’.

Parameters
-

file – Name of file to save key to.

+
    +
  • flag – Flag to control what and how to print.

  • +
  • indent – How many spaces to print before actual value.

  • +
-
-save_pub_key_bio(bio: BIO.BIO) → int[source]
-

Save the public key to an M2Crypto.BIO.BIO object in PEM format.

+
+m2_x509_extension_free()
+
+ +
+
+set_critical(critical: int = 1) → int[source]
+

Mark this extension critical or noncritical. By default an +extension is not critical.

Parameters
-

bio – M2Crypto.BIO.BIO object to save key to.

+

critical – Nonzero sets this extension as critical. +Calling this method without arguments will +set this extension to critical.

+
+
Returns
+

1 for success, 0 for failure

+
+ +
+
+class M2Crypto.X509.X509_Extension_Stack(stack: Optional[bytes] = None, _pyfree: int = 0)[source]
+

Bases: object

+

X509 Extension Stack

+
+
Warning
+

Do not modify the underlying OpenSSL stack +except through this interface, or use any OpenSSL +functions that do so indirectly. Doing so will get the +OpenSSL stack and the internal pystack of this class out +of sync, leading to python memory leaks, exceptions or +even python crashes!

+
+
-
-sign(digest: bytes, algo: str = 'sha1') → bytes[source]
-

Signs a digest with the private key

+
+m2_sk_x509_extension_free()
+
+ +
+
+pop()M2Crypto.X509.X509_Extension[source]
+

Pop X509_Extension object from the stack.

+
+
Returns
+

X509_Extension popped

+
+
+
+ +
+
+push(x509_ext: M2Crypto.X509.X509_Extension) → int[source]
+

Push X509_Extension object onto the stack.

+
+
Parameters
+

x509_ext – X509_Extension object to be pushed onto the stack.

+
+
Returns
+

The number of extensions on the stack.

+
+
+
+ +
+ +
+
+class M2Crypto.X509.X509_Name(x509_name: Optional[bytes] = None, _pyfree: int = 0)[source]
+

Bases: object

+

X509 Name

+
+
+add_entry_by_txt(field, type, entry, len, loc, set)[source]
+

Add X509_Name field whose name is identified by its name.

Parameters
    -
  • digest – A digest created by using the digest method

  • -
  • algo – The method that created the digest. -Legal values like ‘sha1’,’sha224’, ‘sha256’, -‘ripemd160’, and ‘md5’.

  • +
  • field – name of the entry

  • +
  • type – use MBSTRING_ASC or MBSTRING_UTF8 +(or standard ASN1 type like V_ASN1_IA5STRING)

  • +
  • entry – value

  • +
  • len – buf_len of the entry +(-1 and the length is computed automagically)

  • +
+
+
+

The loc and set parameters determine where a new entry +should be added. +For almost all applications loc can be set to -1 and set to 0. +This adds a new entry to the end of name as a single valued +RelativeDistinguishedName (RDN).

+
+
Parameters
+
    +
  • loc – determines the index where the new entry is +inserted: if it is -1 it is appended.

  • +
  • set – determines how the new type is added. If it is zero +a new RDN is created. +If set is -1 or 1 it is added to the previous or next RDN +structure respectively. This will then be a multivalued +RDN: since multivalues RDNs are very seldom used set is +almost always set to zero.

Returns
-

a string which is the signature

+

1 for success of 0 if an error occurred.

-
-sign_rsassa_pss(digest: bytes, algo: str = 'sha1', salt_length: int = 20) → bytes[source]
-

Signs a digest with the private key using RSASSA-PSS

+
+as_der() → bytes[source]
+
+ +
+
+as_hash() → int[source]
+
+ +
+
+as_text(indent: int = 0, flags: int = 0) → str[source]
+

as_text returns the name as a string.

Parameters
    -
  • digest – A digest created by using the digest method

  • -
  • salt_length – The length of the salt to use

  • -
  • algo – The hash algorithm to use -Legal values like ‘sha1’,’sha224’, ‘sha256’, -‘ripemd160’, and ‘md5’.

  • +
  • indent – Each line in multiline format is indented +by this many spaces.

  • +
  • flags – Flags that control how the output should be formatted.

+
+
+ +
+
+entry_count() → int[source]
+
+ +
+
+get_entries_by_nid(nid: int) → List[M2Crypto.X509.X509_Name_Entry][source]
+

Retrieve the next index matching nid.

+
+
Parameters
+

nid – name of the entry (as m2.NID* constants)

+
+
Returns
+

list of X509_Name_Entry items

+
+
+
+ +
+
+m2_x509_name_free()
+
+ +
+
+nid = {'C': 14, 'CN': 13, 'Email': 48, 'GN': 99, 'L': 15, 'O': 17, 'OU': 18, 'SN': 100, 'SP': 16, 'ST': 16, 'commonName': 13, 'emailAddress': 48, 'givenName': 99, 'localityName': 15, 'organizationName': 17, 'organizationUnitName': 18, 'serialNumber': 105, 'stateOrProvinceName': 16, 'surname': 100}
+
+ +
+ +
+
+class M2Crypto.X509.X509_Name_Entry(x509_name_entry: bytes, _pyfree: int = 0)[source]
+

Bases: object

+

X509 Name Entry

+
+
+create_by_txt(field, type, entry, len)[source]
+
+ +
+
+get_data()M2Crypto.ASN1.ASN1_String[source]
+
+ +
+
+get_object()M2Crypto.ASN1.ASN1_Object[source]
+
+ +
+
+m2_x509_name_entry_free()
+
+ +
+
+set_data(data: bytes, type: int = 4097) → int[source]
+

Sets the field name to asn1obj

+
+
Parameters
+

data – data in a binary form to be set

+
+
Returns
+

0 on failure, 1 on success

+
+
+
+ +
+
+set_object(asn1obj: M2Crypto.ASN1.ASN1_Object) → int[source]
+

Sets the field name to asn1obj

+
+
Parameters
+

asn1obj

+
+
Returns
+

0 on failure, 1 on success

+
+
+
+ +
+ +
+
+class M2Crypto.X509.X509_Stack(stack: Optional[bytes] = None, _pyfree: int = 0, _pyfree_x509: int = 0)[source]
+

Bases: object

+

X509 Stack

+
+
Warning
+

Do not modify the underlying OpenSSL stack +except through this interface, or use any OpenSSL +functions that do so indirectly. Doing so will get the +OpenSSL stack and the internal pystack of this class out +of sync, leading to python memory leaks, exceptions or +even python crashes!

+
+
+
+
+as_der() → bytes[source]
+

Return the stack as a DER encoded string

+
+ +
+
+m2_sk_x509_free()
+
+ +
+
+pop()M2Crypto.X509.X509[source]
+

pop a certificate from the stack.

+
+
Returns
+

X509 object that was popped, or None if there is +nothing to pop.

+
+
+
+ +
+
+push(x509: M2Crypto.X509.X509) → int[source]
+

push an X509 certificate onto the stack.

+
+
Parameters
+

x509 – X509 object.

+
+
Returns
+

The number of X509 objects currently on the stack.

+
+
+
+ +
+ +
+
+class M2Crypto.X509.X509_Store(store: Optional[bytes] = None, _pyfree: int = 0)[source]
+

Bases: object

+

X509 Store

+
+
+add_cert(x509: M2Crypto.X509.X509) → int
+
+ +
+
+add_x509(x509: M2Crypto.X509.X509) → int[source]
+
+ +
+
+load_info(file: AnyStr) → int[source]
+
+
Parameters
+

file – filename

+
Returns
-

a string which is the signature

+

1 on success, 0 on failure

-
-verify(data: bytes, signature: bytes, algo: str = 'sha1') → int[source]
-

Verifies the signature with the public key

-
+
+load_locations(file: AnyStr) → int
+
Parameters
-
    -
  • data – Data that has been signed

  • -
  • signature – The signature signed with the private key

  • -
  • algo – The method use to create digest from the data -before it was signed. Legal values like -‘sha1’,’sha224’, ‘sha256’, ‘ripemd160’, and ‘md5’.

  • -
+

file – filename

Returns
-

1 or 0, depending on whether the signature was -verified or not.

+

1 on success, 0 on failure

-
-verify_rsassa_pss(data: bytes, signature: bytes, algo: str = 'sha1', salt_length: int = 20) → int[source]
-

Verifies the signature RSASSA-PSS

+
+m2_x509_store_free()
+
+ +
+
+set_flags(flags: int) → int[source]
+

Set the verification flags for the X509Store +Wrapper over OpenSSL X509_STORE_set_flags()

Parameters
-
    -
  • data – Data that has been signed

  • -
  • signature – The signature signed with RSASSA-PSS

  • -
  • salt_length – The length of the salt that was used

  • -
  • algo – The hash algorithm to use -Legal values are for example ‘sha1’,’sha224’, -‘sha256’, ‘ripemd160’, and ‘md5’.

  • -
-
-
Returns
-

1 or 0, depending on whether the signature was -verified or not.

+

flagsVERIFICATION FLAGS section of the +X509_VERIFY_PARAM_set_flags man page has +a complete description of values the flags +parameter can take. +Their M2Crypto equivalent is transformed following +the pattern: “X509_V_FLAG_XYZ” -> lowercase(“VERIFY_XYZ”)

+
+
+set_verify_cb(callback: Optional[callable] = None) → None[source]
+

Set callback which will be called when the store is verified. +Wrapper over OpenSSL X509_STORE_set_verify_cb().

+
+
Parameters
+

callback – Callable to specify verification options. +Type of the callable must be: +(int, X509_Store_Context) -> int. +If None: set the standard options.

+
+
Note
+

compile-time or run-time errors in the callback would result +in mysterious errors during verification, which could be hard +to trace.

+
+
Note
+

Python exceptions raised in callbacks do not propagate to +verify() call.

+
+
Returns
+

None

+
+
-
-
-exception M2Crypto.RSA.RSAError[source]
-

Bases: Exception

-
-class M2Crypto.RSA.RSA_pub(rsa: bytes, _pyfree: int = 0)[source]
-

Bases: M2Crypto.RSA.RSA

-

Object interface to an RSA public key.

+
+class M2Crypto.X509.X509_Store_Context(x509_store_ctx: bytes, _pyfree: int = 0)[source]
+

Bases: object

+

X509 Store Context

-
-check_key() → int[source]
-

Validate RSA keys.

-

It checks that p and q are in fact prime, and that n = p*q.

+
+get1_chain()M2Crypto.X509.X509_Stack[source]
+

Get certificate chain.

Returns
-

returns 1 if rsa is a valid RSA key, and 0 otherwise. --1 is returned if an error occurs while checking the key. -If the key is invalid or an error occurred, the reason -code can be obtained using ERR_get_error(3).

+

Reference counted (i.e. safe to use even after the store +context goes away) stack of certificates in the chain.

-
-private_decrypt(*argv: Any) → None[source]
-
+
+get_current_cert()M2Crypto.X509.X509[source]
+

Get current X.509 certificate.

+
+
Warning
+

The returned certificate is NOT refcounted, so you can not +rely on it being valid once the store context goes +away or is modified.

+
+
+
-
-private_encrypt(*argv: Any) → None[source]
-
+
+get_error() → int[source]
+

Get error code.

+
-
-save_key(file: AnyStr, *args: Any, **kw: Any) → int[source]
-

Save public key to file.

+
+get_error_depth() → int[source]
+

Get error depth.

-
-save_key_bio(bio: BIO.BIO, *args: Any, **kw: Any) → int[source]
-

Save public key to BIO.

+
+m2_x509_store_ctx_free()
+
+
+
+
+M2Crypto.X509.load_cert(file: AnyStr, format: int = 1)M2Crypto.X509.X509[source]
+

Load certificate from file.

+
+
Parameters
+
    +
  • file – Name of file containing certificate in either DER or +PEM format.

  • +
  • format – Describes the format of the file to be loaded, +either PEM or DER.

  • +
+
+
Returns
+

M2Crypto.X509.X509 object.

+
+
-
-M2Crypto.RSA.gen_key(bits: int, e: int, callback: Callable = <function keygen_callback>)M2Crypto.RSA.RSA[source]
-

Generate an RSA key pair.

+
+M2Crypto.X509.load_cert_bio(bio: M2Crypto.BIO.BIO, format: int = 1)M2Crypto.X509.X509[source]
+

Load certificate from a bio.

Parameters
    -
  • bits – Key length, in bits.

  • -
  • e – The RSA public exponent.

  • -
  • callback – A Python callable object that is invoked -during key generation; its usual purpose is to -provide visual feedback. The default callback is -keygen_callback.

  • +
  • bio – BIO pointing at a certificate in either DER or PEM format.

  • +
  • format – Describes the format of the cert to be loaded, +either PEM or DER (via constants FORMAT_PEM +and FORMAT_FORMAT_DER)

Returns
-

M2Crypto.RSA.RSA object.

+

M2Crypto.X509.X509 object.

-
-M2Crypto.RSA.keygen_callback(p: int, n: Any, out: IO[str] = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) → None[source]
-

Default callback for gen_key().

+
+M2Crypto.X509.load_cert_der_string(string: AnyStr)M2Crypto.X509.X509[source]
+

Load certificate from a string.

+
+
Parameters
+

string – String containing a certificate in DER format.

+
+
Returns
+

M2Crypto.X509.X509 object.

+
+
-
-M2Crypto.RSA.load_key(file: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.RSA.RSA[source]
-

Load an RSA key pair from file.

+
+M2Crypto.X509.load_cert_string(string: AnyStr, format: int = 1)M2Crypto.X509.X509[source]
+

Load certificate from a string.

Parameters
    -
  • file – Name of file containing RSA public key in PEM format.

  • -
  • callback – A Python callable object that is invoked -to acquire a passphrase with which to unlock the -key. The default is util.passphrase_callback.

  • +
  • string – String containing a certificate in either DER or PEM format.

  • +
  • format – Describes the format of the cert to be loaded, +either PEM or DER (via constants FORMAT_PEM +and FORMAT_FORMAT_DER)

Returns
-

M2Crypto.RSA.RSA object.

+

M2Crypto.X509.X509 object.

-
-M2Crypto.RSA.load_key_bio(bio: BIO.BIO, callback: Callable = <function passphrase_callback>)RSA[source]
-

Load an RSA key pair from an M2Crypto.BIO.BIO object.

+
+M2Crypto.X509.load_crl(file: AnyStr)M2Crypto.X509.CRL[source]
+

Load CRL from file.

Parameters
-
    -
  • bio – M2Crypto.BIO.BIO object containing RSA key pair in PEM -format.

  • -
  • callback – A Python callable object that is invoked -to acquire a passphrase with which to unlock the -key. The default is util.passphrase_callback.

  • -
+

file – Name of file containing CRL in PEM format.

Returns
-

M2Crypto.RSA.RSA object.

+

M2Crypto.X509.CRL object.

-
-M2Crypto.RSA.load_key_string(string: AnyStr, callback: Callable = <function passphrase_callback>)M2Crypto.RSA.RSA[source]
-

Load an RSA key pair from a string.

+
+M2Crypto.X509.load_request(file: AnyStr, format: int = 1)M2Crypto.X509.Request[source]
+

Load certificate request from file.

Parameters
    -
  • string – String containing RSA key pair in PEM format.

  • -
  • callback – A Python callable object that is invoked -to acquire a passphrase with which to unlock the -key. The default is util.passphrase_callback.

  • +
  • file – Name of file containing certificate request in +either PEM or DER format.

  • +
  • format – Describes the format of the file to be loaded, +either PEM or DER. (using constants FORMAT_PEM +and FORMAT_DER)

Returns
-

M2Crypto.RSA.RSA object.

+

Request object.

-
-M2Crypto.RSA.load_pub_key(file: AnyStr)M2Crypto.RSA.RSA_pub[source]
-

Load an RSA public key from file.

+
+M2Crypto.X509.load_request_bio(bio: M2Crypto.BIO.BIO, format: int = 1)M2Crypto.X509.Request[source]
+

Load certificate request from a bio.

Parameters
-

file – Name of file containing RSA public key in PEM format.

+
    +
  • bio – BIO pointing at a certificate request in +either DER or PEM format.

  • +
  • format – Describes the format of the request to be loaded, +either PEM or DER. (using constants FORMAT_PEM +and FORMAT_DER)

  • +
Returns
-

M2Crypto.RSA.RSA_pub object.

+

M2Crypto.X509.Request object.

-
-M2Crypto.RSA.load_pub_key_bio(bio: BIO.BIO)RSA_pub[source]
-

Load an RSA public key from an M2Crypto.BIO.BIO object.

+
+M2Crypto.X509.load_request_der_string(string: AnyStr)M2Crypto.X509.Request[source]
+

Load certificate request from a string.

Parameters
-

bio – M2Crypto.BIO.BIO object containing RSA public key in PEM -format.

+

string – String containing a certificate request in DER format.

Returns
-

M2Crypto.RSA.RSA_pub object.

+

M2Crypto.X509.Request object.

-
-M2Crypto.RSA.new_pub_key(e_n: Tuple[bytes, bytes])M2Crypto.RSA.RSA_pub[source]
-

Instantiate an RSA_pub object from an (e, n) tuple.

+
+M2Crypto.X509.load_request_string(string: AnyStr, format: int = 1)M2Crypto.X509.Request[source]
+

Load certificate request from a string.

Parameters
    -
  • e – The RSA public exponent; it is a string in OpenSSL’s MPINT -format - 4-byte big-endian bit-count followed by the -appropriate number of bits.

  • -
  • n – The RSA composite of primes; it is a string in OpenSSL’s -MPINT format - 4-byte big-endian bit-count followed by the -appropriate number of bits.

  • +
  • string – String containing a certificate request in +either DER or PEM format.

  • +
  • format – Describes the format of the request to be loaded, +either PEM or DER. (using constants FORMAT_PEM +and FORMAT_DER)

Returns
-

M2Crypto.RSA.RSA_pub object.

+

M2Crypto.X509.Request object.

-
-M2Crypto.RSA.rsa_error() → None[source]
+
+M2Crypto.X509.new_extension(name: str, value: bytes, critical: int = 0, _pyfree: int = 1)M2Crypto.X509.X509_Extension[source]
+

Create new X509_Extension instance.

+
+ +
+
+M2Crypto.X509.new_stack_from_der(der_string: bytes)M2Crypto.X509.X509_Stack[source]
+

Create a new X509_Stack from DER string.

+
+
Returns
+

X509_Stack

+
+
+
+ +
+
+M2Crypto.X509.x509_store_default_cb(ok: int, ctx: M2Crypto.X509.X509_Store_Context) → int[source]
-
-

Rand Module

-
-
-

SMIME Module

-
-
-

X509 Module

-
-
-

callback Module

+
+

callback Module

-
-

ftpslib Module

+
+

ftpslib Module

+
+
+class M2Crypto.ftpslib.FTP_TLS(host=None, ssl_ctx=None)[source]
+

Bases: ftplib.FTP

+

Python OO interface to client-side FTP/TLS.

+
+
+auth_ssl()[source]
+

Secure the control connection per AUTH SSL, aka AUTH TLS-P.

+
+ +
+
+auth_tls()[source]
+

Secure the control connection per AUTH TLS, aka AUTH TLS-C.

+
+ +
+
+ntransfercmd(cmd, rest=None)[source]
+

Initiate a data transfer.

+
+ +
+
+prot_c()[source]
+

Set up data connection in the clear.

+
+ +
+
+prot_p()[source]
+

Set up secure data connection.

+
+ +
+
-
-

httpslib Module

+
+

httpslib Module

+
+
+class M2Crypto.httpslib.HTTPSConnection(host: str, port: Optional[int] = None, strict: Optional[bool] = None, **ssl: Any)[source]
+

Bases: http.client.HTTPConnection

+

This class allows communication via SSL using M2Crypto.

+
+
+close() → None[source]
+

Close the connection to the HTTP server.

+
+ +
+
+connect() → None[source]
+

Connect to the host and port specified in __init__.

+
+ +
+
+default_port = 443
+
+ +
+
+get_session()M2Crypto.SSL.Session.Session[source]
+
+ +
+
+set_session(session: M2Crypto.SSL.Session.Session) → None[source]
+
+ +
+ +
+
+class M2Crypto.httpslib.ProxyHTTPSConnection(host: str, port: Optional[int] = None, strict: Optional[bool] = None, username: Optional[AnyStr] = None, password: Optional[AnyStr] = None, **ssl: Any)[source]
+

Bases: M2Crypto.httpslib.HTTPSConnection

+

An HTTPS Connection that uses a proxy and the CONNECT request.

+

When the connection is initiated, CONNECT is first sent to the proxy (along +with authorization headers, if supplied). If successful, an SSL connection +will be established over the socket through the proxy and to the target +host.

+

Finally, the actual request is sent over the SSL connection tunneling +through the proxy.

+
+
+connect() → None[source]
+

Connect to the host and port specified in __init__.

+
+ +
+
+endheaders(*args: Any, **kwargs: Any) → None[source]
+

Indicate that the last header line has been sent to the server.

+

This method sends the request to the server. The optional message_body +argument can be used to pass a message body associated with the +request.

+
+ +
+
+putheader(header: AnyStr, value: AnyStr) → None[source]
+

Send a request header line to the server.

+

For example: h.putheader(‘Accept’, ‘text/html’)

+
+ +
+
+putrequest(method: AnyStr, url: AnyStr, skip_host: int = 0, skip_accept_encoding: int = 0) → None[source]
+

putrequest is called before connect, so can interpret url and get +real host/port to be used to make CONNECT request to proxy

+
+ +
+

m2 Module

@@ -1127,17 +4250,100 @@ appropriate number of bits.

m2crypto Module

-
-

m2urllib Module

+
+

m2urllib Module

+
+
+M2Crypto.m2urllib.open_https(self: URLOpener, url: AnyStr, data: Optional[bytes] = None, ssl_context: Optional[SSL.Context] = None) → addinfourl[source]
+

Open URL over the SSL connection.

+
+
Parameters
+
    +
  • url – URL to be opened

  • +
  • data – data for the POST request

  • +
  • ssl_context – SSL.Context to be used

  • +
+
+
Returns
+

+
+
+
+
-
-

m2urllib2 Module

+
+

m2urllib2 Module

+
+
+class M2Crypto.m2urllib2.HTTPSHandler(ssl_context: Optional[M2Crypto.SSL.Context.Context] = None)[source]
+

Bases: urllib.request.AbstractHTTPHandler

+
+
+https_open(req: urllib.request.Request) → urllib.response.addinfourl[source]
+

Return an addinfourl object for the request, using http_class.

+

http_class must implement the HTTPConnection API from httplib. +The addinfourl return value is a file-like object. It also +has methods and attributes including:

+
+
    +
  • info(): return a mimetools.Message object for the headers

  • +
  • geturl(): return the original request URL

  • +
  • code: HTTP status code

  • +
+
+
+ +
+
+https_request(request)
+
+ +
+ +
+
+M2Crypto.m2urllib2.build_opener(ssl_context: Optional[M2Crypto.SSL.Context.Context] = None, *handlers: object) → urllib.request.OpenerDirector[source]
+

Create an opener object from a list of handlers.

+

The opener will use several default handlers, including support +for HTTP and FTP.

+

If any of the handlers passed as arguments are subclasses of the +default handlers, the default handlers will not be used.

+
+
-
-

m2xmlrpclib Module

+
+

m2xmlrpclib Module

+
+
+class M2Crypto.m2xmlrpclib.SSL_Transport(ssl_context: Optional[M2Crypto.SSL.Context.Context] = None, *args: Any, **kw: Any)[source]
+

Bases: xmlrpc.client.Transport

+
+
+request(host: AnyStr, handler: Callable, request_body: bytes, verbose: int = 0) → object[source]
+
+ +
+
+user_agent = 'M2Crypto_XMLRPC/0.36.0 - Python-xmlrpc/3.8'
+
+ +
+
-
-

threading Module

+
+

threading Module

+
+
+M2Crypto.threading.cleanup() → None[source]
+

End and cleanup threading support.

+
+ +
+
+M2Crypto.threading.init() → None[source]
+

Initialize threading support.

+
+

util Module

@@ -1154,7 +4360,7 @@ appropriate number of bits.

-M2Crypto.util.genparam_callback(p: int, n: Any, out: io.IOBase = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) → None[source]
+M2Crypto.util.genparam_callback(p: int, n: Any, out: TextIO = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) → None[source]
@@ -1194,16 +4400,16 @@ appropriate number of bits.

@@ -1231,30 +4437,30 @@ appropriate number of bits.

  • M2Crypto Package
    • M2Crypto Package
    • -
    • ASN1 Module
    • -
    • AuthCookie Module
    • -
    • BIO Module
    • -
    • BN Module
    • -
    • DH Module
    • -
    • DSA Module
    • -
    • EC Module
    • +
    • ASN1 Module
    • +
    • AuthCookie Module
    • +
    • BIO Module
    • +
    • BN Module
    • +
    • DH Module
    • +
    • DSA Module
    • +
    • EC Module
    • EVP Module
    • -
    • Engine Module
    • +
    • Engine Module
    • Err Module
    • -
    • RC4 Module
    • +
    • RC4 Module
    • RSA Module
    • -
    • Rand Module
    • -
    • SMIME Module
    • -
    • X509 Module
    • -
    • callback Module
    • -
    • ftpslib Module
    • -
    • httpslib Module
    • +
    • Rand Module
    • +
    • SMIME Module
    • +
    • X509 Module
    • +
    • callback Module
    • +
    • ftpslib Module
    • +
    • httpslib Module
    • m2 Module
    • m2crypto Module
    • -
    • m2urllib Module
    • -
    • m2urllib2 Module
    • -
    • m2xmlrpclib Module
    • -
    • threading Module
    • +
    • m2urllib Module
    • +
    • m2urllib2 Module
    • +
    • m2xmlrpclib Module
    • +
    • threading Module
    • util Module
    • Subpackages
      • SSL Package
      • diff --git a/doc/html/_modules/M2Crypto/ASN1.html b/doc/html/_modules/M2Crypto/ASN1.html index bac4c1b..fea6386 100644 --- a/doc/html/_modules/M2Crypto/ASN1.html +++ b/doc/html/_modules/M2Crypto/ASN1.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.ASN1 — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

        Source code for M2Crypto.ASN1

        -from __future__ import absolute_import
        +from __future__ import absolute_import
         
         """
         M2Crypto wrapper for OpenSSL ASN1 API.
        @@ -47,9 +46,8 @@
         import datetime
         import time
         
        -from M2Crypto import BIO, m2, py27plus, six
        -if py27plus:
        -    from typing import Any, Callable, Optional, Tuple  # noqa
        +from M2Crypto import BIO, m2, six
        +from typing import Optional  # noqa
         
         MBSTRING_FLAG = 0x1000
         MBSTRING_ASC = MBSTRING_FLAG | 1
        @@ -60,7 +58,7 @@
         
             m2_asn1_integer_free = m2.asn1_integer_free
         
        -    def __init__(self, asn1int, _pyfree=0):
        +    def __init__(self, asn1int, _pyfree=0):
                 # type: (ASN1_Integer, int) -> None
                 self.asn1int = asn1int
                 self._pyfree = _pyfree
        @@ -73,12 +71,12 @@
         
                 return m2.asn1_integer_cmp(self.asn1int, other.asn1int)
         
        -    def __del__(self):
        +    def __del__(self):
                 # type: () -> None
                 if self._pyfree:
                     self.m2_asn1_integer_free(self.asn1int)
         
        -    def __int__(self):
        +    def __int__(self):
                 # type: () -> int
                 return m2.asn1_integer_get(self.asn1int)
        @@ -87,22 +85,22 @@ m2_asn1_string_free = m2.asn1_string_free - def __init__(self, asn1str, _pyfree=0): + def __init__(self, asn1str, _pyfree=0): # type: (ASN1_String, int) -> None self.asn1str = asn1str self._pyfree = _pyfree - def __bytes__(self): + def __bytes__(self): # type: () -> bytes buf = BIO.MemoryBuffer() m2.asn1_string_print(buf.bio_ptr(), self.asn1str) return buf.read_all() - def __str__(self): + def __str__(self): # type: () -> str return six.ensure_text(self.__bytes__()) - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_asn1_string_free(self.asn1str) @@ -128,12 +126,12 @@ m2_asn1_object_free = m2.asn1_object_free - def __init__(self, asn1obj, _pyfree=0): + def __init__(self, asn1obj, _pyfree=0): # type: (ASN1_Object, int) -> None self.asn1obj = asn1obj self._pyfree = _pyfree - def __del__(self): + def __del__(self): # type: () -> None if self._pyfree: self.m2_asn1_object_free(self.asn1obj) @@ -155,7 +153,7 @@ # type: (Optional[datetime.datetime]) -> datetime.timedelta return datetime.timedelta(0) - def __repr__(self): + def __repr__(self): return "<Timezone: %s>" % self.tzname(None) @@ -165,7 +163,7 @@
        [docs]class LocalTimezone(datetime.tzinfo): """Localtimezone from datetime manual.""" - def __init__(self): + def __init__(self): # type: () -> None self._stdoffset = datetime.timedelta(seconds=-time.timezone) if time.daylight: @@ -207,7 +205,7 @@ "Sep", "Oct", "Nov", "Dec"] m2_asn1_time_free = m2.asn1_time_free - def __init__(self, asn1_time=None, _pyfree=0, asn1_utctime=None): + def __init__(self, asn1_time=None, _pyfree=0, asn1_utctime=None): # type: (Optional[ASN1_TIME], Optional[int], Optional[ASN1_TIME]) -> None # handle old keyword parameter if asn1_time is None: @@ -221,12 +219,12 @@ self.asn1_time = m2.asn1_time_new() self._pyfree = 1 - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_asn1_time_free(self.asn1_time) - def __str__(self): + def __str__(self): # type: () -> str assert m2.asn1_time_type_check(self.asn1_time), \ "'asn1_time' type error'" @@ -318,17 +316,15 @@
- + @@ -345,7 +341,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/AuthCookie.html b/doc/html/_modules/M2Crypto/AuthCookie.html index 3b2d629..92205f6 100644 --- a/doc/html/_modules/M2Crypto/AuthCookie.html +++ b/doc/html/_modules/M2Crypto/AuthCookie.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.AuthCookie — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.AuthCookie

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """Secure Authenticator Cookies
 
@@ -43,11 +42,10 @@
 import re
 import time
 
-from M2Crypto import Rand, m2, py27plus, six, util
-from M2Crypto.six.moves.http_cookies import SimpleCookie  # pylint: disable=no-name-in-module,import-error
+from M2Crypto import Rand, m2, six, util
+from M2Crypto.six.moves.http_cookies import SimpleCookie
 
-if py27plus:
-    from typing import re as type_re, AnyStr, Dict, Optional, Union  # noqa
+from typing import re as type_re, AnyStr, Optional, Union  # noqa
 
 _MIX_FORMAT = 'exp=%f&data=%s&digest='
 _MIX_RE = re.compile(r'exp=(\d+\.\d+)&data=(.+)&digest=(\S*)')
@@ -85,7 +83,7 @@
 
     _keylen = 20  # type: int
 
-    def __init__(self):
+    def __init__(self):
         # type: () -> None
         self._key = Rand.rand_bytes(self._keylen)
 
@@ -142,7 +140,7 @@
 
 
[docs]class AuthCookie(object): - def __init__(self, expiry, data, dough, mac): + def __init__(self, expiry, data, dough, mac): # type: (float, str, str, str) -> None """ Create new authentication cookie @@ -234,17 +232,15 @@
- + @@ -261,7 +257,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/BIO.html b/doc/html/_modules/M2Crypto/BIO.html index 212c05d..b7d66ff 100644 --- a/doc/html/_modules/M2Crypto/BIO.html +++ b/doc/html/_modules/M2Crypto/BIO.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.BIO — M2Crypto documentation - - - - - + + + + + @@ -33,17 +32,17 @@

Source code for M2Crypto.BIO

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """M2Crypto wrapper for OpenSSL BIO API.
 
 Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved."""
 
+import io
 import logging
+from typing import Any, AnyStr, Callable, Iterable, Optional, Union  # noqa
 
-from M2Crypto import m2, py27plus, six
-if py27plus:
-    from typing import AnyStr, Callable, Iterable, Optional, Union  # noqa
+from M2Crypto import m2, six
 
 log = logging.getLogger('BIO')
 
@@ -60,7 +59,7 @@
 
     m2_bio_free = m2.bio_free
 
-    def __init__(self, bio=None, _pyfree=0, _close_cb=None):
+    def __init__(self, bio=None, _pyfree=0, _close_cb=None):
         # type: (Optional[BIO], int, Optional[Callable]) -> None
         self.bio = bio
         self._pyfree = _pyfree
@@ -68,7 +67,7 @@
         self.closed = 0
         self.write_closed = 0
 
-    def __del__(self):
+    def __del__(self):
         if self._pyfree:
             self.m2_bio_free(self.bio)
 
@@ -196,10 +195,10 @@
         """Seek to the specified absolute offset."""
         return m2.bio_seek(self.bio, off)
- def __enter__(self): + def __enter__(self): return self - def __exit__(self, *args): + def __exit__(self, *args): # type: (*Any) -> int self.close()
@@ -214,7 +213,7 @@ a MemoryBuffer object only when necessary. """ - def __init__(self, data=None): + def __init__(self, data=None): # type: (Optional[bytes]) -> None super(MemoryBuffer, self).__init__(self) if data is not None and not isinstance(data, bytes): @@ -225,7 +224,7 @@ if data is not None: m2.bio_write(self.bio, data) - def __len__(self): + def __len__(self): # type: () -> int return m2.bio_ctrl_pending(self.bio) @@ -256,7 +255,7 @@ general file manipulation in Python, use Python's builtin file object. """ - def __init__(self, pyfile, close_pyfile=1, mode='rb'): + def __init__(self, pyfile, close_pyfile=1, mode='rb'): # type: (Union[io.BytesIO, AnyStr], int, AnyStr) -> None super(File, self).__init__(self, _pyfree=1) @@ -303,7 +302,7 @@ """ return super(File, self).reset()
- def __del__(self): + def __del__(self): if not self.closed: m2.bio_free(self.bio)
@@ -328,7 +327,7 @@ m2_bio_pop = m2.bio_pop m2_bio_free = m2.bio_free - def __init__(self, under_bio, mode='rwb', _pyfree=1): + def __init__(self, under_bio, mode='rwb', _pyfree=1): # type: (BIO, str, int) -> None super(IOBuffer, self).__init__(self, _pyfree=_pyfree) self.io = m2.bio_new(m2.bio_f_buffer()) @@ -340,7 +339,7 @@ else: self.write_closed = 1 - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_bio_pop(self.bio) @@ -359,14 +358,14 @@ m2_bio_pop = m2.bio_pop m2_bio_free = m2.bio_free - def __init__(self, obio): + def __init__(self, obio): # type: (BIO) -> None super(CipherStream, self).__init__(self, _pyfree=1) self.obio = obio self.bio = m2.bio_new(m2.bio_f_cipher()) self.closed = 0 - def __del__(self): + def __del__(self): # type: () -> None if not getattr(self, 'closed', 1): self.close() @@ -398,14 +397,14 @@
[docs]class SSLBio(BIO): """Object interface to BIO_f_ssl.""" - def __init__(self, _pyfree=1): + def __init__(self, _pyfree=1): # type: (int) -> None super(SSLBio, self).__init__(self, _pyfree=_pyfree) self.bio = m2.bio_new(m2.bio_f_ssl()) self.closed = 0
[docs] def set_ssl(self, conn, close_flag=m2.bio_noclose): - # type: (Connection, int) -> None + ## type: (Connection, int) -> None """ Sets the bio to the SSL pointer which is contained in the connection object. @@ -455,17 +454,15 @@
- + @@ -482,7 +479,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/BN.html b/doc/html/_modules/M2Crypto/BN.html index b8287fb..8e643eb 100644 --- a/doc/html/_modules/M2Crypto/BN.html +++ b/doc/html/_modules/M2Crypto/BN.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.BN — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.BN

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """
 M2Crypto wrapper for OpenSSL BN (BIGNUM) API.
@@ -41,9 +40,8 @@
 Copyright (c) 2005 Open Source Applications Foundation. All rights reserved.
 """
 
-from M2Crypto import m2, util
-if util.py27plus:
-    from typing import Optional  # noqa
+from M2Crypto import m2
+from typing import Optional  # noqa
 
 
 
[docs]def rand(bits, top=-1, bottom=0): @@ -123,17 +121,15 @@
- + @@ -150,7 +146,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/DH.html b/doc/html/_modules/M2Crypto/DH.html index 0e6d33a..ed4bb1b 100644 --- a/doc/html/_modules/M2Crypto/DH.html +++ b/doc/html/_modules/M2Crypto/DH.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.DH — M2Crypto documentation - - - - - + + + + + @@ -33,21 +32,21 @@

Source code for M2Crypto.DH

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """M2Crypto wrapper for OpenSSL DH API.
 
 Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved."""
 
-from M2Crypto import BIO, m2, util
-from M2Crypto.util import genparam_callback
-if util.py27plus:
-    from typing import AnyStr, Callable  # noqa
+from M2Crypto import BIO, m2
+from M2Crypto.util import genparam_callback
+from typing import AnyStr, Callable, Optional  # noqa
 
 
 
[docs]class DHError(Exception): pass
+ m2.dh_init(DHError) @@ -57,23 +56,23 @@ m2_dh_free = m2.dh_free - def __init__(self, dh, _pyfree=0): + def __init__(self, dh, _pyfree=0): # type: (bytes, int) -> None assert m2.dh_type_check(dh) self.dh = dh self._pyfree = _pyfree - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_dh_free(self.dh) - def __len__(self): + def __len__(self): # type: () -> int assert m2.dh_type_check(self.dh), "'dh' type error" return int(m2.dh_size(self.dh)) - def __getattr__(self, name): + def __getattr__(self, name): # type: (str) -> bytes if name in ('p', 'g', 'pub', 'priv'): method = getattr(m2, 'dh_get_%s' % (name,)) @@ -82,7 +81,7 @@ else: raise AttributeError - def __setattr__(self, name, value): + def __setattr__(self, name, value): # type: (str, bytes) -> bytes if name in ('p', 'g'): raise DHError('set (p, g) via set_params()') @@ -178,17 +177,15 @@
- + @@ -205,7 +202,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/DSA.html b/doc/html/_modules/M2Crypto/DSA.html index 6d97c52..267aaaf 100644 --- a/doc/html/_modules/M2Crypto/DSA.html +++ b/doc/html/_modules/M2Crypto/DSA.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.DSA — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.DSA

-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function
 
 """
     M2Crypto wrapper for OpenSSL DSA API.
@@ -44,14 +43,14 @@
     Copyright (C) 2004 OSAF. All Rights Reserved.
 """
 
-from M2Crypto import BIO, m2, util
-if util.py27plus:
-    from typing import AnyStr, Callable, Tuple  # noqa
+from M2Crypto import BIO, m2, util
+from typing import Any, AnyStr, Callable, Tuple  # noqa
 
 
 
[docs]class DSAError(Exception): pass
+ m2.dsa_init(DSAError) @@ -82,7 +81,7 @@ m2_dsa_free = m2.dsa_free - def __init__(self, dsa, _pyfree=0): + def __init__(self, dsa, _pyfree=0): # type: (bytes, int) -> None """ Use one of the factory functions to create an instance. @@ -92,12 +91,12 @@ self.dsa = dsa self._pyfree = _pyfree - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_dsa_free(self.dsa) - def __len__(self): + def __len__(self): # type: () -> int """ Return the key length. @@ -107,7 +106,7 @@ assert m2.dsa_type_check(self.dsa), "'dsa' type error" return m2.dsa_keylen(self.dsa) - def __getattr__(self, name): + def __getattr__(self, name): # type: (str) -> bytes """ Return specified DSA parameters and key values. @@ -123,7 +122,7 @@ else: raise AttributeError - def __setattr__(self, name, value): + def __setattr__(self, name, value): # type: (str, bytes) -> None if name in ['p', 'q', 'g']: raise DSAError('set (p, q, g) via set_params()') @@ -513,17 +512,15 @@
- + @@ -540,7 +537,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/EC.html b/doc/html/_modules/M2Crypto/EC.html index 8b62996..a850afc 100644 --- a/doc/html/_modules/M2Crypto/EC.html +++ b/doc/html/_modules/M2Crypto/EC.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.EC — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.EC

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """
 M2Crypto wrapper for OpenSSL ECDH/ECDSA API.
@@ -45,9 +44,9 @@
 Portions copyright (c) 2005-2006 Vrije Universiteit Amsterdam.
 All rights reserved."""
 
-from M2Crypto import BIO, Err, EVP, m2, util
-if util.py27plus:
-    from typing import AnyStr, Callable, Dict, Optional, Tuple, Union  # noqa
+from M2Crypto import BIO, Err, EVP, m2, util
+from typing import AnyStr, Callable, Dict, Optional, Tuple, Union  # noqa
+from M2Crypto.EVP import PKey
 
 EC_Key = bytes
 
@@ -55,6 +54,7 @@
 
[docs]class ECError(Exception): pass
+ m2.ec_init(ECError) # Curve identifier constants @@ -171,18 +171,18 @@ m2_ec_key_free = m2.ec_key_free - def __init__(self, ec, _pyfree=0): + def __init__(self, ec, _pyfree=0): # type: (EC, int) -> None assert m2.ec_key_type_check(ec), "'ec' type error" self.ec = ec self._pyfree = _pyfree - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_ec_key_free(self.ec) - def __len__(self): + def __len__(self): # type: () -> int assert m2.ec_key_type_check(self.ec), "'ec' type error" return m2.ec_key_keylen(self.ec) @@ -333,7 +333,7 @@ Object interface to an EC public key. ((don't like this implementation inheritance)) """ - def __init__(self, ec, _pyfree=0): + def __init__(self, ec, _pyfree=0): # type: (EC, int) -> None EC.__init__(self, ec, _pyfree) self.der = None # type: Optional[bytes] @@ -524,17 +524,15 @@
- + @@ -551,7 +549,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/EVP.html b/doc/html/_modules/M2Crypto/EVP.html index 861dd5f..71b14d0 100644 --- a/doc/html/_modules/M2Crypto/EVP.html +++ b/doc/html/_modules/M2Crypto/EVP.html @@ -45,7 +45,6 @@ import logging from M2Crypto import BIO, Err, RSA, m2, util from typing import AnyStr, Optional, Callable # noqa -from M2Crypto.SSL.Context import Context log = logging.getLogger('EVP') @@ -230,7 +229,7 @@ if mda is None: raise ValueError('unknown message digest', md) self.md = mda() - self.ctx = m2.md_ctx_new() # type: Context + self.ctx = m2.md_ctx_new() ## type: Context
[docs] def reset_context(self, md='sha1'): # type: (str) -> None @@ -333,6 +332,11 @@ :return: The signature. """ + + if m2.OPENSSL_VERSION_NUMBER < 0x10101000: + raise NotImplemented('This method requires OpenSSL version ' + + '1.1.1 or greater.') + return m2.digest_sign(self.ctx, data)
[docs] def digest_verify_init(self): @@ -376,6 +380,11 @@ :return: Result of verification: 1 for success, 0 for failure, -1 on other error. """ + + if m2.OPENSSL_VERSION_NUMBER < 0x10101000: + raise NotImplemented('This method requires OpenSSL version ' + + '1.1.1 or greater.') + return m2.digest_verify(self.ctx, sign, data)
[docs] def assign_rsa(self, rsa, capture=1): diff --git a/doc/html/_modules/M2Crypto/Engine.html b/doc/html/_modules/M2Crypto/Engine.html index 4d8474c..ef05bd2 100644 --- a/doc/html/_modules/M2Crypto/Engine.html +++ b/doc/html/_modules/M2Crypto/Engine.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.Engine — M2Crypto documentation - - - - - + + + + + @@ -34,7 +33,7 @@

Source code for M2Crypto.Engine

 # vim: sts=4 sw=4 et
-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """
 M2Crypto wrapper for OpenSSL ENGINE API.
@@ -43,14 +42,14 @@
 IMEC MSU
 """
 
-from M2Crypto import EVP, Err, X509, m2, six, util
-if util.py27plus:
-    from typing import AnyStr, Callable, Optional  # noqa
+from M2Crypto import EVP, Err, X509, m2, six
+from typing import AnyStr, Callable, Optional  # noqa
 
 
 
[docs]class EngineError(Exception): pass
+ m2.engine_init_error(EngineError) @@ -59,7 +58,7 @@ m2_engine_free = m2.engine_free - def __init__(self, id=None, _ptr=None, _pyfree=1): + def __init__(self, id=None, _ptr=None, _pyfree=1): # type: (Optional[bytes], Optional[bytes], int) -> None """Create new Engine from ENGINE pointer or obtain by id""" if not _ptr and not id: @@ -71,7 +70,7 @@ raise ValueError("Unknown engine: %s" % id) self._pyfree = _pyfree - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_engine_free(self._ptr) @@ -215,17 +214,15 @@
- + @@ -242,7 +239,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/RC4.html b/doc/html/_modules/M2Crypto/RC4.html index 95456f5..527f625 100644 --- a/doc/html/_modules/M2Crypto/RC4.html +++ b/doc/html/_modules/M2Crypto/RC4.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.RC4 — M2Crypto documentation - - - - - + + + + + @@ -33,13 +32,13 @@

Source code for M2Crypto.RC4

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """M2Crypto wrapper for OpenSSL RC4 API.
 
 Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved."""
 
-from M2Crypto.m2 import rc4_free, rc4_new, rc4_set_key, rc4_update
+from M2Crypto.m2 import rc4_free, rc4_new, rc4_set_key, rc4_update
 
 
 
[docs]class RC4(object): @@ -47,13 +46,13 @@ rc4_free = rc4_free - def __init__(self, key=None): + def __init__(self, key=None): # type: (bytes) -> None self.cipher = rc4_new() if key: rc4_set_key(self.cipher, key) - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, 'cipher', None): self.rc4_free(self.cipher) @@ -101,17 +100,15 @@
- + @@ -128,7 +125,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/Rand.html b/doc/html/_modules/M2Crypto/Rand.html index b2fa075..e23e4ee 100644 --- a/doc/html/_modules/M2Crypto/Rand.html +++ b/doc/html/_modules/M2Crypto/Rand.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.Rand — M2Crypto documentation - - - - - + + + + + @@ -40,11 +39,10 @@ See LICENCE for the license information. """ -from __future__ import absolute_import +from __future__ import absolute_import -from M2Crypto import m2, py27plus, six -if py27plus: - from typing import AnyStr, Tuple # noqa +from M2Crypto import m2, six +from typing import AnyStr, Tuple # noqa __all__ = ['rand_seed', 'rand_add', 'load_file', 'save_file', 'rand_bytes', @@ -212,17 +210,15 @@
- + @@ -239,7 +235,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/SMIME.html b/doc/html/_modules/M2Crypto/SMIME.html index dbd0bb3..967e491 100644 --- a/doc/html/_modules/M2Crypto/SMIME.html +++ b/doc/html/_modules/M2Crypto/SMIME.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.SMIME — M2Crypto documentation - - - - - + + + + + @@ -33,15 +32,14 @@

Source code for M2Crypto.SMIME

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """M2Crypto wrapper for OpenSSL S/MIME API.
 
 Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved."""
 
-from M2Crypto import BIO, EVP, Err, X509, m2, util
-if util.py27plus:
-    from typing import AnyStr, Callable, Optional  # noqa
+from M2Crypto import BIO, EVP, Err, X509, m2, util
+from typing import AnyStr, Callable, Optional  # noqa
 
 PKCS7_TEXT = m2.PKCS7_TEXT  # type: int
 PKCS7_NOCERTS = m2.PKCS7_NOCERTS  # type: int
@@ -62,6 +60,7 @@
 
[docs]class PKCS7_Error(Exception): pass
+ m2.pkcs7_init(PKCS7_Error) @@ -69,7 +68,7 @@ m2_pkcs7_free = m2.pkcs7_free - def __init__(self, pkcs7=None, _pyfree=0): + def __init__(self, pkcs7=None, _pyfree=0): # type: (Optional[bytes], int) -> None """PKCS7 object. @@ -83,7 +82,7 @@ self.pkcs7 = m2.pkcs7_new() self._pyfree = 1 - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_pkcs7_free(self.pkcs7) @@ -171,7 +170,7 @@ M2Crypto.EVP.Cipher. """ - def __init__(self, algo): + def __init__(self, algo): # type: (str) -> None cipher = getattr(m2, algo, None) if cipher is None: @@ -356,17 +355,15 @@
- + @@ -383,7 +380,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/SSL.html b/doc/html/_modules/M2Crypto/SSL.html index ff0aa7a..f081292 100644 --- a/doc/html/_modules/M2Crypto/SSL.html +++ b/doc/html/_modules/M2Crypto/SSL.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.SSL — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.SSL

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """M2Crypto SSL services.
 
@@ -42,7 +41,7 @@
 import socket, os
 
 # M2Crypto
-from M2Crypto import _m2crypto as m2
+from M2Crypto import _m2crypto as m2
 
 
 
[docs]class SSLError(Exception): @@ -55,25 +54,28 @@ m2.ssl_init(SSLError, SSLTimeoutError) # M2Crypto.SSL -from M2Crypto.SSL.Cipher import Cipher, Cipher_Stack -from M2Crypto.SSL.Connection import Connection -from M2Crypto.SSL.Context import Context -from M2Crypto.SSL.SSLServer import SSLServer, ThreadingSSLServer +from M2Crypto.SSL.Cipher import Cipher, Cipher_Stack +from M2Crypto.SSL.Connection import Connection +from M2Crypto.SSL.Context import Context +from M2Crypto.SSL.SSLServer import SSLServer, ThreadingSSLServer if os.name != 'nt': - from M2Crypto.SSL.SSLServer import ForkingSSLServer -from M2Crypto.SSL.ssl_dispatcher import ssl_dispatcher -from M2Crypto.SSL.timeout import timeout, struct_to_timeout, struct_size + from M2Crypto.SSL.SSLServer import ForkingSSLServer +from M2Crypto.SSL.ssl_dispatcher import ssl_dispatcher +from M2Crypto.SSL.timeout import timeout, struct_to_timeout, struct_size verify_none = m2.SSL_VERIFY_NONE # type: int verify_peer = m2.SSL_VERIFY_PEER # type: int verify_fail_if_no_peer_cert = m2.SSL_VERIFY_FAIL_IF_NO_PEER_CERT # type: int verify_client_once = m2.SSL_VERIFY_CLIENT_ONCE # type: int +verify_crl_check_chain = m2.VERIFY_CRL_CHECK_CHAIN # type: int +verify_crl_check_leaf = m2.VERIFY_CRL_CHECK_LEAF # type: int SSL_SENT_SHUTDOWN = m2.SSL_SENT_SHUTDOWN # type: int SSL_RECEIVED_SHUTDOWN = m2.SSL_RECEIVED_SHUTDOWN # type: int op_all = m2.SSL_OP_ALL # type: int op_no_sslv2 = m2.SSL_OP_NO_SSLv2 # type: int +
@@ -106,17 +108,15 @@
- + @@ -133,7 +133,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/SSL/Checker.html b/doc/html/_modules/M2Crypto/SSL/Checker.html index dc1aea8..1bce837 100644 --- a/doc/html/_modules/M2Crypto/SSL/Checker.html +++ b/doc/html/_modules/M2Crypto/SSL/Checker.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.SSL.Checker — M2Crypto documentation - - - - - + + + + + @@ -48,9 +47,8 @@ import re import socket -from M2Crypto import X509, m2, six, util # noqa -if util.py27plus: - from typing import AnyStr, Optional # noqa +from M2Crypto import X509, m2, six # noqa +from typing import AnyStr, Optional # noqa
[docs]class SSLVerificationError(Exception): @@ -66,7 +64,7 @@
[docs]class WrongHost(SSLVerificationError): - def __init__(self, expectedHost, actualHost, fieldName='commonName'): + def __init__(self, expectedHost, actualHost, fieldName='commonName'): # type: (str, AnyStr, str) -> None """ This exception will be raised if the certificate returned by the @@ -90,7 +88,7 @@ self.actualHost = actualHost self.fieldName = fieldName - def __str__(self): + def __str__(self): # type: () -> str s = 'Peer certificate %s does not match host, expected %s, got %s' \ % (self.fieldName, self.expectedHost, self.actualHost) @@ -101,7 +99,7 @@ numericIpMatch = re.compile('^[0-9]+(\.[0-9]+)*$') - def __init__(self, host=None, peerCertHash=None, peerCertDigest='sha1'): + def __init__(self, host=None, peerCertHash=None, peerCertDigest='sha1'): # type: (Optional[str], Optional[bytes], str) -> None self.host = host if peerCertHash is not None: @@ -109,7 +107,7 @@ self.fingerprint = peerCertHash self.digest = peerCertDigest # type: str - def __call__(self, peerCert, host=None): + def __call__(self, peerCert, host=None): # type: (X509.X509, Optional[str]) -> bool if peerCert is None: raise NoCertificate('peer did not return certificate') @@ -364,17 +362,15 @@
- + @@ -391,7 +387,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/SSL/Cipher.html b/doc/html/_modules/M2Crypto/SSL/Cipher.html index 5206169..9154ebc 100644 --- a/doc/html/_modules/M2Crypto/SSL/Cipher.html +++ b/doc/html/_modules/M2Crypto/SSL/Cipher.html @@ -118,6 +118,8 @@ diff --git a/doc/html/_modules/M2Crypto/SSL/Context.html b/doc/html/_modules/M2Crypto/SSL/Context.html index 21ccdc7..4f7dd23 100644 --- a/doc/html/_modules/M2Crypto/SSL/Context.html +++ b/doc/html/_modules/M2Crypto/SSL/Context.html @@ -504,6 +504,8 @@ diff --git a/doc/html/_modules/M2Crypto/SSL/SSLServer.html b/doc/html/_modules/M2Crypto/SSL/SSLServer.html index 3abb777..ac3f6a8 100644 --- a/doc/html/_modules/M2Crypto/SSL/SSLServer.html +++ b/doc/html/_modules/M2Crypto/SSL/SSLServer.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.SSL.SSLServer — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.SSL.SSLServer

-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function
 
 """SSLServer
 
@@ -41,27 +40,26 @@
 
 
 # M2Crypto
-from M2Crypto.SSL import SSLError
-from M2Crypto.SSL.Connection import Connection
-from M2Crypto.SSL.Context import Context  # noqa
-from M2Crypto import six  # noqa
-from M2Crypto import util  # noqa
-from M2Crypto.six.moves.socketserver import (BaseServer, TCPServer,
-                                             ThreadingMixIn)
+from M2Crypto.SSL import SSLError
+from M2Crypto.SSL.Connection import Connection
+from M2Crypto.SSL.Context import Context  # noqa
+# from M2Crypto import six  # noqa
+from M2Crypto import util  # noqa
+from M2Crypto.six.moves.socketserver import (BaseRequestHandler, BaseServer,
+                                             TCPServer, ThreadingMixIn)
 import os
 if os.name != 'nt':
-   from M2Crypto.six.moves.socketserver import ForkingMixIn
-from socket import socket  # noqa
-if util.py27plus:
-    from typing import Union  # noqa
+    from M2Crypto.six.moves.socketserver import ForkingMixIn
+from socket import socket  # noqa
+from typing import Union  # noqa
 
 __all__ = ['SSLServer', 'ForkingSSLServer', 'ThreadingSSLServer']
 
 
 
[docs]class SSLServer(TCPServer): - def __init__(self, server_address, RequestHandlerClass, ssl_context, # noqa + def __init__(self, server_address, RequestHandlerClass, ssl_context, # noqa bind_and_activate=True): - # type: (util.AddrType, socketserver.BaseRequestHandler, Context, bool) -> None + # type: (util.AddrType, BaseRequestHandler, Context, bool) -> None """ Superclass says: Constructor. May be extended, do not override. This class says: Ho-hum. @@ -133,17 +131,15 @@
- + @@ -160,7 +156,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/SSL/Session.html b/doc/html/_modules/M2Crypto/SSL/Session.html index d0c4435..b0c7bb8 100644 --- a/doc/html/_modules/M2Crypto/SSL/Session.html +++ b/doc/html/_modules/M2Crypto/SSL/Session.html @@ -128,6 +128,8 @@ diff --git a/doc/html/_modules/M2Crypto/SSL/TwistedProtocolWrapper.html b/doc/html/_modules/M2Crypto/SSL/TwistedProtocolWrapper.html index 88c32e0..b3357c1 100644 --- a/doc/html/_modules/M2Crypto/SSL/TwistedProtocolWrapper.html +++ b/doc/html/_modules/M2Crypto/SSL/TwistedProtocolWrapper.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.SSL.TwistedProtocolWrapper — M2Crypto documentation - - - - - + + + + + @@ -49,19 +48,18 @@ import logging -from functools import partial +from functools import partial import twisted.internet.reactor import twisted.protocols.policies as policies -from M2Crypto import BIO, X509, m2, util -from M2Crypto.SSL.Checker import Checker, SSLVerificationError +from M2Crypto import BIO, X509, m2, util +from M2Crypto.SSL.Checker import Checker, SSLVerificationError -from twisted.internet.interfaces import ITLSTransport -from twisted.protocols.policies import ProtocolWrapper -if util.py27plus: - from typing import AnyStr, Callable, Iterable, Optional # noqa - from zope.interface import implementer +from twisted.internet.interfaces import ITLSTransport +from twisted.protocols.policies import ProtocolWrapper +from typing import AnyStr, Callable, Iterable, Optional # noqa +from zope.interface import implementer log = logging.getLogger(__name__) @@ -161,13 +159,13 @@ m2_bio_free_all = m2.bio_free_all - def __init__(self, bio): + def __init__(self, bio): self.bio = bio def _ptr(self): return self.bio - def __del__(self): + def __del__(self): if self.bio is not None: self.m2_bio_free_all(self.bio) @@ -180,13 +178,13 @@ m2_ssl_free = m2.ssl_free - def __init__(self, ssl): + def __init__(self, ssl): self.ssl = ssl def _ptr(self): return self.ssl - def __del__(self): + def __del__(self): if self.ssl is not None: self.m2_ssl_free(self.ssl) @@ -200,7 +198,7 @@ which will hook in this class. """ - def __init__(self, factory, wrappedProtocol, startPassThrough, client, + def __init__(self, factory, wrappedProtocol, startPassThrough, client, contextFactory, postConnectionCheck): # type: (policies.WrappingFactory, object, int, int, object, Checker) -> None """ @@ -558,17 +556,15 @@
- + @@ -585,7 +581,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/SSL/cb.html b/doc/html/_modules/M2Crypto/SSL/cb.html index 1eaa457..55487aa 100644 --- a/doc/html/_modules/M2Crypto/SSL/cb.html +++ b/doc/html/_modules/M2Crypto/SSL/cb.html @@ -155,6 +155,8 @@ diff --git a/doc/html/_modules/M2Crypto/SSL/ssl_dispatcher.html b/doc/html/_modules/M2Crypto/SSL/ssl_dispatcher.html index a6b964d..4c660d8 100644 --- a/doc/html/_modules/M2Crypto/SSL/ssl_dispatcher.html +++ b/doc/html/_modules/M2Crypto/SSL/ssl_dispatcher.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.SSL.ssl_dispatcher — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.SSL.ssl_dispatcher

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """SSL dispatcher
 
@@ -44,9 +43,9 @@
 import socket
 
 # M2Crypto
-from M2Crypto import util  # noqa
-from M2Crypto.SSL.Connection import Connection
-from M2Crypto.SSL.Context import Context  # noqa
+from M2Crypto import util  # noqa
+from M2Crypto.SSL.Connection import Connection
+from M2Crypto.SSL.Context import Context  # noqa
 
 __all__ = ['ssl_dispatcher']
 
@@ -110,17 +109,15 @@
 
 
- + @@ -137,7 +134,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/SSL/timeout.html b/doc/html/_modules/M2Crypto/SSL/timeout.html index d7fb07f..83fcd75 100644 --- a/doc/html/_modules/M2Crypto/SSL/timeout.html +++ b/doc/html/_modules/M2Crypto/SSL/timeout.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.SSL.timeout — M2Crypto documentation - - - - - + + + + + @@ -50,7 +49,7 @@
[docs]class timeout(object): - def __init__(self, sec=DEFAULT_TIMEOUT, microsec=0): + def __init__(self, sec=DEFAULT_TIMEOUT, microsec=0): # type: (int, int) -> None self.sec = sec self.microsec = microsec @@ -117,17 +116,15 @@
- + @@ -144,7 +141,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/X509.html b/doc/html/_modules/M2Crypto/X509.html index b546394..31b71c9 100644 --- a/doc/html/_modules/M2Crypto/X509.html +++ b/doc/html/_modules/M2Crypto/X509.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.X509 — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.X509

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """M2Crypto wrapper for OpenSSL X509 API.
 
@@ -47,19 +46,39 @@
 import binascii
 import logging
 
-from M2Crypto import ASN1, BIO, EVP, m2, py27plus, six  # noqa
-if py27plus:
-    from typing import AnyStr, Optional  # noqa
+from M2Crypto import ASN1, BIO, EVP, m2, six  # noqa
+from typing import AnyStr, List, Optional  # noqa
 
 FORMAT_DER = 0
 FORMAT_PEM = 1
 
+verify_allow_proxy_certs = m2.VERIFY_ALLOW_PROXY_CERTS
+verify_cb_issuer_check = m2.VERIFY_CB_ISSUER_CHECK
+verify_check_ss_signature = m2.VERIFY_CHECK_SS_SIGNATURE
+verify_crl_check = m2.VERIFY_CRL_CHECK
+verify_crl_check_all = m2.VERIFY_CRL_CHECK_ALL
+verify_explicit_policy = m2.VERIFY_EXPLICIT_POLICY
+verify_extended_crl_support = m2.VERIFY_EXTENDED_CRL_SUPPORT
+verify_ignore_critical = m2.VERIFY_IGNORE_CRITICAL
+verify_inhibit_any = m2.VERIFY_INHIBIT_ANY
+verify_inhibit_map = m2.VERIFY_INHIBIT_MAP
+verify_no_alt_chains = m2.VERIFY_NO_ALT_CHAINS
+if hasattr(m2, "VERIFY_NO_CHECK_TIME"):
+    verify_no_check_time = m2.VERIFY_NO_CHECK_TIME
+verify_notify_policy = m2.VERIFY_NOTIFY_POLICY
+verify_partial_chain = m2.VERIFY_PARTIAL_CHAIN
+verify_policy_check = m2.VERIFY_POLICY_CHECK
+verify_trusted_first = m2.VERIFY_TRUSTED_FIRST
+verify_use_deltas = m2.VERIFY_USE_DELTAS
+verify_x509_strict = m2.VERIFY_X509_STRICT
+
 log = logging.getLogger(__name__)
 
 
 
[docs]class X509Error(ValueError): pass
+ m2.x509_init(X509Error) V_OK = m2.X509_V_OK # type: int @@ -76,7 +95,7 @@ Create new X509_Extension instance. """ if name == 'subjectKeyIdentifier' and \ - value.strip('0123456789abcdefABCDEF:') is not '': + value.strip('0123456789abcdefABCDEF:') != '': raise ValueError('value must be precomputed hash') ctx = m2.x509v3_set_nconf() x509_ext_ptr = m2.x509v3_ext_conf(None, ctx, name, value) @@ -96,12 +115,12 @@ m2_x509_extension_free = m2.x509_extension_free - def __init__(self, x509_ext_ptr=None, _pyfree=1): + def __init__(self, x509_ext_ptr=None, _pyfree=1): # type: (Optional[bytes], int) -> None self.x509_ext = x509_ext_ptr self._pyfree = _pyfree - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0) and self.x509_ext: self.m2_x509_extension_free(self.x509_ext) @@ -166,7 +185,7 @@ m2_sk_x509_extension_free = m2.sk_x509_extension_free - def __init__(self, stack=None, _pyfree=0): + def __init__(self, stack=None, _pyfree=0): # type: (Optional[bytes], int) -> None if stack is not None: self.stack = stack @@ -181,22 +200,22 @@ self._pyfree = 1 self.pystack = [] # This must be kept in sync with self.stack - def __del__(self): + def __del__(self): # type: () -> None # see BIO.py - unbalanced __init__ / __del__ if getattr(self, '_pyfree', 0): self.m2_sk_x509_extension_free(self.stack) - def __len__(self): + def __len__(self): # type: () -> int assert m2.sk_x509_extension_num(self.stack) == len(self.pystack) return len(self.pystack) - def __getitem__(self, idx): + def __getitem__(self, idx): # type: (int) -> X509_Extension return self.pystack[idx] - def __iter__(self): + def __iter__(self): return iter(self.pystack) def _ptr(self): @@ -237,7 +256,7 @@ m2_x509_name_entry_free = m2.x509_name_entry_free - def __init__(self, x509_name_entry, _pyfree=0): + def __init__(self, x509_name_entry, _pyfree=0): # type: (bytes, int) -> None """ :param x509_name_entry: this should be OpenSSL X509_NAME_ENTRY binary @@ -246,7 +265,7 @@ self.x509_name_entry = x509_name_entry self._pyfree = _pyfree - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_x509_name_entry_free(self.x509_name_entry) @@ -319,7 +338,7 @@ m2_x509_name_free = m2.x509_name_free - def __init__(self, x509_name=None, _pyfree=0): + def __init__(self, x509_name=None, _pyfree=0): # type: (bytes, int) -> None """ :param x509_name: this should be OpenSSL X509_NAME binary @@ -333,18 +352,18 @@ self.x509_name = m2.x509_name_new() self._pyfree = 1 - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_x509_name_free(self.x509_name) - def __str__(self): + def __str__(self): # type: () -> bytes assert m2.x509_name_type_check(self.x509_name), \ "'x509_name' type error" return m2.x509_name_oneline(self.x509_name) - def __getattr__(self, attr): + def __getattr__(self, attr): # type: (str) -> str if attr in self.nid: assert m2.x509_name_type_check(self.x509_name), \ @@ -356,7 +375,7 @@ raise AttributeError(self, attr) - def __setattr__(self, attr, value): + def __setattr__(self, attr, value): # type: (str, AnyStr) -> int """ :return: 1 for success of 0 if an error occurred. @@ -369,17 +388,17 @@ self.__dict__[attr] = value - def __len__(self): + def __len__(self): # type: () -> int return m2.x509_name_entry_count(self.x509_name) - def __getitem__(self, idx): + def __getitem__(self, idx): # type: (int) -> X509_Name_Entry if not 0 <= idx < self.entry_count(): raise IndexError("index out of range") return X509_Name_Entry(m2.x509_name_get_entry(self.x509_name, idx)) - def __iter__(self): + def __iter__(self): for i in range(self.entry_count()): yield self[i] @@ -482,7 +501,7 @@ m2_x509_free = m2.x509_free - def __init__(self, x509=None, _pyfree=0): + def __init__(self, x509=None, _pyfree=0): # type: (Optional[bytes], int) -> None """ :param x509: binary representation of @@ -497,7 +516,7 @@ self.x509 = m2.x509_new() self._pyfree = 1 - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_x509_free(self.x509) @@ -908,7 +927,7 @@ m2_x509_store_ctx_free = m2.x509_store_ctx_free - def __init__(self, x509_store_ctx, _pyfree=0): + def __init__(self, x509_store_ctx, _pyfree=0): # type: (bytes, int) -> None """ @@ -918,7 +937,7 @@ self.ctx = x509_store_ctx self._pyfree = _pyfree - def __del__(self): + def __del__(self): # type: () -> None # see BIO.py - unbalanced __init__ / __del__ if not hasattr(self, '_pyfree'): @@ -972,7 +991,7 @@ m2_x509_store_free = m2.x509_store_free - def __init__(self, store=None, _pyfree=0): + def __init__(self, store=None, _pyfree=0): # type: (Optional[bytes], int) -> None """ :param store: binary data for OpenSSL X509_STORE_CTX type. @@ -984,7 +1003,7 @@ self.store = m2.x509_store_new() self._pyfree = 1 - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_x509_store_free(self.store) @@ -1036,7 +1055,22 @@ raise X509Error("set_verify(): callback is not callable") return m2.x509_store_set_verify_cb(self.store, callback)
- add_cert = add_x509
+ add_cert = add_x509 + +
[docs] def set_flags(self, flags): + # type: (int) -> int + """ + Set the verification flags for the X509Store + Wrapper over OpenSSL X509_STORE_set_flags() + + :param flags: `VERIFICATION FLAGS` section of the + X509_VERIFY_PARAM_set_flags man page has + a complete description of values the flags + parameter can take. + Their M2Crypto equivalent is transformed following + the pattern: "X509_V_FLAG_XYZ" -> lowercase("VERIFY_XYZ") + """ + return m2.x509_store_set_flags(self.store, flags)
[docs]class X509_Stack(object): @@ -1053,7 +1087,7 @@ m2_sk_x509_free = m2.sk_x509_free - def __init__(self, stack=None, _pyfree=0, _pyfree_x509=0): + def __init__(self, stack=None, _pyfree=0, _pyfree_x509=0): # type: (bytes, int, int) -> None if stack is not None: self.stack = stack @@ -1068,21 +1102,21 @@ self._pyfree = 1 self.pystack = [] # This must be kept in sync with self.stack - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_sk_x509_free(self.stack) - def __len__(self): + def __len__(self): # type: () -> int assert m2.sk_x509_num(self.stack) == len(self.pystack) return len(self.pystack) - def __getitem__(self, idx): + def __getitem__(self, idx): # type: (int) -> X509 return self.pystack[idx] - def __iter__(self): + def __iter__(self): return iter(self.pystack) def _ptr(self): @@ -1144,7 +1178,7 @@ m2_x509_req_free = m2.x509_req_free - def __init__(self, req=None, _pyfree=0): + def __init__(self, req=None, _pyfree=0): # type: (Optional[int], int) -> None if req is not None: self.req = req @@ -1154,7 +1188,7 @@ m2.x509_req_set_version(self.req, 0) self._pyfree = 1 - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_x509_req_free(self.req) @@ -1380,7 +1414,7 @@ m2_x509_crl_free = m2.x509_crl_free - def __init__(self, crl=None, _pyfree=0): + def __init__(self, crl=None, _pyfree=0): # type: (Optional[bytes], int) -> None """ @@ -1394,7 +1428,7 @@ self.crl = m2.x509_crl_new() self._pyfree = 1 - def __del__(self): + def __del__(self): # type: () -> None if getattr(self, '_pyfree', 0): self.m2_x509_crl_free(self.crl) @@ -1456,17 +1490,15 @@
- + @@ -1483,7 +1515,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/ftpslib.html b/doc/html/_modules/M2Crypto/ftpslib.html index b0db673..426695b 100644 --- a/doc/html/_modules/M2Crypto/ftpslib.html +++ b/doc/html/_modules/M2Crypto/ftpslib.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.ftpslib — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.ftpslib

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """M2Crypto client-side FTP/TLS.
 
@@ -70,17 +69,17 @@
 
 # We want to import whole stdlib ftplib objects, because our users want
 # to use them.
-from ftplib import *  # noqa
+from ftplib import *  # noqa
 
 # M2Crypto
-from M2Crypto import SSL
+from M2Crypto import SSL
 
 
 
[docs]class FTP_TLS(FTP): """Python OO interface to client-side FTP/TLS.""" - def __init__(self, host=None, ssl_ctx=None): + def __init__(self, host=None, ssl_ctx=None): """Initialise the client. If 'host' is supplied, connect to it.""" if ssl_ctx is not None: self.ssl_ctx = ssl_ctx @@ -156,17 +155,15 @@
- + @@ -183,7 +180,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/httpslib.html b/doc/html/_modules/M2Crypto/httpslib.html index 93c1cc5..c6437cb 100644 --- a/doc/html/_modules/M2Crypto/httpslib.html +++ b/doc/html/_modules/M2Crypto/httpslib.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.httpslib — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.httpslib

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 import warnings
 
@@ -44,13 +43,12 @@
 import base64
 import socket
 
-from M2Crypto import SSL, py27plus, six
-from M2Crypto.six.moves.urllib_parse import urlsplit, urlunsplit
-from M2Crypto.six.moves.http_client import *  # noqa
+from M2Crypto import SSL, six
+from M2Crypto.six.moves.urllib_parse import urlsplit, urlunsplit
+from M2Crypto.six.moves.http_client import *  # noqa
 # This is not imported with just '*'
-from M2Crypto.six.moves.http_client import HTTPS_PORT
-if py27plus:
-    from typing import Any, AnyStr, Callable, Dict, List, Optional  # noqa
+from M2Crypto.six.moves.http_client import HTTPS_PORT
+from typing import Any, AnyStr, Callable, Dict, Optional  # noqa
 
 
 
[docs]class HTTPSConnection(HTTPConnection): @@ -61,7 +59,7 @@ default_port = HTTPS_PORT - def __init__(self, host, port=None, strict=None, **ssl): + def __init__(self, host, port=None, strict=None, **ssl): # type: (str, Optional[int], Optional[bool], **Any) -> None """ Represents one transaction with an HTTP server over the SSL @@ -168,7 +166,7 @@ _AUTH_HEADER = "Proxy-Authorization" _UA_HEADER = "User-Agent" - def __init__(self, host, port=None, strict=None, username=None, + def __init__(self, host, port=None, strict=None, username=None, password=None, **ssl): # type: (str, Optional[int], Optional[bool], Optional[AnyStr], Optional[AnyStr], **Any) -> None """ @@ -334,17 +332,15 @@
- + @@ -361,7 +357,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/m2urllib.html b/doc/html/_modules/M2Crypto/m2urllib.html index bb1f8cb..3ddad86 100644 --- a/doc/html/_modules/M2Crypto/m2urllib.html +++ b/doc/html/_modules/M2Crypto/m2urllib.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.m2urllib — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.m2urllib

-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function
 
 """M2Crypto enhancement to Python's urllib for handling
 'https' url's.
@@ -46,19 +45,18 @@
 import base64
 import warnings
 
-from M2Crypto import SSL, httpslib, six, util
+from M2Crypto import SSL, httpslib, six
 
-from M2Crypto.six.moves.urllib_response import addinfourl
-if util.py27plus:
-    from typing import AnyStr, Optional  # noqa
+from M2Crypto.six.moves.urllib_response import addinfourl
+from typing import AnyStr, Optional  # noqa
 
 # six.moves doesn't support star imports
 if six.PY3:
-    from urllib.request import *  # noqa for other modules to import
-    from urllib.parse import *  # noqa for other modules to import
-    from urllib.error import *  # noqa for other modules to import
+    from urllib.request import *  # noqa for other modules to import
+    from urllib.parse import *  # noqa for other modules to import
+    from urllib.error import *  # noqa for other modules to import
 else:
-    from urllib import *  # noqa
+    from urllib import *  # noqa
 
 
 
[docs]def open_https(self, url, data=None, ssl_context=None): @@ -186,17 +184,15 @@
- + @@ -213,7 +209,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/m2urllib2.html b/doc/html/_modules/M2Crypto/m2urllib2.html index 23bf5f2..deaace3 100644 --- a/doc/html/_modules/M2Crypto/m2urllib2.html +++ b/doc/html/_modules/M2Crypto/m2urllib2.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.m2urllib2 — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.m2urllib2

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """
 M2Crypto enhancement to Python's urllib2 for handling
@@ -50,19 +49,18 @@
 
 import socket
 
-from M2Crypto import SSL, httpslib, six, util
+from M2Crypto import SSL, httpslib, six
 
-from M2Crypto.six.moves.urllib_parse import urldefrag, urlparse as url_parse
-from M2Crypto.six.moves.urllib_response import addinfourl
-if util.py27plus:
-    from typing import List, Optional  # noqa
+from M2Crypto.six.moves.urllib_parse import urldefrag, urlparse as url_parse
+from M2Crypto.six.moves.urllib_response import addinfourl
+from typing import Optional  # noqa
 
 # six.moves doesn't support star imports
 if six.PY3:
-    from urllib.request import *  # noqa other modules want to import
-    from urllib.error import *  # noqa other modules want to import
+    from urllib.request import *  # noqa other modules want to import
+    from urllib.error import *  # noqa other modules want to import
 else:
-    from urllib2 import *  # noqa
+    from urllib2 import *  # noqa
 
 
 try:
@@ -87,7 +85,7 @@
 
 
 
[docs]class HTTPSHandler(AbstractHTTPHandler): - def __init__(self, ssl_context=None): + def __init__(self, ssl_context=None): # type: (SSL.Context) -> None AbstractHTTPHandler.__init__(self) @@ -251,17 +249,15 @@
- + @@ -278,7 +274,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/m2xmlrpclib.html b/doc/html/_modules/M2Crypto/m2xmlrpclib.html index fb3834f..2ef4060 100644 --- a/doc/html/_modules/M2Crypto/m2xmlrpclib.html +++ b/doc/html/_modules/M2Crypto/m2xmlrpclib.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.m2xmlrpclib — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.m2xmlrpclib

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """M2Crypto enhancement to xmlrpclib.
 
@@ -43,16 +42,15 @@
 
 import M2Crypto
 
-from M2Crypto import SSL, httpslib, m2urllib, six, util
-if util.py27plus:
-    from typing import Any, AnyStr, Callable, Optional  # noqa
+from M2Crypto import SSL, httpslib, m2urllib, six
+from typing import Any, AnyStr, Callable, Optional  # noqa
 
-from M2Crypto.six.moves.xmlrpc_client import ProtocolError, Transport
+from M2Crypto.six.moves.xmlrpc_client import ProtocolError, Transport
 # six.moves doesn't support star imports
 if six.PY3:
-    from xmlrpc.client import *  # noqa
+    from xmlrpc.client import *  # noqa
 else:
-    from xmlrpclib import *  # noqa
+    from xmlrpclib import *  # noqa
 
 __version__ = M2Crypto.__version__
 
@@ -62,7 +60,7 @@
     user_agent = "M2Crypto_XMLRPC/%s - %s" % (__version__,
                                               Transport.user_agent)
 
-    def __init__(self, ssl_context=None, *args, **kw):
+    def __init__(self, ssl_context=None, *args, **kw):
         # type: (Optional[SSL.Context], *Any, **Any) -> None
         Transport.__init__(self, *args, **kw)
         if ssl_context is None:
@@ -101,17 +99,17 @@
         if request_body:
             h.send(request_body)
 
-        errcode, errmsg, headers = h.getreply()
+        response = h.getresponse()
 
-        if errcode != 200:
+        if response.status != 200:
             raise ProtocolError(
                 host + handler,
-                errcode, errmsg,
-                headers
+                response.status, response.reason,
+                response.getheaders()
             )
 
         self.verbose = verbose
-        return self.parse_response(h.getfile())
+ return self.parse_response(response)
@@ -144,17 +142,15 @@
- + @@ -171,7 +167,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/threading.html b/doc/html/_modules/M2Crypto/threading.html index 7074d6c..5069ea6 100644 --- a/doc/html/_modules/M2Crypto/threading.html +++ b/doc/html/_modules/M2Crypto/threading.html @@ -1,19 +1,18 @@ - + - + - - + + M2Crypto.threading — M2Crypto documentation - - - - - + + + + + @@ -33,7 +32,7 @@

Source code for M2Crypto.threading

-from __future__ import absolute_import
+from __future__ import absolute_import
 
 """
 M2Crypto threading support, required for multithreaded applications.
@@ -41,7 +40,7 @@
 Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved."""
 
 # M2Crypto
-from M2Crypto import m2
+from M2Crypto import m2
 
 
 
[docs]def init(): @@ -90,17 +89,15 @@
- + @@ -117,7 +114,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/_modules/M2Crypto/util.html b/doc/html/_modules/M2Crypto/util.html index c92cf20..134f261 100644 --- a/doc/html/_modules/M2Crypto/util.html +++ b/doc/html/_modules/M2Crypto/util.html @@ -46,12 +46,11 @@ """ import binascii -import io import logging import sys from M2Crypto import m2, six -from typing import Any, Optional, Tuple, Union # noqa +from typing import Any, Optional, TextIO, Tuple, Union # noqa # see https://github.com/python/typeshed/issues/222 AddrType = Union[Tuple[str, int], str] @@ -90,7 +89,7 @@
[docs]def genparam_callback(p, n, out=sys.stdout): - # type: (int, Any, io.IOBase) -> None + # type: (int, Any, TextIO) -> None ch = ['.', '+', '*', '\n'] out.write(ch[p]) out.flush()
diff --git a/doc/html/_modules/index.html b/doc/html/_modules/index.html index f6b2fe8..a843a44 100644 --- a/doc/html/_modules/index.html +++ b/doc/html/_modules/index.html @@ -32,15 +32,41 @@ diff --git a/doc/html/_modules/urllib/request.html b/doc/html/_modules/urllib/request.html index ee22b9d..12c0509 100644 --- a/doc/html/_modules/urllib/request.html +++ b/doc/html/_modules/urllib/request.html @@ -1,19 +1,18 @@ - + - + - - + + urllib.request — M2Crypto documentation - - - - - + + + + + @@ -134,13 +133,13 @@ import warnings -from urllib.error import URLError, HTTPError, ContentTooShortError -from urllib.parse import ( +from urllib.error import URLError, HTTPError, ContentTooShortError +from urllib.parse import ( urlparse, urlsplit, urljoin, unwrap, quote, unquote, - splittype, splithost, splitport, splituser, splitpasswd, - splitattr, splitquery, splitvalue, splittag, to_bytes, + _splittype, _splithost, _splitport, _splituser, _splitpasswd, + _splitattr, _splitquery, _splitvalue, _splittag, _to_bytes, unquote_to_bytes, urlunparse) -from urllib.response import addinfourl, addclosehook +from urllib.response import addinfourl, addclosehook # check for SSL try: @@ -277,7 +276,7 @@ Returns a tuple containing the path to the newly created data file as well as the resulting HTTPMessage object. """ - url_type, path = splittype(url) + url_type, path = _splittype(url) with contextlib.closing(urlopen(url, data)) as fp: headers = fp.info() @@ -357,7 +356,7 @@ class Request: - def __init__(self, url, data=None, headers={}, + def __init__(self, url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None): self.full_url = url @@ -385,7 +384,7 @@ def full_url(self, url): # unwrap('<URL:type://host/path>') --> 'type://host/path' self._full_url = unwrap(url) - self._full_url, self.fragment = splittag(self._full_url) + self._full_url, self.fragment = _splittag(self._full_url) self._parse() @full_url.deleter @@ -413,10 +412,10 @@ self.data = None def _parse(self): - self.type, rest = splittype(self._full_url) + self.type, rest = _splittype(self._full_url) if self.type is None: raise ValueError("unknown url type: %r" % self.full_url) - self.host, self.selector = splithost(rest) + self.host, self.selector = _splithost(rest) if self.host: self.host = unquote(self.host) @@ -461,12 +460,11 @@ self.unredirected_hdrs.pop(header_name, None) def header_items(self): - hdrs = self.unredirected_hdrs.copy() - hdrs.update(self.headers) + hdrs = {**self.unredirected_hdrs, **self.headers} return list(hdrs.items()) class OpenerDirector: - def __init__(self): + def __init__(self): client_version = "Python-urllib/%s" % __version__ self.addheaders = [('User-agent', client_version)] # self.handlers is retained only for backward compatibility @@ -557,6 +555,7 @@ meth = getattr(processor, meth_name) req = meth(req) + sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method()) response = self._open(req, data) # post-process response @@ -653,7 +652,7 @@ # Only exists for backwards compatibility pass - def __lt__(self, other): + def __lt__(self, other): if not hasattr(other, "handler_order"): # Try to preserve the old behavior of having custom classes # inserted after default ones (works only for custom user @@ -803,7 +802,7 @@ According to RFC 3986, having an authority component means the URL must have two slashes after the scheme. """ - scheme, r_scheme = splittype(proxy) + scheme, r_scheme = _splittype(proxy) if not r_scheme.startswith("/"): # authority scheme = None @@ -818,9 +817,9 @@ if end == -1: end = None authority = r_scheme[2:end] - userinfo, hostport = splituser(authority) + userinfo, hostport = _splituser(authority) if userinfo is not None: - user, password = splitpasswd(userinfo) + user, password = _splitpasswd(userinfo) else: user = password = None return scheme, user, password, hostport @@ -829,12 +828,13 @@ # Proxies must be in front handler_order = 100 - def __init__(self, proxies=None): + def __init__(self, proxies=None): if proxies is None: proxies = getproxies() assert hasattr(proxies, 'keys'), "proxies must be a mapping" self.proxies = proxies for type, url in proxies.items(): + type = type.lower() setattr(self, '%s_open' % type, lambda r, proxy=url, type=type, meth=self.proxy_open: meth(r, proxy, type)) @@ -869,7 +869,7 @@ class HTTPPasswordMgr: - def __init__(self): + def __init__(self): self.passwd = {} def add_password(self, realm, uri, user, passwd): @@ -907,7 +907,7 @@ scheme = None authority = uri path = '/' - host, port = splitport(authority) + host, port = _splitport(authority) if default_port and port is None and scheme is not None: dport = {"http": 80, "https": 443, @@ -943,7 +943,7 @@ class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm): - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs): self.authenticated = {} super().__init__(*args, **kwargs) @@ -979,40 +979,71 @@ # allow for double- and single-quoted realm values # (single quotes are a violation of the RFC, but appear in the wild) - rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+' - 'realm=(["\']?)([^"\']*)\\2', re.I) + rx = re.compile('(?:^|,)' # start of the string or ',' + '[ \t]*' # optional whitespaces + '([^ \t]+)' # scheme like "Basic" + '[ \t]+' # mandatory whitespaces + # realm=xxx + # realm='xxx' + # realm="xxx" + 'realm=(["\']?)([^"\']*)\\2', + re.I) # XXX could pre-emptively send auth info already accepted (RFC 2617, # end of section 2, and section 1.2 immediately after "credentials" # production). - def __init__(self, password_mgr=None): + def __init__(self, password_mgr=None): if password_mgr is None: password_mgr = HTTPPasswordMgr() self.passwd = password_mgr self.add_password = self.passwd.add_password + def _parse_realm(self, header): + # parse WWW-Authenticate header: accept multiple challenges per header + found_challenge = False + for mo in AbstractBasicAuthHandler.rx.finditer(header): + scheme, quote, realm = mo.groups() + if quote not in ['"', "'"]: + warnings.warn("Basic Auth Realm was unquoted", + UserWarning, 3) + + yield (scheme, realm) + + found_challenge = True + + if not found_challenge: + if header: + scheme = header.split()[0] + else: + scheme = '' + yield (scheme, None) + def http_error_auth_reqed(self, authreq, host, req, headers): # host may be an authority (without userinfo) or a URL with an # authority - # XXX could be multiple headers - authreq = headers.get(authreq, None) + headers = headers.get_all(authreq) + if not headers: + # no header found + return - if authreq: - scheme = authreq.split()[0] - if scheme.lower() != 'basic': - raise ValueError("AbstractBasicAuthHandler does not" - " support the following scheme: '%s'" % - scheme) - else: - mo = AbstractBasicAuthHandler.rx.search(authreq) - if mo: - scheme, quote, realm = mo.groups() - if quote not in ['"',"'"]: - warnings.warn("Basic Auth Realm was unquoted", - UserWarning, 2) - if scheme.lower() == 'basic': - return self.retry_http_basic_auth(host, req, realm) + unsupported = None + for header in headers: + for scheme, realm in self._parse_realm(header): + if scheme.lower() != 'basic': + unsupported = scheme + continue + + if realm is not None: + # Use the first matching Basic challenge. + # Ignore following challenges even if they use the Basic + # scheme. + return self.retry_http_basic_auth(host, req, realm) + + if unsupported is not None: + raise ValueError("AbstractBasicAuthHandler does not " + "support the following scheme: %r" + % (scheme,)) def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) @@ -1093,7 +1124,7 @@ # XXX qop="auth-int" supports is shaky - def __init__(self, passwd=None): + def __init__(self, passwd=None): if passwd is None: passwd = HTTPPasswordMgr() self.passwd = passwd @@ -1178,7 +1209,11 @@ A2 = "%s:%s" % (req.get_method(), # XXX selector: what about proxies and full urls req.selector) - if qop == 'auth': + # NOTE: As per RFC 2617, when server sends "auth,auth-int", the client could use either `auth` + # or `auth-int` to the response back. we use `auth` to send the response back. + if qop is None: + respdig = KD(H(A1), "%s:%s" % (nonce, H(A2))) + elif 'auth' in qop.split(','): if nonce == self.last_nonce: self.nonce_count += 1 else: @@ -1186,10 +1221,8 @@ self.last_nonce = nonce ncvalue = '%08x' % self.nonce_count cnonce = self.get_cnonce(nonce) - noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, H(A2)) + noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, 'auth', H(A2)) respdig = KD(H(A1), noncebit) - elif qop is None: - respdig = KD(H(A1), "%s:%s" % (nonce, H(A2))) else: # XXX handle auth-int. raise URLError("qop '%s' is not supported." % qop) @@ -1258,7 +1291,7 @@ class AbstractHTTPHandler(BaseHandler): - def __init__(self, debuglevel=0): + def __init__(self, debuglevel=0): self._debuglevel = debuglevel def set_http_debuglevel(self, level): @@ -1296,8 +1329,8 @@ sel_host = host if request.has_proxy(): - scheme, sel = splittype(request.selector) - sel_host, sel_path = splithost(sel) + scheme, sel = _splittype(request.selector) + sel_host, sel_path = _splithost(sel) if not request.has_header('Host'): request.add_unredirected_header('Host', sel_host) for name, value in self.parent.addheaders: @@ -1385,7 +1418,7 @@ class HTTPSHandler(AbstractHTTPHandler): - def __init__(self, debuglevel=0, context=None, check_hostname=None): + def __init__(self, debuglevel=0, context=None, check_hostname=None): AbstractHTTPHandler.__init__(self, debuglevel) self._context = context self._check_hostname = check_hostname @@ -1399,7 +1432,7 @@ __all__.append('HTTPSHandler') class HTTPCookieProcessor(BaseHandler): - def __init__(self, cookiejar=None): + def __init__(self, cookiejar=None): import http.cookiejar if cookiejar is None: cookiejar = http.cookiejar.CookieJar() @@ -1513,7 +1546,7 @@ 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % (mtype or 'text/plain', size, modified)) if host: - host, port = splitport(host) + host, port = _splitport(host) if not host or \ (not port and _safe_gethostbyname(host) in self.get_names()): if host: @@ -1538,16 +1571,16 @@ host = req.host if not host: raise URLError('ftp error: no host given') - host, port = splitport(host) + host, port = _splitport(host) if port is None: port = ftplib.FTP_PORT else: port = int(port) # username/password handling - user, host = splituser(host) + user, host = _splituser(host) if user: - user, passwd = splitpasswd(user) + user, passwd = _splitpasswd(user) else: passwd = None host = unquote(host) @@ -1558,7 +1591,7 @@ host = socket.gethostbyname(host) except OSError as msg: raise URLError(msg) - path, attrs = splitattr(req.selector) + path, attrs = _splitattr(req.selector) dirs = path.split('/') dirs = list(map(unquote, dirs)) dirs, file = dirs[:-1], dirs[-1] @@ -1568,7 +1601,7 @@ fw = self.connect_ftp(user, passwd, host, port, dirs, req.timeout) type = file and 'I' or 'D' for attr in attrs: - attr, value = splitvalue(attr) + attr, value = _splitvalue(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() @@ -1592,7 +1625,7 @@ class CacheFTPHandler(FTPHandler): # XXX would be nice to have pluggable cache strategies # XXX this stuff is definitely not thread safe - def __init__(self): + def __init__(self): self.cache = {} self.timeout = {} self.soonest = 0 @@ -1679,7 +1712,7 @@ # Helper for non-unix systems if os.name == 'nt': - from nturl2path import url2pathname, pathname2url + from nturl2path import url2pathname, pathname2url else: def url2pathname(pathname): """OS-specific conversion from a relative URL of the 'file' scheme @@ -1708,7 +1741,7 @@ version = "Python-urllib/%s" % __version__ # Constructor - def __init__(self, proxies=None, **x509): + def __init__(self, proxies=None, **x509): msg = "%(class)s style of invoking requests is deprecated. " \ "Use newer urlopen functions/methods" % {'class': self.__class__.__name__} warnings.warn(msg, DeprecationWarning, stacklevel=3) @@ -1734,7 +1767,7 @@ # in case you want logically independent URL openers # XXX This is not threadsafe. Bah. - def __del__(self): + def __del__(self): self.close() def close(self): @@ -1762,26 +1795,26 @@ # External interface def open(self, fullurl, data=None): """Use URLopener().open(file) instead of open(file, 'r').""" - fullurl = unwrap(to_bytes(fullurl)) + fullurl = unwrap(_to_bytes(fullurl)) fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]|") if self.tempcache and fullurl in self.tempcache: filename, headers = self.tempcache[fullurl] fp = open(filename, 'rb') return addinfourl(fp, headers, fullurl) - urltype, url = splittype(fullurl) + urltype, url = _splittype(fullurl) if not urltype: urltype = 'file' if urltype in self.proxies: proxy = self.proxies[urltype] - urltype, proxyhost = splittype(proxy) - host, selector = splithost(proxyhost) + urltype, proxyhost = _splittype(proxy) + host, selector = _splithost(proxyhost) url = (host, fullurl) # Signal special case to open_*() else: proxy = None name = 'open_' + urltype self.type = urltype name = name.replace('-', '_') - if not hasattr(self, name): + if not hasattr(self, name) or name == 'open_local_file': if proxy: return self.open_unknown_proxy(proxy, fullurl, data) else: @@ -1798,28 +1831,28 @@ def open_unknown(self, fullurl, data=None): """Overridable interface to open unknown URL type.""" - type, url = splittype(fullurl) + type, url = _splittype(fullurl) raise OSError('url error', 'unknown url type', type) def open_unknown_proxy(self, proxy, fullurl, data=None): """Overridable interface to open unknown URL type.""" - type, url = splittype(fullurl) + type, url = _splittype(fullurl) raise OSError('url error', 'invalid proxy for %s' % type, proxy) # External interface def retrieve(self, url, filename=None, reporthook=None, data=None): """retrieve(url) returns (filename, headers) for a local object or (tempfilename, headers) for a remote object.""" - url = unwrap(to_bytes(url)) + url = unwrap(_to_bytes(url)) if self.tempcache and url in self.tempcache: return self.tempcache[url] - type, url1 = splittype(url) + type, url1 = _splittype(url) if filename is None and (not type or type == 'file'): try: fp = self.open_local_file(url1) hdrs = fp.info() fp.close() - return url2pathname(splithost(url1)[1]), hdrs + return url2pathname(_splithost(url1)[1]), hdrs except OSError as msg: pass fp = self.open(url, data) @@ -1828,10 +1861,10 @@ if filename: tfp = open(filename, 'wb') else: - garbage, path = splittype(url) - garbage, path = splithost(path or "") - path, garbage = splitquery(path or "") - path, garbage = splitattr(path or "") + garbage, path = _splittype(url) + garbage, path = _splithost(path or "") + path, garbage = _splitquery(path or "") + path, garbage = _splitattr(path or "") suffix = os.path.splitext(path)[1] (fd, filename) = tempfile.mkstemp(suffix) self.__tempfiles.append(filename) @@ -1888,25 +1921,25 @@ user_passwd = None proxy_passwd= None if isinstance(url, str): - host, selector = splithost(url) + host, selector = _splithost(url) if host: - user_passwd, host = splituser(host) + user_passwd, host = _splituser(host) host = unquote(host) realhost = host else: host, selector = url # check whether the proxy contains authorization information - proxy_passwd, host = splituser(host) + proxy_passwd, host = _splituser(host) # now we proceed with the url we want to obtain - urltype, rest = splittype(selector) + urltype, rest = _splittype(selector) url = rest user_passwd = None if urltype.lower() != 'http': realhost = None else: - realhost, rest = splithost(rest) + realhost, rest = _splithost(rest) if realhost: - user_passwd, realhost = splituser(realhost) + user_passwd, realhost = _splituser(realhost) if user_passwd: selector = "%s://%s%s" % (urltype, realhost, rest) if proxy_bypass(realhost): @@ -2012,7 +2045,7 @@ """Use local file.""" import email.utils import mimetypes - host, file = splithost(url) + host, file = _splithost(url) localname = url2pathname(file) try: stats = os.stat(localname) @@ -2029,7 +2062,7 @@ if file[:1] == '/': urlfile = 'file://' + file return addinfourl(open(localname, 'rb'), headers, urlfile) - host, port = splitport(host) + host, port = _splitport(host) if (not port and socket.gethostbyname(host) in ((localhost(),) + thishost())): urlfile = file @@ -2045,11 +2078,11 @@ if not isinstance(url, str): raise URLError('ftp error: proxy support for ftp protocol currently not implemented') import mimetypes - host, path = splithost(url) + host, path = _splithost(url) if not host: raise URLError('ftp error: no host given') - host, port = splitport(host) - user, host = splituser(host) - if user: user, passwd = splitpasswd(user) + host, port = _splitport(host) + user, host = _splituser(host) + if user: user, passwd = _splitpasswd(user) else: passwd = None host = unquote(host) user = unquote(user or '') @@ -2060,7 +2093,7 @@ port = ftplib.FTP_PORT else: port = int(port) - path, attrs = splitattr(path) + path, attrs = _splitattr(path) path = unquote(path) dirs = path.split('/') dirs, file = dirs[:-1], dirs[-1] @@ -2082,7 +2115,7 @@ if not file: type = 'D' else: type = 'I' for attr in attrs: - attr, value = splitvalue(attr) + attr, value = _splitvalue(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() @@ -2143,7 +2176,7 @@ class FancyURLopener(URLopener): """Derived class with handlers for errors we can handle (perhaps).""" - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs): URLopener.__init__(self, *args, **kwargs) self.auth_cache = {} self.tries = 0 @@ -2265,11 +2298,11 @@ return getattr(self,name)(url, realm, data) def retry_proxy_http_basic_auth(self, url, realm, data=None): - host, selector = splithost(url) + host, selector = _splithost(url) newurl = 'http://' + host + selector proxy = self.proxies['http'] - urltype, proxyhost = splittype(proxy) - proxyhost, proxyselector = splithost(proxyhost) + urltype, proxyhost = _splittype(proxy) + proxyhost, proxyselector = _splithost(proxyhost) i = proxyhost.find('@') + 1 proxyhost = proxyhost[i:] user, passwd = self.get_user_passwd(proxyhost, realm, i) @@ -2283,11 +2316,11 @@ return self.open(newurl, data) def retry_proxy_https_basic_auth(self, url, realm, data=None): - host, selector = splithost(url) + host, selector = _splithost(url) newurl = 'https://' + host + selector proxy = self.proxies['https'] - urltype, proxyhost = splittype(proxy) - proxyhost, proxyselector = splithost(proxyhost) + urltype, proxyhost = _splittype(proxy) + proxyhost, proxyselector = _splithost(proxyhost) i = proxyhost.find('@') + 1 proxyhost = proxyhost[i:] user, passwd = self.get_user_passwd(proxyhost, realm, i) @@ -2301,7 +2334,7 @@ return self.open(newurl, data) def retry_http_basic_auth(self, url, realm, data=None): - host, selector = splithost(url) + host, selector = _splithost(url) i = host.find('@') + 1 host = host[i:] user, passwd = self.get_user_passwd(host, realm, i) @@ -2315,7 +2348,7 @@ return self.open(newurl, data) def retry_https_basic_auth(self, url, realm, data=None): - host, selector = splithost(url) + host, selector = _splithost(url) i = host.find('@') + 1 host = host[i:] user, passwd = self.get_user_passwd(host, realm, i) @@ -2396,7 +2429,7 @@ class ftpwrapper: """Class used by open_ftp() for cache of open FTP connections.""" - def __init__(self, user, passwd, host, port, dirs, timeout=None, + def __init__(self, user, passwd, host, port, dirs, timeout=None, persistent=True): self.user = user self.passwd = passwd @@ -2532,24 +2565,26 @@ try: no_proxy = proxies['no'] except KeyError: - return 0 + return False # '*' is special case for always bypass if no_proxy == '*': - return 1 + return True + host = host.lower() # strip port off host - hostonly, port = splitport(host) + hostonly, port = _splitport(host) # check if the host ends with any of the DNS suffixes - no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')] - for name in no_proxy_list: + for name in no_proxy.split(','): + name = name.strip() if name: name = name.lstrip('.') # ignore leading dots - name = re.escape(name) - pattern = r'(.+\.)?%s$' % name - if (re.match(pattern, hostonly, re.I) - or re.match(pattern, host, re.I)): - return 1 + name = name.lower() + if hostonly == name or host == name: + return True + name = '.' + name + if hostonly.endswith(name) or host.endswith(name): + return True # otherwise, don't bypass - return 0 + return False # This code tests an OSX specific data structure but is testable on all @@ -2566,9 +2601,9 @@ 'exceptions': ['foo.bar', '*.bar.com', '127.0.0.1', '10.1', '10.0/16'] } """ - from fnmatch import fnmatch + from fnmatch import fnmatch - hostonly, port = splitport(host) + hostonly, port = _splitport(host) def ip2num(ipAddr): parts = ipAddr.split('.') @@ -2615,7 +2650,7 @@ if sys.platform == 'darwin': - from _scproxy import _get_proxy_settings, _get_proxies + from _scproxy import _get_proxy_settings, _get_proxies def proxy_bypass_macosx_sysconf(host): proxy_settings = _get_proxy_settings() @@ -2675,7 +2710,7 @@ for p in proxyServer.split(';'): protocol, address = p.split('=', 1) # See if address has a type:// prefix - if not re.match('^([^/:]+)://', address): + if not re.match('(?:[^/:]+)://', address): address = '%s://%s' % (protocol, address) proxies[protocol] = address else: @@ -2722,7 +2757,7 @@ if not proxyEnable or not proxyOverride: return 0 # try to make a host list from name and IP address. - rawHost, port = splitport(host) + rawHost, port = _splitport(host) host = [rawHost] try: addr = socket.gethostbyname(rawHost) @@ -2802,17 +2837,15 @@
- + @@ -2829,7 +2862,7 @@ ©2017, Matej Cepl . | - Powered by Sphinx 1.8.5 + Powered by Sphinx 3.2.1 & Alabaster 0.7.12
diff --git a/doc/html/genindex.html b/doc/html/genindex.html index c214985..d22a11f 100644 --- a/doc/html/genindex.html +++ b/doc/html/genindex.html @@ -43,6 +43,7 @@ | F | G | H + | I | K | L | M @@ -52,33 +53,95 @@ | Q | R | S + | T | U | V | W + | X

A

@@ -87,6 +150,18 @@ +
@@ -94,25 +169,105 @@

C