aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Stapleton <alexs@prol.etari.at>2014-07-06 15:12:57 +0100
committerAlex Stapleton <alexs@prol.etari.at>2014-07-06 15:12:57 +0100
commit43a7f4b42956ffbeeac82f443a5ef11d24182325 (patch)
treecb48bc3474ba65c1cae66d5868180239aa972d13
parent5cb305d90489c42e9c8a6877f3b438175333e44c (diff)
parent419e67a1d515ec7883a1e31608c1618e226fbffb (diff)
downloadcryptography-43a7f4b42956ffbeeac82f443a5ef11d24182325.tar.gz
cryptography-43a7f4b42956ffbeeac82f443a5ef11d24182325.tar.bz2
cryptography-43a7f4b42956ffbeeac82f443a5ef11d24182325.zip
Merge pull request #1206 from reaperhulk/static-windows-builds
switch to static linking on windows and update installation page
-rw-r--r--cryptography/hazmat/bindings/openssl/binding.py16
-rw-r--r--docs/installation.rst31
-rw-r--r--tests/hazmat/bindings/test_openssl.py14
3 files changed, 53 insertions, 8 deletions
diff --git a/cryptography/hazmat/bindings/openssl/binding.py b/cryptography/hazmat/bindings/openssl/binding.py
index 554c3c3e..4cd1b89b 100644
--- a/cryptography/hazmat/bindings/openssl/binding.py
+++ b/cryptography/hazmat/bindings/openssl/binding.py
@@ -13,6 +13,7 @@
from __future__ import absolute_import, division, print_function
+import os
import sys
import threading
@@ -97,7 +98,8 @@ class Binding(object):
if sys.platform != "win32":
libraries = ["crypto", "ssl"]
else: # pragma: no cover
- libraries = ["libeay32", "ssleay32", "advapi32"]
+ link_type = os.environ.get("PYCA_WINDOWS_LINK_TYPE", "static")
+ libraries = _get_windows_libraries(link_type)
cls.ffi, cls.lib = build_ffi(
module_prefix=cls._module_prefix,
@@ -154,3 +156,15 @@ class Binding(object):
mode, n, file, line
)
)
+
+
+def _get_windows_libraries(link_type):
+ if link_type == "dynamic":
+ return ["libeay32", "ssleay32", "advapi32"]
+ elif link_type == "static" or link_type == "":
+ return ["libeay32mt", "ssleay32mt", "advapi32",
+ "crypt32", "gdi32", "user32", "ws2_32"]
+ else:
+ raise ValueError(
+ "PYCA_WINDOWS_LINK_TYPE must be 'static' or 'dynamic'"
+ )
diff --git a/docs/installation.rst b/docs/installation.rst
index 8fbbcb30..339d8b76 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -35,16 +35,35 @@ OpenSSL releases:
On Windows
----------
-If you're on Windows you'll need to make sure you have OpenSSL installed.
-There are `pre-compiled binaries`_ available. If your installation is in
-an unusual location set the ``LIB`` and ``INCLUDE`` environment variables
-to include the corresponding locations. For example:
+The wheel package on Windows is a statically linked build (as of 0.5) so all
+dependencies are included. Just run
+
+.. code-block:: console
+
+ $ pip install cryptography
+
+If you prefer to compile it yourself you'll need to have OpenSSL installed.
+There are `pre-compiled binaries`_ available. If your installation is in an
+unusual location set the ``LIB`` and ``INCLUDE`` environment variables to
+include the corresponding locations.For example:
+
+.. code-block:: console
+
+ C:\> \path\to\vcvarsall.bat x86_amd64
+ C:\> set LIB=C:\OpenSSL\lib\VC\static;C:\OpenSSL\lib;%LIB%
+ C:\> set INCLUDE=C:\OpenSSL\include;%INCLUDE%
+ C:\> pip install cryptography
+
+You can also choose to build statically or dynamically using the
+``PYCA_WINDOWS_LINK_TYPE`` variable. Allowed values are ``static`` (default)
+and ``dynamic``.
.. code-block:: console
C:\> \path\to\vcvarsall.bat x86_amd64
- C:\> set LIB=C:\OpenSSL-1.0.1g-64bit\lib;%LIB%
- C:\> set INCLUDE=C:\OpenSSL-1.0.1g-64bit\include;%INCLUDE%
+ C:\> set LIB=C:\OpenSSL\lib\VC\static;C:\OpenSSL\lib;%LIB%
+ C:\> set INCLUDE=C:\OpenSSL\include;%INCLUDE%
+ C:\> set PYCA_WINDOWS_LINK_TYPE=dynamic
C:\> pip install cryptography
Building cryptography on Linux
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index 58d7602b..d22c4fd2 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -15,7 +15,9 @@ from __future__ import absolute_import, division, print_function
import pytest
-from cryptography.hazmat.bindings.openssl.binding import Binding
+from cryptography.hazmat.bindings.openssl.binding import (
+ Binding, _get_windows_libraries
+)
class TestOpenSSL(object):
@@ -137,3 +139,13 @@ class TestOpenSSL(object):
resp = b.lib.SSL_set_mode(ssl, b.lib.SSL_OP_ALL)
assert resp == b.lib.SSL_OP_ALL
assert b.lib.SSL_OP_ALL == b.lib.SSL_get_mode(ssl)
+
+ def test_windows_static_dynamic_libraries(self):
+ assert "ssleay32mt" in _get_windows_libraries("static")
+
+ assert "ssleay32mt" in _get_windows_libraries("")
+
+ assert "ssleay32" in _get_windows_libraries("dynamic")
+
+ with pytest.raises(ValueError):
+ _get_windows_libraries("notvalid")