aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-08-21 12:31:16 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-08-21 12:31:16 +0200
commiteb65f031af04a8f5c1ceaa014cdbdf5106b94c22 (patch)
tree24e34f4939f23ae57fa2807ad50b1271d3c693b3 /src
parentc0412619215b124add447c7c53b22b619bcbd659 (diff)
downloadlibssh-eb65f031af04a8f5c1ceaa014cdbdf5106b94c22.tar.gz
libssh-eb65f031af04a8f5c1ceaa014cdbdf5106b94c22.tar.xz
libssh-eb65f031af04a8f5c1ceaa014cdbdf5106b94c22.zip
pki: Fix setting flags in ssh_key_dup().
Diffstat (limited to 'src')
-rw-r--r--src/pki_crypto.c6
-rw-r--r--src/pki_gcrypt.c21
2 files changed, 18 insertions, 9 deletions
diff --git a/src/pki_crypto.c b/src/pki_crypto.c
index 33e77c62..147b2035 100644
--- a/src/pki_crypto.c
+++ b/src/pki_crypto.c
@@ -80,7 +80,11 @@ ssh_key pki_key_dup(const ssh_key key, int demote)
new->type = key->type;
new->type_c = key->type_c;
- new->flags = key->flags;
+ if (demote) {
+ new->flags = SSH_KEY_FLAG_PUBLIC;
+ } else {
+ new->flags = key->flags;
+ }
switch (key->type) {
case SSH_KEYTYPE_DSS:
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index a39b2607..65c9107f 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -749,6 +749,11 @@ ssh_key pki_key_dup(const ssh_key key, int demote)
}
new->type = key->type;
new->type_c = key->type_c;
+ if (demote) {
+ new->flags = SSH_KEY_FLAG_PUBLIC;
+ } else {
+ new->flags = key->flags;
+ }
switch(key->type) {
case SSH_KEYTYPE_DSS:
@@ -845,28 +850,28 @@ ssh_key pki_key_dup(const ssh_key key, int demote)
break;
case SSH_KEYTYPE_RSA:
case SSH_KEYTYPE_RSA1:
- sexp = gcry_sexp_find_token(key->rsa, "n", 0);
+ sexp = gcry_sexp_find_token(key->rsa, "e", 0);
if (sexp == NULL) {
goto fail;
}
tmp = gcry_sexp_nth_data(sexp, 1, &size);
- n = ssh_string_new(size);
- if (n == NULL) {
+ e = ssh_string_new(size);
+ if (e == NULL) {
goto fail;
}
- ssh_string_fill(n, (char *)tmp, size);
+ ssh_string_fill(e, (char *)tmp, size);
gcry_sexp_release(sexp);
- sexp = gcry_sexp_find_token(key->rsa, "e", 0);
+ sexp = gcry_sexp_find_token(key->rsa, "n", 0);
if (sexp == NULL) {
goto fail;
}
tmp = gcry_sexp_nth_data(sexp, 1, &size);
- e = ssh_string_new(size);
- if (e == NULL) {
+ n = ssh_string_new(size);
+ if (n == NULL) {
goto fail;
}
- ssh_string_fill(e, (char *)tmp, size);
+ ssh_string_fill(n, (char *)tmp, size);
gcry_sexp_release(sexp);
if (!demote && (key->flags & SSH_KEY_FLAG_PRIVATE)) {