Blame SOURCES/rhnlib-2.5.65-4-el7-to-rhnlib-2.5.65-5-el7.patch

48e10a
diff --git a/rhn/SSL.py b/rhn/SSL.py
48e10a
index db26fd8541..c3d338868f 100644
48e10a
--- a/rhn/SSL.py
48e10a
+++ b/rhn/SSL.py
48e10a
@@ -28,6 +28,7 @@ from OpenSSL import SSL
48e10a
 # SSL.crypto is provided to other modules
48e10a
 from OpenSSL import crypto
48e10a
 import os
48e10a
+import sys
48e10a
 
48e10a
 import socket
48e10a
 import select
48e10a
@@ -134,7 +135,19 @@ class SSLSocket:
48e10a
         self._makefile_called = self._makefile_called - 1
48e10a
 
48e10a
     def _really_close(self):
48e10a
-        self._connection.shutdown()
48e10a
+        # No connection was established
48e10a
+        if self._connection is None:
48e10a
+            return
48e10a
+
48e10a
+        # for Python 3
48e10a
+        if sys.version_info[0] == 3:
48e10a
+            if self._connection.get_state_string() == b'SSL negotiation finished successfully':
48e10a
+                self._connection.shutdown()
48e10a
+        # for Python 2
48e10a
+        else:
48e10a
+            if self._connection.state_string() == 'SSL negotiation finished successfully':
48e10a
+                self._connection.shutdown()
48e10a
+
48e10a
         self._connection.close()
48e10a
         self._closed = 1
48e10a
 
48e10a
diff --git a/rhnlib.spec b/rhnlib.spec
48e10a
index 2de48689f4..57e2128001 100644
48e10a
--- a/rhnlib.spec
48e10a
+++ b/rhnlib.spec
48e10a
@@ -5,7 +5,7 @@ Name: rhnlib
48e10a
 URL:     https://fedorahosted.org/spacewalk
48e10a
 Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
48e10a
 Version: 2.5.65
48e10a
-Release: 4%{?dist}
48e10a
+Release: 5%{?dist}
48e10a
 
48e10a
 Group: Development/Libraries
48e10a
 License: GPLv2
48e10a
@@ -59,6 +59,10 @@ rm -rf $RPM_BUILD_ROOT
48e10a
 %{python_sitelib}/*
48e10a
 
48e10a
 %changelog
48e10a
+* Thu Sep 21 2017 Tomas Kasparek <tkasparek@redhat.com> 2.5.65-5
48e10a
+- Resolves: #1471045 - check a state of handshake before shutdown SSL
48e10a
+  connection (grinrag@gmail.com)
48e10a
+
48e10a
 * Mon Mar 06 2017 Gennadii Altukhov <galt@redhat.com> 2.5.65-4
48e10a
 - Resolves: #1409577 - fixed BZ ID in changelog (galt@redhat.com)
48e10a