summaryrefslogtreecommitdiffhomepage
path: root/signkey.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2020-05-17 23:58:31 +0800
committerMatt Johnston <matt@ucc.asn.au>2020-05-17 23:58:31 +0800
commit972d723484d89c71e73ed63cc17bb2a6ce8cca5a (patch)
treea235001a141556ea7e2578ff12f2765d6a953280 /signkey.c
parent7dc2f36c3e2d21455ae432da4d8f338e7dc0668c (diff)
split signkey_type and signature_type for RSA sha1 vs sha256
Diffstat (limited to 'signkey.c')
-rw-r--r--signkey.c63
1 files changed, 45 insertions, 18 deletions
diff --git a/signkey.c b/signkey.c
index 27b09a3..47c8c8e 100644
--- a/signkey.c
+++ b/signkey.c
@@ -111,34 +111,52 @@ enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen)
/* Special case for rsa-sha2-256. This could be generalised if more
signature names are added that aren't 1-1 with public key names */
-const char* signature_name_from_type(enum signkey_type type, unsigned int *namelen) {
+const char* signature_name_from_type(enum signature_type type, unsigned int *namelen) {
#if DROPBEAR_RSA_SHA256
- if (type == DROPBEAR_SIGNKEY_RSA_SHA256) {
- *namelen = strlen(SSH_SIGNKEY_RSA_SHA256);
- return SSH_SIGNKEY_RSA_SHA256;
+ if (type == DROPBEAR_SIGNATURE_RSA_SHA256) {
+ *namelen = strlen(SSH_SIGNATURE_RSA_SHA256);
+ return SSH_SIGNATURE_RSA_SHA256;
}
#endif
- return signkey_name_from_type(type, namelen);
+#if DROPBEAR_RSA_SHA1
+ if (type == DROPBEAR_SIGNATURE_RSA_SHA1) {
+ *namelen = strlen(SSH_SIGNKEY_RSA);
+ return SSH_SIGNKEY_RSA;
+ }
+#endif
+ return signkey_name_from_type((enum signkey_type)type, namelen);
}
-enum signkey_type signature_type_from_name(const char* name, unsigned int namelen) {
+/* Returns DROPBEAR_SIGNATURE_NONE if none match */
+enum signature_type signature_type_from_name(const char* name, unsigned int namelen) {
#if DROPBEAR_RSA_SHA256
- if (namelen == strlen(SSH_SIGNKEY_RSA_SHA256)
- && memcmp(name, SSH_SIGNKEY_RSA_SHA256, namelen) == 0) {
- return DROPBEAR_SIGNKEY_RSA_SHA256;
+ if (namelen == strlen(SSH_SIGNATURE_RSA_SHA256)
+ && memcmp(name, SSH_SIGNATURE_RSA_SHA256, namelen) == 0) {
+ return DROPBEAR_SIGNATURE_RSA_SHA256;
}
#endif
- return signkey_type_from_name(name, namelen);
+#if DROPBEAR_RSA_SHA256
+ if (namelen == strlen(SSH_SIGNKEY_RSA)
+ && memcmp(name, SSH_SIGNKEY_RSA, namelen) == 0) {
+ return DROPBEAR_SIGNATURE_RSA_SHA1;
+ }
+#endif
+ return (enum signature_type)signkey_type_from_name(name, namelen);
}
-enum signkey_type signkey_type_from_signature(enum signkey_type sigtype) {
+enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
#if DROPBEAR_RSA_SHA256
- if (sigtype == DROPBEAR_SIGNKEY_RSA_SHA256) {
+ if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) {
+ return DROPBEAR_SIGNKEY_RSA;
+ }
+#endif
+#if DROPBEAR_RSA_SHA1
+ if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA1) {
return DROPBEAR_SIGNKEY_RSA;
}
#endif
assert(sigtype < DROPBEAR_SIGNKEY_NUM_NAMED);
- return sigtype;
+ return (enum signkey_type)sigtype;
}
/* Returns a pointer to the key part specific to "type".
@@ -562,11 +580,20 @@ char * sign_key_fingerprint(const unsigned char* keyblob, unsigned int keybloble
#endif
}
-void buf_put_sign(buffer* buf, sign_key *key, enum signkey_type sigtype,
+void buf_put_sign(buffer* buf, sign_key *key, enum signature_type sigtype,
const buffer *data_buf) {
buffer *sigblob = buf_new(MAX_PUBKEY_SIZE);
enum signkey_type keytype = signkey_type_from_signature(sigtype);
+#if DEBUG_TRACE
+ {
+ int namelen;
+ const char* signame = signature_name_from_type(sigtype, &namelen);
+ TRACE(("buf_put_sign type %d %s", sigtype, signame));
+ }
+#endif
+
+
#if DROPBEAR_DSS
if (keytype == DROPBEAR_SIGNKEY_DSS) {
buf_put_dss_sign(sigblob, key->dsskey, data_buf);
@@ -603,11 +630,12 @@ void buf_put_sign(buffer* buf, sign_key *key, enum signkey_type sigtype,
* If FAILURE is returned, the position of
* buf is undefined. If SUCCESS is returned, buf will be positioned after the
* signature blob */
-int buf_verify(buffer * buf, sign_key *key, enum signkey_type expect_sigtype, const buffer *data_buf) {
+int buf_verify(buffer * buf, sign_key *key, enum signature_type expect_sigtype, const buffer *data_buf) {
char *type_name = NULL;
unsigned int type_name_len = 0;
- enum signkey_type sigtype, keytype;
+ enum signature_type sigtype;
+ enum signkey_type keytype;
TRACE(("enter buf_verify"))
@@ -616,8 +644,7 @@ int buf_verify(buffer * buf, sign_key *key, enum signkey_type expect_sigtype, co
sigtype = signature_type_from_name(type_name, type_name_len);
m_free(type_name);
- if (expect_sigtype != DROPBEAR_SIGNKEY_ANY
- && expect_sigtype != sigtype) {
+ if (expect_sigtype != sigtype) {
dropbear_exit("Non-matching signing type");
}