本文整理汇总了C++中QSslCertificate::effectiveDate方法的典型用法代码示例。如果您正苦于以下问题:C++ QSslCertificate::effectiveDate方法的具体用法?C++ QSslCertificate::effectiveDate怎么用?C++ QSslCertificate::effectiveDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSslCertificate
的用法示例。
在下文中一共展示了QSslCertificate::effectiveDate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addClientCertToTable
void PreferencesDialog::addClientCertToTable(const QString& path, const QSslCertificate& cert)
{
// Do nothing if the file doesn't even exist
if(!QFile::exists(path))
return;
// Add new row
int row = ui->tableClientCerts->rowCount();
ui->tableClientCerts->setRowCount(row + 1);
// Fill row with data
QTableWidgetItem* cert_file = new QTableWidgetItem(path);
cert_file->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->tableClientCerts->setItem(row, 0, cert_file);
QTableWidgetItem* cert_subject_cn = new QTableWidgetItem(cert.subjectInfo(QSslCertificate::CommonName).at(0));
cert_subject_cn->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->tableClientCerts->setItem(row, 1, cert_subject_cn);
QTableWidgetItem* cert_issuer_cn = new QTableWidgetItem(cert.issuerInfo(QSslCertificate::CommonName).at(0));
cert_issuer_cn->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->tableClientCerts->setItem(row, 2, cert_issuer_cn);
QTableWidgetItem* cert_from = new QTableWidgetItem(cert.effectiveDate().toString());
cert_from->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->tableClientCerts->setItem(row, 3, cert_from);
QTableWidgetItem* cert_to = new QTableWidgetItem(cert.expiryDate().toString());
cert_to->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->tableClientCerts->setItem(row, 4, cert_to);
QTableWidgetItem* cert_serialno = new QTableWidgetItem(QString(cert.serialNumber()));
cert_serialno->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->tableClientCerts->setItem(row, 5, cert_serialno);
}
示例2: certToFormattedString
static QString certToFormattedString(QSslCertificate cert)
{
QString resultstring = QLatin1String("<p>");
QStringList tmplist;
resultstring += cert.subjectInfo(QSslCertificate::CommonName);
resultstring += QString::fromLatin1("<br/>Issuer: %1")
.arg(cert.issuerInfo(QSslCertificate::CommonName));
resultstring += QString::fromLatin1("<br/>Not valid before: %1<br/>Valid Until: %2")
.arg(cert.effectiveDate().toString(Qt::ISODate))
.arg(cert.expiryDate().toString(Qt::ISODate));
QMultiMap<QSsl::AlternateNameEntryType, QString> names = cert.alternateSubjectNames();
if (names.count() > 0) {
tmplist = names.values(QSsl::DnsEntry);
resultstring += QLatin1String("<br/>Alternate Names:<ul><li>")
+ tmplist.join(QLatin1String("</li><li>"))
+ QLatin1String("</li><</ul>");
}
resultstring += QLatin1String("</p>");
return resultstring;
}
示例3: setCurrentCert
void SslInfoDlg::setCurrentCert(int index)
{
QSslCertificate cert = socket()->peerCertificateChain().at(index);
ui.subjectCommonName->setText(cert.subjectInfo(QSslCertificate::CommonName));
ui.subjectOrganization->setText(cert.subjectInfo(QSslCertificate::Organization));
ui.subjectOrganizationalUnit->setText(cert.subjectInfo(QSslCertificate::OrganizationalUnitName));
ui.subjectCountry->setText(cert.subjectInfo(QSslCertificate::CountryName));
ui.subjectState->setText(cert.subjectInfo(QSslCertificate::StateOrProvinceName));
ui.subjectCity->setText(cert.subjectInfo(QSslCertificate::LocalityName));
ui.issuerCommonName->setText(cert.issuerInfo(QSslCertificate::CommonName));
ui.issuerOrganization->setText(cert.issuerInfo(QSslCertificate::Organization));
ui.issuerOrganizationalUnit->setText(cert.issuerInfo(QSslCertificate::OrganizationalUnitName));
ui.issuerCountry->setText(cert.issuerInfo(QSslCertificate::CountryName));
ui.issuerState->setText(cert.issuerInfo(QSslCertificate::StateOrProvinceName));
ui.issuerCity->setText(cert.issuerInfo(QSslCertificate::LocalityName));
if (socket()->sslErrors().isEmpty())
ui.trusted->setText(tr("Yes"));
else {
QString errorString = tr("No, for the following reasons:<ul>");
foreach(const QSslError &error, socket()->sslErrors())
errorString += "<li>" + error.errorString() + "</li>";
errorString += "</ul>";
ui.trusted->setText(errorString);
}
ui.validity->setText(tr("%1 to %2").arg(cert.effectiveDate().date().toString(Qt::ISODate), cert.expiryDate().date().toString(Qt::ISODate)));
ui.md5Digest->setText(prettyDigest(cert.digest(QCryptographicHash::Md5)));
ui.sha1Digest->setText(prettyDigest(cert.digest(QCryptographicHash::Sha1)));
}
示例4: onSslErrors
void Pastebin::onSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
{
QStringList ignoreCerts = AppSettings::instance()->ignoreErrorCerts();
QList<QSslError> ignoreErrors;
QList<QSslError> promptErrors;
QSslCertificate cert;
QStringList errorStrings;
foreach(const QSslError &error, errors) {
if(ignoreCerts.contains(QString(error.certificate().serialNumber()))) {
ignoreErrors.append(error);
}
else {
promptErrors.append(error);
if(cert.isNull()) {
cert = error.certificate();
}
errorStrings << error.errorString();
}
}
if(!ignoreErrors.isEmpty()) {
reply->ignoreSslErrors(ignoreErrors);
}
if(!promptErrors.isEmpty()) {
QString bodyText = tr(
"Issued to: %1\n"
"Serial number: %2\n"
"Issued by: %3\n"
"Effective: %4\n"
"Expires: %5\n"
"\n%6\n\n"
"Ignore this error?")
.arg(cert.subjectInfo(QSslCertificate::CommonName))
.arg(QString(cert.serialNumber()))
.arg(cert.issuerInfo(QSslCertificate::CommonName))
.arg(cert.effectiveDate().toLocalTime().toString(Qt::SystemLocaleShortDate))
.arg(cert.expiryDate().toLocalTime().toString(Qt::SystemLocaleShortDate))
.arg(errorStrings.join("\n"));
bb::system::SystemDialog dialog(tr("Yes"), tr("Always"), tr("No"));
dialog.setTitle(tr("SSL Error"));
dialog.setBody(bodyText);
bb::system::SystemUiResult::Type result = dialog.exec();
if(result == bb::system::SystemUiResult::ConfirmButtonSelection
|| result == bb::system::SystemUiResult::CustomButtonSelection) {
reply->ignoreSslErrors(promptErrors);
if(result == bb::system::SystemUiResult::CustomButtonSelection) {
ignoreCerts << QString(cert.serialNumber());
AppSettings::instance()->setIgnoreErrorCerts(ignoreCerts);
}
}
}
}
示例5:
QDebug operator<<(QDebug debug, const QSslCertificate &certificate)
{
debug << "QSslCertificate("
<< certificate.version()
<< "," << certificate.serialNumber()
<< "," << certificate.digest()
<< "," << certificate.issuerInfo(QSslCertificate::Organization)
<< "," << certificate.subjectInfo(QSslCertificate::Organization)
<< "," << certificate.alternateSubjectNames()
#ifndef QT_NO_TEXTSTREAM
<< "," << certificate.effectiveDate()
<< "," << certificate.expiryDate()
#endif
<< ")";
return debug;
}
示例6:
QDebug operator<<(QDebug debug, const QSslCertificate &certificate)
{
debug << "QSslCertificate("
<< certificate.version()
<< ',' << certificate.serialNumber()
<< ',' << certificate.digest().toBase64()
<< ',' << certificate.issuerInfo(QSslCertificate::Organization)
<< ',' << certificate.subjectInfo(QSslCertificate::Organization)
<< ',' << certificate.subjectAlternativeNames()
#ifndef QT_NO_DATESTRING
<< ',' << certificate.effectiveDate()
<< ',' << certificate.expiryDate()
#endif
<< ')';
return debug;
}
示例7: getCertificateString
QString clientController::getCertificateString(const QSslCertificate &cert)
{
QString certInfo;
certInfo += "Issuer Org: ";
certInfo += cert.issuerInfo(QSslCertificate::Organization).join(" ") + QString("\n");
certInfo += "Common Name: ";
certInfo += cert.issuerInfo(QSslCertificate::CommonName).join(" ") + "\n";
certInfo += "Effective Date: ";
certInfo += cert.effectiveDate().toString() + "\n";
certInfo += "Expiry Date: ";
certInfo += cert.expiryDate().toString() + "\n";
certInfo += "Public Key: ";
certInfo += cert.publicKey().toPem() + "\n";
certInfo += "Serial Number: ";
certInfo += cert.serialNumber() + "\n";
return certInfo;
}
示例8: getCertificateString
QString Client::getCertificateString(const QSslCertificate &cert)
{
// Grab the fields and append to certInfo
QString certInfo;
certInfo += "Issuer Org: ";
certInfo += cert.issuerInfo(QSslCertificate::Organization) + "\n";
certInfo += "Common Name: ";
certInfo += cert.issuerInfo(QSslCertificate::CommonName) + "\n";
certInfo += "Effective Date: ";
certInfo += cert.effectiveDate().toString() + "\n";
certInfo += "Expiry Date: ";
certInfo += cert.expiryDate().toString() + "\n";
certInfo += "Public Key: ";
certInfo += cert.publicKey().toPem() + "\n";
certInfo += "Serial Number: ";
certInfo += cert.serialNumber() + "\n";
return certInfo;
}
示例9: QWidget
CertificateInfoWidget::CertificateInfoWidget(const QSslCertificate &cert, QWidget* parent)
: QWidget(parent)
, ui(new Ui::CertificateInfoWidget)
{
ui->setupUi(this);
//Issued to
ui->issuedToCN->setText(showCertInfo(cert.subjectInfo(QSslCertificate::CommonName)));
ui->issuedToO->setText(showCertInfo(cert.subjectInfo(QSslCertificate::Organization)));
ui->issuedToOU->setText(showCertInfo(cert.subjectInfo(QSslCertificate::OrganizationalUnitName)));
ui->issuedToSN->setText(showCertInfo(cert.serialNumber()));
//Issued By
ui->issuedByCN->setText(showCertInfo(cert.issuerInfo(QSslCertificate::CommonName)));
ui->issuedByO->setText(showCertInfo(cert.issuerInfo(QSslCertificate::Organization)));
ui->issuedByOU->setText(showCertInfo(cert.issuerInfo(QSslCertificate::OrganizationalUnitName)));
//Validity
ui->validityIssuedOn->setText(cert.effectiveDate().toString("dddd d. MMMM yyyy"));
ui->validityExpiresOn->setText(cert.expiryDate().toString("dddd d. MMMM yyyy"));
}
示例10: dumpCertificate
QString dumpCertificate(const QSslCertificate &cert)
{
if (cert.isNull())
return "\n-\n";
QString s = "\n";
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
s += cert.toText();
#else
QString s_none = QObject::tr("<Not Part of Certificate>");
#define CERTIFICATE_STR(x) ( ((x) == "" ) ? s_none : (x) )
s += "Certificate:\n";
s += "\nIssued To:\n";
s += "CommonName(CN): " + CERTIFICATE_STR(cert.subjectInfo(QSslCertificate::CommonName)) + "\n";
s += "Organization(O): " + CERTIFICATE_STR(cert.subjectInfo(QSslCertificate::Organization)) + "\n";
s += "OrganizationalUnitName(OU): " + CERTIFICATE_STR(cert.subjectInfo(QSslCertificate::OrganizationalUnitName)) + "\n";
s += "Serial Number: " + dumpHexPresentation(cert.serialNumber()) + "\n";
s += "\nIssued By:\n";
s += "CommonName(CN): " + CERTIFICATE_STR(cert.issuerInfo(QSslCertificate::CommonName)) + "\n";
s += "Organization(O): " + CERTIFICATE_STR(cert.issuerInfo(QSslCertificate::Organization)) + "\n";
s += "OrganizationalUnitName(OU): " + CERTIFICATE_STR(cert.issuerInfo(QSslCertificate::OrganizationalUnitName)) + "\n";
s += "\nPeriod Of Validity\n";
s += "Begins On: " + cert.effectiveDate().toString() + "\n";
s += "Expires On: " + cert.expiryDate().toString() + "\n";
s += "IsValid: " + (cert.isValid() ? QString("Yes") : QString("No")) + "\n";
s += "\nFingerprints\n";
s += "SHA1 Fingerprint:\n" + dumpCertificateFingerprint(cert, QCryptographicHash::Sha1) + "\n";
s += "MD5 Fingerprint:\n" + dumpCertificateFingerprint(cert, QCryptographicHash::Md5) + "\n";
#endif
s += "\n\n";
s += cert.toPem();
return s;
}
示例11: QTreeWidgetItem
void LeechCraft::SslErrorsDialog::PopulateTree (const QSslError& error)
{
QTreeWidgetItem *item = new QTreeWidgetItem (Ui_.Errors_,
QStringList ("Error:") << error.errorString ());
QSslCertificate cer = error.certificate ();
if (cer.isNull ())
{
new QTreeWidgetItem (item,
QStringList (tr ("Certificate")) <<
tr ("(No certificate available for this error)"));
return;
}
new QTreeWidgetItem (item, QStringList (tr ("Valid:")) <<
(cer.isValid () ? tr ("yes") : tr ("no")));
new QTreeWidgetItem (item, QStringList (tr ("Effective date:")) <<
cer.effectiveDate ().toString ());
new QTreeWidgetItem (item, QStringList (tr ("Expiry date:")) <<
cer.expiryDate ().toString ());
new QTreeWidgetItem (item, QStringList (tr ("Version:")) <<
cer.version ());
new QTreeWidgetItem (item, QStringList (tr ("Serial number:")) <<
cer.serialNumber ());
new QTreeWidgetItem (item, QStringList (tr ("MD5 digest:")) <<
cer.digest ().toHex ());
new QTreeWidgetItem (item, QStringList (tr ("SHA1 digest:")) <<
cer.digest (QCryptographicHash::Sha1).toHex ());
QTreeWidgetItem *issuer = new QTreeWidgetItem (item,
QStringList (tr ("Issuer info")));
QString tmpString;
#if QT_VERSION >= 0x050000
auto cvt = [] (const QStringList& list) { return list.join ("; "); };
#else
auto cvt = [] (const QString& str) { return str; };
#endif
tmpString = cvt (cer.issuerInfo (QSslCertificate::Organization));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (issuer,
QStringList (tr ("Organization:")) << tmpString);
tmpString = cvt (cer.issuerInfo (QSslCertificate::CommonName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (issuer,
QStringList (tr ("Common name:")) << tmpString);
tmpString = cvt (cer.issuerInfo (QSslCertificate::LocalityName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (issuer,
QStringList (tr ("Locality:")) << tmpString);
tmpString = cvt (cer.issuerInfo (QSslCertificate::OrganizationalUnitName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (issuer,
QStringList (tr ("Organizational unit name:")) << tmpString);
tmpString = cvt (cer.issuerInfo (QSslCertificate::CountryName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (issuer,
QStringList (tr ("Country name:")) << tmpString);
tmpString = cvt (cer.issuerInfo (QSslCertificate::StateOrProvinceName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (issuer,
QStringList (tr ("State or province name:")) << tmpString);
QTreeWidgetItem *subject = new QTreeWidgetItem (item,
QStringList (tr ("Subject info")));
tmpString = cvt (cer.subjectInfo (QSslCertificate::Organization));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (subject,
QStringList (tr ("Organization:")) << tmpString);
tmpString = cvt (cer.subjectInfo (QSslCertificate::CommonName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (subject,
QStringList (tr ("Common name:")) << tmpString);
tmpString = cvt (cer.subjectInfo (QSslCertificate::LocalityName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (subject,
QStringList (tr ("Locality:")) << tmpString);
tmpString = cvt (cer.subjectInfo (QSslCertificate::OrganizationalUnitName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (subject,
QStringList (tr ("Organizational unit name:")) << tmpString);
tmpString = cvt (cer.subjectInfo (QSslCertificate::CountryName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (subject,
QStringList (tr ("Country name:")) << tmpString);
tmpString = cvt (cer.subjectInfo (QSslCertificate::StateOrProvinceName));
if (!tmpString.isEmpty ())
new QTreeWidgetItem (subject,
QStringList (tr ("State or province name:")) << tmpString);
//.........这里部分代码省略.........
示例12: characterEncoding
//.........这里部分代码省略.........
{
m_ui->geolocationValueLabel->setText(tr("Always ask"));
}
const QString fullScreenPolicy(widget->getOption(SettingsManager::Browser_EnableFullScreenOption).toString());
if (fullScreenPolicy == QLatin1String("enabled"))
{
m_ui->fullScreenValueLabel->setText(tr("Always"));
}
else if (fullScreenPolicy == QLatin1String("disabled"))
{
m_ui->fullScreenValueLabel->setText(tr("Never"));
}
else
{
m_ui->fullScreenValueLabel->setText(tr("Always ask"));
}
const QString notificationsPolicy(widget->getOption(SettingsManager::Browser_EnableNotificationsOption).toString());
if (notificationsPolicy == QLatin1String("enabled"))
{
m_ui->notificationsValueLabel->setText(tr("Always"));
}
else if (notificationsPolicy == QLatin1String("disabled"))
{
m_ui->notificationsValueLabel->setText(tr("Never"));
}
else
{
m_ui->notificationsValueLabel->setText(tr("Always ask"));
}
const QString popupsPolicy(widget->getOption(SettingsManager::Content_PopupsPolicyOption).toString());
if (popupsPolicy == QLatin1String("openAll"))
{
m_ui->popupsValueLabel->setText(tr("Always"));
}
else if (popupsPolicy == QLatin1String("openAllInBackground"))
{
m_ui->popupsValueLabel->setText(tr("Always (open in backgound)"));
}
else if (popupsPolicy == QLatin1String("blockAll"))
{
m_ui->popupsValueLabel->setText(tr("Never"));
}
else
{
m_ui->popupsValueLabel->setText(tr("Ask"));
}
if (m_sslInformation.certificates.isEmpty())
{
m_ui->tabWidget->setTabEnabled(2, false);
}
else
{
const QSslCertificate certificate(m_sslInformation.certificates.first());
m_ui->certificateIssuedToLabelWidget->setText(certificate.subjectInfo(QSslCertificate::CommonName).join(QLatin1String(", ")));
m_ui->certificateIssuedByLabelWidget->setText(certificate.issuerInfo(QSslCertificate::CommonName).join(QLatin1String(", ")));
m_ui->certificateIssuedOnLabelWidget->setText(Utils::formatDateTime(certificate.effectiveDate()));
m_ui->certificateExpiresOnLabelWidget->setText(Utils::formatDateTime(certificate.expiryDate()));
m_ui->cipherProtocolLabelWidget->setText(m_sslInformation.cipher.protocolString());
m_ui->cipherAuthenticationMethodLabelWidget->setText(m_sslInformation.cipher.authenticationMethod());
m_ui->cipherEncryptionMethodLabelWidget->setText(m_sslInformation.cipher.encryptionMethod());
m_ui->cipherKeyExchangeMethodLabelWidget->setText(m_sslInformation.cipher.keyExchangeMethod());
}
if (m_sslInformation.errors.isEmpty())
{
m_ui->sslErrorsHeaderLabel->hide();
m_ui->sslErrorsViewWidget->hide();
}
else
{
QStandardItemModel *sslErrorsModel(new QStandardItemModel(this));
sslErrorsModel->setHorizontalHeaderLabels(QStringList({tr("Error Message"), tr("URL")}));
for (int i = 0; i < m_sslInformation.errors.count(); ++i)
{
QList<QStandardItem*> items({new QStandardItem(m_sslInformation.errors.at(i).second.errorString()), new QStandardItem(m_sslInformation.errors.at(i).first.toDisplayString())});
items[0]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
items[0]->setToolTip(items[0]->text());
items[1]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
items[1]->setToolTip(items[1]->text());
sslErrorsModel->appendRow(items);
}
m_ui->sslErrorsViewWidget->setModel(sslErrorsModel);
}
setWindowTitle(tr("Information for %1").arg(host));
connect(m_ui->preferencesDetailsButton, SIGNAL(clicked(bool)), this, SLOT(showPreferences()));
connect(m_ui->certificateDetailsButton, SIGNAL(clicked(bool)), this, SLOT(showCertificate()));
}
示例13: setCertificate
bool SslServer::setCertificate(const QString &path, const QString &keyPath)
{
// Don't reset _isCertValid here, in case an older but valid certificate is still loaded.
// Use temporary variables in order to avoid overwriting the existing certificates until
// everything is confirmed good.
QSslCertificate untestedCert;
QList<QSslCertificate> untestedCA;
QSslKey untestedKey;
if (path.isEmpty())
return false;
QFile certFile(path);
if (!certFile.exists()) {
quWarning() << "SslServer: Certificate file" << qPrintable(path) << "does not exist";
return false;
}
if (!certFile.open(QIODevice::ReadOnly)) {
quWarning()
<< "SslServer: Failed to open certificate file" << qPrintable(path)
<< "error:" << certFile.error();
return false;
}
QList<QSslCertificate> certList = QSslCertificate::fromDevice(&certFile);
if (certList.isEmpty()) {
quWarning() << "SslServer: Certificate file doesn't contain a certificate";
return false;
}
untestedCert = certList[0];
certList.removeFirst(); // remove server cert
// store CA and intermediates certs
untestedCA = certList;
if (!certFile.reset()) {
quWarning() << "SslServer: IO error reading certificate file";
return false;
}
// load key from keyPath if it differs from path, otherwise load key from path
if(path != keyPath) {
QFile keyFile(keyPath);
if(!keyFile.exists()) {
quWarning() << "SslServer: Key file" << qPrintable(keyPath) << "does not exist";
return false;
}
if (!keyFile.open(QIODevice::ReadOnly)) {
quWarning()
<< "SslServer: Failed to open key file" << qPrintable(keyPath)
<< "error:" << keyFile.error();
return false;
}
untestedKey = QSslKey(&keyFile, QSsl::Rsa);
keyFile.close();
} else {
untestedKey = QSslKey(&certFile, QSsl::Rsa);
}
certFile.close();
if (untestedCert.isNull()) {
quWarning() << "SslServer:" << qPrintable(path) << "contains no certificate data";
return false;
}
// We allow the core to offer SSL anyway, so no "return false" here. Client will warn about the cert being invalid.
const QDateTime now = QDateTime::currentDateTime();
if (now < untestedCert.effectiveDate())
quWarning() << "SslServer: Certificate won't be valid before" << untestedCert.effectiveDate().toString();
else if (now > untestedCert.expiryDate())
quWarning() << "SslServer: Certificate expired on" << untestedCert.expiryDate().toString();
else { // Qt4's isValid() checks for time range and blacklist; avoid a double warning, hence the else block
#if QT_VERSION < 0x050000
if (!untestedCert.isValid())
#else
if (untestedCert.isBlacklisted())
#endif
quWarning() << "SslServer: Certificate blacklisted";
}
if (untestedKey.isNull()) {
quWarning() << "SslServer:" << qPrintable(keyPath) << "contains no key data";
return false;
}
_isCertValid = true;
// All keys are valid, update the externally visible copy used for new connections.
_cert = untestedCert;
_ca = untestedCA;
_key = untestedKey;
return _isCertValid;
//.........这里部分代码省略.........
示例14: validateConfig
bool QgsAuthPkiPathsEdit::validateConfig()
{
// required components
QString certpath( lePkiPathsCert->text() );
QString keypath( lePkiPathsKey->text() );
bool certfound = QFile::exists( certpath );
bool keyfound = QFile::exists( keypath );
QgsAuthGuiUtils::fileFound( certpath.isEmpty() || certfound, lePkiPathsCert );
QgsAuthGuiUtils::fileFound( keypath.isEmpty() || keyfound, lePkiPathsKey );
if ( !certfound || !keyfound )
{
writePkiMessage( lePkiPathsMsg, tr( "Missing components" ), Invalid );
return validityChange( false );
}
// check for issue date validity, then notify status
QSslCertificate cert;
QFile file( certpath );
QFileInfo fileinfo( file );
QString ext( fileinfo.fileName().replace( fileinfo.completeBaseName(), "" ).toLower() );
if ( ext.isEmpty() )
{
writePkiMessage( lePkiPathsMsg, tr( "Certificate file has no extension" ), Invalid );
return validityChange( false );
}
QFile::OpenMode openflags( QIODevice::ReadOnly );
QSsl::EncodingFormat encformat( QSsl::Der );
if ( ext == ".pem" )
{
openflags |= QIODevice::Text;
encformat = QSsl::Pem;
}
if ( file.open( openflags ) )
{
cert = QSslCertificate( file.readAll(), encformat );
file.close();
}
else
{
writePkiMessage( lePkiPathsMsg, tr( "Failed to read certificate file" ), Invalid );
return validityChange( false );
}
if ( cert.isNull() )
{
writePkiMessage( lePkiPathsMsg, tr( "Failed to load certificate from file" ), Invalid );
return validityChange( false );
}
bool certvalid = cert.isValid();
QDateTime startdate( cert.effectiveDate() );
QDateTime enddate( cert.expiryDate() );
writePkiMessage( lePkiPathsMsg,
tr( "%1 thru %2" ).arg( startdate.toString(), enddate.toString() ),
( certvalid ? Valid : Invalid ) );
return validityChange( certvalid );
}
示例15: updateValue
void CertificateDialog::updateValue()
{
const QSslCertificate certificate(m_certificates.value(m_ui->chainItemView->currentIndex().data(Qt::UserRole).toInt()));
const CertificateField field(static_cast<CertificateField>(m_ui->detailsItemView->currentIndex().data(Qt::UserRole).toInt()));
m_ui->valueTextEdit->clear();
switch (field)
{
case ValidityField:
case PublicKeyField:
case ExtensionsField:
case DigestField:
break;
case VersionField:
m_ui->valueTextEdit->setPlainText(QString(certificate.version()));
break;
case SerialNumberField:
m_ui->valueTextEdit->setPlainText(formatHex(QString(certificate.serialNumber()), QLatin1Char(':')));
break;
case SignatureAlgorithmField:
m_ui->valueTextEdit->setPlainText(QRegularExpression(QLatin1String("Signature Algorithm:(.+)")).match(certificate.toText()).captured(1).trimmed());
break;
case IssuerField:
{
const QList<QByteArray> attributes(certificate.issuerInfoAttributes());
for (int i = 0; i < attributes.count(); ++i)
{
m_ui->valueTextEdit->appendPlainText(QStringLiteral("%1 = %2").arg(QString(attributes.at(i))).arg(certificate.issuerInfo(attributes.at(i)).join(QLatin1String(", "))));
}
}
break;
case ValidityNotBeforeField:
m_ui->valueTextEdit->setPlainText(certificate.effectiveDate().toString(QLatin1String("yyyy-MM-dd hh:mm:ss t")));
break;
case ValidityNotAfterField:
m_ui->valueTextEdit->setPlainText(certificate.expiryDate().toString(QLatin1String("yyyy-MM-dd hh:mm:ss t")));
break;
case SubjectField:
{
const QList<QByteArray> attributes(certificate.subjectInfoAttributes());
for (int i = 0; i < attributes.count(); ++i)
{
m_ui->valueTextEdit->appendPlainText(QStringLiteral("%1 = %2").arg(QString(attributes.at(i))).arg(certificate.subjectInfo(attributes.at(i)).join(QLatin1String(", "))));
}
}
break;
case PublicKeyValueField:
{
const QRegularExpression expression(QLatin1String("Public-Key:[.\\s\\S]+Modulus:([.\\s\\S]+)Exponent:(.+)"), QRegularExpression::MultilineOption);
const QRegularExpressionMatch match(expression.match(certificate.toText()));
if (match.hasMatch())
{
m_ui->valueTextEdit->setPlainText(tr("Modulus:\n%1\n\nExponent: %2").arg(formatHex(match.captured(1).trimmed().mid(3))).arg(match.captured(2).trimmed()));
}
}
break;
case PublicKeyAlgorithmField:
m_ui->valueTextEdit->setPlainText(QRegularExpression(QLatin1String("Public Key Algorithm:(.+)")).match(certificate.toText()).captured(1).trimmed());
break;
case ExtensionField:
{
const QSslCertificateExtension extension(certificate.extensions().value(m_ui->detailsItemView->currentIndex().data(Qt::UserRole + 1).toInt()));
m_ui->valueTextEdit->setPlainText(extension.isCritical() ? tr("Critical") : tr("Not Critical"));
m_ui->valueTextEdit->appendPlainText(tr("OID: %1").arg(extension.oid()));
if (!extension.value().isNull())
{
m_ui->valueTextEdit->appendPlainText(tr("Value:"));
if (extension.value().type() == QVariant::List)
{
const QVariantList list(extension.value().toList());
for (int i = 0; i < list.count(); ++i)
{
m_ui->valueTextEdit->appendPlainText(list.at(i).toString());
}
}
else if (extension.value().type() == QVariant::Map)
{
const QVariantMap map(extension.value().toMap());
QVariantMap::const_iterator iterator;
for (iterator = map.constBegin(); iterator != map.constEnd(); ++iterator)
{
m_ui->valueTextEdit->appendPlainText(QStringLiteral("%1 = %2").arg(iterator.key()).arg(iterator.value().toString()));
//.........这里部分代码省略.........