diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php index 85aadf45..a92de0b4 100644 --- a/src/Protocol/Imap.php +++ b/src/Protocol/Imap.php @@ -13,6 +13,8 @@ class Imap { + use ProtocolTrait; + /** * Default timeout in seconds for initiating session */ @@ -102,7 +104,7 @@ public function connect($host, $port = null, $ssl = false) if ($isTls) { $result = $this->requestAndResponse('STARTTLS'); - $result = $result && stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); + $result = $result && stream_socket_enable_crypto($this->socket, true, $this->getCryptoMethod()); if (! $result) { throw new Exception\RuntimeException('cannot enable TLS'); } diff --git a/src/Protocol/Pop3.php b/src/Protocol/Pop3.php index 0c52df2c..a28a2ee3 100644 --- a/src/Protocol/Pop3.php +++ b/src/Protocol/Pop3.php @@ -13,6 +13,8 @@ class Pop3 { + use ProtocolTrait; + /** * Default timeout in seconds for initiating session */ @@ -113,7 +115,7 @@ public function connect($host, $port = null, $ssl = false) if ($isTls) { $this->request('STLS'); - $result = stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); + $result = stream_socket_enable_crypto($this->socket, true, $this->getCryptoMethod()); if (! $result) { throw new Exception\RuntimeException('cannot enable TLS'); } diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php new file mode 100644 index 00000000..f252bae6 --- /dev/null +++ b/src/Protocol/ProtocolTrait.php @@ -0,0 +1,31 @@ +secure == 'tls') { $this->_send('STARTTLS'); $this->_expect(220, 180); - if (! stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { + if (! stream_socket_enable_crypto($this->socket, true, $this->getCryptoMethod())) { throw new Exception\RuntimeException('Unable to connect via TLS'); } $this->ehlo($host); diff --git a/test/Protocol/ProtocolTraitTest.php b/test/Protocol/ProtocolTraitTest.php new file mode 100644 index 00000000..57f77c77 --- /dev/null +++ b/test/Protocol/ProtocolTraitTest.php @@ -0,0 +1,29 @@ +getMockForTrait(ProtocolTrait::class); + + $this->assertNotEmpty(STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT & $mock->getCryptoMethod(), 'TLSv1.2 must be present in crypto method list'); + } +}