File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,15 @@ Return list of concatenated certs from a PEM Base64 text block
127
127
:rtype: list of QSslCertificate
128
128
%End
129
129
130
+
131
+ static QList<QSslCertificate> casRemoveSelfSigned( const QList<QSslCertificate> &caList );
132
+ %Docstring
133
+ casRemoveSelfSigned remove self-signed CA certificates from ``caList``
134
+ \param caList list of CA certificates
135
+ :return: a list of non self-signed certificates
136
+ :rtype: list of QSslCertificate
137
+ %End
138
+
130
139
static QStringList certKeyBundleToPem( const QString &certpath,
131
140
const QString &keypath,
132
141
const QString &keypass = QString(),
Original file line number Diff line number Diff line change @@ -224,6 +224,19 @@ QList<QSslCertificate> QgsAuthCertUtils::certsFromString( const QString &pemtext
224
224
return certs;
225
225
}
226
226
227
+ QList<QSslCertificate> QgsAuthCertUtils::casRemoveSelfSigned ( const QList<QSslCertificate> &caList )
228
+ {
229
+ QList<QSslCertificate> certs;
230
+ for ( const auto cert : caList )
231
+ {
232
+ if ( ! cert.isSelfSigned ( ) )
233
+ {
234
+ certs.append ( cert );
235
+ }
236
+ }
237
+ return certs;
238
+ }
239
+
227
240
QStringList QgsAuthCertUtils::certKeyBundleToPem ( const QString &certpath,
228
241
const QString &keypath,
229
242
const QString &keypass,
Original file line number Diff line number Diff line change @@ -136,6 +136,14 @@ class CORE_EXPORT QgsAuthCertUtils
136
136
// ! Return list of concatenated certs from a PEM Base64 text block
137
137
static QList<QSslCertificate> certsFromString ( const QString &pemtext );
138
138
139
+
140
+ /* *
141
+ * \brief casRemoveSelfSigned remove self-signed CA certificates from \a caList
142
+ * \param caList list of CA certificates
143
+ * \return a list of non self-signed certificates
144
+ */
145
+ static QList<QSslCertificate> casRemoveSelfSigned ( const QList<QSslCertificate> &caList );
146
+
139
147
/* *
140
148
* Return list of certificate, private key and algorithm (as PEM text) from file path components
141
149
* \param certpath File path to certificate
Original file line number Diff line number Diff line change @@ -603,6 +603,21 @@ def test_130_cas_merge(self):
603
603
604
604
self .assertTrue (trusted [0 ] in merged )
605
605
606
+ def test_140_cas_remove_self_signed (self ):
607
+ """Test CAs merge """
608
+ extra_path = PKIDATA + '/alice-cert_w-chain.pem'
609
+
610
+ extra = QgsAuthCertUtils .casFromFile (extra_path )
611
+ filtered = QgsAuthCertUtils .casRemoveSelfSigned (extra )
612
+
613
+ self .assertEqual (len (filtered ), 1 )
614
+ self .assertEqual (len (extra ), 2 )
615
+
616
+ self .assertTrue (extra [1 ].isSelfSigned ())
617
+
618
+ for c in filtered :
619
+ self .assertFalse (c .isSelfSigned ())
620
+
606
621
607
622
if __name__ == '__main__' :
608
623
unittest .main ()
You can’t perform that action at this time.
0 commit comments