- markus@cvs.openbsd.org 2002/03/25 17:34:27
     [scard.c scard.h ssh-agent.c ssh-keygen.c ssh.c]
     change sc_get_key to sc_get_keys and hide smartcard details in scard.c
diff --git a/ssh.c b/ssh.c
index ae2e854..dd926b7 100644
--- a/ssh.c
+++ b/ssh.c
@@ -39,7 +39,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh.c,v 1.166 2002/03/21 22:44:05 rees Exp $");
+RCSID("$OpenBSD: ssh.c,v 1.167 2002/03/25 17:34:27 markus Exp $");
 
 #include <openssl/evp.h>
 #include <openssl/err.h>
@@ -70,7 +70,6 @@
 #include "sshtty.h"
 
 #ifdef SMARTCARD
-#include <openssl/engine.h>
 #include "scard.h"
 #endif
 
@@ -1187,40 +1186,29 @@
 load_public_identity_files(void)
 {
 	char *filename;
-	Key *public;
 	int i = 0;
-
+	Key *public;
 #ifdef SMARTCARD
+	Key **keys;
+
 	if (options.smartcard_device != NULL &&
-	    options.num_identity_files + 1 < SSH_MAX_IDENTITY_FILES &&
-	    (public = sc_get_key(options.smartcard_device, NULL)) != NULL ) {
-		Key *new;
-
-		if (options.num_identity_files + 2 > SSH_MAX_IDENTITY_FILES)
-			options.num_identity_files = SSH_MAX_IDENTITY_FILES - 2;
-		memmove(&options.identity_files[2], &options.identity_files[0],
-		    sizeof(char *) * options.num_identity_files);
-		options.num_identity_files += 2;
-		i = 2;
-
-		/* XXX ssh1 vs ssh2 */
-		new = key_new(KEY_RSA);
-		new->flags = KEY_FLAG_EXT;
-		BN_copy(new->rsa->n, public->rsa->n);
-		BN_copy(new->rsa->e, public->rsa->e);
-		RSA_set_method(new->rsa, sc_get_engine());
-		options.identity_keys[0] = new;
-		options.identity_files[0] = xstrdup("smartcard rsa key");;
-
-		new = key_new(KEY_RSA1);
-		new->flags = KEY_FLAG_EXT;
-		BN_copy(new->rsa->n, public->rsa->n);
-		BN_copy(new->rsa->e, public->rsa->e);
-		RSA_set_method(new->rsa, sc_get_engine());
-		options.identity_keys[1] = new;
-		options.identity_files[1] = xstrdup("smartcard rsa1 key");
-
-		key_free(public);
+	    options.num_identity_files < SSH_MAX_IDENTITY_FILES &&
+	    (keys = sc_get_keys(options.smartcard_device, NULL)) != NULL ) {
+		int count = 0;
+		for (i = 0; keys[i] != NULL; i++) {
+			count++;
+			if (options.num_identity_files + 1 > SSH_MAX_IDENTITY_FILES)
+				options.num_identity_files = SSH_MAX_IDENTITY_FILES - 1;
+			memmove(&options.identity_files[1], &options.identity_files[0],
+			    sizeof(char *) * (SSH_MAX_IDENTITY_FILES - 1));
+			memmove(&options.identity_keys[1], &options.identity_keys[0],
+			    sizeof(Key *) * (SSH_MAX_IDENTITY_FILES - 1));
+			options.num_identity_files++;
+			options.identity_keys[0] = keys[i];
+			options.identity_files[0] = xstrdup("smartcard key");;
+		}
+		i = count;
+		xfree(keys);
 	}
 #endif /* SMARTCARD */
 	for (; i < options.num_identity_files; i++) {