Skip to content

Commit de7c5ba

Browse files
committed
Handle no entitlement exceptions in SSL file utils
1 parent b369cbc commit de7c5ba

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
lines changed

libs/ssl-config/src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
module org.elasticsearch.sslconfig {
11-
requires org.elasticsearch.base;
11+
requires org.elasticsearch.entitlement;
1212

1313
exports org.elasticsearch.common.ssl;
1414
}

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemKeyConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.common.ssl;
1111

1212
import org.elasticsearch.core.Tuple;
13+
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
1314

1415
import java.io.IOException;
1516
import java.nio.file.Path;
@@ -127,6 +128,8 @@ private PrivateKey getPrivateKey(Path path) {
127128
return privateKey;
128129
} catch (AccessControlException e) {
129130
throw SslFileUtil.accessControlFailure(KEY_FILE_TYPE, List.of(path), e, configBasePath);
131+
} catch (NotEntitledException e) {
132+
throw SslFileUtil.accessControlFailure(KEY_FILE_TYPE, List.of(path), e, configBasePath);
130133
} catch (IOException e) {
131134
throw SslFileUtil.ioException(KEY_FILE_TYPE, List.of(path), e);
132135
} catch (GeneralSecurityException e) {

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemTrustConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
package org.elasticsearch.common.ssl;
1111

12+
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
13+
1214
import java.io.IOException;
1315
import java.io.InputStream;
1416
import java.nio.file.Path;
@@ -99,6 +101,8 @@ private List<Certificate> readCertificates(List<Path> paths) {
99101
return PemUtils.readCertificates(paths);
100102
} catch (AccessControlException e) {
101103
throw SslFileUtil.accessControlFailure(CA_FILE_TYPE, paths, e, basePath);
104+
} catch (NotEntitledException e) {
105+
throw SslFileUtil.accessControlFailure(CA_FILE_TYPE, paths, e, basePath);
102106
} catch (IOException e) {
103107
throw SslFileUtil.ioException(CA_FILE_TYPE, paths, e);
104108
} catch (GeneralSecurityException e) {

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/PemUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.common.ssl;
1111

1212
import org.elasticsearch.core.CharArrays;
13+
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
1314

1415
import java.io.BufferedReader;
1516
import java.io.IOException;
@@ -112,6 +113,8 @@ public static PrivateKey readPrivateKey(Path path, Supplier<char[]> passwordSupp
112113
return privateKey;
113114
} catch (AccessControlException e) {
114115
throw SslFileUtil.accessControlFailure("PEM private key", List.of(path), e, null);
116+
} catch (NotEntitledException e) {
117+
throw SslFileUtil.accessControlFailure("PEM private key", List.of(path), e, null);
115118
} catch (IOException e) {
116119
throw SslFileUtil.ioException("PEM private key", List.of(path), e);
117120
} catch (GeneralSecurityException e) {

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/SslFileUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
package org.elasticsearch.common.ssl;
1111

12+
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
13+
1214
import java.io.FileNotFoundException;
1315
import java.io.IOException;
1416
import java.nio.file.AccessDeniedException;
@@ -78,7 +80,15 @@ static SslConfigException accessDenied(String fileType, List<Path> paths, Access
7880
return new SslConfigException(message, cause);
7981
}
8082

83+
static SslConfigException accessControlFailure(String fileType, List<Path> paths, NotEntitledException cause, Path basePath) {
84+
return innerAccessControlFailure(fileType, paths, cause, basePath);
85+
}
86+
8187
static SslConfigException accessControlFailure(String fileType, List<Path> paths, AccessControlException cause, Path basePath) {
88+
return innerAccessControlFailure(fileType, paths, cause, basePath);
89+
}
90+
91+
private static SslConfigException innerAccessControlFailure(String fileType, List<Path> paths, Exception cause, Path basePath) {
8292
String message = "cannot read configured " + fileType + " [" + pathsToString(paths) + "] because ";
8393
if (paths.size() == 1) {
8494
message += "access to read the file is blocked";

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreKeyConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.core.Nullable;
1313
import org.elasticsearch.core.Tuple;
14+
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
1415

1516
import java.io.IOException;
1617
import java.nio.file.Path;
@@ -168,6 +169,8 @@ private KeyStore readKeyStore(Path path) {
168169
return KeyStoreUtil.readKeyStore(path, type, storePassword);
169170
} catch (AccessControlException e) {
170171
throw SslFileUtil.accessControlFailure("[" + type + "] keystore", List.of(path), e, configBasePath);
172+
} catch (NotEntitledException e) {
173+
throw SslFileUtil.accessControlFailure("[" + type + "] keystore", List.of(path), e, configBasePath);
171174
} catch (IOException e) {
172175
throw SslFileUtil.ioException("[" + type + "] keystore", List.of(path), e);
173176
} catch (GeneralSecurityException e) {

libs/ssl-config/src/main/java/org/elasticsearch/common/ssl/StoreTrustConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
package org.elasticsearch.common.ssl;
1111

12+
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
13+
1214
import java.io.IOException;
1315
import java.nio.file.Path;
1416
import java.security.AccessControlException;
@@ -95,6 +97,8 @@ private KeyStore readKeyStore(Path path) {
9597
return KeyStoreUtil.readKeyStore(path, type, password);
9698
} catch (AccessControlException e) {
9799
throw SslFileUtil.accessControlFailure(fileTypeForException(), List.of(path), e, configBasePath);
100+
} catch (NotEntitledException e) {
101+
throw SslFileUtil.accessControlFailure(fileTypeForException(), List.of(path), e, configBasePath);
98102
} catch (IOException e) {
99103
throw SslFileUtil.ioException(fileTypeForException(), List.of(path), e, getAdditionalErrorDetails());
100104
} catch (GeneralSecurityException e) {

0 commit comments

Comments
 (0)