+/* $OpenBSD: scard.c,v 1.36 2006/11/06 21:25:28 markus Exp $ */
/*
* Copyright (c) 2001 Markus Friedl. All rights reserved.
*
#include "includes.h"
#if defined(SMARTCARD) && defined(USE_SECTOK)
-RCSID("$OpenBSD: scard.c,v 1.28 2003/06/12 19:12:02 markus Exp $");
-#include <openssl/evp.h>
+#include <sys/types.h>
+
#include <sectok.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include <openssl/evp.h>
+#include "xmalloc.h"
#include "key.h"
#include "log.h"
-#include "xmalloc.h"
-#include "readpass.h"
+#include "misc.h"
#include "scard.h"
#if OPENSSL_VERSION_NUMBER < 0x00907000L
if (status == SCARD_ERROR_NOCARD) {
return SCARD_ERROR_NOCARD;
}
- if (status < 0 ) {
+ if (status < 0) {
error("sc_open failed");
return status;
}
olen = len = sw = 0;
if (sc_fd < 0) {
status = sc_init();
- if (status < 0 )
+ if (status < 0)
goto err;
}
if (padding != RSA_PKCS1_PADDING)
len = sw = 0;
if (sc_fd < 0) {
status = sc_init();
- if (status < 0 )
+ if (status < 0)
goto err;
}
if (padding != RSA_PKCS1_PADDING)
key_free(k);
return NULL;
}
- if (status < 0 ) {
+ if (status < 0) {
error("sc_read_pubkey failed");
key_free(k);
return NULL;
}
- keys = xmalloc((nkeys+1) * sizeof(Key *));
+ keys = xcalloc((nkeys+1), sizeof(Key *));
n = key_new(KEY_RSA1);
- BN_copy(n->rsa->n, k->rsa->n);
- BN_copy(n->rsa->e, k->rsa->e);
+ if ((BN_copy(n->rsa->n, k->rsa->n) == NULL) ||
+ (BN_copy(n->rsa->e, k->rsa->e) == NULL))
+ fatal("sc_get_keys: BN_copy failed");
RSA_set_method(n->rsa, sc_get_rsa());
n->flags |= KEY_FLAG_EXT;
keys[0] = n;
n = key_new(KEY_RSA);
- BN_copy(n->rsa->n, k->rsa->n);
- BN_copy(n->rsa->e, k->rsa->e);
+ if ((BN_copy(n->rsa->n, k->rsa->n) == NULL) ||
+ (BN_copy(n->rsa->e, k->rsa->e) == NULL))
+ fatal("sc_get_keys: BN_copy failed");
RSA_set_method(n->rsa, sc_get_rsa());
n->flags |= KEY_FLAG_EXT;
keys[1] = n;