6eb79c8ed0b81e86a9a72c33b7ec2199e630fb97
[strongswan.git] / src / libcharon / encoding / payloads / cert_payload.h
1 /*
2 * Copyright (C) 2008 Tobias Brunner
3 * Copyright (C) 2005-2007 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup cert_payload cert_payload
20 * @{ @ingroup payloads
21 */
22
23 #ifndef CERT_PAYLOAD_H_
24 #define CERT_PAYLOAD_H_
25
26 typedef struct cert_payload_t cert_payload_t;
27 typedef enum cert_encoding_t cert_encoding_t;
28
29 #include <library.h>
30 #include <credentials/certificates/certificate.h>
31 #include <encoding/payloads/payload.h>
32
33 /**
34 * Certifcate encodings, as in RFC4306
35 */
36 enum cert_encoding_t {
37 ENC_PKCS7_WRAPPED_X509 = 1,
38 ENC_PGP = 2,
39 ENC_DNS_SIGNED_KEY = 3,
40 ENC_X509_SIGNATURE = 4,
41 ENC_KERBEROS_TOKEN = 6,
42 ENC_CRL = 7,
43 ENC_ARL = 8,
44 ENC_SPKI = 9,
45 ENC_X509_ATTRIBUTE = 10,
46 ENC_RAW_RSA_KEY = 11,
47 ENC_X509_HASH_AND_URL = 12,
48 ENC_X509_HASH_AND_URL_BUNDLE = 13,
49 ENC_OCSP_CONTENT = 14, /* from RFC 4806 */
50 };
51
52 /**
53 * Enum names for cert_encoding_t
54 */
55 extern enum_name_t *cert_encoding_names;
56
57 /**
58 * Class representing an IKEv2 CERT payload.
59 *
60 * The CERT payload format is described in RFC section 3.6.
61 */
62 struct cert_payload_t {
63
64 /**
65 * The payload_t interface.
66 */
67 payload_t payload_interface;
68
69 /**
70 * Get the playoads encoded certifcate.
71 *
72 * @return certifcate copy
73 */
74 certificate_t *(*get_cert)(cert_payload_t *this);
75
76 /**
77 * Get the encoding of the certificate.
78 *
79 * @return encoding
80 */
81 cert_encoding_t (*get_cert_encoding)(cert_payload_t *this);
82
83 /**
84 * Get the hash if this is a hash and URL encoded certificate.
85 *
86 * This function returns internal data, do not free.
87 *
88 * @return hash
89 */
90 chunk_t (*get_hash)(cert_payload_t *this);
91
92 /**
93 * Get the URL if this is a hash and URL encoded certificate.
94 *
95 * This function returns internal data, do not free.
96 *
97 * @return url
98 */
99 char *(*get_url)(cert_payload_t *this);
100
101
102 /**
103 * Destroys the cert_payload object.
104 */
105 void (*destroy) (cert_payload_t *this);
106 };
107
108 /**
109 * Creates an empty certificate payload.
110 *
111 * @return cert_payload_t object
112 */
113 cert_payload_t *cert_payload_create(void);
114
115 /**
116 * Creates a certificate payload with an embedded certificate.
117 *
118 * @param cert certificate to embed
119 * @return cert_payload_t object
120 */
121 cert_payload_t *cert_payload_create_from_cert(certificate_t *cert);
122
123 /**
124 * Creates a certificate payload with hash and URL encoding of a certificate.
125 *
126 * @param hash hash of the DER encoded certificate (get's cloned)
127 * @param url the URL to locate the certificate (get's cloned)
128 * @return cert_payload_t object
129 */
130 cert_payload_t *cert_payload_create_from_hash_and_url(chunk_t hash, char *url);
131
132 /**
133 * Creates a custom certificate payload using type and associated data.
134 *
135 * @param type encoding type of certificate
136 * @param data associated data (gets owned)
137 * @return cert_payload_t object
138 */
139 cert_payload_t *cert_payload_create_custom(cert_encoding_t type, chunk_t data);
140
141 #endif /** CERT_PAYLOAD_H_ @}*/