1
/* $Id: ssl_sock_dump.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2009-2011 Teluu Inc. (http://www.teluu.com)
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#include <pj/ssl_sock.h>
22
#include <pj/string.h>
25
/* Only build when PJ_HAS_SSL_SOCK is enabled */
26
#if defined(PJ_HAS_SSL_SOCK) && PJ_HAS_SSL_SOCK!=0
28
#define THIS_FILE "ssl_sock_dump.c"
30
#define CHECK_BUF_LEN() \
31
if ((len < 0) || (len >= end-p)) { \
37
PJ_DEF(pj_ssize_t) pj_ssl_cert_info_dump(const pj_ssl_cert_info *ci,
42
const char *wdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
52
pj_time_decode(&ci->validity.start, &pt1);
53
pj_time_decode(&ci->validity.end, &pt2);
56
len = pj_ansi_snprintf(p, end-p, "%sVersion : v%d\n",
61
len = pj_ansi_snprintf(p, end-p, "%sSerial : ", indent);
64
for (i = 0; i < sizeof(ci->serial_no) && !ci->serial_no[i]; ++i);
65
for (; i < sizeof(ci->serial_no); ++i) {
66
len = pj_ansi_snprintf(p, end-p, "%02X ", ci->serial_no[i]);
72
len = pj_ansi_snprintf( p, end-p, "%sSubject : %.*s\n", indent,
73
(int)ci->subject.cn.slen,
76
len = pj_ansi_snprintf( p, end-p, "%s %.*s\n", indent,
77
(int)ci->subject.info.slen,
78
ci->subject.info.ptr);
82
len = pj_ansi_snprintf( p, end-p, "%sIssuer : %.*s\n", indent,
83
(int)ci->issuer.cn.slen,
86
len = pj_ansi_snprintf( p, end-p, "%s %.*s\n", indent,
87
(int)ci->issuer.info.slen,
92
len = pj_ansi_snprintf( p, end-p, "%sValid from : %s %4d-%02d-%02d "
93
"%02d:%02d:%02d.%03d %s\n", indent,
94
wdays[pt1.wday], pt1.year, pt1.mon+1, pt1.day,
95
pt1.hour, pt1.min, pt1.sec, pt1.msec,
96
(ci->validity.gmt? "GMT":""));
99
len = pj_ansi_snprintf( p, end-p, "%sValid to : %s %4d-%02d-%02d "
100
"%02d:%02d:%02d.%03d %s\n", indent,
101
wdays[pt2.wday], pt2.year, pt2.mon+1, pt2.day,
102
pt2.hour, pt2.min, pt2.sec, pt2.msec,
103
(ci->validity.gmt? "GMT":""));
106
/* Subject alternative name extension */
107
if (ci->subj_alt_name.cnt) {
110
len = pj_ansi_snprintf(p, end-p, "%ssubjectAltName extension\n",
114
for (i = 0; i < ci->subj_alt_name.cnt; ++i) {
115
const char *type = NULL;
117
switch(ci->subj_alt_name.entry[i].type) {
118
case PJ_SSL_CERT_NAME_RFC822:
121
case PJ_SSL_CERT_NAME_DNS:
124
case PJ_SSL_CERT_NAME_URI:
127
case PJ_SSL_CERT_NAME_IP:
134
len = pj_ansi_snprintf( p, end-p, "%s %s : %.*s\n", indent,
136
(int)ci->subj_alt_name.entry[i].name.slen,
137
ci->subj_alt_name.entry[i].name.ptr);
147
#endif /* PJ_HAS_SSL_SOCK */