|
20 | 20 | package org.elasticsearch.common.settings;
|
21 | 21 |
|
22 | 22 | import org.apache.lucene.codecs.CodecUtil;
|
| 23 | +import org.apache.lucene.index.IndexFormatTooNewException; |
| 24 | +import org.apache.lucene.index.IndexFormatTooOldException; |
23 | 25 | import org.apache.lucene.store.BufferedChecksumIndexInput;
|
24 | 26 | import org.apache.lucene.store.ChecksumIndexInput;
|
25 | 27 | import org.apache.lucene.store.IOContext;
|
|
40 | 42 | import javax.crypto.spec.GCMParameterSpec;
|
41 | 43 | import javax.crypto.spec.PBEKeySpec;
|
42 | 44 | import javax.crypto.spec.SecretKeySpec;
|
43 |
| - |
44 | 45 | import java.io.ByteArrayInputStream;
|
45 | 46 | import java.io.ByteArrayOutputStream;
|
46 | 47 | import java.io.DataInputStream;
|
@@ -217,7 +218,16 @@ public static KeyStoreWrapper load(Path configDir) throws IOException {
|
217 | 218 | SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
|
218 | 219 | try (IndexInput indexInput = directory.openInput(KEYSTORE_FILENAME, IOContext.READONCE)) {
|
219 | 220 | ChecksumIndexInput input = new BufferedChecksumIndexInput(indexInput);
|
220 |
| - int formatVersion = CodecUtil.checkHeader(input, KEYSTORE_FILENAME, MIN_FORMAT_VERSION, FORMAT_VERSION); |
| 221 | + final int formatVersion; |
| 222 | + try { |
| 223 | + formatVersion = CodecUtil.checkHeader(input, KEYSTORE_FILENAME, MIN_FORMAT_VERSION, FORMAT_VERSION); |
| 224 | + } catch (IndexFormatTooOldException e) { |
| 225 | + throw new IllegalStateException("The Elasticsearch keystore [" + keystoreFile + "] format is too old. " + |
| 226 | + "You should delete and recreate it in order to upgrade.", e); |
| 227 | + } catch (IndexFormatTooNewException e) { |
| 228 | + throw new IllegalStateException("The Elasticsearch keystore [" + keystoreFile + "] format is too new. " + |
| 229 | + "Are you trying to downgrade? You should delete and recreate it in order to downgrade.", e); |
| 230 | + } |
221 | 231 | byte hasPasswordByte = input.readByte();
|
222 | 232 | boolean hasPassword = hasPasswordByte == 1;
|
223 | 233 | if (hasPassword == false && hasPasswordByte != 0) {
|
|
0 commit comments