|
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;
|
|
39 | 41 | import javax.crypto.spec.GCMParameterSpec;
|
40 | 42 | import javax.crypto.spec.PBEKeySpec;
|
41 | 43 | import javax.crypto.spec.SecretKeySpec;
|
42 |
| - |
43 | 44 | import java.io.ByteArrayInputStream;
|
44 | 45 | import java.io.ByteArrayOutputStream;
|
45 | 46 | import java.io.DataInputStream;
|
@@ -205,7 +206,16 @@ public static KeyStoreWrapper load(Path configDir) throws IOException {
|
205 | 206 | SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
|
206 | 207 | try (IndexInput indexInput = directory.openInput(KEYSTORE_FILENAME, IOContext.READONCE)) {
|
207 | 208 | ChecksumIndexInput input = new BufferedChecksumIndexInput(indexInput);
|
208 |
| - int formatVersion = CodecUtil.checkHeader(input, KEYSTORE_FILENAME, MIN_FORMAT_VERSION, FORMAT_VERSION); |
| 209 | + final int formatVersion; |
| 210 | + try { |
| 211 | + formatVersion = CodecUtil.checkHeader(input, KEYSTORE_FILENAME, MIN_FORMAT_VERSION, FORMAT_VERSION); |
| 212 | + } catch (IndexFormatTooOldException e) { |
| 213 | + throw new IllegalStateException("The Elasticsearch keystore [" + keystoreFile + "] format is too old. " + |
| 214 | + "You should delete and recreate it in order to upgrade.", e); |
| 215 | + } catch (IndexFormatTooNewException e) { |
| 216 | + throw new IllegalStateException("The Elasticsearch keystore [" + keystoreFile + "] format is too new. " + |
| 217 | + "Are you trying to downgrade? You should delete and recreate it in order to downgrade.", e); |
| 218 | + } |
209 | 219 | byte hasPasswordByte = input.readByte();
|
210 | 220 | boolean hasPassword = hasPasswordByte == 1;
|
211 | 221 | if (hasPassword == false && hasPasswordByte != 0) {
|
|
0 commit comments