Defend against IO exceptions when attempting to read non existent keys
@@ -6,6 +6,7 @@ import com.quorum.tessera.config.PrivateKeyData;
import com.quorum.tessera.config.PrivateKeyType;
import com.quorum.tessera.config.keys.KeyEncryptor;
import com.quorum.tessera.config.keys.KeyEncryptorFactory;
+import com.quorum.tessera.config.util.FilesDelegate;
import com.quorum.tessera.config.util.IOCallback;
import com.quorum.tessera.config.util.JaxbUtil;
import com.quorum.tessera.nacl.NaclException;
@@ -23,6 +24,8 @@ import java.util.Objects;
public class KeyDataAdapter extends XmlAdapter<KeyData, KeyData> {
+ private FilesDelegate filesDelegate = FilesDelegate.create();
+
private static final Logger LOGGER = LoggerFactory.getLogger(KeyDataAdapter.class);
@Override
@@ -38,7 +41,9 @@ public class KeyDataAdapter extends XmlAdapter<KeyData, KeyData> {
return unmarshalInline(keyData);
}
- if (keyData.getPublicKeyPath() == null || keyData.getPrivateKeyPath() == null) {
+
+ if (keyData.getPublicKeyPath() == null || keyData.getPrivateKeyPath() == null
+ || filesDelegate.notExists(keyData.getPublicKeyPath()) || filesDelegate.notExists(keyData.getPrivateKeyPath())) {
return keyData;
}
