00001 #include "wvx509.h"
00002 #include "wvfile.h"
00003 #include "wvlog.h"
00004 #include "wvstrutils.h"
00005 #include "wvcrash.h"
00006
00007 #include <openssl/pem.h>
00008 #include <openssl/x509v3.h>
00009
00010 void print_details(WvX509Mgr *x509)
00011 {
00012 wvcon->print("Subject: %s\n", x509->get_subject());
00013 wvcon->print("Issuer: %s\n", x509->get_issuer());
00014 wvcon->print("Serial: %s\n", x509->get_serial());
00015 time_t t1 = x509->get_notvalid_before();
00016 time_t t2 = x509->get_notvalid_after();
00017
00018 wvcon->print("Not Valid Before: %s\n", ctime(&t1));
00019 wvcon->print("Not Valid After: %s\n", ctime(&t2));
00020 wvcon->print("Key Usage: %s\n", x509->get_key_usage());
00021 wvcon->print("Ext Key Usage: %s\n", x509->get_ext_key_usage());
00022 wvcon->print("Authority Info Access: \n%s\n", x509->get_aia());
00023 WvStringList urls;
00024 wvcon->print("CA Issuers available from:\n%s\n", x509->get_ca_urls(&urls)->join("\n"));
00025 urls.zap();
00026 wvcon->print("OCSP Responders available from:\n%s\n", x509->get_ocsp(&urls)->join("\n"));
00027 wvcon->print("CRL Distribution Point:\n%s\n", x509->get_crl_dp());
00028 wvcon->print("Certificate Policy: %s\n", x509->get_cp_oid());
00029 }
00030
00031
00032
00033 int main(int argc, char **argv)
00034 {
00035 wvcrash_setup(argv[0]);
00036
00037 WvDynBuf buffer;
00038
00039 if (argc < 2)
00040 {
00041 wvcon->print("You must specify a certificate in PEM format\n");
00042 return -1;
00043 }
00044
00045 WvFile f(argv[1], O_RDONLY);
00046
00047 while (f.isok())
00048 {
00049 f.read(buffer, 1000);
00050 }
00051 f.close();
00052
00053 WvX509Mgr x509;
00054 x509.decode(WvX509Mgr::CertPEM, buffer.getstr());
00055
00056 print_details(&x509);
00057
00058
00059
00060 return 0;
00061 }