- private SvrPinData restoreMasterKey(
- String pin,
- String basicStorageCredentials,
- TokenResponse tokenResponse,
- final KeyBackupService keyBackupService
- ) throws IOException, SvrNoDataException, KeyBackupServicePinException {
- if (pin == null) return null;
-
- if (basicStorageCredentials == null) {
- throw new AssertionError("Cannot restore KBS key, no storage credentials supplied");
- }
-
- var session = keyBackupService.newRegistrationSession(basicStorageCredentials, tokenResponse);
-
- try {
- var hashedPin = PinHashUtil.hashPin(pin, session.hashSalt());
- var kbsData = session.restorePin(hashedPin);
- if (kbsData == null) {
- throw new AssertionError("Null not expected");
- }
- return kbsData;
- } catch (UnauthenticatedResponseException | InvalidKeyException e) {
- throw new IOException(e);
+ public SecureValueRecovery.RestoreResponse.Success getRegistrationLockData(
+ SecureValueRecovery secureValueRecovery, AuthCredentials authCredentials, String pin
+ ) throws IOException, IncorrectPinException {
+ final var restoreResponse = secureValueRecovery.restoreDataPreRegistration(authCredentials, pin);
+
+ if (restoreResponse instanceof SecureValueRecovery.RestoreResponse.Success s) {
+ return s;
+ } else if (restoreResponse instanceof SecureValueRecovery.RestoreResponse.PinMismatch pinMismatch) {
+ throw new IncorrectPinException(pinMismatch.getTriesRemaining());
+ } else if (restoreResponse instanceof SecureValueRecovery.RestoreResponse.ApplicationError error) {
+ throw new IOException(error.getException());
+ } else if (restoreResponse instanceof SecureValueRecovery.RestoreResponse.NetworkError error) {
+ throw error.getException();
+ } else {
+ throw new AssertionError("Unexpected response");