OpenVPN 3 Core Library
Loading...
Searching...
No Matches
validatecreds.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
#ifndef OPENVPN_AUTH_VALIDATE_CREDS_H
13
#define OPENVPN_AUTH_VALIDATE_CREDS_H
14
15
#include <
openvpn/common/unicode.hpp
>
16
17
// Validate authentication credential.
18
// Must be UTF-8.
19
// Other checks on size and content below.
20
// We don't check that the credential is non-empty.
21
namespace
openvpn::ValidateCreds
{
22
23
enum
Type
24
{
25
USERNAME
,
26
PASSWORD
,
27
RESPONSE
28
};
29
30
template
<
typename
STRING>
31
static
bool
is_valid
(
const
Type
type,
const
STRING &cred,
const
bool
strict)
32
{
33
size_t
max_len_flags;
34
if
(strict)
35
{
36
// length <= 512 unicode chars, no control chars allowed
37
max_len_flags = 512 |
Unicode::UTF8_NO_CTRL
;
38
}
39
else
40
{
41
switch
(type)
42
{
43
case
USERNAME
:
44
// length <= 512 unicode chars, no control chars allowed
45
max_len_flags = 512 |
Unicode::UTF8_NO_CTRL
;
46
break
;
47
case
PASSWORD
:
48
case
RESPONSE
:
49
// length <= 16384 unicode chars
50
max_len_flags = 16384;
51
break
;
52
default
:
53
return
false
;
54
}
55
}
56
return
Unicode::is_valid_utf8
(cred, max_len_flags);
57
}
58
}
// namespace openvpn::ValidateCreds
59
60
#endif
unicode.hpp
openvpn::Unicode::is_valid_utf8
bool is_valid_utf8(const STRING &str, const size_t max_len_flags=0)
Definition
unicode.hpp:75
openvpn::Unicode::UTF8_NO_CTRL
@ UTF8_NO_CTRL
Definition
unicode.hpp:38
openvpn::ValidateCreds
Definition
validatecreds.hpp:21
openvpn::ValidateCreds::is_valid
static bool is_valid(const Type type, const STRING &cred, const bool strict)
Definition
validatecreds.hpp:31
openvpn::ValidateCreds::Type
Type
Definition
validatecreds.hpp:24
openvpn::ValidateCreds::PASSWORD
@ PASSWORD
Definition
validatecreds.hpp:26
openvpn::ValidateCreds::RESPONSE
@ RESPONSE
Definition
validatecreds.hpp:27
openvpn::ValidateCreds::USERNAME
@ USERNAME
Definition
validatecreds.hpp:25
openvpn
auth
validatecreds.hpp
Generated by
1.9.8