diff keyimport.c @ 1913:38c6fd7d7a82

Fix dropbearconvert ecdsa parsing error typo Simplify handling for different key types
author Matt Johnston <matt@ucc.asn.au>
date Tue, 29 Mar 2022 23:55:35 +0800
parents 8b4274d34fe8
children f978a15194ba
line wrap: on
line diff
--- a/keyimport.c	Tue Mar 29 23:47:30 2022 +0800
+++ b/keyimport.c	Tue Mar 29 23:55:35 2022 +0800
@@ -601,51 +601,35 @@
 		/* discard checkkey2 */
 		buf_getint(blobbuf);
 
-		if (type != DROPBEAR_SIGNKEY_NONE) {
-			retkey->type = type;
+		errmsg = "Unsupported OpenSSH key type";
+		retkey->type = type;
+		ret = DROPBEAR_FAILURE;
+		/* Parse private key part */
 #if DROPBEAR_RSA
-			if (type == DROPBEAR_SIGNKEY_RSA) {
-				if (buf_get_rsa_priv_ossh(blobbuf, retkey)
-						== DROPBEAR_SUCCESS) {
-					errmsg = NULL;
-					retval = retkey;
-					goto error;
-				} else {
-					errmsg = "Error parsing OpenSSH RSA key";
-					goto ossh_error;
-				}
-			}
+		if (type == DROPBEAR_SIGNKEY_RSA) {
+			errmsg = "Error parsing OpenSSH RSA key";
+			ret = buf_get_rsa_priv_ossh(blobbuf, retkey);
+		}
 #endif
 #if DROPBEAR_ED25519
-			if (type == DROPBEAR_SIGNKEY_ED25519) {
-				if (buf_get_ed25519_priv_ossh(blobbuf, retkey)
-						== DROPBEAR_SUCCESS) {
-					errmsg = NULL;
-					retval = retkey;
-					goto error;
-				} else {
-					errmsg = "Error parsing OpenSSH ed25519 key";
-					goto ossh_error;
-				}
-			}
+		if (type == DROPBEAR_SIGNKEY_ED25519) {
+			errmsg = "Error parsing OpenSSH ed25519 key";
+			ret = buf_get_ed25519_priv_ossh(blobbuf, retkey);
+		}
 #endif
 #if DROPBEAR_ECDSA
-			if (signkey_is_ecdsa(type)) {
-				if (buf_get_ecdsa_priv_ossh(blobbuf, retkey)
-						== DROPBEAR_SUCCESS) {
-					errmsg = NULL;
-					retval = retkey;
-					goto error;
-				} else {
-					errmsg = "Error parsing OpenSSH ed25519 key";
-					goto ossh_error;
-				}
-			}
+		if (signkey_is_ecdsa(type)) {
+			errmsg = "Error parsing OpenSSH ecdsa key";
+			ret = buf_get_ecdsa_priv_ossh(blobbuf, retkey);
+		}
 #endif
+		if (ret == DROPBEAR_SUCCESS) {
+				errmsg = NULL;
+				retval = retkey;
+				goto error;
 		}
 
-		errmsg = "Unsupported OpenSSH key type";
-		ossh_error:
+ossh_error:
 		sign_key_free(retkey);
 		retkey = NULL;
 		goto error;