Commit ba1d8e2c authored by Christian Strømme's avatar Christian Strømme Committed by Christian Stromme

Android: Improve the Keystore and Certificate dialog.

- Display all information in one place.
- Checkbox to enable the certificate to use the same password as the
  Keystore.
- Display information when alias field is empty.
- Misc. layout changes.

Task-number: QTCREATORBUG-10061
Change-Id: I99a3e7019dfbf72bcd2374594f3ebe45c26680d2
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarBogDan Vatra <bogdan@kde.org>
parent e90633a8
......@@ -46,6 +46,8 @@ AndroidCreateKeystoreCertificate::AndroidCreateKeystoreCertificate(QWidget *pare
connect(ui->keystoreRetypePassLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkKeystorePassword()));
connect(ui->certificatePassLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkCertificatePassword()));
connect(ui->certificateRetypePassLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkCertificatePassword()));
connect(ui->certificateAliasLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkCertificateAlias()));
connect(ui->countryLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkCountryCode()));
}
AndroidCreateKeystoreCertificate::~AndroidCreateKeystoreCertificate()
......@@ -65,42 +67,71 @@ QString AndroidCreateKeystoreCertificate::keystorePassword()
QString AndroidCreateKeystoreCertificate::certificateAlias()
{
return ui->aliasNameLineEdit->text();
return ui->certificateAliasLineEdit->text();
}
QString AndroidCreateKeystoreCertificate::certificatePassword()
{
return ui->certificatePassLineEdit->text();
return (ui->samePasswordCheckBox->checkState() == Qt::Checked)
? keystorePassword()
: ui->certificatePassLineEdit->text();
}
AndroidCreateKeystoreCertificate::PasswordStatus AndroidCreateKeystoreCertificate::checkKeystorePassword()
{
if (ui->keystorePassLineEdit->text().length() < 6) {
ui->keystorePassInfoLabel->setText(tr("<span style=\" color:#ff0000;\">Password is too short</span>"));
ui->infoLabel->setText(tr("<span style=\" color:#ff0000;\">Keystore password is too short</span>"));
return Invalid;
}
if (ui->keystorePassLineEdit->text() != ui->keystoreRetypePassLineEdit->text()) {
ui->keystorePassInfoLabel->setText(tr("<span style=\" color:#ff0000;\">Passwords don't match</span>"));
ui->infoLabel->setText(tr("<span style=\" color:#ff0000;\">Keystore passwords do not match</span>"));
return NoMatch;
}
ui->keystorePassInfoLabel->setText(tr("<span style=\" color:#00ff00;\">Password is ok</span>"));
ui->infoLabel->clear();
return Match;
}
AndroidCreateKeystoreCertificate::PasswordStatus AndroidCreateKeystoreCertificate::checkCertificatePassword()
{
if (ui->samePasswordCheckBox->checkState() == Qt::Checked)
return Match;
if (ui->certificatePassLineEdit->text().length() < 6) {
ui->certificatePassInfoLabel->setText(tr("<span style=\" color:#ff0000;\">Password is too short</span>"));
ui->infoLabel->setText(tr("<span style=\" color:#ff0000;\">Certificate password is too short</span>"));
return Invalid;
}
if (ui->certificatePassLineEdit->text() != ui->certificateRetypePassLineEdit->text()) {
ui->certificatePassInfoLabel->setText(tr("<span style=\" color:#ff0000;\">Passwords don't match</span>"));
ui->infoLabel->setText(tr("<span style=\" color:#ff0000;\">Certificate passwords do not match</span>"));
return NoMatch;
}
ui->certificatePassInfoLabel->setText(tr("<span style=\" color:#00ff00;\">Password is ok</span>"));
ui->infoLabel->clear();
return Match;
}
bool AndroidCreateKeystoreCertificate::checkCertificateAlias()
{
if (ui->certificateAliasLineEdit->text().length() == 0) {
ui->infoLabel->setText(tr("<span style=\" color:#ff0000;\">Certificate alias is missing</span>"));
return false;
}
ui->infoLabel->clear();
return true;
}
bool AndroidCreateKeystoreCertificate::checkCountryCode()
{
if (!ui->countryLineEdit->text().contains(QRegExp(QLatin1String("[A-Z]{2}")))) {
ui->infoLabel->setText(tr("<span style=\" color:#ff0000;\">Invalid country code</span>"));
return false;
}
ui->infoLabel->clear();
return true;
}
void AndroidCreateKeystoreCertificate::on_keystoreShowPassCheckBox_stateChanged(int state)
{
ui->keystorePassLineEdit->setEchoMode(state == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password);
......@@ -115,44 +146,8 @@ void AndroidCreateKeystoreCertificate::on_certificateShowPassCheckBox_stateChang
void AndroidCreateKeystoreCertificate::on_buttonBox_accepted()
{
switch (checkKeystorePassword()) {
case Invalid:
ui->keystorePassLineEdit->setFocus();
return;
case NoMatch:
ui->keystoreRetypePassLineEdit->setFocus();
if (!validateUserInput())
return;
default:
break;
}
switch (checkCertificatePassword()) {
case Invalid:
ui->certificatePassLineEdit->setFocus();
return;
case NoMatch:
ui->certificateRetypePassLineEdit->setFocus();
return;
default:
break;
}
if (!ui->aliasNameLineEdit->text().length()) {
ui->aliasNameLineEdit->setFocus();
return;
}
if (!ui->commonNameLineEdit->text().length())
ui->commonNameLineEdit->setFocus();
if (!ui->organizationNameLineEdit->text().length())
ui->organizationNameLineEdit->setFocus();
if (!ui->localityNameLineEdit->text().length())
ui->localityNameLineEdit->setFocus();
if (!ui->countryLineEdit->text().length())
ui->countryLineEdit->setFocus();
m_keystoreFilePath = Utils::FileName::fromString(QFileDialog::getSaveFileName(this, tr("Keystore file name"),
QDir::homePath() + QLatin1String("/android_release.keystore"),
......@@ -174,11 +169,11 @@ void AndroidCreateKeystoreCertificate::on_buttonBox_accepted()
QStringList params;
params << QLatin1String("-genkey") << QLatin1String("-keyalg") << QLatin1String("RSA")
<< QLatin1String("-keystore") << m_keystoreFilePath.toString()
<< QLatin1String("-storepass") << ui->keystorePassLineEdit->text()
<< QLatin1String("-alias") << ui->aliasNameLineEdit->text()
<< QLatin1String("-storepass") << keystorePassword()
<< QLatin1String("-alias") << certificateAlias()
<< QLatin1String("-keysize") << ui->keySizeSpinBox->text()
<< QLatin1String("-validity") << ui->validitySpinBox->text()
<< QLatin1String("-keypass") << ui->certificatePassLineEdit->text()
<< QLatin1String("-keypass") << certificatePassword()
<< QLatin1String("-dname") << distinguishedNames;
QProcess genKeyCertProc;
......@@ -195,3 +190,57 @@ void AndroidCreateKeystoreCertificate::on_buttonBox_accepted()
}
accept();
}
void AndroidCreateKeystoreCertificate::on_samePasswordCheckBox_stateChanged(int state)
{
if (state == Qt::Checked) {
ui->certificatePassLineEdit->setDisabled(true);
ui->certificateRetypePassLineEdit->setDisabled(true);
ui->certificateShowPassCheckBox->setDisabled(true);
}
if (state == Qt::Unchecked) {
ui->certificatePassLineEdit->setEnabled(true);
ui->certificateRetypePassLineEdit->setEnabled(true);
ui->certificateShowPassCheckBox->setEnabled(true);
}
validateUserInput();
}
bool AndroidCreateKeystoreCertificate::validateUserInput()
{
switch (checkKeystorePassword()) {
case Invalid:
ui->keystorePassLineEdit->setFocus();
return false;
case NoMatch:
ui->keystoreRetypePassLineEdit->setFocus();
return false;
default:
break;
}
if (!checkCertificateAlias()) {
ui->certificateAliasLineEdit->setFocus();
return false;
}
switch (checkCertificatePassword()) {
case Invalid:
ui->certificatePassLineEdit->setFocus();
return false;
case NoMatch:
ui->certificateRetypePassLineEdit->setFocus();
return false;
default:
break;
}
if (!checkCountryCode()) {
ui->countryLineEdit->setFocus();
return false;
}
return true;
}
......@@ -62,11 +62,15 @@ public:
private slots:
PasswordStatus checkKeystorePassword();
PasswordStatus checkCertificatePassword();
bool checkCertificateAlias();
bool checkCountryCode();
void on_keystoreShowPassCheckBox_stateChanged(int state);
void on_certificateShowPassCheckBox_stateChanged(int state);
void on_buttonBox_accepted();
void on_samePasswordCheckBox_stateChanged(int state);
private:
bool validateUserInput();
Ui::AndroidCreateKeystoreCertificate *ui;
Utils::FileName m_keystoreFilePath;
};
......
......@@ -7,23 +7,23 @@
<x>0</x>
<y>0</y>
<width>638</width>
<height>429</height>
<height>473</height>
</rect>
</property>
<property name="windowTitle">
<string>Create a keystore and a certificate</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Keystore</string>
<string>Certificate Distinguished Names</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Password:</string>
<string>First and last name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
......@@ -31,16 +31,12 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="keystorePassLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
<widget class="QLineEdit" name="commonNameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Retype password:</string>
<string>Organizational unit (e.g. Necessitas):</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
......@@ -48,78 +44,97 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="keystoreRetypePassLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
<widget class="QLineEdit" name="organizationUnitLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="keystoreShowPassCheckBox">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Show password</string>
<string>Organization (e.g. KDE):</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="keystorePassInfoLabel">
<widget class="QLineEdit" name="organizationNameLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>&lt;span style=&quot; color:#ff0000;&quot;&gt;Password is too short&lt;/span&gt;</string>
<string>City or locality:</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="localityNameLineEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>State or province:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Certificate</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_11">
<item row="4" column="1">
<widget class="QLineEdit" name="stateNameLineEdit"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Alias name:</string>
<string>Two-letter country code for this unit (e.g. RO):</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="aliasNameLineEdit">
<item row="5" column="1">
<widget class="QLineEdit" name="countryLineEdit">
<property name="inputMask">
<string>Aaaaaaaa; </string>
<string/>
</property>
<property name="maxLength">
<number>8</number>
<number>2</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Keysize:</string>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Certificate</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="1">
<widget class="QLineEdit" name="certificateRetypePassLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="certificateShowPassCheckBox">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="keySizeSpinBox">
<item row="2" column="1">
<widget class="QSpinBox" name="validitySpinBox">
<property name="minimum">
<number>2048</number>
<number>10000</number>
</property>
<property name="maximum">
<number>2097152</number>
<number>100000</number>
</property>
</widget>
</item>
......@@ -133,13 +148,13 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="validitySpinBox">
<property name="minimum">
<number>10000</number>
<item row="0" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Alias name:</string>
</property>
<property name="maximum">
<number>100000</number>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
......@@ -153,148 +168,127 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="certificatePassLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
<item row="0" column="1">
<widget class="QLineEdit" name="certificateAliasLineEdit">
<property name="inputMask">
<string notr="true"/>
</property>
<property name="maxLength">
<number>8</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_18">
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Retype password:</string>
<string>Keysize:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="certificateRetypePassLineEdit">
<item row="3" column="1">
<widget class="QLineEdit" name="certificatePassLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="certificateShowPassCheckBox">
<property name="text">
<string>Show password</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="certificatePassInfoLabel">
<property name="text">
<string>&lt;span style=&quot; color:#ff0000;&quot;&gt;Password is too short&lt;/span&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
<item row="1" column="1">
<widget class="QSpinBox" name="keySizeSpinBox">
<property name="minimum">
<number>2048</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<property name="maximum">
<number>2097152</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Certificate Distinguished Names</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<item row="4" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>First and last name:</string>
<string>Retype password:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="commonNameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<item row="5" column="0">
<widget class="QCheckBox" name="samePasswordCheckBox">
<property name="text">
<string>Organizational unit (e.g. Necessitas):</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<string>Use Keystore password</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Keystore</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QLineEdit" name="organizationUnitLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Organization (e.g. KDE):</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<widget class="QLineEdit" name="keystorePassLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="organizationNameLineEdit"/>
<widget class="QLineEdit" name="keystoreRetypePassLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<widget class="QCheckBox" name="keystoreShowPassCheckBox">
<property name="text">
<string>City or locality:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<string>Show password</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="localityNameLineEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_9">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>State or province:</string>
<string>Password:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>