LoginSignup
1
0

More than 5 years have passed since last update.

CakePHP2のHttpScoketで複数のホストにSSLアクセスするとSSL証明書の検証に失敗する

Last updated at Posted at 2018-06-24

CakePHP2.10.10で確認。

$httpSocket = new HttpSocket();
try {
    $httpSocket->get('https://example.com');
    $httpSocket->get('https://netcommons.ryus.co.jp');
} catch (Exception $e) {
    debug($e->getMessage());
}

こんなコード実行すると

stream_socket_client(): Peer certificate CN=`*.coreserver.jp' did not match expected CN=`example.com'
stream_socket_client(): Failed to enable crypto
stream_socket_client(): unable to connect to ssl://netcommons.ryus.co.jp:443 (Unknown error)

こんな例外投げられる。

というわけで別ホストにもSSL接続するときは、新たに HttpSocket の別インスタンスつくって接続した方がいいようです。

追記
別ホストに接続する前に reset(); 呼べば良かっただけかも

$httpSocket = new HttpSocket();
try {
    $httpSocket->get('https://example.com');
    $httpSocket->reset(); // これを追加
    $httpSocket->get('https://netcommons.ryus.co.jp');
} catch (Exception $e) {
    debug($e->getMessage());
}

これなら大丈夫そう

1
0
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
1
0