-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pwdf retry logic to OpenSSHKeyV1KeyFile (#587)
* Add pwdf retry logic to OpenSSHKeyV1KeyFile While PKCS8KeyFile uses PasswordFinder's shouldRetry to determine whether it should call reqPassword again if decryption of they key file fails, OpenSSHKeyV1KeyFile simply gives up and throws an exception. With this commit, retry logic similar to that of PKCS8KeyFile is added to OpenSSHKeyV1KeyFile. The PasswordFinder's reqPassword is called again if the validation of the "checkint" fails, which indicates an incorrect passphrase. * Use new exception to signal incorrect passphrase * Throw common exception on key decryption failure * Add test coverage for retry logic Co-authored-by: Jeroen van Erp <jeroen@hierynomus.com>
- Loading branch information
1 parent
fa7c40c
commit dfdc464
Showing
4 changed files
with
88 additions
and
9 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/com/hierynomus/sshj/common/KeyDecryptionFailedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C)2009 - SSHJ Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.hierynomus.sshj.common; | ||
|
||
import org.bouncycastle.openssl.EncryptionException; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Thrown when a key file could not be decrypted correctly, e.g. if its checkInts differed in the case of an OpenSSH | ||
* key file. | ||
*/ | ||
public class KeyDecryptionFailedException extends IOException { | ||
|
||
public static final String MESSAGE = "Decryption of the key failed. A supplied passphrase may be incorrect."; | ||
|
||
public KeyDecryptionFailedException() { | ||
super(MESSAGE); | ||
} | ||
|
||
public KeyDecryptionFailedException(EncryptionException cause) { | ||
super(MESSAGE, cause); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters