OpenVPN 3 Core Library
Loading...
Searching...
No Matches
kuparse.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12// Parse the remote-cert-tls, remote-cert-ku, and remote-cert-eku options.
13
14#ifndef OPENVPN_SSL_KUPARSE_H
15#define OPENVPN_SSL_KUPARSE_H
16
17#include <vector>
18#include <string>
19
24
32
33inline void remote_cert_tls(const TLSWebType wt, std::vector<unsigned int> &ku, std::string &eku)
34{
35 ku.clear();
36 eku = "";
37
38 switch (wt)
39 {
40 case TLS_WEB_NONE:
41 break;
42 case TLS_WEB_SERVER:
43 ku.clear();
44 ku.push_back(0xa0);
45 ku.push_back(0x88);
46 eku = "TLS Web Server Authentication";
47 break;
48 case TLS_WEB_CLIENT:
49 ku.clear();
50 ku.push_back(0x80);
51 ku.push_back(0x08);
52 ku.push_back(0x88);
53 eku = "TLS Web Client Authentication";
54 break;
55 }
56}
57
58inline TLSWebType remote_cert_type(const std::string &ct)
59{
60 if (ct == "server")
61 return TLS_WEB_SERVER;
62 if (ct == "client")
63 return TLS_WEB_CLIENT;
64 throw option_error(ERR_INVALID_OPTION_CRYPTO, "remote-cert-tls must be 'client' or 'server'");
65}
66
67inline void remote_cert_tls(const std::string &ct,
68 std::vector<unsigned int> &ku,
69 std::string &eku)
70{
72}
73
74inline void remote_cert_tls(const OptionList &opt,
75 const std::string &relay_prefix,
76 std::vector<unsigned int> &ku,
77 std::string &eku)
78{
80 const Option *o = opt.get_ptr(relay_prefix + "remote-cert-tls");
81 if (o)
82 {
83 const std::string ct = o->get_optional(1, 16);
84 wt = remote_cert_type(ct);
85 }
86 remote_cert_tls(wt, ku, eku);
87}
88
89inline void remote_cert_ku(const OptionList &opt,
90 const std::string &relay_prefix,
91 std::vector<unsigned int> &ku)
92{
93 ku.clear();
94
95 const Option *o = opt.get_ptr(relay_prefix + "remote-cert-ku");
96 if (o)
97 {
98 if (o->empty())
99 throw option_error(ERR_INVALID_OPTION_CRYPTO, "remote-cert-ku: no hex values specified");
100 if (o->size() >= 64)
101 throw option_error(ERR_INVALID_OPTION_CRYPTO, "remote-cert-ku: too many parameters");
102
103 try
104 {
105 for (size_t i = 1; i < o->size(); ++i)
106 ku.push_back(parse_hex_number<unsigned int>(o->get(i, 16)));
107 }
108 catch (parse_hex_error &)
109 {
110 throw option_error(ERR_INVALID_OPTION_CRYPTO, "remote-cert-ku: error parsing hex value list");
111 }
112 }
113}
114
115inline void remote_cert_eku(const OptionList &opt,
116 const std::string &relay_prefix,
117 std::string &eku)
118{
119 eku = "";
120
121 const Option *o = opt.get_ptr(relay_prefix + "remote-cert-eku");
122 if (o)
123 eku = o->get(1, 256);
124}
125} // namespace openvpn::KUParse
126
127#endif
const Option * get_ptr(const std::string &name) const
Definition options.hpp:1174
std::string get_optional(const size_t index, const size_t max_len) const
Definition options.hpp:191
const std::string & get(const size_t index, const size_t max_len) const
Definition options.hpp:184
size_t size() const
Definition options.hpp:320
bool empty() const
Definition options.hpp:324
void remote_cert_ku(const OptionList &opt, const std::string &relay_prefix, std::vector< unsigned int > &ku)
Definition kuparse.hpp:89
TLSWebType remote_cert_type(const std::string &ct)
Definition kuparse.hpp:58
void remote_cert_tls(const TLSWebType wt, std::vector< unsigned int > &ku, std::string &eku)
Definition kuparse.hpp:33
void remote_cert_eku(const OptionList &opt, const std::string &relay_prefix, std::string &eku)
Definition kuparse.hpp:115