Skip to content

Commit 546eeca

Browse files
committed
added option to filter out CRLs when reading PEM
1 parent 6f525d7 commit 546eeca

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/CertUtils.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ public static LoadCertError loadVerifyLocations(TruffleFile file, TruffleFile pa
394394

395395
@TruffleBoundary
396396
public static LoadCertError getCertificates(BufferedReader r, List<Object> result) throws IOException, CertificateException, CRLException {
397+
return getCertificates(r, result, false);
398+
}
399+
400+
@TruffleBoundary
401+
public static LoadCertError getCertificates(BufferedReader r, List<Object> result, boolean onlyCertificates) throws IOException, CertificateException, CRLException {
397402
boolean sawBegin = false;
398403
boolean sawBeginCrl = false;
399404
StringBuilder certBuilder = new StringBuilder(2000);
@@ -435,9 +440,11 @@ public static LoadCertError getCertificates(BufferedReader r, List<Object> resul
435440
if (res != LoadCertError.NO_ERROR) {
436441
return res;
437442
}
438-
res = add(dataCrl, l, decoder, factory::generateCRL);
439-
if (res != LoadCertError.NO_ERROR) {
440-
return res;
443+
if (!onlyCertificates) {
444+
res = add(dataCrl, l, decoder, factory::generateCRL);
445+
if (res != LoadCertError.NO_ERROR) {
446+
return res;
447+
}
441448
}
442449
if (l.isEmpty()) {
443450
return LoadCertError.NO_CERT_DATA;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLContextBuiltins.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,8 @@ private Object load(PSSLContext self, BufferedReader certReader, BufferedReader
850850
try {
851851
// if keyReader and certReader are from the same file, key is expected to come first
852852
byte[] pkBytes = CertUtils.getEncodedPrivateKey(this, keyReader);
853-
X509Certificate[] certs;
854853
List<Object> certificates = new ArrayList<>();
855-
LoadCertError result = getCertificates(certReader, certificates);
854+
LoadCertError result = getCertificates(certReader, certificates, true);
856855
switch (result) {
857856
case BAD_BASE64_DECODE:
858857
case BEGIN_CERTIFICATE_WITHOUT_END:
@@ -866,7 +865,7 @@ private Object load(PSSLContext self, BufferedReader certReader, BufferedReader
866865
default:
867866
assert false : "not handled: " + result;
868867
}
869-
certs = certificates.toArray(new X509Certificate[certificates.size()]);
868+
X509Certificate[] certs = certificates.toArray(new X509Certificate[certificates.size()]);
870869
PrivateKey pk = CertUtils.createPrivateKey(this, pkBytes, certs[0]);
871870
self.setCertChain(pk, PythonUtils.EMPTY_CHAR_ARRAY, certs);
872871
} catch (InvalidKeySpecException | IOException | NoSuchAlgorithmException | KeyStoreException | CertificateException | CRLException ex) {

0 commit comments

Comments
 (0)