| 
									
										
										
										
											2022-08-19 15:59:36 +02:00
										 |  |  | // Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
 | 
					
						
							| 
									
										
										
										
											2022-12-21 10:12:09 +01:00
										 |  |  | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
 | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "androidconfigurations.h"
 | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  | #include "androidcreatekeystorecertificate.h"
 | 
					
						
							|  |  |  | #include "androidtr.h"
 | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | #include <utils/infolabel.h>
 | 
					
						
							|  |  |  | #include <utils/layoutbuilder.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-03 17:05:35 +02:00
										 |  |  | #include <utils/process.h>
 | 
					
						
							| 
									
										
										
										
											2016-04-29 16:52:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | #include <QCheckBox>
 | 
					
						
							|  |  |  | #include <QDialog>
 | 
					
						
							|  |  |  | #include <QDialogButtonBox>
 | 
					
						
							|  |  |  | #include <QLineEdit>
 | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | #include <QRegularExpression>
 | 
					
						
							|  |  |  | #include <QSpinBox>
 | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 16:27:55 +02:00
										 |  |  | using namespace Utils; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | namespace Android::Internal { | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | AndroidCreateKeystoreCertificate::AndroidCreateKeystoreCertificate(QWidget *parent) | 
					
						
							|  |  |  |     : QDialog(parent) | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     resize(638, 473); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     setWindowTitle(Tr::tr("Create a keystore and a certificate")); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_commonNameLineEdit = new QLineEdit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_organizationUnitLineEdit = new QLineEdit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_organizationNameLineEdit = new QLineEdit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_localityNameLineEdit = new QLineEdit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_stateNameLineEdit = new QLineEdit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_countryLineEdit = new QLineEdit; | 
					
						
							|  |  |  |     m_countryLineEdit->setMaxLength(2); | 
					
						
							|  |  |  |     m_countryLineEdit->setInputMask(QString()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_certificateRetypePassLineEdit = new QLineEdit; | 
					
						
							|  |  |  |     m_certificateRetypePassLineEdit->setEchoMode(QLineEdit::Password); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     m_certificateShowPassCheckBox = new QCheckBox(Tr::tr("Show password")); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_validitySpinBox = new QSpinBox; | 
					
						
							|  |  |  |     m_validitySpinBox->setRange(10000, 100000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_certificateAliasLineEdit = new QLineEdit; | 
					
						
							|  |  |  |     m_certificateAliasLineEdit->setInputMask({}); | 
					
						
							|  |  |  |     m_certificateAliasLineEdit->setMaxLength(32); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_certificatePassLineEdit = new QLineEdit; | 
					
						
							|  |  |  |     m_certificatePassLineEdit->setEchoMode(QLineEdit::Password); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_keySizeSpinBox = new QSpinBox; | 
					
						
							|  |  |  |     m_keySizeSpinBox->setRange(2048, 2097152); | 
					
						
							| 
									
										
										
										
											2022-01-29 00:36:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     m_samePasswordCheckBox = new QCheckBox(Tr::tr("Use Keystore password")); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_keystorePassLineEdit = new QLineEdit; | 
					
						
							|  |  |  |     m_keystorePassLineEdit->setEchoMode(QLineEdit::Password); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_keystoreRetypePassLineEdit = new QLineEdit; | 
					
						
							|  |  |  |     m_keystoreRetypePassLineEdit->setEchoMode(QLineEdit::Password); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_infoLabel = new InfoLabel; | 
					
						
							|  |  |  |     m_infoLabel->setType(InfoLabel::Error); | 
					
						
							|  |  |  |     m_infoLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); | 
					
						
							|  |  |  |     m_infoLabel->hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     auto keystoreShowPassCheckBox = new QCheckBox(Tr::tr("Show password")); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close|QDialogButtonBox::Save); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     using namespace Layouting; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Column { | 
					
						
							|  |  |  |         Group { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |             title(Tr::tr("Keystore")), | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |             Form { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |                 Tr::tr("Password:"), m_keystorePassLineEdit, br, | 
					
						
							|  |  |  |                 Tr::tr("Retype password:"), m_keystoreRetypePassLineEdit, br, | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |                 Span(2, keystoreShowPassCheckBox), br, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Group { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |             title(Tr::tr("Certificate")), | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |             Form { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |                 Tr::tr("Alias name:"), m_certificateAliasLineEdit, br, | 
					
						
							|  |  |  |                 Tr::tr("Keysize:"), m_keySizeSpinBox, br, | 
					
						
							|  |  |  |                 Tr::tr("Validity (days):"), m_validitySpinBox, br, | 
					
						
							|  |  |  |                 Tr::tr("Password:"), m_certificatePassLineEdit, br, | 
					
						
							|  |  |  |                 Tr::tr("Retype password:"), m_certificateRetypePassLineEdit, br, | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |                 Span(2, m_samePasswordCheckBox), br, | 
					
						
							|  |  |  |                 Span(2, m_certificateShowPassCheckBox), br, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Group { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |             title(Tr::tr("Certificate Distinguished Names")), | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |             Form { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |                 Tr::tr("First and last name:"), m_commonNameLineEdit, br, | 
					
						
							|  |  |  |                 Tr::tr("Organizational unit (e.g. Necessitas):"),  m_organizationUnitLineEdit, br, | 
					
						
							|  |  |  |                 Tr::tr("Organization (e.g. KDE):"), m_organizationNameLineEdit, br, | 
					
						
							|  |  |  |                 Tr::tr("City or locality:"), m_localityNameLineEdit, br, | 
					
						
							|  |  |  |                 Tr::tr("State or province:"), m_stateNameLineEdit, br, | 
					
						
							|  |  |  |                 Tr::tr("Two-letter country code for this unit (e.g. RO):"), m_countryLineEdit, | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Row { m_infoLabel, buttonBox } | 
					
						
							|  |  |  |     }.attachTo(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     connect(m_keystorePassLineEdit, &QLineEdit::textChanged, | 
					
						
							| 
									
										
										
										
											2016-06-26 22:52:59 +03:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::checkKeystorePassword); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(m_keystoreRetypePassLineEdit, &QLineEdit::textChanged, | 
					
						
							| 
									
										
										
										
											2016-06-26 22:52:59 +03:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::checkKeystorePassword); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(m_certificatePassLineEdit, &QLineEdit::textChanged, | 
					
						
							| 
									
										
										
										
											2016-06-26 22:52:59 +03:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::checkCertificatePassword); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(m_certificateRetypePassLineEdit, &QLineEdit::textChanged, | 
					
						
							| 
									
										
										
										
											2016-06-26 22:52:59 +03:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::checkCertificatePassword); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(m_certificateAliasLineEdit, &QLineEdit::textChanged, | 
					
						
							| 
									
										
										
										
											2016-06-26 22:52:59 +03:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::checkCertificateAlias); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(m_countryLineEdit, &QLineEdit::textChanged, | 
					
						
							| 
									
										
										
										
											2016-06-26 22:52:59 +03:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::checkCountryCode); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(keystoreShowPassCheckBox, &QCheckBox::stateChanged, | 
					
						
							| 
									
										
										
										
											2020-11-17 10:49:48 +01:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::keystoreShowPassStateChanged); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(m_certificateShowPassCheckBox, &QCheckBox::stateChanged, | 
					
						
							| 
									
										
										
										
											2020-11-17 10:49:48 +01:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::certificateShowPassStateChanged); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(m_samePasswordCheckBox, &QCheckBox::stateChanged, | 
					
						
							| 
									
										
										
										
											2020-11-17 10:49:48 +01:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::samePasswordStateChanged); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(buttonBox, &QDialogButtonBox::accepted, | 
					
						
							| 
									
										
										
										
											2020-11-17 10:49:48 +01:00
										 |  |  |             this, &AndroidCreateKeystoreCertificate::buttonBoxAccepted); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(buttonBox, &QDialogButtonBox::rejected, | 
					
						
							| 
									
										
										
										
											2020-06-25 13:37:29 +02:00
										 |  |  |             this, &QDialog::reject); | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     connect(m_keystorePassLineEdit, &QLineEdit::editingFinished, | 
					
						
							|  |  |  |             m_keystoreRetypePassLineEdit, QOverload<>::of(&QWidget::setFocus)); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | AndroidCreateKeystoreCertificate::~AndroidCreateKeystoreCertificate() = default; | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | FilePath AndroidCreateKeystoreCertificate::keystoreFilePath() const | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_keystoreFilePath; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | QString AndroidCreateKeystoreCertificate::keystorePassword() const | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     return m_keystorePassLineEdit->text(); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | QString AndroidCreateKeystoreCertificate::certificateAlias() const | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     return m_certificateAliasLineEdit->text(); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | QString AndroidCreateKeystoreCertificate::certificatePassword() const | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     return (m_samePasswordCheckBox->checkState() == Qt::Checked) | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |             ? keystorePassword() | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |             : m_certificatePassLineEdit->text(); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AndroidCreateKeystoreCertificate::PasswordStatus AndroidCreateKeystoreCertificate::checkKeystorePassword() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     if (m_keystorePassLineEdit->text().length() < 6) { | 
					
						
							|  |  |  |         m_infoLabel->show(); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         m_infoLabel->setText(Tr::tr("Keystore password is too short.")); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         return Invalid; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     if (m_keystorePassLineEdit->text() != m_keystoreRetypePassLineEdit->text()) { | 
					
						
							|  |  |  |         m_infoLabel->show(); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         m_infoLabel->setText(Tr::tr("Keystore passwords do not match.")); | 
					
						
							| 
									
										
										
										
											2022-01-29 00:36:49 +01:00
										 |  |  |         return NoMatch; | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     m_infoLabel->hide(); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |     return Match; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AndroidCreateKeystoreCertificate::PasswordStatus AndroidCreateKeystoreCertificate::checkCertificatePassword() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     if (m_samePasswordCheckBox->checkState() == Qt::Checked) | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |         return Match; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     if (m_certificatePassLineEdit->text().length() < 6) { | 
					
						
							|  |  |  |         m_infoLabel->show(); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         m_infoLabel->setText(Tr::tr("Certificate password is too short.")); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         return Invalid; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     if (m_certificatePassLineEdit->text() != m_certificateRetypePassLineEdit->text()) { | 
					
						
							|  |  |  |         m_infoLabel->show(); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         m_infoLabel->setText(Tr::tr("Certificate passwords do not match.")); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         return NoMatch; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     m_infoLabel->hide(); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |     return Match; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  | bool AndroidCreateKeystoreCertificate::checkCertificateAlias() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     if (m_certificateAliasLineEdit->text().length() == 0) { | 
					
						
							|  |  |  |         m_infoLabel->show(); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         m_infoLabel->setText(Tr::tr("Certificate alias is missing.")); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     m_infoLabel->hide(); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AndroidCreateKeystoreCertificate::checkCountryCode() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-03-22 16:13:40 +01:00
										 |  |  |     static const QRegularExpression re("[A-Z]{2}"); | 
					
						
							|  |  |  |     if (!m_countryLineEdit->text().contains(re)) { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |         m_infoLabel->show(); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         m_infoLabel->setText(Tr::tr("Invalid country code.")); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     m_infoLabel->hide(); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 10:49:48 +01:00
										 |  |  | void AndroidCreateKeystoreCertificate::keystoreShowPassStateChanged(int state) | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     m_keystorePassLineEdit->setEchoMode(state == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password); | 
					
						
							|  |  |  |     m_keystoreRetypePassLineEdit->setEchoMode(m_keystorePassLineEdit->echoMode()); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 10:49:48 +01:00
										 |  |  | void AndroidCreateKeystoreCertificate::certificateShowPassStateChanged(int state) | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     m_certificatePassLineEdit->setEchoMode(state == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password); | 
					
						
							|  |  |  |     m_certificateRetypePassLineEdit->setEchoMode(m_certificatePassLineEdit->echoMode()); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 10:49:48 +01:00
										 |  |  | void AndroidCreateKeystoreCertificate::buttonBoxAccepted() | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |     if (!validateUserInput()) | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     m_keystoreFilePath = FileUtils::getSaveFilePath(this, Tr::tr("Keystore Filename"), | 
					
						
							| 
									
										
										
										
											2021-08-17 16:36:42 +02:00
										 |  |  |                                                     FileUtils::homePath() / "android_release.keystore", | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |                                                     Tr::tr("Keystore files (*.keystore *.jks)")); | 
					
						
							| 
									
										
										
										
											2012-04-24 15:49:09 +02:00
										 |  |  |     if (m_keystoreFilePath.isEmpty()) | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         return; | 
					
						
							|  |  |  |     QString distinguishedNames(QString::fromLatin1("CN=%1, O=%2, L=%3, C=%4") | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |                                .arg(m_commonNameLineEdit->text().replace(QLatin1Char(','), QLatin1String("\\,"))) | 
					
						
							|  |  |  |                                .arg(m_organizationNameLineEdit->text().replace(QLatin1Char(','), QLatin1String("\\,"))) | 
					
						
							|  |  |  |                                .arg(m_localityNameLineEdit->text().replace(QLatin1Char(','), QLatin1String("\\,"))) | 
					
						
							|  |  |  |                                .arg(m_countryLineEdit->text().replace(QLatin1Char(','), QLatin1String("\\,")))); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     if (!m_organizationUnitLineEdit->text().isEmpty()) | 
					
						
							|  |  |  |         distinguishedNames += QLatin1String(", OU=") + m_organizationUnitLineEdit->text().replace(',', QLatin1String("\\,")); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |     if (!m_stateNameLineEdit->text().isEmpty()) | 
					
						
							|  |  |  |         distinguishedNames += QLatin1String(", S=") + m_stateNameLineEdit->text().replace(',', QLatin1String("\\,")); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 16:27:55 +02:00
										 |  |  |     const CommandLine command(AndroidConfigurations::currentConfig().keytoolPath(), | 
					
						
							|  |  |  |                             { "-genkey", "-keyalg", "RSA", | 
					
						
							|  |  |  |                               "-keystore",  m_keystoreFilePath.toString(), | 
					
						
							|  |  |  |                               "-storepass", keystorePassword(), | 
					
						
							|  |  |  |                               "-alias", certificateAlias(), | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |                               "-keysize", m_keySizeSpinBox->text(), | 
					
						
							|  |  |  |                               "-validity", m_validitySpinBox->text(), | 
					
						
							| 
									
										
										
										
											2019-06-06 16:27:55 +02:00
										 |  |  |                               "-keypass", certificatePassword(), | 
					
						
							|  |  |  |                               "-dname", distinguishedNames}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-03 16:00:22 +02:00
										 |  |  |     Process genKeyCertProc; | 
					
						
							| 
									
										
										
										
											2016-04-29 16:52:58 +02:00
										 |  |  |     genKeyCertProc.setTimeoutS(15); | 
					
						
							| 
									
										
										
										
											2021-05-17 12:02:42 +02:00
										 |  |  |     genKeyCertProc.setCommand(command); | 
					
						
							| 
									
										
										
										
											2022-03-02 04:12:25 +01:00
										 |  |  |     genKeyCertProc.runBlocking(EventLoopMode::On); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 04:12:25 +01:00
										 |  |  |     if (genKeyCertProc.result() != ProcessResult::FinishedWithSuccess) { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         QMessageBox::critical(this, Tr::tr("Error"), | 
					
						
							| 
									
										
										
										
											2021-05-14 13:12:46 +02:00
										 |  |  |                               genKeyCertProc.exitMessage() + '\n' + genKeyCertProc.allOutput()); | 
					
						
							| 
									
										
										
										
											2012-04-18 20:30:57 +03:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     accept(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 10:49:48 +01:00
										 |  |  | void AndroidCreateKeystoreCertificate::samePasswordStateChanged(int state) | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (state == Qt::Checked) { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |         m_certificatePassLineEdit->setDisabled(true); | 
					
						
							|  |  |  |         m_certificateRetypePassLineEdit->setDisabled(true); | 
					
						
							|  |  |  |         m_certificateShowPassCheckBox->setDisabled(true); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (state == Qt::Unchecked) { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |         m_certificatePassLineEdit->setEnabled(true); | 
					
						
							|  |  |  |         m_certificateRetypePassLineEdit->setEnabled(true); | 
					
						
							|  |  |  |         m_certificateShowPassCheckBox->setEnabled(true); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     validateUserInput(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AndroidCreateKeystoreCertificate::validateUserInput() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     switch (checkKeystorePassword()) { | 
					
						
							|  |  |  |     case Invalid: | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |         m_keystorePassLineEdit->setFocus(); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     case NoMatch: | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |         m_keystoreRetypePassLineEdit->setFocus(); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!checkCertificateAlias()) { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |         m_certificateAliasLineEdit->setFocus(); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (checkCertificatePassword()) { | 
					
						
							|  |  |  |     case Invalid: | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |         m_certificatePassLineEdit->setFocus(); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     case NoMatch: | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |         m_certificateRetypePassLineEdit->setFocus(); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!checkCountryCode()) { | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  |         m_countryLineEdit->setFocus(); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:53:52 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-07-22 12:28:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // Android::Internal
 |