1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/*
* X.509 Cert Path Validation
* (C) 2010-2011 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#ifndef BOTAN_X509_CERT_PATH_VALIDATION_H__
#define BOTAN_X509_CERT_PATH_VALIDATION_H__
#include <botan/x509cert.h>
#include <botan/certstor.h>
#include <set>
namespace Botan {
/**
* Specifies restrictions on the PKIX path validation
*/
class BOTAN_DLL Path_Validation_Restrictions
{
public:
/**
* @param require_rev if true, revocation information is required
* @param minimum_key_strength is the minimum strength (in terms of
* operations, eg 80 means 2^80) of a signature. Signatures
* weaker than this are rejected.
*/
Path_Validation_Restrictions(bool require_rev = false,
size_t minimum_key_strength = 80);
/**
* @param require_rev if true, revocation information is required
* @param minimum_key_strength is the minimum strength (in terms of
* operations, eg 80 means 2^80) of a signature. Signatures
* weaker than this are rejected.
* @param trusted_hashes a set of trusted hashes. Any signatures
* created using a hash other than one of these will be
* rejected.
*/
Path_Validation_Restrictions(bool require_rev,
size_t minimum_key_strength,
const std::set<std::string>& trusted_hashes) :
m_require_revocation_information(require_rev),
m_trusted_hashes(trusted_hashes),
m_minimum_key_strength(minimum_key_strength) {}
bool require_revocation_information() const
{ return m_require_revocation_information; }
const std::set<std::string>& trusted_hashes() const
{ return m_trusted_hashes; }
size_t minimum_key_strength() const
{ return m_minimum_key_strength; }
private:
bool m_require_revocation_information;
std::set<std::string> m_trusted_hashes;
size_t m_minimum_key_strength;
};
/**
* Represents the result of a PKIX path validation
*/
class BOTAN_DLL Path_Validation_Result
{
public:
/**
* X.509 Certificate Validation Result
*/
enum Code {
VERIFIED,
UNKNOWN_X509_ERROR,
CANNOT_ESTABLISH_TRUST,
CERT_CHAIN_TOO_LONG,
SIGNATURE_ERROR,
POLICY_ERROR,
INVALID_USAGE,
SIGNATURE_METHOD_TOO_WEAK,
UNTRUSTED_HASH,
CERT_MULTIPLE_ISSUERS_FOUND,
CERT_FORMAT_ERROR,
CERT_ISSUER_NOT_FOUND,
CERT_NOT_YET_VALID,
CERT_HAS_EXPIRED,
CERT_IS_REVOKED,
CRL_NOT_FOUND,
CRL_FORMAT_ERROR,
CRL_NOT_YET_VALID,
CRL_HAS_EXPIRED,
CA_CERT_CANNOT_SIGN,
CA_CERT_NOT_FOR_CERT_ISSUER,
CA_CERT_NOT_FOR_CRL_ISSUER
};
/**
* @return the set of hash functions you are implicitly
* trusting by trusting this result.
*/
std::set<std::string> trusted_hashes() const;
/**
* @return the trust root of the validation
*/
const X509_Certificate& trust_root() const;
/**
* @return the full path from subject to trust root
*/
const std::vector<X509_Certificate>& cert_path() const { return m_cert_path; }
/**
* @return true iff the validation was succesful
*/
bool successful_validation() const { return result() == VERIFIED; }
/**
* @return validation result code
*/
Code result() const { return m_result; }
/**
* @return string representation of the validation result
*/
std::string result_string() const;
private:
Path_Validation_Result() : m_result(UNKNOWN_X509_ERROR) {}
friend Path_Validation_Result x509_path_validate(
const std::vector<X509_Certificate>& end_certs,
const Path_Validation_Restrictions& restrictions,
const std::vector<Certificate_Store*>& certstores);
void set_result(Code result) { m_result = result; }
Code m_result;
std::vector<X509_Certificate> m_cert_path;
};
/**
* PKIX Path Validation
*/
Path_Validation_Result BOTAN_DLL x509_path_validate(
const std::vector<X509_Certificate>& end_certs,
const Path_Validation_Restrictions& restrictions,
const std::vector<Certificate_Store*>& certstores);
/**
* PKIX Path Validation
*/
Path_Validation_Result BOTAN_DLL x509_path_validate(
const X509_Certificate& end_cert,
const Path_Validation_Restrictions& restrictions,
const std::vector<Certificate_Store*>& certstores);
/**
* PKIX Path Validation
*/
Path_Validation_Result BOTAN_DLL x509_path_validate(
const X509_Certificate& end_cert,
const Path_Validation_Restrictions& restrictions,
const Certificate_Store& store);
/**
* PKIX Path Validation
*/
Path_Validation_Result BOTAN_DLL x509_path_validate(
const std::vector<X509_Certificate>& end_certs,
const Path_Validation_Restrictions& restrictions,
const Certificate_Store& store);
}
#endif
|