Repository: pyca/cryptography

Issue:
No EC support in OpenSSL fails entire build
We should still be able to build cryptography module even if EC isn't supported. Currently, cryptography module cannot be built with an OpenSSL that doesn't support EC.

```
sholsapp@sholsapp-ld(~/workspace/cryptography) $ python setup.py install
running install
running build_ext
building '_cffi__x63e6cd6axfba2f231' extension
creating /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/cryptography
creating /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/cryptography/hazmat
creating /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/cryptography/hazmat/primitives
creating /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/cryptography/hazmat/primitives/__pycache__
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.6 -c cryptography/hazmat/primitives/__pycache__/_cffi__x63e6cd6axfba2f231.c -o /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/cryptography/hazmat/primitives/__pycache__/_cffi__x63e6cd6axfba2f231.o
gcc -pthread -shared /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/cryptography/hazmat/primitives/__pycache__/_cffi__x63e6cd6axfba2f231.o -L/usr/lib64 -lpython2.6 -o /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/_cffi__x63e6cd6axfba2f231.so
running build_ext
building '_cffi__xe2e07463x4a8b9ec1' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.6 -c cryptography/hazmat/primitives/__pycache__/_cffi__xe2e07463x4a8b9ec1.c -o /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/cryptography/hazmat/primitives/__pycache__/_cffi__xe2e07463x4a8b9ec1.o
gcc -pthread -shared /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/cryptography/hazmat/primitives/__pycache__/_cffi__xe2e07463x4a8b9ec1.o -L/usr/lib64 -lpython2.6 -o /home/sholsapp/workspace/cryptography/cryptography/hazmat/primitives/__pycache__/_cffi__xe2e07463x4a8b9ec1.so
running build_ext
building '_cffi__x8355722ax9815b403' extension
creating /home/sholsapp/workspace/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography
creating /home/sholsapp/workspace/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat
creating /home/sholsapp/workspace/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat/bindings
creating /home/sholsapp/workspace/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat/bindings/__pycache__
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.6 -c cryptography/hazmat/bindings/__pycache__/_cffi__x8355722ax9815b403.c -o /home/sholsapp/workspace/crypto
graphy/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat/bindings/__pycache__/_cffi__x8355722ax9815b403.o
cryptography/hazmat/bindings/__pycache__/_cffi__x8355722ax9815b403.c:189:24: error: openssl/ec.h: No such file or directory
...
```



Discussion:

Resolving patch:
diff --git a/cryptography/hazmat/bindings/openssl/ec.py b/cryptography/hazmat/bindings/openssl/ec.py
--- a/cryptography/hazmat/bindings/openssl/ec.py
+++ b/cryptography/hazmat/bindings/openssl/ec.py
@@ -12,7 +12,10 @@
 # limitations under the License.
 
 INCLUDES = """
+#ifndef OPENSSL_NO_EC
 #include <openssl/ec.h>
+#endif
+
 #include <openssl/obj_mac.h>
 """
 
@@ -31,16 +34,17 @@
 """
 
 FUNCTIONS = """
-EC_KEY *EC_KEY_new_by_curve_name(int);
-void EC_KEY_free(EC_KEY *);
 """
 
 MACROS = """
+EC_KEY *EC_KEY_new_by_curve_name(int);
+void EC_KEY_free(EC_KEY *);
 """
 
 CUSTOMIZATIONS = """
 #ifdef OPENSSL_NO_EC
 static const long Cryptography_HAS_EC = 0;
+typedef void EC_KEY;
 EC_KEY* (*EC_KEY_new_by_curve_name)(int) = NULL;
 void (*EC_KEY_free)(EC_KEY *) = NULL;
 #else
diff --git a/cryptography/hazmat/bindings/openssl/ssl.py b/cryptography/hazmat/bindings/openssl/ssl.py
--- a/cryptography/hazmat/bindings/openssl/ssl.py
+++ b/cryptography/hazmat/bindings/openssl/ssl.py
@@ -393,6 +393,6 @@
     ],
 
     "Cryptography_HAS_EC": [
-        "EC_KEY_new_by_curve_name",
+        "SSL_CTX_set_tmp_ecdh",
     ]
 }


Test patch: