Skip to content

Commit

Permalink
[auth] Add CAs to the connection for pkipaths
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Oct 13, 2017
1 parent 0a2f754 commit 7cb908a
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 122 deletions.
46 changes: 46 additions & 0 deletions src/auth/pkipaths/qgsauthpkipathsedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ QgsAuthPkiPathsEdit::QgsAuthPkiPathsEdit( QWidget *parent )
connect( chkPkiPathsPassShow, &QCheckBox::stateChanged, this, &QgsAuthPkiPathsEdit::chkPkiPathsPassShow_stateChanged );
connect( btnPkiPathsCert, &QToolButton::clicked, this, &QgsAuthPkiPathsEdit::btnPkiPathsCert_clicked );
connect( btnPkiPathsKey, &QToolButton::clicked, this, &QgsAuthPkiPathsEdit::btnPkiPathsKey_clicked );
lblCas->hide();
twCas->hide();
cbAddCas->hide();
}

bool QgsAuthPkiPathsEdit::validateConfig()
Expand Down Expand Up @@ -100,6 +103,11 @@ bool QgsAuthPkiPathsEdit::validateConfig()
tr( "%1 thru %2" ).arg( startdate.toString(), enddate.toString() ),
( certvalid ? Valid : Invalid ) );

bool showCas( certvalid && populateCas() );
lblCas->setVisible( showCas );
twCas->setVisible( showCas );
cbAddCas->setVisible( showCas );

return validityChange( certvalid );
}

Expand All @@ -109,6 +117,7 @@ QgsStringMap QgsAuthPkiPathsEdit::configMap() const
config.insert( QStringLiteral( "certpath" ), lePkiPathsCert->text() );
config.insert( QStringLiteral( "keypath" ), lePkiPathsKey->text() );
config.insert( QStringLiteral( "keypass" ), lePkiPathsKeyPass->text() );
config.insert( QStringLiteral( "addcas" ), cbAddCas->isChecked() ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );

return config;
}
Expand All @@ -121,6 +130,7 @@ void QgsAuthPkiPathsEdit::loadConfig( const QgsStringMap &configmap )
lePkiPathsCert->setText( configmap.value( QStringLiteral( "certpath" ) ) );
lePkiPathsKey->setText( configmap.value( QStringLiteral( "keypath" ) ) );
lePkiPathsKeyPass->setText( configmap.value( QStringLiteral( "keypass" ) ) );
cbAddCas->setChecked( configmap.value( QStringLiteral( "addcas" ), QStringLiteral( "false " ) ) == QStringLiteral( "true" ) );

validateConfig();
}
Expand Down Expand Up @@ -224,3 +234,39 @@ bool QgsAuthPkiPathsEdit::validityChange( bool curvalid )
}
return curvalid;
}


bool QgsAuthPkiPathsEdit::populateCas()
{
twCas->clear();
const QList<QSslCertificate> cas( QgsAuthCertUtils::casFromFile( lePkiPathsCert->text() ) );
if ( cas.isEmpty() )
{
return false;
}

QTreeWidgetItem *prevItem( nullptr );
QList<QSslCertificate>::const_iterator it( cas.constEnd() );
while ( it != cas.constBegin() )
{
--it;
const QSslCertificate cert = static_cast<QSslCertificate>( *it );
QTreeWidgetItem *item;

if ( prevItem && cert.issuerInfo( QSslCertificate::SubjectInfo::CommonName ).contains( prevItem->text( 0 ) ) )
{
item = new QTreeWidgetItem( QStringList( cert.subjectInfo( QSslCertificate::SubjectInfo::CommonName ) ) );
prevItem->addChild( item );
}
else
{
item = new QTreeWidgetItem( twCas, QStringList( cert.subjectInfo( QSslCertificate::SubjectInfo::CommonName ) ) );
}
item->setIcon( 0, QgsApplication::getThemeIcon( QStringLiteral( "/mIconCertificate.svg" ) ) );
item->setToolTip( 0, tr( "<ul><li>Serial #: %1</li><li>Expiry date: %2</li></ul>" ).arg( cert.serialNumber( ), cert.expiryDate().toString( Qt::TextDate ) ) );
prevItem = item;
}
twCas->expandAll();

return true;
}
2 changes: 1 addition & 1 deletion src/auth/pkipaths/qgsauthpkipathsedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class QgsAuthPkiPathsEdit : public QgsAuthMethodEdit, private Ui::QgsAuthPkiPath

private:
bool validityChange( bool curvalid );

bool populateCas();
QgsStringMap mConfigMap;
bool mValid = 0;
};
Expand Down
242 changes: 123 additions & 119 deletions src/auth/pkipaths/qgsauthpkipathsedit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,148 +6,119 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>449</width>
<height>260</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="1">
<layout class="QGridLayout" name="gridLayout_4">
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLineEdit" name="lePkiPathsCert">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Required</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="btnPkiPathsCert">
<property name="text">
<string>…</string>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLineEdit" name="lePkiPathsMsg">
<property name="styleSheet">
<string notr="true">background-color: rgba(255, 255, 255, 0);</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="lePkiPathsKey">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Required</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnPkiPathsKey">
<property name="text">
<string>…</string>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLineEdit" name="lePkiPathsKeyPass">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>Optional passphrase</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkPkiPathsPassShow">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblPkiPathsKey">
<item row="0" column="0">
<widget class="QLabel" name="lblPkiPathsCert">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Key</string>
<string>Cert</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblPkiPathsCert">
<item row="0" column="1">
<widget class="QLineEdit" name="lePkiPathsCert">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Required</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lePkiPathsMsg">
<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>CAs</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QTreeWidget" name="twCas">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
<property name="columnCount">
<number>1</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item row="2" column="2" colspan="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="3" column="0">
<widget class="QLabel" name="lblPkiPathsKey">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cert</string>
<string>Key</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QLineEdit" name="lePkiPathsKey">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Required</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lePkiPathsKeyPass">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>Optional passphrase</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -160,6 +131,39 @@
</property>
</spacer>
</item>
<item row="3" column="2">
<widget class="QToolButton" name="btnPkiPathsKey">
<property name="text">
<string>…</string>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="chkPkiPathsPassShow">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="btnPkiPathsCert">
<property name="text">
<string>…</string>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
Loading

0 comments on commit 7cb908a

Please sign in to comment.