void SMTPClientSession::loginUsingCRAM(const std::string& username, const std::string& method, Poco::DigestEngine& hmac) { std::string response; int status = sendCommand(std::string("AUTH ") + method, response); if (!isPositiveIntermediate(status)) throw SMTPException(std::string("Cannot authenticate using ") + method, response, status); std::string challengeBase64 = response.substr(4); std::istringstream istr(challengeBase64); Base64Decoder decoder(istr); std::string challenge; StreamCopier::copyToString(decoder, challenge); hmac.update(challenge); const DigestEngine::Digest& digest = hmac.digest(); std::string digestString(DigestEngine::digestToHex(digest)); std::string challengeResponse = username + " " + digestString; std::ostringstream challengeResponseBase64; Base64Encoder encoder(challengeResponseBase64); encoder.rdbuf()->setLineLength(0); encoder << challengeResponse; encoder.close(); status = sendCommand(challengeResponseBase64.str(), response); if (!isPositiveCompletion(status)) throw SMTPException(std::string("Login using ") + method + " failed", response, status); }
static CFDataRef createIVFromPassword(CFStringRef password) { CFDataRef hashedPassword, retval; CFMutableDataRef iv; if((hashedPassword = digestString(password)) == NULL) return NULL; iv = CFDataCreateMutableCopy(kCFAllocatorDefault, CFDataGetLength(hashedPassword)+1, hashedPassword); CFDataDeleteBytes(iv, CFRangeMake(IVBYTECOUNT, CFDataGetLength(iv)-IVBYTECOUNT)); retval = CFDataCreateCopy(kCFAllocatorDefault, iv); CFRelease(hashedPassword); CFRelease(iv); return retval; }
SwiftResult<int*>* Object::swiftCreateReplaceObject(const char* _data, ulong _size, bool _calculateETag, std::vector<HTTPHeader>* _uriParams, std::vector<HTTPHeader>* _reqMap) { //Check Container if (container == nullptr) return returnNullError<int*>("container"); //Path string path = container->getName() + "/" + name; /** * Check HTTP return code * 201: * Normal response code * * Error response codes: * timeout (408), * lengthRequired (411), * unprocessableEntity (422) */ vector<int> validHTTPCodes; validHTTPCodes.push_back(HTTPResponse::HTTP_CREATED); //Calculate ETag if requested bool shouldDelete = false; if (_calculateETag) { MD5Engine md5; md5.reset(); md5.update(_data, _size); string digestString(DigestEngine::digestToHex(md5.digest())); //Set Header if (_reqMap == nullptr) { _reqMap = new vector<HTTPHeader>(); shouldDelete = true; } HTTPHeader etagHeader("ETag", digestString); _reqMap->push_back(etagHeader); } //Do swift transaction SwiftResult<int*>* result = doSwiftTransaction<int*>( container->getAccount(), path, HTTPRequest::HTTP_PUT, _uriParams, _reqMap, &validHTTPCodes, _data, _size, nullptr); if (!shouldDelete) return result; else { delete _reqMap; return result; } }