From 767bf82ec85ed3b2e049ae59e285cfd7c40e209e Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 19 Feb 2016 15:13:29 -0500 Subject: [PATCH] Finish fixing up the new auth_ssl option (lots of debugging still enabled). The SSL encode/decode systems still are not working yet - looks like an inherent incompatibility with a text-base transport system (JSON), so we will need to find another method (acting on a file and sending the hash instead?). --- src/server/AuthorizationManager.cpp | 11 ++++++-- src/server/WebSocket.cpp | 41 ++++++++++++++++------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/server/AuthorizationManager.cpp b/src/server/AuthorizationManager.cpp index 3cb65fe..92fb7d2 100644 --- a/src/server/AuthorizationManager.cpp +++ b/src/server/AuthorizationManager.cpp @@ -211,7 +211,7 @@ QString AuthorizationManager::GenerateEncCheckString(){ QString AuthorizationManager::LoginUC(QHostAddress host, QString encstring){ //Login w/ SSL certificate bool ok = false; - + qDebug() << "SSL Auth Attempt"; //First clean out any old strings/keys QStringList pubkeys = QStringList(HASH.keys()).filter("SSL_CHECK_STRING/"); //temporary, re-use variable below for(int i=0; iallKeys().filter("RegisteredCerts/"); //Format: "RegisteredCerts//" + qDebug() << " - Check pubkeys";// << pubkeys; for(int i=0; iclearAuth(SockAuthToken); //new auth requested - clear any old token - if(DEBUG){ qDebug() << "Authenticate Peer:" << SOCKET->peerAddress().toString(); } - //Now do the auth - if(out.in_struct.name=="auth" && out.in_struct.args.isObject() ){ + if(out.in_struct.name.startsWith("auth")){ + //Now perform authentication based on type of auth given + //Note: This sets/changes the current SockAuthToken + AUTHSYSTEM->clearAuth(SockAuthToken); //new auth requested - clear any old token + if(DEBUG){ qDebug() << "Authenticate Peer:" << SOCKET->peerAddress().toString(); } + //Now do the auth + if(out.in_struct.name=="auth" && out.in_struct.args.isObject() ){ //username/[password/cert] authentication QString user, pass; if(out.in_struct.args.toObject().contains("username")){ user = JsonValueToString(out.in_struct.args.toObject().value("username")); } @@ -160,21 +160,24 @@ if(out.in_struct.namesp.toLower() == "rpc"){ //Use the given password SockAuthToken = AUTHSYSTEM->LoginUP(host, user, pass); - }else if(out.in_struct.name=="auth_ssl" && out.in_struct.args.isObject() ){ - if(!out.in_struct.args.toObject().contains("encrypted_string")){ + }else if(out.in_struct.name=="auth_ssl"){ + if(out.in_struct.args.isObject() && out.in_struct.args.toObject().contains("encrypted_string")){ + //Stage 2: Check the returned encrypted/string + SockAuthToken = AUTHSYSTEM->LoginUC(host, JsonValueToString(out.in_struct.args.toObject().value("encrypted_string")) ); + }else{ //Stage 1: Send the client a random string to encrypt with their SSL key QString key = AUTHSYSTEM->GenerateEncCheckString(); QJsonObject obj; obj.insert("test_string", key); - out.CODE = RestOutputStruct::PARTIALCONTENT; - }else{ - //Stage 2: Check the returned encrypted/string - SockAuthToken = AUTHSYSTEM->LoginUC(host, JsonValueToString(out.in_struct.args.toObject().value("encrypted_string")) ); - } - }else if(out.in_struct.name == "auth_token" && out.in_struct.args.isObject()){ - SockAuthToken = JsonValueToString(out.in_struct.args.toObject().value("token")); - }else if(out.in_struct.name == "auth_clear"){ - return; //don't send a return message after clearing an auth (already done) - } + out.out_args = obj; + out.CODE = RestOutputStruct::OK; + this->sendReply(out.assembleMessage()); + return; + } + }else if(out.in_struct.name == "auth_token" && out.in_struct.args.isObject()){ + SockAuthToken = JsonValueToString(out.in_struct.args.toObject().value("token")); + }else if(out.in_struct.name == "auth_clear"){ + return; //don't send a return message after clearing an auth (already done) + } //Now check the auth and respond appropriately if(AUTHSYSTEM->checkAuth(SockAuthToken)){