本文整理汇总了C++中QSslConfiguration::setLocalCertificate方法的典型用法代码示例。如果您正苦于以下问题:C++ QSslConfiguration::setLocalCertificate方法的具体用法?C++ QSslConfiguration::setLocalCertificate怎么用?C++ QSslConfiguration::setLocalCertificate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSslConfiguration
的用法示例。
在下文中一共展示了QSslConfiguration::setLocalCertificate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file
void QMQTT::ClientPrivate::init(const QString& hostName, const quint16 port, const bool ssl,
const bool ignoreSelfSigned)
{
_hostName = hostName;
_port = port;
if (ssl)
{
#ifndef QT_NO_SSL
QSslConfiguration sslConf = QSslConfiguration::defaultConfiguration();
QList<QSslCertificate> certs = QSslCertificate::fromPath(QStringLiteral("./cert.crt"));
if (!certs.isEmpty())
sslConf.setLocalCertificate(certs.first());
QFile file(QStringLiteral("./cert.key"));
if (file.open(QIODevice::ReadOnly)) {
sslConf.setPrivateKey(QSslKey(file.readAll(), QSsl::Rsa));
}
sslConf.setPeerVerifyMode(QSslSocket::VerifyNone);
#if QT_VERSION < 0x050000
sslConf.setProtocol(QSsl::TlsV1);
#endif
init(hostName, port, sslConf, ignoreSelfSigned);
#else
Q_UNUSED(ignoreSelfSigned)
qCritical() << "SSL not supported in this QT build";
#endif // QT_NO_SSL
}
else
{
init(new Network);
}
}
示例2: updateNetworkRequest
bool QgsAuthIdentCertMethod::updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
QMutexLocker locker( &mMutex );
// TODO: is this too restrictive, to intercept only HTTPS connections?
if ( request.url().scheme().toLower() != QLatin1String( "https" ) )
{
QgsDebugMsg( QStringLiteral( "Update request SSL config SKIPPED for authcfg %1: not HTTPS" ).arg( authcfg ) );
return true;
}
QgsDebugMsg( QStringLiteral( "Update request SSL config: HTTPS connection for authcfg: %1" ).arg( authcfg ) );
QgsPkiConfigBundle *pkibundle = getPkiConfigBundle( authcfg );
if ( !pkibundle || !pkibundle->isValid() )
{
QgsDebugMsg( QStringLiteral( "Update request SSL config FAILED for authcfg: %1: PKI bundle invalid" ).arg( authcfg ) );
return false;
}
QgsDebugMsg( QStringLiteral( "Update request SSL config: PKI bundle valid for authcfg: %1" ).arg( authcfg ) );
QSslConfiguration sslConfig = request.sslConfiguration();
//QSslConfiguration sslConfig( QSslConfiguration::defaultConfiguration() );
sslConfig.setLocalCertificate( pkibundle->clientCert() );
sslConfig.setPrivateKey( pkibundle->clientCertKey() );
request.setSslConfiguration( sslConfig );
return true;
}
示例3: certFile
QT_USE_NAMESPACE
//! [constructor]
SslEchoServer::SslEchoServer(quint16 port, QObject *parent) :
QObject(parent),
m_pWebSocketServer(Q_NULLPTR),
m_clients()
{
m_pWebSocketServer = new QWebSocketServer(QStringLiteral("SSL Echo Server"),
QWebSocketServer::SecureMode,
this);
QSslConfiguration sslConfiguration;
QFile certFile(QStringLiteral("./localhost.cert"));
QFile keyFile(QStringLiteral("./localhost.key"));
certFile.open(QIODevice::ReadOnly);
keyFile.open(QIODevice::ReadOnly);
QSslCertificate certificate(&certFile, QSsl::Pem);
QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem);
certFile.close();
keyFile.close();
sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);
sslConfiguration.setLocalCertificate(certificate);
sslConfiguration.setPrivateKey(sslKey);
sslConfiguration.setProtocol(QSsl::TlsV1SslV3);
m_pWebSocketServer->setSslConfiguration(sslConfiguration);
if (m_pWebSocketServer->listen(QHostAddress::Any, port))
{
qDebug() << "SSL Echo Server listening on port" << port;
connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
this, &SslEchoServer::onNewConnection);
connect(m_pWebSocketServer, &QWebSocketServer::sslErrors,
this, &SslEchoServer::onSslErrors);
}
}
示例4: sendRequest
void NetworkManager::sendRequest(ChatUnit *contact, const QString &text)
{
Config config("control");
config.beginGroup("general");
QUrl url = QUrl::fromUserInput(config.value("requestUrl", QString()));
QNetworkRequest request(url);
QSslConfiguration ssl;
ssl.setLocalCertificate(m_localCertificate);
ssl.setPrivateKey(m_privateKey);
request.setSslConfiguration(ssl);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QByteArray data = "request=" + paranoicEscape(text.toUtf8());
QNetworkReply *reply = QNetworkAccessManager::post(request, data);
connect(contact, SIGNAL(destroyed()), reply, SLOT(deleteLater()));
reply->setProperty("__control_contact", qVariantFromValue(contact));
}
示例5: getOrCreateSslConfig
QSslConfiguration Account::getOrCreateSslConfig()
{
if (!_sslConfiguration.isNull()) {
// Will be set by CheckServerJob::finished()
// We need to use a central shared config to get SSL session tickets
return _sslConfiguration;
}
// if setting the client certificate fails, you will probably get an error similar to this:
// "An internal error number 1060 happened. SSL handshake failed, client certificate was requested: SSL error: sslv3 alert handshake failure"
QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration();
QSslCertificate sslClientCertificate;
ConfigFile cfgFile;
if(!cfgFile.certificatePath().isEmpty() && !cfgFile.certificatePasswd().isEmpty()) {
resultP12ToPem certif = p12ToPem(cfgFile.certificatePath().toStdString(), cfgFile.certificatePasswd().toStdString());
QString s = QString::fromStdString(certif.Certificate);
QByteArray ba = s.toLocal8Bit();
this->setCertificate(ba, QString::fromStdString(certif.PrivateKey));
}
if((!_pemCertificate.isEmpty())&&(!_pemPrivateKey.isEmpty())) {
// Read certificates
QList<QSslCertificate> sslCertificateList = QSslCertificate::fromData(_pemCertificate, QSsl::Pem);
if(sslCertificateList.length() != 0) {
sslClientCertificate = sslCertificateList.takeAt(0);
}
// Read key from file
QSslKey privateKey(_pemPrivateKey.toLocal8Bit(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey , "");
// SSL configuration
sslConfig.setCaCertificates(QSslSocket::systemCaCertificates());
sslConfig.setLocalCertificate(sslClientCertificate);
sslConfig.setPrivateKey(privateKey);
qDebug() << "Added SSL client certificate to the query";
}
#if QT_VERSION > QT_VERSION_CHECK(5, 2, 0)
// Try hard to re-use session for different requests
sslConfig.setSslOption(QSsl::SslOptionDisableSessionTickets, false);
sslConfig.setSslOption(QSsl::SslOptionDisableSessionSharing, false);
sslConfig.setSslOption(QSsl::SslOptionDisableSessionPersistence, false);
#endif
return sslConfig;
}
示例6: file
Server::Server(int port, QtWebsocket::Protocol protocol)
{
if(protocol == QtWebsocket::Tcp)
server = new QtWebsocket::QWsServer(this, protocol);
else
{
QFile file("server-key.pem");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "can't open key server-key.pem";
throw -1;
}
QSslKey key(&file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, QByteArray("qtwebsocket-server-key"));
file.close();
QFile file2("server-crt.pem");
if (!file2.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "cant load server certificate server-crt.pem";
throw -2;
}
QSslCertificate localCert(&file2, QSsl::Pem);
file2.close();
QSslConfiguration sslConfiguration;
sslConfiguration.setPrivateKey(key);
sslConfiguration.setLocalCertificate(localCert);
sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);
QList<QSslCertificate> caCerts = QSslCertificate::fromPath("ca.pem");
server = new QtWebsocket::QWsServer(this, protocol, sslConfiguration, caCerts);
}
if (! server->listen(QHostAddress::Any, port))
{
qDebug() << tr("Error: Can't launch server");
qDebug() << tr("QWsServer error : %1").arg(server->errorString());
}
else
{
qDebug() << tr("Server is listening on port %1").arg(port);
}
QObject::connect(server, SIGNAL(newConnection()), this, SLOT(processNewConnection()));
}
示例7: certFile
QT_USE_NAMESPACE
//! [constructor]
BCWebSocketServer::BCWebSocketServer(quint16 port, QObject *parent) :
QObject(parent),
m_pWebSocketServer(Q_NULLPTR),
m_clients()
{
m_pWebSocketServer = new QWebSocketServer(QStringLiteral("Bitcoin Exchange Server"),
QWebSocketServer::NonSecureMode, //**** To be Changed after setting up OpenSSL
this);
QSslConfiguration sslConfiguration;
QFile certFile(QStringLiteral("./localhost.cert"));
QFile keyFile(QStringLiteral("./localhost.key"));
/*if ( */
certFile.open(stderr, QIODevice::ReadOnly | QIODevice::Text ) ; //&&
keyFile.open(stderr, QIODevice::ReadOnly | QIODevice::Text) ; // )
{
QSslCertificate certificate(&certFile, QSsl::Pem);
QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem);
certFile.close();
keyFile.close();
sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);
sslConfiguration.setLocalCertificate(certificate);
sslConfiguration.setPrivateKey(sslKey);
sslConfiguration.setProtocol(QSsl::TlsV1SslV3);
m_pWebSocketServer->setSslConfiguration(sslConfiguration);
if (m_pWebSocketServer->listen(QHostAddress::Any, port))
{
qDebug() << "Bitcoin Exchange Server listening on port" << port;
connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
this, &BCWebSocketServer::onNewConnection);
connect(m_pWebSocketServer, &QWebSocketServer::sslErrors,
this, &BCWebSocketServer::onSslErrors);
}
_logged = false;
_lang = NULL;
this->data.rank = 0;
}
}
示例8: setupWebSocket
//===================
// PRIVATE
//===================
bool WebServer::setupWebSocket(quint16 port){
WSServer = new QWebSocketServer("sysadm-server", QWebSocketServer::SecureMode, this);
//SSL Configuration
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
QFile CF( QStringLiteral(SSLCERTFILE) );
if(CF.open(QIODevice::ReadOnly) ){
QSslCertificate CERT(&CF,QSsl::Pem);
config.setLocalCertificate( CERT );
CF.close();
}else{
qWarning() << "Could not read WS certificate file:" << CF.fileName();
}
QFile KF( QStringLiteral(SSLKEYFILE));
if(KF.open(QIODevice::ReadOnly) ){
QSslKey KEY(&KF, QSsl::Rsa, QSsl::Pem);
config.setPrivateKey( KEY );
KF.close();
}else{
qWarning() << "Could not read WS key file:" << KF.fileName();
}
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(SSLVERSION);
WSServer->setSslConfiguration(config);
//Setup Connections
connect(WSServer, SIGNAL(newConnection()), this, SLOT(NewSocketConnection()) );
connect(WSServer, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(NewConnectError(QAbstractSocket::SocketError)) );
// -- websocket specific signals
connect(WSServer, SIGNAL(closed()), this, SLOT(ServerClosed()) );
connect(WSServer, SIGNAL(serverError(QWebSocketProtocol::CloseCode)), this, SLOT(ServerError(QWebSocketProtocol::CloseCode)) );
connect(WSServer, SIGNAL(originAuthenticationRequired(QWebSocketCorsAuthenticator*)), this, SLOT(OriginAuthRequired(QWebSocketCorsAuthenticator*)) );
connect(WSServer, SIGNAL(peerVerifyError(const QSslError&)), this, SLOT(PeerVerifyError(const QSslError&)) );
connect(WSServer, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(SslErrors(const QList<QSslError>&)) );
connect(WSServer, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(ConnectError(QAbstractSocket::SocketError)) );
//Now start the server
return WSServer->listen(QHostAddress::Any, port);
}
示例9: tr
//.........这里部分代码省略.........
if( !Application::confValue( Application::ProxyHost ).toString().isEmpty() )
{
manager->setProxy( QNetworkProxy(
QNetworkProxy::HttpProxy,
Application::confValue( Application::ProxyHost ).toString(),
Application::confValue( Application::ProxyPort ).toUInt(),
Application::confValue( Application::ProxyUser ).toString(),
Application::confValue( Application::ProxyPass ).toString() ) );
}
if( !Application::confValue( Application::PKCS12Disable ).toBool() )
{
QSslConfiguration ssl = QSslConfiguration::defaultConfiguration();
ssl.setCaCertificates( ssl.caCertificates()
#ifdef Q_OS_LINUX
<< QSslCertificate::fromPath( "/usr/share/esteid/certs/*.crt", QSsl::Pem, QRegExp::Wildcard )
#endif
<< QSslCertificate( "-----BEGIN CERTIFICATE-----\n"
"MIIEOzCCAyOgAwIBAgIBADANBgkqhkiG9w0BAQUFADB2MQswCQYDVQQGEwJFRTEi\n"
"MCAGA1UEChMZQVMgU2VydGlmaXRzZWVyaW1pc2tlc2t1czEeMBwGA1UECxMVU0sg\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2KXC\n"
"9yZ8YQPWBLY4Mh3OVLFJqWyKC+8JHy9D5tJTG49F5UHyDJPufD/XvC2rjRlkqvS/\n"
"W7sy3MqGh7e+6bg+aD4mo+98Oalnqi12UD+ki+N8JKPXjHNJ31AvH6E/xDsCsvtz\n"
"ubylxI+FU8R0XODIUFbBqRtatRI1/zVaKRhD6LNGPt3rz/3IJKmuEv6b29mzL+p4\n"
"oNULqpPr6aTmheZme8ZHuEIh3Zp5kdoX3i2D4hsmgClpevZifo196zeKRLk0Qs6n\n"
"mRjoMxyk6jYIric3/VnV81oyhXSBY1GZnbM4qP1w2S5kSA2bb1pkwFo=\n"
"-----END CERTIFICATE-----\n"));
ssl.setPrivateKey( AccessCert::key() );
ssl.setLocalCertificate( AccessCert::cert() );
request.setSslConfiguration( ssl );
}
request.setHeader( QNetworkRequest::ContentTypeHeader, "text/xml" );
request.setRawHeader( "User-Agent", QString( "%1/%2 (%3)")
.arg( qApp->applicationName() ).arg( qApp->applicationVersion() ).arg( Common::applicationOs() ).toUtf8() );
}
示例10: setupSocketWithSSLDataSource
void WebSocketQt::setupSocketWithSSLDataSource(SSLDataSource * dataSource)
{
QSslConfiguration config;
QFile localFile(WebSocketQt::toString(dataSource->clientLocalCertificateFilePath()));
if (localFile.open(QIODevice::ReadOnly))
{
QSslCertificate cert(localFile.readAll());
localFile.close();
if (cert.isNull())
{
#ifdef FAYECPP_DEBUG_MESSAGES
qDebug() << "SocketQT: LocalCertificate is NULL";
#endif
}
else
{
config.setLocalCertificate(cert);
}
}
QFile keyFile(WebSocketQt::toString(dataSource->clientPrivateKeyFilePath()));
if (keyFile.open(QIODevice::ReadOnly))
{
QByteArray pp;
pp.append(WebSocketQt::toString(dataSource->clientPrivateKeyPassPhrase()));
QSslKey key(keyFile.readAll(),
QSsl::Rsa,
QSsl::Pem,
QSsl::PrivateKey,
pp);
pp.clear();
keyFile.close();
if (key.isNull())
{
#ifdef FAYECPP_DEBUG_MESSAGES
qDebug() << "SocketQT: PrivateKey is NULL";
#endif
}
else
{
config.setPrivateKey(key);
}
}
QFile caFile(WebSocketQt::toString(dataSource->clientCACertificateFilePath()));
if (caFile.open(QIODevice::ReadOnly))
{
QSslCertificate cert(caFile.readAll());
caFile.close();
if (cert.isNull())
{
#ifdef FAYECPP_DEBUG_MESSAGES
qDebug() << "SocketQT: CACertificate is NULL";
#endif
}
else
{
QList<QSslCertificate> caList(config.caCertificates());
caList.append(cert);
config.setCaCertificates(caList);
}
}
_socket->setSslConfiguration(config);
}
示例11: update
void Server::update() {
if (!((! qsRegName.isEmpty()) && (! qsRegName.isEmpty()) && (! qsRegPassword.isEmpty()) && qurlRegWeb.isValid() && qsPassword.isEmpty() && bAllowPing))
return;
// When QNAM distinguishes connections by client cert, move this to Meta
if (! qnamNetwork)
qnamNetwork = new QNetworkAccessManager(this);
qtTick.start(1000 * (60 * 60 + (qrand() % 300)));
QDomDocument doc;
QDomElement root=doc.createElement(QLatin1String("server"));
doc.appendChild(root);
OSInfo::fillXml(doc, root, meta->qsOS, meta->qsOSVersion, qlBind);
QDomElement tag;
QDomText t;
tag=doc.createElement(QLatin1String("name"));
root.appendChild(tag);
t=doc.createTextNode(qsRegName);
tag.appendChild(t);
tag=doc.createElement(QLatin1String("host"));
root.appendChild(tag);
t=doc.createTextNode(qsRegHost);
tag.appendChild(t);
tag=doc.createElement(QLatin1String("password"));
root.appendChild(tag);
t=doc.createTextNode(qsRegPassword);
tag.appendChild(t);
tag=doc.createElement(QLatin1String("port"));
root.appendChild(tag);
t=doc.createTextNode(QString::number(usPort));
tag.appendChild(t);
tag=doc.createElement(QLatin1String("url"));
root.appendChild(tag);
t=doc.createTextNode(qurlRegWeb.toString());
tag.appendChild(t);
tag=doc.createElement(QLatin1String("digest"));
root.appendChild(tag);
t=doc.createTextNode(getDigest());
tag.appendChild(t);
tag=doc.createElement(QLatin1String("users"));
root.appendChild(tag);
t=doc.createTextNode(QString::number(qhUsers.count()));
tag.appendChild(t);
tag=doc.createElement(QLatin1String("channels"));
root.appendChild(tag);
t=doc.createTextNode(QString::number(qhChannels.count()));
tag.appendChild(t);
QNetworkRequest qnr(QUrl(QLatin1String("https://mumble.hive.no/register.cgi")));
qnr.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml"));
QSslConfiguration ssl = qnr.sslConfiguration();
ssl.setLocalCertificate(qscCert);
ssl.setPrivateKey(qskKey);
/* Work around bug in QSslConfiguration */
QList<QSslCertificate> calist = ssl.caCertificates();
calist << QSslSocket::defaultCaCertificates();
calist << qscCert;
ssl.setCaCertificates(calist);
qnr.setSslConfiguration(ssl);
QNetworkReply *rep = qnamNetwork->post(qnr, doc.toString().toUtf8());
connect(rep, SIGNAL(finished()), this, SLOT(finished()));
connect(rep, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(regSslError(const QList<QSslError> &)));
}
示例12: updateCredentials
void Ssu::updateCredentials(bool force){
SsuCoreConfig *settings = SsuCoreConfig::instance();
errorFlag = false;
SsuLog *ssuLog = SsuLog::instance();
if (deviceInfo.deviceUid() == ""){
setError("No valid UID available for your device. For phones: is your modem online?");
return;
}
QString ssuCaCertificate, ssuCredentialsUrl;
if (!settings->contains("ca-certificate")){
setError("CA certificate for SSU not set (config key 'ca-certificate')");
return;
} else
ssuCaCertificate = settings->value("ca-certificate").toString();
if (!settings->contains("credentials-url")){
ssuCredentialsUrl = repoUrl("credentials-url");
if (ssuCredentialsUrl.isEmpty()){
setError("URL for credentials update not set (config key 'credentials-url')");
return;
}
} else
ssuCredentialsUrl = settings->value("credentials-url").toString();
if (!isRegistered()){
setError("Device is not registered.");
return;
}
if (!force){
// skip updating if the last update was less than 30 minutes ago
QDateTime now = QDateTime::currentDateTime();
if (settings->contains("lastCredentialsUpdate")){
QDateTime last = settings->value("lastCredentialsUpdate").toDateTime();
if (last >= now.addSecs(-1800)){
ssuLog->print(LOG_DEBUG, QString("Skipping credentials update, last update was at %1")
.arg(last.toString()));
emit done();
return;
}
}
}
// check when the last update was, decide if an update is required
QSslConfiguration sslConfiguration;
if (!useSslVerify())
sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);
QSslKey privateKey(settings->value("privateKey").toByteArray(), QSsl::Rsa);
QSslCertificate certificate(settings->value("certificate").toByteArray());
QList<QSslCertificate> caCertificates;
caCertificates << QSslCertificate::fromPath(ssuCaCertificate);
sslConfiguration.setCaCertificates(caCertificates);
sslConfiguration.setPrivateKey(privateKey);
sslConfiguration.setLocalCertificate(certificate);
QNetworkRequest request;
request.setUrl(QUrl(ssuCredentialsUrl.arg(deviceInfo.deviceUid())));
ssuLog->print(LOG_DEBUG, QString("Sending credential update request to %1")
.arg(request.url().toString()));
request.setSslConfiguration(sslConfiguration);
pendingRequests++;
manager->get(request);
}