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
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.
22
29
30template <typename STRING>
31static 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
bool is_valid_utf8(const STRING &str, const size_t max_len_flags=0)
Definition unicode.hpp:75
static bool is_valid(const Type type, const STRING &cred, const bool strict)