diff options
author | fireice-uk <fireice-uk@users.noreply.github.com> | 2017-11-10 19:14:29 +0000 |
---|---|---|
committer | psychocrypt <psychocrypt@users.noreply.github.com> | 2017-11-10 20:14:29 +0100 |
commit | 7942372e218568f8b27446115cfbb743f7cabf6c (patch) | |
tree | 3e658ac8b856fe4b78f8b808d059cfadc2776496 /xmrstak/http | |
parent | d35893d926c74893d7c85d1b87b24ffa55744649 (diff) | |
download | xmr-stak-7942372e218568f8b27446115cfbb743f7cabf6c.zip xmr-stak-7942372e218568f8b27446115cfbb743f7cabf6c.tar.gz |
Add HTTP Digest auth (#98)
Diffstat (limited to 'xmrstak/http')
-rw-r--r-- | xmrstak/http/httpd.cpp | 26 | ||||
-rw-r--r-- | xmrstak/http/webdesign.cpp | 11 | ||||
-rw-r--r-- | xmrstak/http/webdesign.hpp | 6 |
3 files changed, 42 insertions, 1 deletions
diff --git a/xmrstak/http/httpd.cpp b/xmrstak/http/httpd.cpp index a112bbb..8debfa7 100644 --- a/xmrstak/http/httpd.cpp +++ b/xmrstak/http/httpd.cpp @@ -62,8 +62,32 @@ int httpd::req_handler(void * cls, if (strcmp(method, "GET") != 0) return MHD_NO; - *ptr = nullptr; + if(strlen(jconf::inst()->GetHttpUsername()) != 0) + { + char* username; + int ret; + + username = MHD_digest_auth_get_username(connection); + if (username == NULL) + { + rsp = MHD_create_response_from_buffer(sHtmlAccessDeniedSize, (void*)sHtmlAccessDenied, MHD_RESPMEM_PERSISTENT); + ret = MHD_queue_auth_fail_response(connection, sHttpAuthRelam, sHttpAuthOpaque, rsp, MHD_NO); + MHD_destroy_response(rsp); + return ret; + } + free(username); + ret = MHD_digest_auth_check(connection, sHttpAuthRelam, jconf::inst()->GetHttpUsername(), jconf::inst()->GetHttpPassword(), 300); + if (ret == MHD_INVALID_NONCE || ret == MHD_NO) + { + rsp = MHD_create_response_from_buffer(sHtmlAccessDeniedSize, (void*)sHtmlAccessDenied, MHD_RESPMEM_PERSISTENT); + ret = MHD_queue_auth_fail_response(connection, sHttpAuthRelam, sHttpAuthOpaque, rsp, (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); + MHD_destroy_response(rsp); + return ret; + } + } + + *ptr = nullptr; std::string str; if(strcasecmp(url, "/style.css") == 0) { diff --git a/xmrstak/http/webdesign.cpp b/xmrstak/http/webdesign.cpp index c6fcea6..1cb76c3 100644 --- a/xmrstak/http/webdesign.cpp +++ b/xmrstak/http/webdesign.cpp @@ -90,6 +90,17 @@ extern const char sHtmlCssFile [] = size_t sHtmlCssSize = sizeof(sHtmlCssFile) - 1; +extern const char sHttpAuthRelam[] = "XMR-Stak-Miner"; +extern const char sHttpAuthOpaque[] = "6c071f0df539e234cadbcd79164af7a594e23ab42bccb834df796aead6ce96e4"; + +extern const char sHtmlAccessDenied[] = + "<!DOCTYPE html><html>" + "<head><title>Access Denied</title></head>" + "<body><h1>Access Denied</h1><p>You have entered a wrong username or password</p></body>" + "</html>"; + +size_t sHtmlAccessDeniedSize = sizeof(sHtmlAccessDenied) - 1; + extern const char sHtmlCommonHeader [] = "<!DOCTYPE html>" "<html>" diff --git a/xmrstak/http/webdesign.hpp b/xmrstak/http/webdesign.hpp index 92639a0..122b5fb 100644 --- a/xmrstak/http/webdesign.hpp +++ b/xmrstak/http/webdesign.hpp @@ -4,6 +4,12 @@ extern const char sHtmlCssEtag[]; extern const char sHtmlCssFile[]; extern size_t sHtmlCssSize; +extern const char sHtmlAccessDenied[]; +extern size_t sHtmlAccessDeniedSize; + +extern const char sHttpAuthRelam[]; +extern const char sHttpAuthOpaque[]; + extern const char sHtmlCommonHeader[]; extern const char sHtmlHashrateBodyHigh[]; |