void SshKeyCreationDialog::saveKeys() { const QString parentDir = QFileInfo(privateKeyFilePath()).dir().path(); if (!QDir::root().mkpath(parentDir)) { QMessageBox::critical(this, tr("Cannot Save Key File"), tr("Failed to create directory: '%1'.").arg(parentDir)); return; } QFile privateKeyFile(privateKeyFilePath()); if (!privateKeyFile.open(QIODevice::WriteOnly) || !privateKeyFile.write(m_keyGenerator->privateKey())) { QMessageBox::critical(this, tr("Cannot Save Private Key File"), tr("The private key file could not be saved: %1").arg(privateKeyFile.errorString())); return; } QFile::setPermissions(privateKeyFilePath(), QFile::ReadOwner | QFile::WriteOwner); QFile publicKeyFile(publicKeyFilePath()); if (!publicKeyFile.open(QIODevice::WriteOnly) || !publicKeyFile.write(m_keyGenerator->publicKey())) { QMessageBox::critical(this, tr("Cannot Save Public Key File"), tr("The public key file could not be saved: %1").arg(publicKeyFile.errorString())); return; } accept(); }
void SshKeyCreationDialog::generateKeys() { if (SshSettings::keygenFilePath().isEmpty()) { showError(tr("The ssh-keygen tool was not found.")); return; } if (QFileInfo::exists(privateKeyFilePath())) { showError(tr("Refusing to overwrite existing private key file \"%1\".") .arg(QDir::toNativeSeparators(privateKeyFilePath()))); return; } const QString keyTypeString = QLatin1String(m_ui->rsa->isChecked() ? "rsa": "ecdsa"); QApplication::setOverrideCursor(Qt::BusyCursor); QProcess keygen; const QStringList args{"-t", keyTypeString, "-b", m_ui->comboBox->currentText(), "-N", QString(), "-f", privateKeyFilePath()}; QString errorMsg; keygen.start(SshSettings::keygenFilePath().toString(), args); keygen.closeWriteChannel(); if (!keygen.waitForStarted() || !keygen.waitForFinished()) errorMsg = keygen.errorString(); else if (keygen.exitCode() != 0) errorMsg = QString::fromLocal8Bit(keygen.readAllStandardError()); if (!errorMsg.isEmpty()) { showError(tr("The ssh-keygen tool at \"%1\" failed: %2") .arg(SshSettings::keygenFilePath().toUserOutput(), errorMsg)); } QApplication::restoreOverrideCursor(); accept(); }
bool SshKeyCreationDialog::userForbidsOverwriting() { if (!QFileInfo(privateKeyFilePath()).exists() && !QFileInfo(publicKeyFilePath()).exists()) return false; const QMessageBox::StandardButton reply = QMessageBox::question(this, tr("File Exists"), tr("There already is a file of that name. Do you want to overwrite it?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); return reply != QMessageBox::Yes; }
void SshKeyCreationDialog::setPrivateKeyFile(const QString &filePath) { m_ui->privateKeyFileValueLabel->setText(filePath); m_ui->generateButton->setEnabled(!privateKeyFilePath().isEmpty()); m_ui->publicKeyFileLabel->setText(filePath + QLatin1String(".pub")); }
bool MaemoPublishingUploadSettingsPageFremantleFree::isComplete() const { return !garageAccountName().isEmpty() && !privateKeyFilePath().isEmpty() && !serverName().isEmpty() && !directoryOnServer().isEmpty(); }
bool MaemoPublishingUploadSettingsPageFremantleFree::validatePage() { m_publisher->setSshParams(serverName(), garageAccountName(), privateKeyFilePath(), directoryOnServer()); return true; }