Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[auth] Add checkbox to exclud root CAs from bundles on pkipkcs12 method
  • Loading branch information
elpaso committed Oct 16, 2017
1 parent 891f8f2 commit c11e5a4
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 75 deletions.
5 changes: 5 additions & 0 deletions src/auth/pkipkcs12/qgsauthpkcs12edit.cpp
Expand Up @@ -36,9 +36,11 @@ QgsAuthPkcs12Edit::QgsAuthPkcs12Edit( QWidget *parent )
connect( lePkcs12KeyPass, &QLineEdit::textChanged, this, &QgsAuthPkcs12Edit::lePkcs12KeyPass_textChanged );
connect( chkPkcs12PassShow, &QCheckBox::stateChanged, this, &QgsAuthPkcs12Edit::chkPkcs12PassShow_stateChanged );
connect( btnPkcs12Bundle, &QToolButton::clicked, this, &QgsAuthPkcs12Edit::btnPkcs12Bundle_clicked );
connect( cbAddCas, &QCheckBox::stateChanged, this, [ = ]( int state ) { cbAddRootCa->setEnabled( state == Qt::Checked ); } );
lblCas->hide();
twCas->hide();
cbAddCas->hide();
cbAddRootCa->hide();
}

bool QgsAuthPkcs12Edit::validateConfig()
Expand Down Expand Up @@ -115,6 +117,7 @@ bool QgsAuthPkcs12Edit::validateConfig()
lblCas->setVisible( showCas );
twCas->setVisible( showCas );
cbAddCas->setVisible( showCas );
cbAddRootCa->setVisible( showCas );

return validityChange( bundlevalid );
}
Expand All @@ -127,6 +130,7 @@ QgsStringMap QgsAuthPkcs12Edit::configMap() const
config.insert( QStringLiteral( "bundlepath" ), lePkcs12Bundle->text() );
config.insert( QStringLiteral( "bundlepass" ), lePkcs12KeyPass->text() );
config.insert( QStringLiteral( "addcas" ), cbAddCas->isChecked() ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
config.insert( QStringLiteral( "addrootca" ), cbAddRootCa->isChecked() ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );

return config;
}
Expand All @@ -139,6 +143,7 @@ void QgsAuthPkcs12Edit::loadConfig( const QgsStringMap &configmap )
lePkcs12Bundle->setText( configmap.value( QStringLiteral( "bundlepath" ) ) );
lePkcs12KeyPass->setText( configmap.value( QStringLiteral( "bundlepass" ) ) );
cbAddCas->setChecked( configmap.value( QStringLiteral( "addcas" ), QStringLiteral( "false " ) ) == QStringLiteral( "true" ) );
cbAddRootCa->setChecked( configmap.value( QStringLiteral( "addrootca" ), QStringLiteral( "false " ) ) == QStringLiteral( "true" ) );

validateConfig();
}
Expand Down
173 changes: 99 additions & 74 deletions src/auth/pkipkcs12/qgsauthpkcs12edit.ui
Expand Up @@ -6,23 +6,24 @@
<rect>
<x>0</x>
<y>0</y>
<width>365</width>
<height>224</height>
<width>397</width>
<height>202</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="lblPkcs12Bundle">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Bundle</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lePkcs12Bundle">
<property name="readOnly">
Expand All @@ -33,20 +34,34 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lblPkcs12Key">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="0" column="3">
<widget class="QToolButton" name="btnPkcs12Bundle">
<property name="text">
<string>…</string>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lePkcs12Msg">
<property name="styleSheet">
<string notr="true">background-color: rgba(255, 255, 255, 0);</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lblCas">
<property name="text">
<string>Key</string>
<string>CAs</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="1" rowspan="2">
<widget class="QTreeWidget" name="twCas">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
Expand All @@ -70,20 +85,30 @@
</column>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblPkcs12Bundle">
<item row="4" column="0">
<widget class="QLabel" name="lblPkcs12Key">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Bundle</string>
<string>Key</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lePkcs12KeyPass">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>Optional passphrase</string>
</property>
</widget>
</item>
<item row="3" column="2">
<item row="4" column="3">
<widget class="QCheckBox" name="chkPkcs12PassShow">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
Expand All @@ -96,27 +121,7 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="btnPkcs12Bundle">
<property name="text">
<string>…</string>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lePkcs12KeyPass">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>Optional passphrase</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -129,35 +134,55 @@
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lePkcs12Msg">
<property name="styleSheet">
<string notr="true">background-color: rgba(255, 255, 255, 0);</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="cbAddCas">
<property name="toolTip">
<string>Add bundle CAs to the connection</string>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lblCas">
<property name="text">
<string>CAs</string>
</property>
</widget>
<item row="2" column="2" rowspan="2" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="cbAddCas">
<property name="toolTip">
<string>Add bundle CAs to the connection</string>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbAddRootCa">
<property name="toolTip">
<string>Add also root (self-signed) CA</string>
</property>
<property name="text">
<string>Root</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
<tabstop>lePkcs12Bundle</tabstop>
<tabstop>btnPkcs12Bundle</tabstop>
<tabstop>twCas</tabstop>
<tabstop>cbAddCas</tabstop>
<tabstop>cbAddRootCa</tabstop>
<tabstop>lePkcs12KeyPass</tabstop>
<tabstop>chkPkcs12PassShow</tabstop>
<tabstop>lePkcs12Msg</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
9 changes: 8 additions & 1 deletion src/auth/pkipkcs12/qgsauthpkcs12method.cpp
Expand Up @@ -103,7 +103,14 @@ bool QgsAuthPkcs12Method::updateNetworkRequest( QNetworkRequest &request, const

if ( pkibundle->config().config( QStringLiteral( "addcas" ), QStringLiteral( "false" ) ) == QStringLiteral( "true" ) )
{
sslConfig.setCaCertificates( pkibundle->caChain() );
if ( pkibundle->config().config( QStringLiteral( "addrootca" ), QStringLiteral( "false" ) ) == QStringLiteral( "true" ) )
{
sslConfig.setCaCertificates( pkibundle->caChain() );
}
else
{
sslConfig.setCaCertificates( QgsAuthCertUtils::casRemoveSelfSigned( pkibundle->caChain() ) );
}
}

request.setSslConfiguration( sslConfig );
Expand Down

0 comments on commit c11e5a4

Please sign in to comment.