aboutsummaryrefslogtreecommitdiffstats
path: root/src/cert/x509path/x509path.cpp
blob: d0153309c3ddc5bf410fb31a17cd40527fb70fd6 (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
45
46
47
/*
* X.509 Certificate Path Validation
* (C) 2010-2011 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#include <botan/x509path.h>
#include <botan/parsing.h>
#include <botan/pubkey.h>
#include <botan/oids.h>
#include <botan/time.h>
#include <algorithm>
#include <memory>

namespace Botan {

Path_Validation_Result x509_path_validate(
   const X509_Certificate& cert,
   const std::vector<Certificate_Store*>& certstores)
   {
   const X509_DN issuer_dn = cert.issuer_dn();
   const MemoryVector<byte> auth_key_id = cert.authority_key_id();

   Path_Validation_Result result;

   std::vector<X509_Certificate> cert_path;

   cert_path.push_back(cert);

   for(size_t i = 0; i != certstores.size(); ++i)
      {
      std::vector<X509_Certificate> got =
         certstores[i]->find_cert_by_subject_and_key_id(issuer_dn, auth_key_id);

      // What to do if it returns more than one match?
      if(got.size() == 1)
         {
         cert_path.push_back(got[0]);
         break;
         }
      }

   return result;
   }

}