mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Get all the MD5 key generation/matching functional for the server/bridge. Also add an internal 1 minute timer to the bridge connections just to check/remove any broken connections as necessary.
This commit is contained in:
@@ -26,6 +26,10 @@ BridgeConnection::BridgeConnection(QObject *parent, QWebSocket *sock, QString ID
|
||||
idletimer->start();
|
||||
requestIdentify();
|
||||
QTimer::singleShot(30000, this, SLOT(checkAuth()));
|
||||
connCheckTimer = new QTimer(this);
|
||||
connCheckTimer->setInterval(60000); //every 1 minute
|
||||
connect(connCheckTimer, SIGNAL(timeout()), this, SLOT(checkConnection()) );
|
||||
connCheckTimer->start();
|
||||
}
|
||||
|
||||
BridgeConnection::~BridgeConnection(){
|
||||
@@ -49,6 +53,10 @@ bool BridgeConnection::isServer(){
|
||||
return serverconn;
|
||||
}
|
||||
|
||||
bool BridgeConnection::isActive(){
|
||||
return (SOCKET!=0 && SOCKET->isValid());
|
||||
}
|
||||
|
||||
QStringList BridgeConnection::validKeySums(){
|
||||
return knownkeys;
|
||||
}
|
||||
@@ -119,7 +127,7 @@ void BridgeConnection::HandleAPIMessage(QString msg){
|
||||
// - Return messages first (check ID)
|
||||
QString id = JM.value("id").toString();
|
||||
if(id=="sysadm_bridge_request_ident"){
|
||||
qDebug() << "Got ident reply:" << JM;
|
||||
//qDebug() << "Got ident reply:" << JM;
|
||||
serverconn = (JM.value("args").toObject().value("type").toString() == "server");
|
||||
}else if("bridge_request_list_keys"){
|
||||
QStringList keys = JsonArrayToStringList(JM.value("args").toObject().value("md5_keys").toArray());
|
||||
@@ -149,7 +157,7 @@ void BridgeConnection::HandleAPIMessage(QString msg){
|
||||
}else if(namesp == "rpc" && name=="auth_ssl"){
|
||||
if(!args.contains("encrypted_string")){
|
||||
//Stage 1 - send a random string to encrypt
|
||||
qDebug() << "Connection Auth Init:" << SockID;
|
||||
//qDebug() << "Connection Auth Init:" << SockID;
|
||||
QString key = AUTHSYSTEM->GenerateEncCheckString();
|
||||
QJsonObject obj; obj.insert("test_string", key);
|
||||
outargs = obj;
|
||||
@@ -173,7 +181,7 @@ void BridgeConnection::HandleAPIMessage(QString msg){
|
||||
//Valid auth - a couple more API calls available here
|
||||
|
||||
}else{
|
||||
out.insert("name","error"); //unknown API call
|
||||
out.insert("name","error"); //unkeys[i] << known API call
|
||||
}
|
||||
out.insert("args",outargs);
|
||||
SOCKET->sendTextMessage( QJsonDocument(out).toJson(QJsonDocument::Compact) );
|
||||
@@ -183,6 +191,12 @@ void BridgeConnection::HandleAPIMessage(QString msg){
|
||||
// =====================
|
||||
// PRIVATE SLOTS
|
||||
// =====================
|
||||
void BridgeConnection::checkConnection(){
|
||||
if(SOCKET==0 && !SOCKET->isValid()){
|
||||
emit SocketClosed(SockID);
|
||||
}
|
||||
}
|
||||
|
||||
void BridgeConnection::checkIdle(){
|
||||
if(SOCKET !=0){
|
||||
if(SOCKET->isValid()){
|
||||
@@ -260,7 +274,7 @@ void BridgeConnection::requestKeyList(){
|
||||
QJsonObject args;
|
||||
args.insert("action","list_ssl_checksums");
|
||||
obj.insert("args",args);
|
||||
qDebug() << "Request Key List";
|
||||
//qDebug() << "Request Key List";
|
||||
SOCKET->sendTextMessage( QJsonDocument(obj).toJson(QJsonDocument::Compact) );
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,12 @@ public:
|
||||
QString ID();
|
||||
void forwardMessage(QString msg);
|
||||
bool isServer();
|
||||
bool isActive();
|
||||
|
||||
QStringList validKeySums();
|
||||
|
||||
private:
|
||||
QTimer *idletimer;
|
||||
QTimer *idletimer, *connCheckTimer;
|
||||
QWebSocket *SOCKET;
|
||||
QString SockID, SockAuthToken, SockPeerIP;
|
||||
bool serverconn;
|
||||
@@ -36,6 +37,7 @@ private:
|
||||
void HandleAPIMessage(QString msg);
|
||||
|
||||
private slots:
|
||||
void checkConnection(); //Check if the connection was closed without announcement somehow
|
||||
void checkIdle(); //see if the currently-connected client is idle
|
||||
void checkAuth(); //see if the currently-connected client has authed yet
|
||||
void SocketClosing();
|
||||
|
||||
@@ -115,7 +115,7 @@ QString BridgeServer::generateID(QString name){
|
||||
void BridgeServer::NewSocketConnection(){
|
||||
BridgeConnection *sock = 0;
|
||||
if(this->hasPendingConnections()){
|
||||
qDebug() << "New incoming connection..";
|
||||
//qDebug() << "New incoming connection..";
|
||||
QWebSocket *ws = this->nextPendingConnection();
|
||||
if(allowConnection(ws->peerAddress()) ){
|
||||
QString name = ws->peerName();
|
||||
@@ -200,15 +200,16 @@ void BridgeServer::announceKeyChange(QString ID, bool isServer, QStringList keys
|
||||
QStringList IDs;
|
||||
for(int i=0; i<OpenSockets.length(); i++){
|
||||
if(i==c){ continue; } //current socket
|
||||
if(!OpenSockets[i]->isActive()){ continue; } //skip right now (probably waiting on a signal that the connection closed)
|
||||
else if(OpenSockets[i]->isServer() != server){ //look for a server/client pair
|
||||
//compare keys to look for matches
|
||||
/*QStringList chkkeys = OpenSockets[i ]->validKeySums();
|
||||
QStringList chkkeys = OpenSockets[i ]->validKeySums();
|
||||
chkkeys.removeDuplicates();
|
||||
qDebug() << "Known Keys for ID:" << OpenSockets[i]->ID() << chkkeys;
|
||||
//qDebug() << "Known Keys for ID:" << OpenSockets[i]->ID() << chkkeys;
|
||||
chkkeys << keys;
|
||||
if(chkkeys.removeDuplicates() > 0){ */
|
||||
if(chkkeys.removeDuplicates() > 0){
|
||||
IDs << OpenSockets[i]->ID();
|
||||
//}
|
||||
}
|
||||
}
|
||||
}//end inner loop of sockets
|
||||
OpenSockets[c]->announceIDAvailability(IDs);
|
||||
|
||||
@@ -142,10 +142,16 @@ void AuthorizationManager::ListCertificateChecksums(QJsonObject *out){
|
||||
keys.sort();
|
||||
QJsonArray arr;
|
||||
QCryptographicHash chash(QCryptographicHash::Md5);
|
||||
//qDebug() << "MD5 Generation:";
|
||||
for(int i=0; i<keys.length(); i++){
|
||||
chash.addData( keys[i].section("/",2,-1).toLocal8Bit() );
|
||||
//qDebug() << "User:" << keys[i].section("/",1,1);
|
||||
QByteArray key = QByteArray::fromBase64( keys[i].section("/",2,-1).toLocal8Bit() ); //remember that the keys are stored internally as base64-encoded strings
|
||||
//qDebug() << " - Key:" << key;
|
||||
chash.addData( key );
|
||||
QByteArray res = chash.result();
|
||||
//qDebug() << " - md5:" << res;
|
||||
chash.reset();
|
||||
//qDebug() << " - base64:" << res.toBase64();
|
||||
arr << QString(res.toBase64());
|
||||
}
|
||||
out->insert("md5_keys", arr);
|
||||
|
||||
Reference in New Issue
Block a user