File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ public function connect()
139
139
140
140
$ options = stream_context_get_options ($ context );
141
141
if (isset ($ options ['ssl ' ]['crypto_method ' ])) {
142
- $ this ->enable_crypto ();
142
+ $ this ->enableCrypto ();
143
143
}
144
144
145
145
$ this ->heartbeat = $ this ->initial_heartbeat ;
@@ -432,16 +432,28 @@ protected function extract_error_code($message)
432
432
return 0 ;
433
433
}
434
434
435
- private function enable_crypto (): void
435
+ /**
436
+ * @throws AMQPIOException
437
+ */
438
+ private function enableCrypto (): void
436
439
{
437
440
$ timeout_at = time () + ($ this ->read_timeout + $ this ->write_timeout ) * 2 ; // 2 round-trips during handshake
438
441
439
- do {
440
- $ enabled = stream_socket_enable_crypto ($ this ->sock , true );
441
- } while ($ enabled !== true && time () < $ timeout_at );
442
+ try {
443
+ $ this ->setErrorHandler ();
444
+ do {
445
+ $ enabled = stream_socket_enable_crypto ($ this ->sock , true );
446
+ $ this ->throwOnError ();
447
+ usleep (1e4 );
448
+ } while ($ enabled === 0 && time () < $ timeout_at );
449
+ } catch (\ErrorException $ exception ) {
450
+ throw new AMQPIOException ($ exception ->getMessage (), $ exception ->getCode (), $ exception );
451
+ } finally {
452
+ $ this ->restoreErrorHandler ();
453
A783
+ }
442
454
443
455
if ($ enabled !== true ) {
444
- throw new AMQPIOException ('Can not enable crypto ' );
456
+ throw new AMQPIOException ('Could not enable socket crypto ' );
445
457
}
446
458
}
447
459
}
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public function external_auth_with_user_credentials()
50
50
public function secure_with_incorrect_crypto_method ()
51
51
{
52
52
$ this ->expectException (AMQPIOException::class);
53
- $ this ->expectExceptionMessage ('Can not enable crypto ' );
53
+ $ this ->expectExceptionMessage ('stream_socket_enable_crypto(): SSL: Connection reset by peer ' );
54
54
55
55
$ cert_dir = realpath (__DIR__ . "/../../certs " );
56
56
$ config = new AMQPConnectionConfig ();
You can’t perform that action at this time.
0 commit comments