Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue whereby H2 encoding ignores method and defaults to HTTP_GET #199 #202

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/PsychicRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static const String md5str(const String &in){
return md5.toString();
}

bool PsychicRequest::authenticate(const char * username, const char * password)
bool PsychicRequest::authenticate(const char * username, const char * password, bool passwordIsHashed)
{
if(hasHeader("Authorization"))
{
Expand Down Expand Up @@ -420,21 +420,29 @@ bool PsychicRequest::authenticate(const char * username, const char * password)
_cnonce = _extractParam(authReq, F("cnonce=\""),'\"');
}

String _H1 = md5str(String(username) + ':' + _realm + ':' + String(password));

String _H1 = passwordIsHashed ? String(password) : md5str(String(username) + ':' + _realm + ':' + String(password));
//ESP_LOGD(PH_TAG, "Hash of user:realm:pass=%s", _H1.c_str());

String _H2 = "";
if(_method == HTTP_GET){
switch(method()) {
case HTTP_GET:
_H2 = md5str(String(F("GET:")) + _uri);
}else if(_method == HTTP_POST){
break;
case HTTP_POST:
_H2 = md5str(String(F("POST:")) + _uri);
}else if(_method == HTTP_PUT){
break;
case HTTP_PUT:
_H2 = md5str(String(F("PUT:")) + _uri);
}else if(_method == HTTP_DELETE){
break;
case HTTP_DELETE:
_H2 = md5str(String(F("DELETE:")) + _uri);
}else{
break;
default:
_H2 = md5str(String(F("GET:")) + _uri);
break;
}

//ESP_LOGD(PH_TAG, "Hash of GET:uri=%s", _H2.c_str());

String _responsecheck = "";
Expand Down Expand Up @@ -504,7 +512,7 @@ esp_err_t PsychicRequest::requestAuthentication(HTTPAuthMethod mode, const char*

response.setCode(401);
response.setContentType("text/html");
response.setContent(authStr.c_str());
response.setContent(authFailMsg);
return response.send();
}

Expand Down Expand Up @@ -539,4 +547,4 @@ esp_err_t PsychicRequest::reply(int code, const char *contentType, const char *c
response.setContent(content);

return response.send();
}
}
4 changes: 2 additions & 2 deletions src/PsychicRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PsychicRequest {

const String getFilename();

bool authenticate(const char * username, const char * password);
bool authenticate(const char * username, const char * password, bool passwordIsHashed = false);
esp_err_t requestAuthentication(HTTPAuthMethod mode, const char* realm, const char* authFailMsg);

esp_err_t redirect(const char *url);
Expand All @@ -95,4 +95,4 @@ class PsychicRequest {
esp_err_t reply(int code, const char *contentType, const char *content);
};

#endif // PsychicRequest_h
#endif // PsychicRequest_h
Loading