]> andersk Git - openssh.git/commitdiff
- markus@cvs.openbsd.org 2002/03/18 17:23:31
authormouring <mouring>
Fri, 22 Mar 2002 01:45:53 +0000 (01:45 +0000)
committermouring <mouring>
Fri, 22 Mar 2002 01:45:53 +0000 (01:45 +0000)
     [key.c key.h]
     add key_demote() for ssh-privsep

ChangeLog
key.c
key.h

index 7b87dd998afb838c3d5ae283f6e8707c8c790418..e227a0d8f284eae320bd20503c078f4ee8ebcad2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -50,6 +50,9 @@
    - markus@cvs.openbsd.org 2002/03/18 17:16:38
      [packet.c packet.h]
      export/import cipher state, iv and ssh2 seqnr; needed by ssh-privsep
+   - markus@cvs.openbsd.org 2002/03/18 17:23:31
+     [key.c key.h]
+     add key_demote() for ssh-privsep
 
 20020317
  - (tim) [configure.ac] Assume path given with --with-pid-dir=PATH is wanted,
diff --git a/key.c b/key.c
index cda91571affd8c4168746459d2a8139cd29ae34c..51902ea257fa3b26310d0e09742462f7c81ff955 100644 (file)
--- a/key.c
+++ b/key.c
@@ -32,7 +32,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "includes.h"
-RCSID("$OpenBSD: key.c,v 1.41 2002/02/28 15:46:33 markus Exp $");
+RCSID("$OpenBSD: key.c,v 1.42 2002/03/18 17:23:31 markus Exp $");
 
 #include <openssl/evp.h>
 
@@ -801,3 +801,46 @@ key_verify(
                break;
        }
 }
+
+/* Converts a private to a public key */
+
+Key *
+key_demote(Key *k)
+{
+       Key *pk;
+       
+       pk = xmalloc(sizeof(*pk));
+       pk->type = k->type;
+       pk->flags = k->flags;
+       pk->dsa = NULL;
+       pk->rsa = NULL;
+
+       switch (k->type) {
+       case KEY_RSA1:
+       case KEY_RSA:
+               if ((pk->rsa = RSA_new()) == NULL)
+                       fatal("key_demote: RSA_new failed");
+               if ((pk->rsa->e = BN_dup(k->rsa->e)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               if ((pk->rsa->n = BN_dup(k->rsa->n)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               break;
+       case KEY_DSA:
+               if ((pk->dsa = DSA_new()) == NULL)
+                       fatal("key_demote: DSA_new failed");
+               if ((pk->dsa->p = BN_dup(k->dsa->p)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               if ((pk->dsa->q = BN_dup(k->dsa->q)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               if ((pk->dsa->g = BN_dup(k->dsa->g)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               if ((pk->dsa->pub_key = BN_dup(k->dsa->pub_key)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               break;
+       default:
+               fatal("key_free: bad key type %d", k->type);
+               break;
+       }
+
+       return (pk);
+}
diff --git a/key.h b/key.h
index a2257731aef55cd9170262e0d0537e79a4745098..8d1fa412672d9342f0572952d6f41ec2719438c0 100644 (file)
--- a/key.h
+++ b/key.h
@@ -1,4 +1,4 @@
-/*     $OpenBSD: key.h,v 1.18 2002/02/24 19:14:59 markus Exp $ */
+/*     $OpenBSD: key.h,v 1.19 2002/03/18 17:23:31 markus Exp $ */
 
 /*
  * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
@@ -58,6 +58,7 @@ struct Key {
 Key    *key_new(int);
 Key    *key_new_private(int);
 void    key_free(Key *);
+Key    *key_demote(Key *);
 int     key_equal(Key *, Key *);
 char   *key_fingerprint(Key *, enum fp_type, enum fp_rep);
 char   *key_type(Key *);
This page took 0.05739 seconds and 5 git commands to generate.