summaryrefslogtreecommitdiff
path: root/scard.c
diff options
context:
space:
mode:
Diffstat (limited to 'scard.c')
-rw-r--r--scard.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/scard.c b/scard.c
index b3d25058a..9fd3ca1b4 100644
--- a/scard.c
+++ b/scard.c
@@ -1,3 +1,4 @@
1/* $OpenBSD: scard.c,v 1.36 2006/11/06 21:25:28 markus Exp $ */
1/* 2/*
2 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
3 * 4 *
@@ -24,14 +25,18 @@
24 25
25#include "includes.h" 26#include "includes.h"
26#if defined(SMARTCARD) && defined(USE_SECTOK) 27#if defined(SMARTCARD) && defined(USE_SECTOK)
27RCSID("$OpenBSD: scard.c,v 1.29 2004/05/08 00:21:31 djm Exp $");
28 28
29#include <openssl/evp.h> 29#include <sys/types.h>
30
30#include <sectok.h> 31#include <sectok.h>
32#include <stdarg.h>
33#include <string.h>
34
35#include <openssl/evp.h>
31 36
37#include "xmalloc.h"
32#include "key.h" 38#include "key.h"
33#include "log.h" 39#include "log.h"
34#include "xmalloc.h"
35#include "misc.h" 40#include "misc.h"
36#include "scard.h" 41#include "scard.h"
37 42
@@ -125,7 +130,7 @@ sc_init(void)
125 if (status == SCARD_ERROR_NOCARD) { 130 if (status == SCARD_ERROR_NOCARD) {
126 return SCARD_ERROR_NOCARD; 131 return SCARD_ERROR_NOCARD;
127 } 132 }
128 if (status < 0 ) { 133 if (status < 0) {
129 error("sc_open failed"); 134 error("sc_open failed");
130 return status; 135 return status;
131 } 136 }
@@ -215,7 +220,7 @@ sc_private_decrypt(int flen, u_char *from, u_char *to, RSA *rsa,
215 olen = len = sw = 0; 220 olen = len = sw = 0;
216 if (sc_fd < 0) { 221 if (sc_fd < 0) {
217 status = sc_init(); 222 status = sc_init();
218 if (status < 0 ) 223 if (status < 0)
219 goto err; 224 goto err;
220 } 225 }
221 if (padding != RSA_PKCS1_PADDING) 226 if (padding != RSA_PKCS1_PADDING)
@@ -255,7 +260,7 @@ sc_private_encrypt(int flen, u_char *from, u_char *to, RSA *rsa,
255 len = sw = 0; 260 len = sw = 0;
256 if (sc_fd < 0) { 261 if (sc_fd < 0) {
257 status = sc_init(); 262 status = sc_init();
258 if (status < 0 ) 263 if (status < 0)
259 goto err; 264 goto err;
260 } 265 }
261 if (padding != RSA_PKCS1_PADDING) 266 if (padding != RSA_PKCS1_PADDING)
@@ -378,23 +383,25 @@ sc_get_keys(const char *id, const char *pin)
378 key_free(k); 383 key_free(k);
379 return NULL; 384 return NULL;
380 } 385 }
381 if (status < 0 ) { 386 if (status < 0) {
382 error("sc_read_pubkey failed"); 387 error("sc_read_pubkey failed");
383 key_free(k); 388 key_free(k);
384 return NULL; 389 return NULL;
385 } 390 }
386 keys = xmalloc((nkeys+1) * sizeof(Key *)); 391 keys = xcalloc((nkeys+1), sizeof(Key *));
387 392
388 n = key_new(KEY_RSA1); 393 n = key_new(KEY_RSA1);
389 BN_copy(n->rsa->n, k->rsa->n); 394 if ((BN_copy(n->rsa->n, k->rsa->n) == NULL) ||
390 BN_copy(n->rsa->e, k->rsa->e); 395 (BN_copy(n->rsa->e, k->rsa->e) == NULL))
396 fatal("sc_get_keys: BN_copy failed");
391 RSA_set_method(n->rsa, sc_get_rsa()); 397 RSA_set_method(n->rsa, sc_get_rsa());
392 n->flags |= KEY_FLAG_EXT; 398 n->flags |= KEY_FLAG_EXT;
393 keys[0] = n; 399 keys[0] = n;
394 400
395 n = key_new(KEY_RSA); 401 n = key_new(KEY_RSA);
396 BN_copy(n->rsa->n, k->rsa->n); 402 if ((BN_copy(n->rsa->n, k->rsa->n) == NULL) ||
397 BN_copy(n->rsa->e, k->rsa->e); 403 (BN_copy(n->rsa->e, k->rsa->e) == NULL))
404 fatal("sc_get_keys: BN_copy failed");
398 RSA_set_method(n->rsa, sc_get_rsa()); 405 RSA_set_method(n->rsa, sc_get_rsa());
399 n->flags |= KEY_FLAG_EXT; 406 n->flags |= KEY_FLAG_EXT;
400 keys[1] = n; 407 keys[1] = n;