added once flag to certinfo_t
[strongswan.git] / src / libstrongswan / crypto / certinfo.c
1 /**
2 * @file certinfo.c
3 *
4 * @brief Implementation of certinfo_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Andreas Steffen
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <time.h>
24
25 #include <library.h>
26
27 #include "certinfo.h"
28
29 typedef struct private_certinfo_t private_certinfo_t;
30
31 /**
32 * Private data of a certinfo_t object.
33 */
34 struct private_certinfo_t {
35 /**
36 * Public interface for this certificate status information object.
37 */
38 certinfo_t public;
39
40 /**
41 * Serial number of the certificate
42 */
43 chunk_t serialNumber;
44
45 /**
46 * Certificate status
47 */
48 cert_status_t status;
49
50 /**
51 * Certificate status is for one-time use only
52 */
53 bool once;
54
55 /**
56 * Time when the certificate status info was generated
57 */
58 time_t thisUpdate;
59
60 /**
61 * Time when an updated certifcate status info will be available
62 */
63 time_t nextUpdate;
64
65 /**
66 * Time of certificate revocation
67 */
68 time_t revocationTime;
69
70 /**
71 * Reason of certificate revocation
72 */
73 crl_reason_t revocationReason;
74 };
75
76 ENUM(cert_status_names, CERT_GOOD, CERT_UNTRUSTED,
77 "good",
78 "revoked",
79 "unknown",
80 "unknown",
81 "untrusted",
82 );
83
84 ENUM(crl_reason_names, REASON_UNSPECIFIED, REASON_REMOVE_FROM_CRL,
85 "unspecified",
86 "key compromise",
87 "ca compromise",
88 "affiliation changed",
89 "superseded",
90 "cessation of operation",
91 "certificate hold",
92 "reason #7",
93 "remove from crl",
94 );
95
96 /**
97 * Implements certinfo_t.get_serialNumber
98 */
99 static chunk_t get_serialNumber(const private_certinfo_t *this)
100 {
101 return this->serialNumber;
102 }
103
104 /**
105 * Implements certinfo_t.set_status
106 */
107 static void set_status(private_certinfo_t *this, cert_status_t status)
108 {
109 this->status = status;
110 }
111
112 /**
113 * Implements certinfo_t.get_status
114 */
115 static cert_status_t get_status(const private_certinfo_t *this)
116 {
117 return this->status;
118 }
119
120 /**
121 * Implements certinfo_t.set_nextUpdate
122 */
123 static void set_nextUpdate(private_certinfo_t *this, time_t nextUpdate)
124 {
125 this->nextUpdate = nextUpdate;
126 }
127
128 /**
129 * Implements certinfo_t.get_nextUpdate
130 */
131 static time_t get_nextUpdate(const private_certinfo_t *this)
132 {
133 return this->nextUpdate;
134 }
135
136 /**
137 * Implements certinfo_t.set_revocationTime
138 */
139 static void set_revocationTime(private_certinfo_t *this, time_t revocationTime)
140 {
141 this->revocationTime = revocationTime;
142 }
143
144 /**
145 * Implements certinfo_t.get_revocationTime
146 */
147 static time_t get_revocationTime(const private_certinfo_t *this)
148 {
149 return this->revocationTime;
150 }
151
152 /**
153 * Implements certinfo_t.set_revocationReason
154 */
155 static void set_revocationReason(private_certinfo_t *this, crl_reason_t reason)
156 {
157 this->revocationReason = reason;
158 }
159
160 /**
161 * Implements certinfo_t.get_revocationReason
162 */
163 static crl_reason_t get_revocationReason(const private_certinfo_t *this)
164 {
165 return this->revocationReason;
166 }
167
168 /**
169 * Implements certinfo_t.destroy
170 */
171 static void destroy(private_certinfo_t *this)
172 {
173 free(this->serialNumber.ptr);
174 free(this);
175 }
176
177 /*
178 * Described in header.
179 */
180 certinfo_t *certinfo_create(chunk_t serial)
181 {
182 private_certinfo_t *this = malloc_thing(private_certinfo_t);
183
184 /* initialize */
185 this->serialNumber = chunk_clone(serial);
186 this->status = CERT_UNDEFINED;
187 this->nextUpdate = UNDEFINED_TIME;
188 this->revocationTime = UNDEFINED_TIME;
189 this->revocationReason = REASON_UNSPECIFIED;
190
191 /* public functions */
192 this->public.get_serialNumber = (chunk_t (*) (const certinfo_t*))get_serialNumber;
193 this->public.set_status = (void (*) (certinfo_t*,cert_status_t))set_status;
194 this->public.get_status = (cert_status_t (*) (const certinfo_t*))get_status;
195 this->public.set_nextUpdate = (void (*) (certinfo_t*,time_t))set_nextUpdate;
196 this->public.get_nextUpdate = (time_t (*) (const certinfo_t*))get_nextUpdate;
197 this->public.set_revocationTime = (void (*) (certinfo_t*,time_t))set_revocationTime;
198 this->public.get_revocationTime = (time_t (*) (const certinfo_t*))get_revocationTime;
199 this->public.set_revocationReason = (void (*) (certinfo_t*, crl_reason_t))set_revocationReason;
200 this->public.get_revocationReason = (crl_reason_t(*) (const certinfo_t*))get_revocationReason;
201 this->public.destroy = (void (*) (certinfo_t*))destroy;
202
203 return &this->public;
204 }