20 #include <QDialogButtonBox> 21 #include <QPushButton> 47 , mConnectionCAs( connectionCAs )
48 , mProtocolItem( nullptr )
49 , mProtocolCmbBx( nullptr )
50 , mIgnoreErrorsItem( nullptr )
51 , mVerifyModeItem( nullptr )
52 , mVerifyPeerCmbBx( nullptr )
53 , mVerifyDepthItem( nullptr )
54 , mVerifyDepthSpnBx( nullptr )
57 , mAuthNotifyLayout( nullptr )
58 , mAuthNotify( nullptr )
66 mAuthNotifyLayout->
addWidget( mAuthNotify );
78 lblLoadedConfig->setVisible(
false );
79 lblLoadedConfig->setText(
"" );
110 return grpbxSslConfig;
118 (
int )ConfigParent );
122 treeSslConfig->insertTopLevelItem( treeSslConfig->topLevelItemCount(), item );
127 void QgsAuthSslConfigWidget::setUpSslConfigTree()
129 treeSslConfig->setColumnCount( 1 );
132 mProtocolItem = addRootItem(
tr(
"Protocol" ) );
133 mProtocolCmbBx =
new QComboBox( treeSslConfig );
134 #if QT_VERSION >= 0x040800 136 (
int )QSsl::SecureProtocols );
138 (
int )QSsl::TlsV1SslV3 );
141 (
int )QSsl::TlsV1 );
143 (
int )QSsl::SslV3 );
145 (
int )QSsl::SslV2 );
152 protocolitem->
setFlags( protocolitem->
flags() & ~
Qt::ItemIsSelectable );
153 treeSslConfig->setItemWidget( protocolitem, 0, mProtocolCmbBx );
156 mVerifyModeItem = addRootItem(
tr(
"Peer verification" ) );
157 mVerifyPeerCmbBx =
new QComboBox( treeSslConfig );
158 mVerifyPeerCmbBx->
addItem(
tr(
"Verify peer certs" ),
159 (
int )QSslSocket::VerifyPeer );
160 mVerifyPeerCmbBx->
addItem(
tr(
"Do not verify peer certs" ),
161 (
int )QSslSocket::VerifyNone );
168 peerverifycmbxitem->
setFlags( peerverifycmbxitem->
flags() & ~
Qt::ItemIsSelectable );
169 treeSslConfig->setItemWidget( peerverifycmbxitem, 0, mVerifyPeerCmbBx );
172 mVerifyDepthItem = addRootItem(
tr(
"Peer verification depth (0 = complete cert chain)" ) );
173 mVerifyDepthSpnBx =
new QSpinBox( treeSslConfig );
182 peerverifyspnbxitem->
setFlags( peerverifyspnbxitem->
flags() & ~
Qt::ItemIsSelectable );
183 treeSslConfig->setItemWidget( peerverifyspnbxitem, 0, mVerifyDepthSpnBx );
186 mIgnoreErrorsItem = addRootItem(
tr(
"Ignore errors" ) );
189 for (
int i = 0; i < errenums.
size(); i++ )
198 item->
setData( 0, Qt::UserRole, errenums.
at( i ).first );
234 return leHost->text();
243 if ( grpbxSslConfig->isCheckable() )
245 grpbxSslConfig->setChecked( enable );
272 lblLoadedConfig->setVisible(
true );
296 QgsDebugMsg(
"Passed-in SSL custom config is null" );
315 lblLoadedConfig->setVisible(
true );
327 QgsDebugMsg(
"SSL custom config FAILED to store in authentication database" );
338 mConnectionCAs.
clear();
339 leCommonName->clear();
340 leCommonName->setStyleSheet(
"" );
343 lblLoadedConfig->setVisible(
false );
344 lblLoadedConfig->setText(
"" );
355 return QSsl::UnknownProtocol;
366 int indx( mProtocolCmbBx->
findData((
int )protocol ) );
388 Q_FOREACH (
const QSslError& err, errors )
390 errenums << err.
error();
393 for (
int i = 0; i < mIgnoreErrorsItem->
childCount(); i++ )
396 if ( errenums.
contains(( QSslError::SslError )item->data( 0, Qt::UserRole ).toInt() ) )
410 Q_FOREACH ( QSslError::SslError errorenum, errorenums )
431 Q_FOREACH (
const QSslError& err, errors )
433 errenums << err.
error();
436 for (
int i = 0; i < mIgnoreErrorsItem->
childCount(); i++ )
439 bool enable( errenums.
contains(( QSslError::SslError )item->data( 0, Qt::UserRole ).toInt() ) );
440 item->setCheckState( 0, enable ? Qt::Checked : Qt::Unchecked );
450 for (
int i = 0; i < mIgnoreErrorsItem->
childCount(); i++ )
463 for (
int i = 0; i < mIgnoreErrorsItem->
childCount(); i++ )
466 if ( item->checkState( 0 ) == Qt::Checked )
468 errs.
append(( QSslError::SslError )item->data( 0, Qt::UserRole ).toInt() );
478 return QSslSocket::AutoVerifyPeer;
480 return ( QSslSocket::PeerVerifyMode )mVerifyPeerCmbBx->
itemData( mVerifyPeerCmbBx->
currentIndex() ).toInt();
489 return mVerifyDepthSpnBx->
value();
500 int indx( mVerifyPeerCmbBx->
findData((
int )mode ) );
503 mVerifyDepthSpnBx->
setValue( modedepth );
523 && ( grpbxSslConfig->isCheckable() ? grpbxSslConfig->isChecked() : true )
524 && validateHostPort( leHost->text() ) );
525 if ( mCanSave != cansave )
539 leHost->setText( host );
542 bool QgsAuthSslConfigWidget::validateHostPort(
const QString &txt )
564 bool valid = validateHostPort( txt );
576 grpbxSslConfig->setCheckable( checkable );
579 grpbxSslConfig->setEnabled(
true );
583 void QgsAuthSslConfigWidget::on_btnCertInfo_clicked()
602 , mSslConfigWdgt( nullptr )
609 connect( mSslConfigWdgt, SIGNAL( readyToSaveChanged(
bool ) ),
610 this, SLOT( checkCanSave(
bool ) ) );
614 QDialogButtonBox::Close | QDialogButtonBox::Save, Qt::Horizontal,
this );
617 mSaveButton = buttonBox->
button( QDialogButtonBox::Save );
636 void QgsAuthSslConfigDialog::checkCanSave(
bool cansave )
bool isNull() const
Whether configuration is null (missing components)
static QgsAuthManager * instance()
Enforce singleton pattern.
int sslPeerVerifyDepth() const
Number or SSL client's peer to verify in connections.
const T & at(int i) const
Configuration container for SSL server connection exceptions or overrides.
QSsl::SslProtocol sslProtocol() const
SSL server protocol to use in connections.
QString tr(const char *sourceText, const char *disambiguation, int n)
QSslSocket::PeerVerifyMode sslPeerVerifyMode() const
SSL client's peer verify mode to use in connections.
void setSslPeerVerifyMode(QSslSocket::PeerVerifyMode mode)
Set SSL client's peer verify mode to use in connections.
void addItem(const QString &text, const QVariant &userData)
void setBold(bool enable)
QString number(int n, int base)
void append(const T &value)
Dialog wrapper for widget displaying detailed info on a certificate and its hierarchical trust chain...
static QString greenTextStyleSheet(const QString &selector="*")
Green text stylesheet representing valid, trusted, etc.
QgsAuthSslConfigDialog(QWidget *parent=nullptr, const QSslCertificate &cert=QSslCertificate(), const QString &hostport=QString())
Construct wrapper dialog for the SSL config widget.
const QString sslHostPort() const
Server host:port string.
void setMargin(int margin)
const QList< QSslError::SslError > sslIgnoredErrorEnums() const
SSL server errors (as enum list) to ignore in connections.
QVariant itemData(int index, int role) const
void setSslHostPort(const QString &hostport)
Set server host:port string.
static QString getSslProtocolName(QSsl::SslProtocol protocol)
SSL Protocol name strings per enum.
bool contains(const T &value) const
void setSslProtocol(QSsl::SslProtocol protocol)
Set SSL server protocol to use in connections.
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Get the sha1 hash for certificate.
void setAlignment(QFlags< Qt::AlignmentFlag > flag)
static QString redTextStyleSheet(const QString &selector="*")
Red text stylesheet representing invalid, untrusted, etc.
const QSslCertificate sslCertificate() const
Server certificate object.
int findData(const QVariant &data, int role, QFlags< Qt::MatchFlag > flags) const
void setSslIgnoredErrorEnums(const QList< QSslError::SslError > &errors)
Set SSL server errors (as enum list) to ignore in connections.
void setCurrentIndex(int index)
void setTextAlignment(int column, int alignment)
void setSslPeerVerifyDepth(int depth)
Set number or SSL client's peer to verify in connections.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void accept() override
Overridden base dialog accept slot.
static QList< QPair< QSslError::SslError, QString > > sslErrorEnumStrings()
Get short strings describing SSL errors.
void setSslCertificate(const QSslCertificate &cert)
Set server certificate object.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
static QString resolvedCertName(const QSslCertificate &cert, bool issuer=false)
Get the general name via RFC 5280 resolution.
~QgsAuthSslConfigDialog()
static QString orangeTextStyleSheet(const QString &selector="*")
Orange text stylesheet representing loaded component, but not stored in database. ...