Commit c04797fd authored by Pawel Polanski's avatar Pawel Polanski

Certificate management should not throw exceptions when loading Dev Certificates

Task-number: QTCREATORBUG-3323
Reviewed-by: Tobias Hunger
parent abe68bf8
......@@ -23,7 +23,8 @@ SOURCES += $$PWD/s60devices.cpp \
$$PWD/s60deployconfiguration.cpp \
$$PWD/s60deployconfigurationwidget.cpp \
$$PWD/s60certificateinfo.cpp \
$$PWD/certificatepathchooser.cpp
$$PWD/certificatepathchooser.cpp \
$$PWD/s60symbiancertificate.cpp
HEADERS += $$PWD/s60devices.h \
$$PWD/s60devicespreferencepane.h \
$$PWD/s60manager.h \
......@@ -46,6 +47,7 @@ HEADERS += $$PWD/s60devices.h \
$$PWD/s60deployconfiguration.h \
$$PWD/s60deployconfigurationwidget.h \
$$PWD/s60certificateinfo.h \
$$PWD/certificatepathchooser.h
$$PWD/certificatepathchooser.h \
$$PWD/s60symbiancertificate.h
FORMS += $$PWD/s60devicespreferencepane.ui \
$$PWD/s60createpackagestep.ui
......@@ -33,52 +33,34 @@
#include <QFileInfo>
#include <QCoreApplication>
#include <botan/x509cert.h>
#include "s60symbiancertificate.h"
S60CertificateInfo::CertificateState S60CertificateInfo::validateCertificate(const QString &certFilePath, QString *errorString)
{
bool certFileCorrupted = false;
CertificateState result = CertificateValid;
Botan::X509_Certificate *certificate = 0;
try {
certificate = new Botan::X509_Certificate(certFilePath.toStdString());
if (certificate) {
const char * const CERTIFICATE_DATE_FORMAT = "yyyy/M/d h:mm:ss UTC";
QDateTime startTime = QDateTime::fromString(QString::fromStdString(certificate->start_time()),
QLatin1String(CERTIFICATE_DATE_FORMAT));
QDateTime startTimeUTC(startTime.date(), startTime.time(), Qt::UTC);
QDateTime endTime = QDateTime::fromString(QString::fromStdString(certificate->end_time()),
QLatin1String(CERTIFICATE_DATE_FORMAT));
QDateTime endTimeUTC(endTime.date(), endTime.time(), Qt::UTC);
QDateTime currentTime(QDateTime::currentDateTimeUtc());
if (currentTime > endTimeUTC) {
if (errorString)
*errorString = QCoreApplication::translate(
"S60Utils::validateCertificate",
"The \"%1\" certificate has already expired and cannot be used.\nExpiration date: %2.")
.arg(QFileInfo(certFilePath).fileName())
.arg(endTimeUTC.toLocalTime().toString());
result = CertificateError;
} else if (currentTime < startTimeUTC) {
if (errorString)
*errorString = QCoreApplication::translate(
"S60Utils::validateCertificate",
"The \"%1\" certificate is not yet valid.\nValid from: %2.")
.arg(QFileInfo(certFilePath).fileName())
.arg(startTimeUTC.toLocalTime().toString());
result = CertificateWarning; //This certificate may be valid in the near future
}
} else
certFileCorrupted = true;
} catch (Botan::Exception &e) {
Q_UNUSED(e)
certFileCorrupted = true;
}
delete certificate;
if (certFileCorrupted) {
S60SymbianCertificate *certificate = new S60SymbianCertificate(certFilePath);
if (certificate->isValid()) {
QDateTime currentTime(QDateTime::currentDateTimeUtc());
QDateTime endTime(certificate->endTime());
QDateTime startTime(certificate->startTime());
if (currentTime > endTime) {
if (errorString)
*errorString = QCoreApplication::translate(
"S60Utils::validateCertificate",
"The \"%1\" certificate has already expired and cannot be used.\nExpiration date: %2.")
.arg(QFileInfo(certFilePath).fileName())
.arg(endTime.toLocalTime().toString());
result = CertificateError;
} else if (currentTime < startTime) {
if (errorString)
*errorString = QCoreApplication::translate(
"S60Utils::validateCertificate",
"The \"%1\" certificate is not yet valid.\nValid from: %2.")
.arg(QFileInfo(certFilePath).fileName())
.arg(startTime.toLocalTime().toString());
result = CertificateWarning; //This certificate may be valid in the near future
}
} else {
if (errorString)
*errorString = QCoreApplication::translate(
"S60Utils::validateCertificate",
......@@ -86,5 +68,6 @@ S60CertificateInfo::CertificateState S60CertificateInfo::validateCertificate(con
.arg(QFileInfo(certFilePath).baseName());
result = CertificateError;
}
delete certificate;
return result;
}
This diff is collapsed.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef S60SYMBIANCERTIFICATE_H
#define S60SYMBIANCERTIFICATE_H
#include <QStringList>
#include <QDateTime>
class S60SymbianCertificatePrivate;
class S60SymbianCertificate
{
public:
explicit S60SymbianCertificate(const QString &filename);
~S60SymbianCertificate();
bool isValid() const;
QString errorString() const;
QStringList subjectInfo(const QString &name);
QStringList issuerInfo(const QString &name);
QDateTime startTime();
QDateTime endTime();
quint32 certificateVersion();
bool isSelfSigned();
bool isCaCert();
private:
QDateTime parseTime(const std::string &time);
protected:
S60SymbianCertificatePrivate const *m_d;
QString m_errorString;
};
#endif // S60SYMBIANCERTIFICATE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment