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 else if (ct == "client")
63 return TLS_WEB_CLIENT;
64 else
65 throw option_error(ERR_INVALID_OPTION_CRYPTO, "remote-cert-tls must be 'client' or 'server'");
66}
67
68inline void remote_cert_tls(const std::string &ct,
69 std::vector<unsigned int> &ku,
70 std::string &eku)
71{
73}
74
75inline void remote_cert_tls(const OptionList &opt,
76 const std::string &relay_prefix,
77 std::vector<unsigned int> &ku,
78 std::string &eku)
79{
81 const Option *o = opt.get_ptr(relay_prefix + "remote-cert-tls");
82 if (o)
83 {
84 const std::string ct = o->get_optional(1, 16);
85 wt = remote_cert_type(ct);
86 }
87 remote_cert_tls(wt, ku, eku);
88}
89
90inline void remote_cert_ku(const OptionList &opt,
91 const std::string &relay_prefix,
92 std::vector<unsigned int> &ku)
93{
94 ku.clear();
95
96 const Option *o = opt.get_ptr(relay_prefix + "remote-cert-ku");
97 if (o)
98 {
99 if (o->empty())
100 throw option_error(ERR_INVALID_OPTION_CRYPTO, "remote-cert-ku: no hex values specified");
101 else if (o->size() >= 64)
102 throw option_error(ERR_INVALID_OPTION_CRYPTO, "remote-cert-ku: too many parameters");
103 else
104 {
105 try
106 {
107 for (size_t i = 1; i < o->size(); ++i)
108 ku.push_back(parse_hex_number<unsigned int>(o->get(i, 16)));
109 }
110 catch (parse_hex_error &)
111 {
112 throw option_error(ERR_INVALID_OPTION_CRYPTO, "remote-cert-ku: error parsing hex value list");
113 }
114 }
115 }
116}
117
118inline void remote_cert_eku(const OptionList &opt,
119 const std::string &relay_prefix,
120 std::string &eku)
121{
122 eku = "";
123
124 const Option *o = opt.get_ptr(relay_prefix + "remote-cert-eku");
125 if (o)
126 eku = o->get(1, 256);
127}
128} // namespace openvpn::KUParse
129
130#endif
const Option * get_ptr(const std::string &name) const
Definition options.hpp:1186
std::string get_optional(const size_t index, const size_t max_len) const
Definition options.hpp:194
const std::string & get(const size_t index, const size_t max_len) const
Definition options.hpp:187
size_t size() const
Definition options.hpp:327
bool empty() const
Definition options.hpp:331
void remote_cert_ku(const OptionList &opt, const std::string &relay_prefix, std::vector< unsigned int > &ku)
Definition kuparse.hpp:90
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:118