LoginSignup
4
4

More than 5 years have passed since last update.

centos6でpython2.6のssl3プロトコルを使用禁止にする

Posted at

なぜ禁止する必要があるのかは、SSL POODLEを検索してみるといいです。
サーバからsslv23をtlsv1に置換すると、まだsslv23を使っているクライアントが接続できなくなりますので、
ここはpython自体にパッチを当てる必要があります。

ステップ1

python2.6のソースパッケージをダウンロードおよび解凍

wget http://vault.centos.org/6.5/updates/Source/SPackages/python-2.6.6-52.el6.src.rpm
mkdir -p ~/rpmbuild/SOURCES
cd ~/rpmbuild/SOURCES
wget http://vault.centos.org/6.5/updates/Source/SPackages/python-2.6.6-52.el6.src.rpm
rpm2cpio python-2.6.6-52.el6.src.rpm | cpio -idmv

ステップ2

パッチを当てる

disable-ssl3.patch
--- /dev/null
+++ b/SOURCES/python-2.6-disable-ssl3.patch
@@ -0,0 +1,17 @@
+--- Python-2.6.6.orig/Modules/_ssl.c
++++ Python-2.6.6/Modules/_ssl.c
+@@ -359,7 +386,12 @@ newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file,
+     }
+ 
+     /* ssl compatibility */
+-    SSL_CTX_set_options(self->ctx, SSL_OP_ALL);
++    long options = SSL_OP_ALL;
++    if (proto_version != PY_SSL_VERSION_SSL2)
++        options |= SSL_OP_NO_SSLv2;
++    if (proto_version != PY_SSL_VERSION_SSL3)
++        options |= SSL_OP_NO_SSLv3;
++    SSL_CTX_set_options(self->ctx, options);
+ 
+     verification_mode = SSL_VERIFY_NONE;
+     if (certreq == PY_SSL_CERT_OPTIONAL)
+
--- a/SOURCES.bak/python.spec
+++ b/SOURCES/python.spec
@@ -47,7 +47,7 @@
 Summary: An interpreted, interactive, object-oriented programming language
 Name: %{python}
 Version: 2.6.6
-Release: 52%{?dist}
+Release: 52%{?dist}_1
 License: Python
 Group: Development/Languages
 Provides: python-abi = %{pybasever}
@@ -453,6 +453,7 @@ Patch171: python-2.6.6-CVE-2013-4238-hostname-check-bypass-in-SSL-module.patch
 # (rhbz#1002983)
 Patch172: python-2.6.6-ssl-memory-leak-_get_peer_alt_names.patch

+Patch10000: python-2.6-disable-ssl3.patch

 # The core python package contains just the executable and manpages; most of
 # the content is now in the -libs subpackage.
@@ -790,6 +791,8 @@ mv Modules/cryptmodule.c Modules/_cryptmodule.c

 %patch172 -p1

+%patch10000 -p1
+
 # Don't build these crypto algorithms; instead rely on _hashlib and OpenSSL:
 for f in md5module.c md5.c shamodule.c sha256module.c sha512module.c; do
     rm Modules/$f

このファイルを~/に置いたあとこのコマンドを実行します

patch < ~/disable-ssl3.patch

ステップ3

リビルトを行う

rpmbuild -ba python.spec

最後にできたrpmをインストールすればいいです。

ssl3の使用が実際に禁止されたかどうかのテスト

openssl s_client -connect ip:port -ssl3

errorとかでハンドシェイクが失敗したら成功になります。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4