diff --git a/src/cpp/Crypto/KeyPair.cpp b/src/cpp/Crypto/KeyPair.cpp index 82dc46286..3f56d3d6a 100644 --- a/src/cpp/Crypto/KeyPair.cpp +++ b/src/cpp/Crypto/KeyPair.cpp @@ -3,6 +3,11 @@ #include #include +#include "../SingletonManager/ErrorManager.h" +#include "../SingletonManager/ConnectionManager.h" + +using namespace Poco::Data::Keywords; + #define STR_BUFFER_SIZE 25 @@ -88,4 +93,40 @@ bool KeyPair::generateFromPassphrase(const char* passphrase, Mnemonic* word_sour // using return true; +} + +std::string KeyPair::getPubkeyHex() +{ + size_t hexSize = crypto_sign_PUBLICKEYBYTES * 2 + 1; + char* hexString = (char*)malloc(hexSize); + memset(hexString, 0, hexSize); + sodium_bin2hex(hexString, hexSize, mSodiumPublic, crypto_sign_PUBLICKEYBYTES); + std::string pubHex = hexString; + free(hexString); + + return pubHex; +} + +bool KeyPair::savePrivKey(int userId) +{ + auto cm = ConnectionManager::getInstance(); + auto em = ErrorManager::getInstance(); + Poco::Data::Statement update(cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER)); + Poco::Data::BLOB privkey_blob((const unsigned char*)(*mPrivateKey), mPrivateKey->size()); + + update << "UPDATE users set privkey = ? where id = ?", + use(privkey_blob), use(userId); + + try { + if (update.execute() != 1) { + em->addError(new ParamError("KeyPair::savePrivKey", "error writing privkey, user not found? ", std::to_string(userId))); + em->sendErrorsAsEmail(); + return false; + } + } catch (Poco::Exception& ex) { + em->addError(new ParamError("KeyPair::savePrivKey", "exception by running mysql", ex.displayText())); + em->sendErrorsAsEmail(); + return false; + } + return true; } \ No newline at end of file diff --git a/src/cpp/Crypto/KeyPair.h b/src/cpp/Crypto/KeyPair.h index f294e9b05..3c1068fdf 100644 --- a/src/cpp/Crypto/KeyPair.h +++ b/src/cpp/Crypto/KeyPair.h @@ -14,6 +14,8 @@ public: ~KeyPair(); bool generateFromPassphrase(const char* passphrase, Mnemonic* word_source); + std::string getPubkeyHex(); + bool savePrivKey(int userId); protected: diff --git a/src/cpp/HTTPInterface/CheckEmailPage.cpp b/src/cpp/HTTPInterface/CheckEmailPage.cpp index 0234b76ad..4f7a50437 100644 --- a/src/cpp/HTTPInterface/CheckEmailPage.cpp +++ b/src/cpp/HTTPInterface/CheckEmailPage.cpp @@ -7,17 +7,7 @@ #line 7 "I:\\Code\\C++\\Eigene_Projekte\\Gradido_LoginServer\\src\\cpsp\\checkEmail.cpsp" -#include "../SingletonManager/SessionManager.h" -#include "../model/User.h" -#include "Poco/Net/HTTPCookie.h" -enum PageState -{ - PAGE_VERIFICATION_FAILED, - PAGE_ASK_PASSPHRASE, - PAGE_SHOW_PASSPHRASE, - PAGE_ASK_VERIFICATION_CODE -}; CheckEmailPage::CheckEmailPage(Session* arg): @@ -34,74 +24,14 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: if (_compressResponse) response.set("Content-Encoding", "gzip"); Poco::Net::HTMLForm form(request, request.stream()); -#line 20 "I:\\Code\\C++\\Eigene_Projekte\\Gradido_LoginServer\\src\\cpsp\\checkEmail.cpsp" +#line 10 "I:\\Code\\C++\\Eigene_Projekte\\Gradido_LoginServer\\src\\cpsp\\checkEmail.cpsp" - auto sm = SessionManager::getInstance(); bool hasErrors = false; - unsigned long long verificationCode = 0; - PageState state = PAGE_ASK_PASSPHRASE; - std::string uri = request.getURI(); - //printf("uri: %s\n", uri.data()); - - if(!form.empty()) { - try { - verificationCode = stoll(form.get("email-verification-code", "0")); - } catch(...) {} - } - if(!verificationCode) { - size_t pos = uri.find_last_of("/"); - try { - verificationCode = stoll(uri.substr(pos+1)); - } catch(...) {} - } - if(!verificationCode) { - state = PAGE_ASK_VERIFICATION_CODE; - } else { - // no session - if(!mSession || mSession->getEmailVerificationCode() != verificationCode) { - mSession = sm->findByEmailVerificationCode(verificationCode); - } - // no session in server, load from db - if(!mSession) { - mSession = sm->getNewSession(); - if(mSession->loadFromEmailVerificationCode(verificationCode)) { - auto cookie_id = mSession->getHandle(); - auto user_host = request.clientAddress().host(); - mSession->setClientIp(user_host); - response.addCookie(Poco::Net::HTTPCookie("user", std::to_string(cookie_id))); - } else { - sm->releseSession(mSession); - mSession = nullptr; - state = PAGE_VERIFICATION_FAILED; - } - } - if(mSession) { - mSession->updateEmailVerification(verificationCode); - hasErrors = mSession->errorCount() > 0; - - if(!hasErrors && !form.empty()) { - auto registerKeyChoice = form.get("register-key", ""); - std::string oldPassphrase = ""; - if(registerKeyChoice == "no") { - auto oldPassphrase = form.get("register-key-existing", ""); - - if(oldPassphrase != "" && User::validatePassphrase(oldPassphrase)) { - // passphrase is valid - mSession->setPassphrase(oldPassphrase); - mSession->updateState(SESSION_STATE_PASSPHRASE_SHOWN); - state = PAGE_SHOW_PASSPHRASE; - } else { - mSession->addError(new Error("Merkspruch", "Dieser Merkspruch ist ungültig, bitte überprüfen oder neu generieren (lassen).")); - } - } else if(registerKeyChoice == "yes") { - mSession->generatePassphrase(); - state = PAGE_SHOW_PASSPHRASE; - } - } - } else { - state = PAGE_VERIFICATION_FAILED; - } + if(mSession) { + hasErrors = mSession->errorCount() > 0; } + + std::ostream& _responseStream = response.send(); Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1); std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream; @@ -111,7 +41,7 @@ void CheckEmailPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: responseStream << "\n"; responseStream << "\n"; responseStream << "\n"; - responseStream << "Gradido Login Server: Email OptIn\n"; + responseStream << "Gradido Login Server: Email Verification\n"; responseStream << "\n"; responseStream << "\n"; responseStream << " + + +
+ <% if(mSession && hasErrors) {%> + <%= mSession->getErrorsHtml() %> + <%} %> +

Einen neuen Account anlegen

+ <% if(state == PAGE_SHOW_PASSPHRASE) {%> +
+
+ Schreibe dir den Merkspruch auf und packe ihn gut weg. Du brauchst ihn um deine Adresse wiederherzustellen. Wenn du ihn verlierst, sind auch deine Gradidos verloren. +
+
+ <%= mSession->getPassphrase() %> +
+ Weiter +
+ <% } else if(state == PAGE_ASK_PASSPHRASE) { %> +
+
+ Neue Gradido Adresse anlegen / wiederherstellen +

Hast du schonmal ein Gradido Konto besessen?

+

+ + +

+

+ + +

+ +
+ + +
+ <% } else { %> +
+ Ungültige Seite, wenn du das siehst stimmt hier etwas nicht. Bitte wende dich an den Server-Admin. +
+ <% } %> +
+ + diff --git a/src/cpsp/register.cpsp b/src/cpsp/register.cpsp index c01c3009b..f1f351447 100644 --- a/src/cpsp/register.cpsp +++ b/src/cpsp/register.cpsp @@ -56,11 +56,6 @@ label:not(.grd_radio_label) {
Deine Anmeldung wird verarbeitet und es wird dir eine E-Mail zugeschickt. Wenn sie da ist, befolge ihren Anweisungen. - Möchtest du wissen ob die E-Mail schon verschickt wurde? - Dann klicke einfach hier: -
- -
<% } else { %> diff --git a/src/cpsp/saveKeys.cpsp b/src/cpsp/saveKeys.cpsp index 1d2d8fdd7..0edbd3b98 100644 --- a/src/cpsp/saveKeys.cpsp +++ b/src/cpsp/saveKeys.cpsp @@ -5,16 +5,42 @@ <%@ page form="true" %> <%@ page compressed="true" %> <%! - -#include "../model/Session.h" - + enum PageState { + PAGE_ASK, + PAGE_SHOW_PUBKEY + } %> <%% bool hasErrors = mSession->errorCount() > 0; bool hasPassword = mSession->getUser()->hasCryptoKey(); + PageState state = PAGE_ASK; if(!form.empty()) { + // privkey + auto savePrivkeyChoice = form.get("save-privkey"); + bool savePrivkey = false; + if(savePrivkeyChoice == "yes") { + if(!hasPassword) { + // check pwd + auto pwd = form.get("save-privkey-password", ""); + if(!mSession->getUser()->validatePwd(pwd)) { + mSession->addError(new Error("Passwort", "Das Passwort stimmt nicht. Bitte verwende dein Passwort von der Registrierung")); + hasErrors = true; + } else { + savePrivkey = true; + } + } else { + savePrivkey = true; + } + } + if(!hasErrors) { + auto savePassphraseChoice = form.get("save-passphrase"); + bool savePassphrase = false; + if(savePassphraseChoice == "yes") { + savePassphrase = true; + } + } } %> @@ -41,6 +67,7 @@ label:not(.grd_radio_label) { <%= mSession->getErrorsHtml() %> <%} %>

Daten speichern

+ <% if(state == PAGE_ASK) { %>
Gradido Private Key speichern @@ -82,6 +109,9 @@ label:not(.grd_radio_label) {
+ <% } else if(state == PAGE_SHOW_PUBKEY) { %> + + <% } %>