1178825Sdfr/*
2233294Sstas * Copyright (c) 2004 - 2007 Kungliga Tekniska H��gskolan
3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden).
4233294Sstas * All rights reserved.
5178825Sdfr *
6233294Sstas * Redistribution and use in source and binary forms, with or without
7233294Sstas * modification, are permitted provided that the following conditions
8233294Sstas * are met:
9178825Sdfr *
10233294Sstas * 1. Redistributions of source code must retain the above copyright
11233294Sstas *    notice, this list of conditions and the following disclaimer.
12178825Sdfr *
13233294Sstas * 2. Redistributions in binary form must reproduce the above copyright
14233294Sstas *    notice, this list of conditions and the following disclaimer in the
15233294Sstas *    documentation and/or other materials provided with the distribution.
16178825Sdfr *
17233294Sstas * 3. Neither the name of the Institute nor the names of its contributors
18233294Sstas *    may be used to endorse or promote products derived from this software
19233294Sstas *    without specific prior written permission.
20178825Sdfr *
21233294Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22233294Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24233294Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25233294Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29233294Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31233294Sstas * SUCH DAMAGE.
32178825Sdfr */
33178825Sdfr
34233294Sstas/* $Id$ */
35178825Sdfr
36233294Sstas#ifndef HEIMDAL_HX509_H
37233294Sstas#define HEIMDAL_HX509_H 1
38233294Sstas
39233294Sstas#include <rfc2459_asn1.h>
40233294Sstas#include <stdarg.h>
41233294Sstas#include <stdio.h>
42233294Sstas
43178825Sdfrtypedef struct hx509_cert_attribute_data *hx509_cert_attribute;
44178825Sdfrtypedef struct hx509_cert_data *hx509_cert;
45178825Sdfrtypedef struct hx509_certs_data *hx509_certs;
46178825Sdfrtypedef struct hx509_context_data *hx509_context;
47178825Sdfrtypedef struct hx509_crypto_data *hx509_crypto;
48178825Sdfrtypedef struct hx509_lock_data *hx509_lock;
49178825Sdfrtypedef struct hx509_name_data *hx509_name;
50178825Sdfrtypedef struct hx509_private_key *hx509_private_key;
51233294Sstastypedef struct hx509_private_key_ops hx509_private_key_ops;
52178825Sdfrtypedef struct hx509_validate_ctx_data *hx509_validate_ctx;
53178825Sdfrtypedef struct hx509_verify_ctx_data *hx509_verify_ctx;
54178825Sdfrtypedef struct hx509_revoke_ctx_data *hx509_revoke_ctx;
55178825Sdfrtypedef struct hx509_query_data hx509_query;
56178825Sdfrtypedef void * hx509_cursor;
57178825Sdfrtypedef struct hx509_request_data *hx509_request;
58178825Sdfrtypedef struct hx509_error_data *hx509_error;
59178825Sdfrtypedef struct hx509_peer_info *hx509_peer_info;
60178825Sdfrtypedef struct hx509_ca_tbs *hx509_ca_tbs;
61233294Sstastypedef struct hx509_env_data *hx509_env;
62178825Sdfrtypedef struct hx509_crl *hx509_crl;
63178825Sdfr
64178825Sdfrtypedef void (*hx509_vprint_func)(void *, const char *, va_list);
65178825Sdfr
66178825Sdfrenum {
67178825Sdfr    HX509_VHN_F_ALLOW_NO_MATCH = 1
68178825Sdfr};
69178825Sdfr
70178825Sdfrenum {
71178825Sdfr    HX509_VALIDATE_F_VALIDATE = 1,
72178825Sdfr    HX509_VALIDATE_F_VERBOSE = 2
73178825Sdfr};
74178825Sdfr
75233294Sstasenum {
76233294Sstas    HX509_CRYPTO_PADDING_PKCS7 = 0,
77233294Sstas    HX509_CRYPTO_PADDING_NONE = 1
78233294Sstas};
79233294Sstas
80233294Sstasenum {
81233294Sstas    HX509_KEY_FORMAT_GUESS = 0,
82233294Sstas    HX509_KEY_FORMAT_DER = 1,
83233294Sstas    HX509_KEY_FORMAT_WIN_BACKUPKEY = 2
84233294Sstas};
85233294Sstastypedef uint32_t hx509_key_format_t;
86233294Sstas
87178825Sdfrstruct hx509_cert_attribute_data {
88178825Sdfr    heim_oid oid;
89178825Sdfr    heim_octet_string data;
90178825Sdfr};
91178825Sdfr
92178825Sdfrtypedef enum {
93178825Sdfr    HX509_PROMPT_TYPE_PASSWORD		= 0x1,	/* password, hidden */
94178825Sdfr    HX509_PROMPT_TYPE_QUESTION		= 0x2,	/* question, not hidden */
95178825Sdfr    HX509_PROMPT_TYPE_INFO		= 0x4	/* infomation, reply doesn't matter */
96178825Sdfr} hx509_prompt_type;
97178825Sdfr
98178825Sdfrtypedef struct hx509_prompt {
99178825Sdfr    const char *prompt;
100178825Sdfr    hx509_prompt_type type;
101178825Sdfr    heim_octet_string reply;
102178825Sdfr} hx509_prompt;
103178825Sdfr
104178825Sdfrtypedef int (*hx509_prompter_fct)(void *, const hx509_prompt *);
105178825Sdfr
106178825Sdfrtypedef struct hx509_octet_string_list {
107178825Sdfr    size_t len;
108178825Sdfr    heim_octet_string *val;
109178825Sdfr} hx509_octet_string_list;
110178825Sdfr
111178825Sdfrtypedef struct hx509_pem_header {
112178825Sdfr    struct hx509_pem_header *next;
113178825Sdfr    char *header;
114178825Sdfr    char *value;
115178825Sdfr} hx509_pem_header;
116178825Sdfr
117178825Sdfrtypedef int
118178825Sdfr(*hx509_pem_read_func)(hx509_context, const char *, const hx509_pem_header *,
119178825Sdfr		       const void *, size_t, void *ctx);
120178825Sdfr
121178825Sdfr/*
122178825Sdfr * Options passed to hx509_query_match_option.
123178825Sdfr */
124178825Sdfrtypedef enum {
125178825Sdfr    HX509_QUERY_OPTION_PRIVATE_KEY = 1,
126178825Sdfr    HX509_QUERY_OPTION_KU_ENCIPHERMENT = 2,
127178825Sdfr    HX509_QUERY_OPTION_KU_DIGITALSIGNATURE = 3,
128178825Sdfr    HX509_QUERY_OPTION_KU_KEYCERTSIGN = 4,
129178825Sdfr    HX509_QUERY_OPTION_END = 0xffff
130178825Sdfr} hx509_query_option;
131178825Sdfr
132178825Sdfr/* flags to hx509_certs_init */
133178825Sdfr#define HX509_CERTS_CREATE				0x01
134178825Sdfr#define HX509_CERTS_UNPROTECT_ALL			0x02
135178825Sdfr
136178825Sdfr/* flags to hx509_set_error_string */
137178825Sdfr#define HX509_ERROR_APPEND				0x01
138178825Sdfr
139178825Sdfr/* flags to hx509_cms_unenvelope */
140178825Sdfr#define HX509_CMS_UE_DONT_REQUIRE_KU_ENCIPHERMENT	0x01
141233294Sstas#define HX509_CMS_UE_ALLOW_WEAK				0x02
142178825Sdfr
143233294Sstas/* flags to hx509_cms_envelope_1 */
144233294Sstas#define HX509_CMS_EV_NO_KU_CHECK			0x01
145233294Sstas#define HX509_CMS_EV_ALLOW_WEAK				0x02
146233294Sstas#define HX509_CMS_EV_ID_NAME				0x04
147233294Sstas
148233294Sstas/* flags to hx509_cms_verify_signed */
149233294Sstas#define HX509_CMS_VS_ALLOW_DATA_OID_MISMATCH		0x01
150233294Sstas#define HX509_CMS_VS_NO_KU_CHECK			0x02
151233294Sstas#define HX509_CMS_VS_ALLOW_ZERO_SIGNER			0x04
152233294Sstas#define HX509_CMS_VS_NO_VALIDATE			0x08
153233294Sstas
154178825Sdfr/* selectors passed to hx509_crypto_select and hx509_crypto_available */
155178825Sdfr#define HX509_SELECT_ALL 0
156178825Sdfr#define HX509_SELECT_DIGEST 1
157178825Sdfr#define HX509_SELECT_PUBLIC_SIG 2
158178825Sdfr#define HX509_SELECT_PUBLIC_ENC 3
159178825Sdfr#define HX509_SELECT_SECRET_ENC 4
160178825Sdfr
161178825Sdfr/* flags to hx509_ca_tbs_set_template */
162178825Sdfr#define HX509_CA_TEMPLATE_SUBJECT 1
163178825Sdfr#define HX509_CA_TEMPLATE_SERIAL 2
164178825Sdfr#define HX509_CA_TEMPLATE_NOTBEFORE 4
165178825Sdfr#define HX509_CA_TEMPLATE_NOTAFTER 8
166178825Sdfr#define HX509_CA_TEMPLATE_SPKI 16
167178825Sdfr#define HX509_CA_TEMPLATE_KU 32
168178825Sdfr#define HX509_CA_TEMPLATE_EKU 64
169178825Sdfr
170178825Sdfr/* flags hx509_cms_create_signed* */
171233294Sstas#define HX509_CMS_SIGNATURE_DETACHED			0x01
172233294Sstas#define HX509_CMS_SIGNATURE_ID_NAME			0x02
173233294Sstas#define HX509_CMS_SIGNATURE_NO_SIGNER			0x04
174233294Sstas#define HX509_CMS_SIGNATURE_LEAF_ONLY			0x08
175233294Sstas#define HX509_CMS_SIGNATURE_NO_CERTS			0x10
176178825Sdfr
177178825Sdfr/* hx509_verify_hostname nametype */
178178825Sdfrtypedef enum  {
179178825Sdfr    HX509_HN_HOSTNAME = 0,
180178825Sdfr    HX509_HN_DNSSRV
181178825Sdfr} hx509_hostname_type;
182178825Sdfr
183178825Sdfr#include <hx509-protos.h>
184233294Sstas#include <hx509_err.h>
185233294Sstas
186233294Sstas#endif /* HEIMDAL_HX509_H */
187