14#ifndef OPENVPN_AUTH_CR_H
15#define OPENVPN_AUTH_CR_H
63 if (!
is_dynamic(cookie) && cookie.find_first_of(
':') == std::string::npos)
72 void init(
const std::string &cookie)
74 typedef std::vector<std::string> StringList;
77 Split::by_char_void<StringList, NullLex, Split::NullLimit>(sl, cookie,
':', 0, 4);
79 throw dynamic_challenge_parse_error();
81 throw dynamic_challenge_parse_error();
87 Split::by_char_void<StringList, NullLex, Split::NullLimit>(opt, sl[1],
',');
88 for (StringList::const_iterator i = opt.begin(); i != opt.end(); ++i)
105 catch (
const Base64::base64_decode_error &)
107 throw dynamic_challenge_parse_error();
131 std::ostringstream
os;
132 os <<
"CRV1::" <<
state_id <<
"::" << response;
137 const std::string &response)
139 std::ostringstream
os;
145 std::string &password,
146 std::string &response)
148 typedef std::vector<std::string> StringList;
151 Split::by_char_void<StringList, NullLex, Split::NullLimit>(sl, cookie,
':');
153 throw static_challenge_parse_error();
154 if (sl[0] !=
"SCRV1")
155 throw static_challenge_parse_error();
162 catch (
const Base64::base64_decode_error &)
164 throw static_challenge_parse_error();
172 catch (
const Base64::base64_decode_error &)
174 throw static_challenge_parse_error();
180 const std::string &challenge,
184 std::ostringstream
os;
201 os <<
':' << session_token;
203 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)
RCPtr< ChallengeResponse > Ptr
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.
bool starts_with(const STRING &str, const std::string &prefix)