Skip to content

Commit

Permalink
#387 fix race condition of cert not available on first launch for DTLS
Browse files Browse the repository at this point in the history
  • Loading branch information
dannagle committed Oct 23, 2024
1 parent efbabf8 commit 35758be
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 46 deletions.
45 changes: 43 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ void myMessageOutputDisable(QtMsgType type, const QMessageLogContext &context, c

int main(int argc, char *argv[])
{
QSettings settings(SETTINGSFILE, QSettings::IniFormat);
settings.setValue("leaveSessionOpen", "false");
int debugMode = DEBUGMODE;

if (QFile::exists("DEBUGMODE")) {
Expand Down Expand Up @@ -168,6 +166,49 @@ int main(int argc, char *argv[])

}

//Create the settings folders if they do not exist
QDir mdir;
mdir.mkpath(TEMPPATH);
mdir.mkpath(SETTINGSPATH);


//this is stored as base64 so smart git repos
//do not complain about shipping a private key.
QFile snakeoilKey("://ps.key.base64");
QFile snakeoilCert("://ps.pem.base64");


QString defaultCertFile = CERTFILE;
QString defaultKeyFile = KEYFILE;

QFile certfile(defaultCertFile);
QFile keyfile(defaultKeyFile);
QByteArray decoded;
decoded.clear();

if (!certfile.exists()) {
if (snakeoilCert.open(QFile::ReadOnly)) {
decoded = QByteArray::fromBase64(snakeoilCert.readAll());
snakeoilCert.close();
}
if (certfile.open(QFile::WriteOnly)) {
certfile.write(decoded);
certfile.close();
}
}

if (!keyfile.exists()) {
if (snakeoilKey.open(QFile::ReadOnly)) {
decoded = QByteArray::fromBase64(snakeoilKey.readAll());
snakeoilKey.close();
}
if (keyfile.open(QFile::WriteOnly)) {
keyfile.write(decoded);
keyfile.close();
}
}




#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
Expand Down
44 changes: 0 additions & 44 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,50 +449,6 @@ MainWindow::MainWindow(QWidget *parent) :
}


//Now that the UI is loaded, create the settings folders if they do not exist
QDir mdir;
mdir.mkpath(TEMPPATH);
mdir.mkpath(SETTINGSPATH);



//this is stored as base64 so smart git repos
//do not complain about shipping a private key.
QFile snakeoilKey("://ps.key.base64");
QFile snakeoilCert("://ps.pem.base64");


QString defaultCertFile = CERTFILE;
QString defaultKeyFile = KEYFILE;

QFile certfile(defaultCertFile);
QFile keyfile(defaultKeyFile);
QByteArray decoded;
decoded.clear();

if (!certfile.exists()) {
if (snakeoilCert.open(QFile::ReadOnly)) {
decoded = QByteArray::fromBase64(snakeoilCert.readAll());
snakeoilCert.close();
}
if (certfile.open(QFile::WriteOnly)) {
certfile.write(decoded);
certfile.close();
}
}

if (!keyfile.exists()) {
if (snakeoilKey.open(QFile::ReadOnly)) {
decoded = QByteArray::fromBase64(snakeoilKey.readAll());
snakeoilKey.close();
}
if (keyfile.open(QFile::WriteOnly)) {
keyfile.write(decoded);
keyfile.close();
}
}


updateManager(QByteArray());

//on_actionExport_Packets_JSON_triggered();
Expand Down

0 comments on commit 35758be

Please sign in to comment.