本文整理汇总了C++中SslCertificate::keyUsage方法的典型用法代码示例。如果您正苦于以下问题:C++ SslCertificate::keyUsage方法的具体用法?C++ SslCertificate::keyUsage怎么用?C++ SslCertificate::keyUsage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SslCertificate
的用法示例。
在下文中一共展示了SslCertificate::keyUsage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QByteArray
TokenData QPKCS11::selectSlot( const QString &card, SslCertificate::KeyUsage usage )
{
delete d->pslot;
d->pslot = 0;
TokenData t;
t.setCard( card );
for( unsigned int i = 0; i < d->nslots; ++i )
{
CK_TOKEN_INFO token;
if( (d->err = d->f->C_GetTokenInfo( d->pslots[i], &token )) != CKR_OK ||
card != QByteArray( (const char*)token.serialNumber, 16 ).trimmed() )
continue;
SslCertificate cert = d->readCert( d->pslots[i] );
if( !cert.keyUsage().keys().contains( usage ) )
continue;
d->pslot = new CK_SLOT_ID( d->pslots[i] );
t.setCert( cert );
if( token.flags & CKF_SO_PIN_COUNT_LOW || token.flags & CKF_USER_PIN_COUNT_LOW )
t.setFlag( TokenData::PinCountLow );
if( token.flags & CKF_SO_PIN_FINAL_TRY || token.flags & CKF_USER_PIN_FINAL_TRY )
t.setFlag( TokenData::PinFinalTry );
if( token.flags & CKF_SO_PIN_LOCKED || token.flags & CKF_USER_PIN_LOCKED )
t.setFlag( TokenData::PinLocked );
break;
}
return t;
}
示例2: selectCert
void QSigner::selectCert( const QString &card )
{
d->selectedCard = card;
d->sign = QSslCertificate();
Q_EMIT dataChanged( d->cards.keys(), d->selectedCard, d->sign );
PKCS11_CERT* certs;
unsigned int numberOfCerts;
for( unsigned int i = 0; i < d->slotCount; ++i )
{
PKCS11_SLOT* slot = &d->slots[i];
if( !slot->token ||
d->selectedCard != QByteArray( (const char*)slot->token->serialnr, 16 ).trimmed() ||
PKCS11_enumerate_certs( slot->token, &certs, &numberOfCerts ) ||
numberOfCerts <= 0 )
continue;
SslCertificate cert = SslCertificate::fromX509( Qt::HANDLE((&certs[0])->x509) );
if( cert.keyUsage().keys().contains( SslCertificate::NonRepudiation ) )
{
d->sign = cert;
d->cards[d->selectedCard] = i;
break;
}
}
Q_EMIT dataChanged( d->cards.keys(), d->selectedCard, d->sign );
}
示例3: selectCert
void QSigner::selectCert( const QString &card )
{
d->selectedCard = card;
d->flags = 0;
d->cert = QSslCertificate();
emitDataChanged();
if( d->slotCount )
{
PKCS11_release_all_slots( d->handle, d->slots, d->slotCount );
d->slotCount = 0;
}
if( PKCS11_enumerate_slots( d->handle, &d->slots, &d->slotCount ) ||
d->cards[card] >= d->slotCount ||
!(d->slot = &d->slots[d->cards[card]]) )
return;
PKCS11_CERT* certs;
unsigned int numberOfCerts;
for( unsigned int i = 0; i < d->slotCount; ++i )
{
if( !d->slot->token ||
d->selectedCard != QByteArray( (const char*)d->slot->token->serialnr, 16 ).trimmed() ||
PKCS11_enumerate_certs( d->slot->token, &certs, &numberOfCerts ) ||
numberOfCerts <= 0 )
continue;
SslCertificate cert = SslCertificate::fromX509( Qt::HANDLE((&certs[0])->x509) );
if( cert.keyUsage().keys().contains( SslCertificate::NonRepudiation ) )
{
d->cert = cert;
d->cards[d->selectedCard] = i;
#ifdef LIBP11_TOKEN_FLAGS
if( d->slot->token->userPinCountLow || d->slot->token->soPinCountLow )
d->flags |= TokenData::PinCountLow;
if( d->slot->token->userPinFinalTry || d->slot->token->soPinFinalTry )
d->flags |= TokenData::PinFinalTry;
if( d->slot->token->userPinLocked || d->slot->token->soPinLocked )
d->flags |= TokenData::PinLocked;
#endif
break;
}
}
emitDataChanged();
}
示例4: selectCert
TokenData QCSP::selectCert( const QString &cn, SslCertificate::KeyUsage usage )
{
TokenData t;
t.setCard( cn );
if( d->h )
CryptReleaseContext( d->h, 0 );
QPair<QString,QString> c = d->certs.value( cn );
if( !CryptAcquireContextW( &d->h, LPCWSTR(c.second.utf16()), LPCWSTR(c.first.utf16()), PROV_RSA_FULL, 0 ) )
return t;
HCRYPTKEY key = 0;
if( !CryptGetUserKey( d->h, usage == SslCertificate::NonRepudiation ? AT_SIGNATURE : AT_KEYEXCHANGE, &key ) )
return t;
SslCertificate cert = QSslCertificate( d->keyParam( key, KP_CERTIFICATE, 0 ), QSsl::Der );
CryptDestroyKey( key );
if( cert.keyUsage().keys().contains( usage ) )
t.setCert( cert );
return t;
}
示例5: s
CertificateDialog::CertificateDialog(const QSslCertificate &cert, QWidget *parent, bool removePath)
: QDialog( parent )
, d( new CertificateDialogPrivate )
{
d->setupUi( this );
QPushButton *save = d->buttonBox->button(QDialogButtonBox::Save);
if(save && Settings(QSettings::SystemScope).value("disableSave", false).toBool())
{
d->buttonBox->removeButton(save);
save->deleteLater();
}
if(removePath)
d->tabWidget->removeTab( 2 );
d->cert = cert;
SslCertificate c = cert;
QString i;
QTextStream s( &i );
s << "<b>" << tr("Certificate Information") << "</b><br />";
s << "<hr>";
s << "<b>" << tr("This certificate is intended for following purpose(s):") << "</b>";
s << "<ul>";
for(const QString &ext: c.enhancedKeyUsage())
s << "<li>" << ext << "</li>";
s << "</ul>";
s << "<br /><br /><br /><br />";
//s << tr("* Refer to the certification authority's statement for details.") << "<br />";
s << "<hr>";
s << "<p style='margin-left: 30px;'>";
s << "<b>" << tr("Issued to:") << "</b> " << c.subjectInfo( QSslCertificate::CommonName );
s << "<br /><br /><br />";
s << "<b>" << tr("Issued by:") << "</b> " << c.issuerInfo( QSslCertificate::CommonName );
s << "<br /><br /><br />";
s << "<b>" << tr("Valid from") << "</b> " << c.effectiveDate().toLocalTime().toString( "dd.MM.yyyy" ) << " ";
s << "<b>" << tr("to") << "</b> "<< c.expiryDate().toLocalTime().toString( "dd.MM.yyyy" );
s << "</p>";
d->info->setHtml( i );
d->addItem( tr("Version"), "V" + c.version() );
d->addItem( tr("Serial number"), QString( "%1 (0x%2)" )
.arg( c.serialNumber().constData() )
.arg( c.serialNumber( true ).constData() ) );
d->addItem( tr("Signature algorithm"), c.signatureAlgorithm() );
QStringList text, textExt;
for(const QByteArray &obj: c.issuerInfoAttributes())
{
const QString &data = c.issuerInfo( obj );
if( data.isEmpty() )
continue;
text << data;
textExt << QString( "%1 = %2" ).arg( obj.constData() ).arg( data );
}
d->addItem( tr("Issuer"), text.join( ", " ), textExt.join( "\n" ) );
d->addItem( tr("Valid from"), DateTime( c.effectiveDate().toLocalTime() ).toStringZ( "dd.MM.yyyy hh:mm:ss" ) );
d->addItem( tr("Valid to"), DateTime( c.expiryDate().toLocalTime() ).toStringZ( "dd.MM.yyyy hh:mm:ss" ) );
text.clear();
textExt.clear();
for(const QByteArray &obj: c.subjectInfoAttributes())
{
const QString &data = c.subjectInfo( obj );
if( data.isEmpty() )
continue;
text << data;
textExt << QString( "%1 = %2" ).arg( obj.constData() ).arg( data );
}
d->addItem( tr("Subject"), text.join( ", " ), textExt.join( "\n" ) );
d->addItem( tr("Public key"), c.keyName(), c.publicKeyHex() );
QStringList enhancedKeyUsage = c.enhancedKeyUsage().values();
if( !enhancedKeyUsage.isEmpty() )
d->addItem( tr("Enhanched key usage"), enhancedKeyUsage.join( ", " ), enhancedKeyUsage.join( "\n" ) );
QStringList policies = c.policies();
if( !policies.isEmpty() )
d->addItem( tr("Certificate policies"), policies.join( ", " ) );
d->addItem( tr("Authority key identifier"), c.toHex( c.authorityKeyIdentifier() ) );
d->addItem( tr("Subject key identifier"), c.toHex( c.subjectKeyIdentifier() ) );
QStringList keyUsage = c.keyUsage().values();
if( !keyUsage.isEmpty() )
d->addItem( tr("Key usage"), keyUsage.join( ", " ), keyUsage.join( "\n" ) );
d->parameters->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
}
示例6: setCertificate
void CertificateDialog::setCertificate( const QSslCertificate &cert )
{
d->cert = cert;
SslCertificate c = cert;
QString i;
QTextStream s( &i );
s << "<b>" << tr("Certificate Information") << "</b><br />";
s << "<hr>";
s << "<b>" << tr("This certificate is intended for following purpose(s):") << "</b>";
s << "<ul>";
Q_FOREACH( const QString &ext, c.enhancedKeyUsage() )
s << "<li>" << ext << "</li>";
s << "</ul>";
s << "<br /><br /><br /><br />";
//s << tr("* Refer to the certification authority's statement for details.") << "<br />";
s << "<hr>";
s << "<p style='margin-left: 30px;'>";
s << "<b>" << tr("Issued to:") << "</b> " << c.subjectInfo( QSslCertificate::CommonName );
s << "<br /><br /><br />";
s << "<b>" << tr("Issued by:") << "</b> " << c.issuerInfo( QSslCertificate::CommonName );
s << "<br /><br /><br />";
s << "<b>" << tr("Valid from") << "</b> " << c.effectiveDate().toLocalTime().toString( "dd.MM.yyyy" ) << " ";
s << "<b>" << tr("to") << "</b> "<< c.expiryDate().toLocalTime().toString( "dd.MM.yyyy" );
s << "</p>";
d->info->setHtml( i );
d->addItem( tr("Version"), "V" + c.version() );
d->addItem( tr("Serial number"), QString( "%1 (0x%2)" )
.arg( c.serialNumber().constData() )
.arg( QString::number( c.serialNumber().toInt(), 16 ) ) );
d->addItem( tr("Signature algorithm"), c.signatureAlgorithm() );
QStringList text, textExt;
Q_FOREACH( const QByteArray &subject, QList<QByteArray>() << "CN" << "OU" << "O" << "C" )
{
const QString &data = c.issuerInfo( subject );
if( data.isEmpty() )
continue;
text << data;
textExt << QString( "%1 = %2" ).arg( subject.constData() ).arg( data );
}
d->addItem( tr("Issuer"), text.join( ", " ), textExt.join( "\n" ) );
d->addItem( tr("Valid from"), c.effectiveDate().toLocalTime().toString( "dd.MM.yyyy hh:mm:ss" ) );
d->addItem( tr("Vaild to"), c.expiryDate().toLocalTime().toString( "dd.MM.yyyy hh:mm:ss" ) );
text.clear();
textExt.clear();
Q_FOREACH( const QByteArray &subject,
QList<QByteArray>() << "serialNumber" << "GN" << "SN" << "CN" << "OU" << "O" << "C" )
{
const QString &data = c.subjectInfo( subject );
if( data.isEmpty() )
continue;
text << data;
textExt << QString( "%1 = %2" ).arg( subject.constData() ).arg( data );
}
d->addItem( tr("Subject"), text.join( ", " ), textExt.join( "\n" ) );
d->addItem( tr("Public key"), QString("%1 (%2)")
.arg( c.publicKey().algorithm() == QSsl::Rsa ? "RSA" : "DSA" )
.arg( d->keyLenght( c.publicKey() ) ),
c.toHex( c.publicKey().toDer() ) );
QStringList enhancedKeyUsage = c.enhancedKeyUsage().values();
if( !enhancedKeyUsage.isEmpty() )
d->addItem( tr("Enhanched key usage"), enhancedKeyUsage.join( ", " ), enhancedKeyUsage.join( "\n" ) );
QStringList policies = c.policies();
if( !policies.isEmpty() )
d->addItem( tr("Certificate policies"), policies.join( ", " ) );
d->addItem( tr("Authority key identifier"), c.toHex( c.authorityKeyIdentifier() ) );
d->addItem( tr("Subject key identifier"), c.toHex( c.subjectKeyIdentifier() ) );
QStringList keyUsage = c.keyUsage().values();
if( !keyUsage.isEmpty() )
d->addItem( tr("Key usage"), keyUsage.join( ", " ), keyUsage.join( "\n" ) );
}