OpenVPN 3 Core Library
Loading...
Searching...
No Matches
authcreds.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_AUTHCREDS
13#define OPENVPN_AUTH_AUTHCREDS
14
15#include <utility> // for std::move
16#include <string>
17
20#include <openvpn/common/rc.hpp>
25
26namespace openvpn {
27
28class AuthCreds : public RC<thread_unsafe_refcount>
29{
30 public:
32
33 AuthCreds(std::string &&username_arg,
34 SafeString &&password_arg,
35 const std::string &peer_info_str)
36 : username(std::move(username_arg)),
37 password(std::move(password_arg))
38 {
39 peer_info.parse_from_peer_info(peer_info_str, nullptr);
41 }
42
43 // for unit test
44 AuthCreds(std::string username_arg,
45 SafeString password_arg,
46 OptionList peer_info_arg)
47 : username(std::move(username_arg)),
48 password(std::move(password_arg)),
49 peer_info(std::move(peer_info_arg))
50 {
51 }
52
53 bool defined() const
54 {
55 return !username.empty();
56 }
57
63
64 bool is_valid(const bool strict) const
65 {
66 return defined() && is_valid_user_pass(strict);
67 }
68
70 {
71 password.wipe();
72 }
73
74 std::string to_string() const
75 {
76 std::ostringstream os;
77 os << "*** AuthCreds ***" << std::endl;
78 os << "user: '" << username << "'" << std::endl;
79 if (password.empty())
80 {
81 os << "pass: (empty)" << std::endl;
82 }
83 else
84 {
85 os << "pass: (non-empty)" << std::endl;
86 }
87 os << "peer info:" << std::endl;
89 return os.str();
90 }
91
92 std::string username;
95};
96
97} // namespace openvpn
98
99#endif
std::string to_string() const
Definition authcreds.hpp:74
bool defined() const
Definition authcreds.hpp:53
AuthCreds(std::string username_arg, SafeString password_arg, OptionList peer_info_arg)
Definition authcreds.hpp:44
bool is_valid(const bool strict) const
Definition authcreds.hpp:64
bool is_valid_user_pass(const bool strict) const
Definition authcreds.hpp:58
RCPtr< AuthCreds > Ptr
Definition authcreds.hpp:31
SafeString password
Definition authcreds.hpp:93
OptionList peer_info
Definition authcreds.hpp:94
std::string username
Definition authcreds.hpp:92
AuthCreds(std::string &&username_arg, SafeString &&password_arg, const std::string &peer_info_str)
Definition authcreds.hpp:33
void parse_from_peer_info(const std::string &str, Limits *lim)
Definition options.hpp:934
std::string render(const unsigned int flags) const
Definition options.hpp:1465
The smart pointer class.
Definition rc.hpp:119
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
Definition rc.hpp:912
A string-like type that clears the buffer contents on delete.
Definition safestr.hpp:27
bool empty() const
Definition safestr.hpp:74
static bool is_valid(const Type type, const STRING &cred, const bool strict)
std::ostringstream os