Improve error handling for curve OID to SSH curve identifier translation

This commit is contained in:
Christian Hagau
2017-11-28 00:00:00 +00:00
parent d4c9f69696
commit de695fa2b0
6 changed files with 105 additions and 26 deletions

View File

@@ -29,6 +29,8 @@ import org.sufficientlysecure.keychain.ssh.key.SshEd25519PublicKey;
import org.sufficientlysecure.keychain.ssh.key.SshRSAPublicKey;
import org.sufficientlysecure.keychain.ssh.utils.SshUtils;
import java.security.NoSuchAlgorithmException;
public class SshPublicKey {
private final static String TAG = "SshPublicKey";
@@ -38,7 +40,7 @@ public class SshPublicKey {
mPublicKey = publicKey;
}
public String getEncodedKey() throws PgpGeneralException {
public String getEncodedKey() throws PgpGeneralException, NoSuchAlgorithmException {
PGPPublicKey key = mPublicKey.getPublicKey();
switch (key.getAlgorithm()) {
@@ -51,9 +53,8 @@ public class SshPublicKey {
case PGPPublicKey.DSA:
return encodeDSAKey(key);
default:
break;
throw new PgpGeneralException("Unknown key algorithm");
}
throw new PgpGeneralException("Unknown algorithm");
}
private String encodeRSAKey(PGPPublicKey publicKey) {
@@ -64,7 +65,7 @@ public class SshPublicKey {
return pubkey.getPublicKeyBlob();
}
private String encodeECKey(PGPPublicKey publicKey) {
private String encodeECKey(PGPPublicKey publicKey) throws NoSuchAlgorithmException {
ECPublicBCPGKey publicBCPGKey = (ECPublicBCPGKey) publicKey.getPublicKeyPacket().getKey();
String curveName = SshUtils.getCurveName(mPublicKey.getCurveOid());