blob: d9b170ef0192a24474376abb4f6687ee20738d65 (
plain)
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
|
/*
* Simple example of a certificate validation
* (C) 2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#include <botan/botan.h>
#include <botan/x509cert.h>
#include <botan/x509path.h>
#include <iostream>
using namespace Botan;
int main(int argc, char* argv[])
{
if(argc <= 2)
{
std::cout << "Usage: " << argv[0] << " subject.pem [CA certificates...]\n";
return 1;
}
LibraryInitializer init;
X509_Certificate subject_cert(argv[1]);
Certificate_Store_In_Memory certs;
for(size_t i = 2; argv[i]; ++i)
certs.add_certificate(X509_Certificate(argv[i]));
Path_Validation_Restrictions restrictions;
Path_Validation_Result result =
x509_path_validate(subject_cert,
restrictions,
certs);
if(result.successful_validation())
std::cout << "Certificate validated\n";
else
std::cout << "Certificate did not validate - " << result.result_string() << "\n";
return 0;
}
|