Skip to content

Commit 75d0f70

Browse files
committed
Changed keystore parse error to be more strict
The Elasticsearch config should error out if a PKCS12 keystore does not contain a key *or* a certificate. This was intended to be the functionality in PR #53810, but it was overlooked. Changing it now since this PR is changing code in the same file.
1 parent 956a475 commit 75d0f70

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/core/server/elasticsearch/elasticsearch_config.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,20 @@ describe('throws when config is invalid', () => {
270270
);
271271
});
272272

273-
it('throws if keystore does not contain a key or certificate', () => {
273+
it('throws if keystore does not contain a key', () => {
274274
mockReadPkcs12Keystore.mockReturnValueOnce({});
275275
const value = { ssl: { keystore: { path: 'some-path' } } };
276276
expect(
277277
() => new ElasticsearchConfig(config.schema.validate(value))
278-
).toThrowErrorMatchingInlineSnapshot(
279-
`"Did not find key or certificate in Elasticsearch keystore."`
280-
);
278+
).toThrowErrorMatchingInlineSnapshot(`"Did not find key in Elasticsearch keystore."`);
279+
});
280+
281+
it('throws if keystore does not contain a certificate', () => {
282+
mockReadPkcs12Keystore.mockReturnValueOnce({ key: 'foo' });
283+
const value = { ssl: { keystore: { path: 'some-path' } } };
284+
expect(
285+
() => new ElasticsearchConfig(config.schema.validate(value))
286+
).toThrowErrorMatchingInlineSnapshot(`"Did not find certificate in Elasticsearch keystore."`);
281287
});
282288

283289
it('throws if truststore path is invalid', () => {

src/core/server/elasticsearch/elasticsearch_config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,10 @@ const readKeyAndCerts = (rawConfig: ElasticsearchConfigType) => {
283283
rawConfig.ssl.keystore.path,
284284
rawConfig.ssl.keystore.password
285285
);
286-
if (!keystore.key && !keystore.cert) {
287-
throw new Error(`Did not find key or certificate in Elasticsearch keystore.`);
286+
if (!keystore.key) {
287+
throw new Error(`Did not find key in Elasticsearch keystore.`);
288+
} else if (!keystore.cert) {
289+
throw new Error(`Did not find certificate in Elasticsearch keystore.`);
288290
}
289291
key = keystore.key;
290292
certificate = keystore.cert;

0 commit comments

Comments
 (0)