HttpOtpPostLogin::HttpOtpPostLogin(const char* buf, unsigned len, const UString& user_field, const UString& pin_field, const UString& token_field, const UString& passwd_field, const UString& cf_field, HttpHeader& header) { U_TRACE(5, "HttpOtpPostLogin::HttpOtpPostLogin(%.*S,%u,%.*S,%.*S,%.*S,%.*S,%p)", len, buf, len, U_STRING_TO_TRACE(user_field), U_STRING_TO_TRACE(pin_field), U_STRING_TO_TRACE(token_field), U_STRING_TO_TRACE(passwd_field), U_STRING_TO_TRACE(cf_field), &header) HttpField* f = header.find(U_STRING_FROM_CONSTANT("Content-Type")); U_INTERNAL_ASSERT_POINTER(f) U_INTERNAL_ASSERT(f->value.find("application/x-www-form-urlencoded") != unsigned(-1)) buffer.assign(buf, len); (void) U_VEC_SPLIT(vec, buffer, "=&"); // "user=stefano+casazza&pin=12345&token=autorizzativo" unsigned i = 0; while (i < vec.size()) { if (vec[i] == user_field) { U_STR_RESERVE(user, 64); Url::decode(vec[i+1], user); } else if (vec[i] == pin_field) { U_STR_RESERVE(pin, 64); Url::decode(vec[i+1], pin); } else if (vec[i] == token_field) { U_STR_RESERVE(token, 64); Url::decode(vec[i+1], token); } else if (vec[i] == passwd_field) { U_STR_RESERVE(passwd, 64); Url::decode(vec[i+1], passwd); } else if (vec[i] == cf_field) { U_STR_RESERVE(cf, 64); Url::decode(vec[i+1], cf); } i += 2; } }
OtpAuthToken::OtpAuthToken(CryptEngine* eng_, const UString& buf) { U_TRACE_REGISTER_OBJECT(5, OtpAuthToken, "%p,%.*S", eng_, U_STRING_TO_TRACE(buf)) eng = eng_; U_STR_RESERVE(buffer, 1000); long pos; unsigned char ptr[1000]; #ifdef U_PROXY_UNIT Base64engine eng1; pos = eng1.decode((unsigned char*)buf.data(), (long)buf.size(), ptr); pos = eng->decrypt(ptr, pos, (unsigned char*)buffer.data()); #else pos = u_base64_decode(U_STRING_TO_PARAM(buf), ptr); # ifdef USE_LIBSSL pos = u_des3_decode(ptr, pos, (unsigned char*)buffer.data()); # endif #endif U_STR_SIZE_ADJUST_FORCE(buffer, pos); migrate = false; valid = (memcmp(buffer.data(), U_CONSTANT_TO_PARAM("TID=")) == 0); timestamp = 0; if (valid) { unsigned n = U_VEC_SPLIT(vec, buffer, "=; \r\n"), i = 10; if (n < i) { valid = false; return; } U_INTERNAL_ASSERT(vec[0] == U_STRING_FROM_CONSTANT("TID")) tid = vec[1]; U_INTERNAL_ASSERT(vec[2] == U_STRING_FROM_CONSTANT("UID")) uid = vec[3]; U_INTERNAL_ASSERT(vec[4] == U_STRING_FROM_CONSTANT("SID")) sid = vec[5]; U_INTERNAL_ASSERT(vec[6] == U_STRING_FROM_CONSTANT("TS")) ts = vec[7]; U_INTERNAL_ASSERT(vec[8] == U_STRING_FROM_CONSTANT("CF")) cf = vec[9]; while (i < n) { if (vec[i] == U_STRING_FROM_CONSTANT("MIGRATE")) { migrate = true; ++i; } else { hp.push_back(vec[i]); ++i; if (i >= n) { valid = false; return; } hp.push_back(vec[i]); ++i; } } # ifdef U_STD_STRING char* _ptr = (char*) ts.c_str(); # else char* _ptr = ts.data(); # endif static struct tm tm; (void) strptime(_ptr, "%Y%m%d%H%M%S", &tm); timestamp = mktime(&tm); } }