Help us understand the problem. What is going on with this article?

PHP で外部サーバーの SSL サーバー証明書の有効期限を取得する

More than 5 years have passed since last update.

下記のコードを実行すると qiita.com の SSL サーバー証明書の有効期限を取得することができます。

<?php
$domain_name = 'qiita.com';

$stream_context = stream_context_create(array(
  'ssl' => array('capture_peer_cert' => true)
));
$resource = stream_socket_client(
  'ssl://' . $domain_name . ':443',
  $errno,
  $errstr,
  30,
  STREAM_CLIENT_CONNECT,
  $stream_context
);
$cont = stream_context_get_params($resource);
$parsed = openssl_x509_parse($cont['options']['ssl']['peer_certificate']);

if(strpos($parsed['subject']['CN'], $domain_name) !== false){
  echo date('Y/m/d', $parsed['validTo_time_t']);
}else{
  echo 'not contract.'; 
}

実行結果です。

2014/03/21

これを PHPUnit などでテストにして Jenkins で定期実行すれば SSL サーバー証明書の有効期限を監視できますね。

下記を参考にしました。ありがとうございます。
http://stackoverflow.com/questions/3081042/how-to-get-ssl-certificate-info-with-curl-in-php

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした