From 3fa45170b5d9a002026510da46f76d7d859cd881 Mon Sep 17 00:00:00 2001 From: Vikas Pachdha Date: Tue, 10 Jan 2017 16:33:56 +0100 Subject: [PATCH] Android: Do sanity check for keystore path and certificate alias Task-number: QTCREATORBUG-17304 Change-Id: Ifc0e354789d49efa3cb1d3e3e67eb40b331b40c7 Reviewed-by: Leena Miettinen Reviewed-by: BogDan Vatra --- src/plugins/android/androidbuildapkstep.cpp | 13 +++++++++++++ src/plugins/android/androidmanager.cpp | 20 ++++++++++++++++++++ src/plugins/android/androidmanager.h | 2 ++ 3 files changed, 35 insertions(+) diff --git a/src/plugins/android/androidbuildapkstep.cpp b/src/plugins/android/androidbuildapkstep.cpp index d1d49570434..e039ba0de10 100644 --- a/src/plugins/android/androidbuildapkstep.cpp +++ b/src/plugins/android/androidbuildapkstep.cpp @@ -182,6 +182,12 @@ void AndroidBuildApkStep::processFinished(int exitCode, QProcess::ExitStatus sta bool AndroidBuildApkStep::verifyKeystorePassword() { + if (!m_keystorePath.exists()) { + addOutput(tr("Cannot sign the package. Invalid keystore path(%1).") + .arg(m_keystorePath.toString()), ErrorOutput); + return false; + } + if (AndroidManager::checkKeystorePassword(m_keystorePath.toString(), m_keystorePasswd)) return true; @@ -195,6 +201,13 @@ bool AndroidBuildApkStep::verifyKeystorePassword() bool AndroidBuildApkStep::verifyCertificatePassword() { + if (!AndroidManager::checkCertificateExists(m_keystorePath.toString(), m_keystorePasswd, + m_certificateAlias)) { + addOutput(tr("Cannot sign the package. Certificate alias %1 does not exist.") + .arg(m_certificateAlias), ErrorOutput); + return false; + } + if (AndroidManager::checkCertificatePassword(m_keystorePath.toString(), m_keystorePasswd, m_certificateAlias, m_certificatePasswd)) { return true; diff --git a/src/plugins/android/androidmanager.cpp b/src/plugins/android/androidmanager.cpp index a91a7404aad..b3526c833f2 100644 --- a/src/plugins/android/androidmanager.cpp +++ b/src/plugins/android/androidmanager.cpp @@ -429,6 +429,26 @@ bool AndroidManager::checkCertificatePassword(const QString &keystorePath, const return response.result == Utils::SynchronousProcessResponse::Finished && response.exitCode == 0; } +bool AndroidManager::checkCertificateExists(const QString &keystorePath, + const QString &keystorePasswd, const QString &alias) +{ + // assumes that the keystore password is correct + QStringList arguments; + arguments << QLatin1String("-list") + << QLatin1String("-keystore") + << keystorePath + << QLatin1String("--storepass") + << keystorePasswd + << QLatin1String("-alias") + << alias; + + Utils::SynchronousProcess proc; + proc.setTimeoutS(10); + Utils::SynchronousProcessResponse response + = proc.run(AndroidConfigurations::currentConfig().keytoolPath().toString(), arguments); + return response.result == Utils::SynchronousProcessResponse::Finished && response.exitCode == 0; +} + bool AndroidManager::checkForQt51Files(Utils::FileName fileName) { fileName.appendPath(QLatin1String("android")).appendPath(QLatin1String("version.xml")); diff --git a/src/plugins/android/androidmanager.h b/src/plugins/android/androidmanager.h index 2bb2f51c26d..2b79cb4c6a3 100644 --- a/src/plugins/android/androidmanager.h +++ b/src/plugins/android/androidmanager.h @@ -83,6 +83,8 @@ public: static bool checkKeystorePassword(const QString &keystorePath, const QString &keystorePasswd); static bool checkCertificatePassword(const QString &keystorePath, const QString &keystorePasswd, const QString &alias, const QString &certificatePasswd); + static bool checkCertificateExists(const QString &keystorePath, const QString &keystorePasswd, + const QString &alias); static bool checkForQt51Files(Utils::FileName fileName); static AndroidQtSupport *androidQtSupport(ProjectExplorer::Target *target); static bool useGradle(ProjectExplorer::Target *target);