Commit 56ab1af5 authored by Dorian Zedler's avatar Dorian Zedler

added the ability to perform a software update via the socket api (see command 5000)

parent 1965a0a1
......@@ -436,6 +436,8 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient,
// init session
socketClient->sessionActive = true;
socketClient->updateSubscriptions = requestData["updateSubs"].toVariant().toStringList();
socketClient->usingTerminationKeys = requestData["usingTerminationKeys"].toBool();
qDebug() << "set update subs to: " << socketClient->updateSubscriptions;
replyHeader = 200;
......@@ -718,6 +720,77 @@ void MainActivity::handleSocketCommand(SocketServer::socketClient *socketClient,
break;
}
case 5000: {
if(this->state != IDLE){
replyHeader = 900;
break;
}
QByteArray pub, priv;
QRSAEncryption e;
// this is the public key of the offical Itsblue Development software team.
pub = QByteArray::fromBase64( "PyPKhbWPzphCjVh3dTXp2Jc5OQ5vEKBRPLTDr2jkzntjVKWJAhlDYysjJQLidERo/1qk5qbATyc4ygwc/MGvfw==" );
// check the signature of the update
QString signedMessage = requestData.toString();
if (!e.checkSignMessage(signedMessage.toUtf8(), pub)) {
replyHeader = 401;
break;
}
// message signed success
qDebug() << "[INFO][MAIN] update signature valid ...";
QString newFirmwareVersion = signedMessage.split("<VER>")[1].split("</VER>")[0];
int newFirmwareVersionMajor = newFirmwareVersion.split(".")[0].toInt();
int newFirmwareVersionMinor = newFirmwareVersion.split(".")[1].toInt();
int newFirmwareVersionPatch = newFirmwareVersion.split(".")[2].toInt();
QString currentFirmwareVersion = APP_VERSION;
int currentFirmwareVersionMajor = currentFirmwareVersion.split(".")[0].toInt();
int currentFirmwareVersionMinor = currentFirmwareVersion.split(".")[1].toInt();
int currentFirmwareVersionPatch = currentFirmwareVersion.split(".")[2].toInt();
if (newFirmwareVersionMajor < currentFirmwareVersionMajor || newFirmwareVersionMinor < currentFirmwareVersionMinor || newFirmwareVersionPatch <= currentFirmwareVersionPatch ) {
// the firmware is already up-to-date
qDebug() << "[INFO][MAIN] ... already up-to-date!";
replyHeader = 304;
break;
}
qDebug() << "[INFO][MAIN] UPDATE ACCEPTED new Version is: " << newFirmwareVersion;
// send a reply to the client
// insert the data into the reply object
replyObj.insert("id", requestId);
replyObj.insert("header", 200);
replyObj.insert("data", replyData);
QJsonDocument jsonReply(replyObj);
// send the reply back to the client
this->socketServer->sendToClient(socket, jsonReply.toJson());
// perform the actual update
QString newFirmwareString = signedMessage.split("<BIN>")[1].split("</BIN>")[0];
//qDebug() << newFirmwareString;
QFile newFile(qApp->applicationFilePath() + "-update.zip");
newFile.open(QFile::WriteOnly);
newFile.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ReadUser | QFileDevice::WriteUser);
newFile.write( QByteArray::fromBase64( newFirmwareString.toUtf8() ));
// trigger a reboot
qDebug() << "[INFO][MAIN] UPDATE extracted, rebooting now ";
qApp->exit(1020);
return;
}
default:
replyHeader = 404;
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment