14#ifndef OPENVPN_AUTH_CR_H
15#define OPENVPN_AUTH_CR_H
62 if (!
is_dynamic(cookie) && cookie.find_first_of(
':') == std::string::npos)
71 void init(
const std::string &cookie)
73 using StringList = std::vector<std::string>;
76 Split::by_char_void<StringList, NullLex, Split::NullLimit>(sl, cookie,
':', 0, 4);
78 throw dynamic_challenge_parse_error();
80 throw dynamic_challenge_parse_error();
86 Split::by_char_void<StringList, NullLex, Split::NullLimit>(opt, sl[1],
',');
87 for (StringList::const_iterator i = opt.begin(); i != opt.end(); ++i)
104 catch (
const Base64::base64_decode_error &)
106 throw dynamic_challenge_parse_error();
115 return s.starts_with(
"CRV1:");
120 return s.starts_with(
"SCRV1:");
130 return "CRV1::" +
state_id +
"::" + response;
134 const std::string &response)
140 std::string &password,
141 std::string &response)
143 using StringList = std::vector<std::string>;
146 Split::by_char_void<StringList, NullLex, Split::NullLimit>(sl, cookie,
':');
148 throw static_challenge_parse_error();
149 if (sl[0] !=
"SCRV1")
150 throw static_challenge_parse_error();
157 catch (
const Base64::base64_decode_error &)
159 throw static_challenge_parse_error();
167 catch (
const Base64::base64_decode_error &)
169 throw static_challenge_parse_error();
175 const std::string &challenge,
179 std::ostringstream
os;
196 os <<
':' << session_token;
198 os <<
':' << challenge;
std::string encode(const V &data) const
size_t decode(void *data, size_t len, const std::string &str) const
static bool is_dynamic(const std::string &s)
std::string construct_dynamic_password(const std::string &response) const
ChallengeResponse(const std::string &cookie, const std::string &user)
const std::string & get_username() const
void init(const std::string &cookie)
static void parse_static_cookie(const std::string &cookie, std::string &password, std::string &response)
static std::string generate_dynamic_challenge(const std::string &session_token, const std::string &username, const std::string &challenge, const bool echo, const bool response_required)
static bool is_static(const std::string &s)
static std::string construct_static_password(const std::string &password, const std::string &response)
const std::string & get_state_id() const
std::string challenge_text
OPENVPN_SIMPLE_EXCEPTION(static_challenge_parse_error)
bool get_response_required() const
const std::string & get_challenge_text() const
static void validate_dynamic(const std::string &cookie)
OPENVPN_SIMPLE_EXCEPTION(dynamic_challenge_parse_error)
ChallengeResponse(const std::string &cookie)
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.