@@ -294,45 +294,59 @@ else if ( keyUsage != null && ! keyUsage[5] ) { // KU_KEY_CERT_SIGN
294
294
295
295
static {
296
296
// roughly following the ideas from https://www.happyassassin.net/2015/01/12/a-note-about-ssltls-trusted-certificate-stores-and-platforms/
297
- // and falling back to trust store from java to be on the save side
298
-
297
+ // and falling back to trust store from java to be on the save side
298
+
299
299
// TODO usability in limited environments should be tested/reviewed
300
300
final String JAVA_HOME = SafePropertyAccessor .getProperty ("java.home" , "" );
301
301
302
302
// if the default files/dirs exist we use them. with this a switch
303
303
// from MRI to JRuby produces the same results. otherwise we use the
304
304
// certs from JAVA_HOME.
305
- final String MAYBE_CERT_FILE ;
306
305
final String LINUX_CERT_AREA = "/etc/ssl" ;
307
306
final String MACOS_CERT_AREA = "/System/Library/OpenSSL" ;
308
- final String MAYBE_PKI_CERT_FILE = "/etc/pki/tls/certs/ca-bundle.crt" ;
309
- if (new File (LINUX_CERT_AREA ).exists ()) {
310
- X509_CERT_AREA = LINUX_CERT_AREA ;
311
- X509_CERT_DIR = X509_CERT_AREA + "/certs" ;
312
- X509_PRIVATE_DIR = X509_CERT_AREA + "/private" ;
313
- MAYBE_CERT_FILE = X509_CERT_DIR + "/cert.pem" ;
314
- }
315
- else if (new File (MACOS_CERT_AREA ).exists ()) {
316
- X509_CERT_AREA = MACOS_CERT_AREA ;
317
- X509_CERT_DIR = X509_CERT_AREA + "/certs" ;
318
- X509_PRIVATE_DIR = X509_CERT_AREA + "/private" ;
319
- MAYBE_CERT_FILE = X509_CERT_AREA + "/cert.pem" ;
307
+
308
+ String certArea , certDir , privateDir ;
309
+ String maybeCertFile ;
310
+ String maybePkiCertFile = "/etc/pki/tls/certs/ca-bundle.crt" ;
311
+ try {
312
+ if (new File (LINUX_CERT_AREA ).exists ()) {
313
+ certArea = LINUX_CERT_AREA ;
314
+ certDir = certArea + "/certs" ;
315
+ privateDir = certArea + "/private" ;
316
+ maybeCertFile = certDir + "/cert.pem" ;
317
+ }
318
+ else if (new File (MACOS_CERT_AREA ).exists ()) {
319
+ certArea = MACOS_CERT_AREA ;
320
+ certDir = certArea + "/certs" ;
321
+ privateDir = certArea + "/private" ;
322
+ maybeCertFile = certArea + "/cert.pem" ;
323
+ }
324
+ else {
325
+ certArea = JAVA_HOME + "/lib/security" ;
326
+ certDir = certArea ;
327
+ privateDir = certArea ;
328
+ maybeCertFile = maybePkiCertFile ;
329
+ }
320
330
}
321
- else {
322
- X509_CERT_AREA = JAVA_HOME + "/lib/security" ;
323
- X509_CERT_DIR = X509_CERT_AREA ;
324
- X509_PRIVATE_DIR = X509_CERT_AREA ;
325
- MAYBE_CERT_FILE = MAYBE_PKI_CERT_FILE ;
331
+ catch (SecurityException e ) {
332
+ maybeCertFile = null ; maybePkiCertFile = null ;
333
+ privateDir = certDir = certArea = JAVA_HOME + "/lib/security" ;
326
334
}
327
- if (new File (MAYBE_PKI_CERT_FILE ).exists ()) {
328
- X509_CERT_FILE = MAYBE_PKI_CERT_FILE ;
335
+
336
+ X509_CERT_AREA = certArea ;
337
+ X509_CERT_DIR = certDir ;
338
+ X509_PRIVATE_DIR = privateDir ;
339
+
340
+ if (maybePkiCertFile != null && new File (maybePkiCertFile ).exists ()) {
341
+ X509_CERT_FILE = maybePkiCertFile ;
329
342
}
330
- else if (new File (MAYBE_CERT_FILE ).exists ()) {
331
- X509_CERT_FILE = MAYBE_CERT_FILE ;
343
+ else if (maybeCertFile != null && new File (maybeCertFile ).exists ()) {
344
+ X509_CERT_FILE = maybeCertFile ;
332
345
}
333
346
else {
334
347
X509_CERT_FILE = JAVA_HOME + "/lib/security/cacerts" ;
335
348
}
349
+
336
350
// keep it with some meaninful content as it is a public constant
337
351
OPENSSLDIR = X509_CERT_AREA ;
338
352
}
0 commit comments