Merges with SCIDI to help integrating build process with it
Remove some gcc specific flags from Makefile.am Rename some header defines size_t vs. int fixups opensc.h: Define inline as null for other compilers than gcc, for now Port pam_pkcs15 to compile for Solaris and HP-UX, untested Fix compiler warnings OpenSC now compiles cleanly for Tru64, AIX and HP-UX. The only problem is the tools using getopt_long() (GNU extension), to be fixed later.. git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@120 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
3e96a893ec
commit
607271df53
|
@ -10,8 +10,6 @@ libopensc_la_SOURCES = sc-asn1.c sc-base64.c sc-defaults.c \
|
|||
sc-card-emv.c sc-card-default.c
|
||||
libopensc_la_LDFLAGS = -version-info 0:4:0
|
||||
libopensc_la_LIBADD = @LIBPCSC@
|
||||
libopensc_la_CFLAGS = $(AM_CFLAGS) -Werror
|
||||
|
||||
include_HEADERS = opensc.h opensc-pkcs15.h
|
||||
noinst_HEADERS = sc-asn1.h sc-log.h sc-internal.h
|
||||
|
||||
|
|
|
@ -251,8 +251,7 @@ void sc_asn1_print_tags(const u8 * buf, int buflen)
|
|||
const u8 *sc_asn1_find_tag(struct sc_context *ctx, const u8 * buf,
|
||||
size_t buflen, unsigned int tag_in, size_t *taglen_in)
|
||||
{
|
||||
size_t left = buflen, taglen;
|
||||
unsigned int cla, tag;
|
||||
int left = buflen, taglen, cla, tag;
|
||||
const u8 *p = buf;
|
||||
|
||||
*taglen_in = 0;
|
||||
|
@ -277,8 +276,7 @@ const u8 *sc_asn1_skip_tag(struct sc_context *ctx, const u8 ** buf, size_t *bufl
|
|||
unsigned int tag_in, size_t *taglen_out)
|
||||
{
|
||||
const u8 *p = *buf;
|
||||
size_t len = *buflen, taglen;
|
||||
unsigned int cla, tag;
|
||||
int len = *buflen, taglen, cla, tag;
|
||||
|
||||
if (read_tag((const u8 **) &p, len, &cla, &tag, &taglen) != 1)
|
||||
return NULL;
|
||||
|
@ -464,7 +462,7 @@ static int asn1_parse_path(struct sc_context *ctx, const u8 *in, int len,
|
|||
{
|
||||
int idx, r;
|
||||
struct sc_asn1_struct asn1_path[] = {
|
||||
{ "path", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0, &path->value, &path->len },
|
||||
{ "path", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0, &path->value, (int *) &path->len },
|
||||
{ "index", SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, &idx },
|
||||
{ NULL }
|
||||
};
|
||||
|
@ -504,12 +502,12 @@ static int asn1_parse_p15_object(struct sc_context *ctx, const u8 *in, int len,
|
|||
}
|
||||
|
||||
static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_struct *entry,
|
||||
const u8 *obj, size_t objlen, int depth)
|
||||
const u8 *obj, int objlen, int depth)
|
||||
{
|
||||
void *parm = entry->parm;
|
||||
int (*callback_func)(struct sc_context *ctx, void *arg, const u8 *obj,
|
||||
size_t objlen, int depth) =
|
||||
(int (*)(struct sc_context *, void *, const u8 *, size_t, int)) parm;
|
||||
int objlen, int depth) =
|
||||
(int (*)(struct sc_context *, void *, const u8 *, int, int)) parm;
|
||||
int *len = (int *) entry->arg;
|
||||
int r = 0;
|
||||
|
||||
|
@ -519,11 +517,11 @@ static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_struct *entr
|
|||
|
||||
line[0] = 0;
|
||||
for (i = 0; i < depth; i++) {
|
||||
strcpy(linep, " ");
|
||||
strcpy((char *) linep, " ");
|
||||
linep += 2;
|
||||
}
|
||||
sprintf(linep, "decoding '%s'\n", entry->name);
|
||||
debug(ctx, line);
|
||||
sprintf((char *) linep, "decoding '%s'\n", entry->name);
|
||||
debug(ctx, (char *) line);
|
||||
}
|
||||
|
||||
switch (entry->type) {
|
||||
|
@ -649,7 +647,7 @@ static int asn1_parse(struct sc_context *ctx, struct sc_asn1_struct *asn1,
|
|||
int r, idx = 0;
|
||||
const u8 *p = in, *obj;
|
||||
struct sc_asn1_struct *entry = asn1;
|
||||
int left = len, objlen;
|
||||
size_t left = len, objlen;
|
||||
|
||||
if (ctx->debug >= 3)
|
||||
debug(ctx, "called, depth %d%s\n", depth, choice ? ", choice" : "");
|
||||
|
@ -677,7 +675,7 @@ static int asn1_parse(struct sc_context *ctx, struct sc_asn1_struct *asn1,
|
|||
|
||||
line[0] = 0;
|
||||
for (i = 0; i < 10 && i < left; i++) {
|
||||
sprintf(linep, "%02X ", p[i]);
|
||||
sprintf((char *) linep, "%02X ", p[i]);
|
||||
linep += 3;
|
||||
}
|
||||
debug(ctx, "next tag: %s\n", line);
|
||||
|
|
|
@ -147,8 +147,9 @@ int sc_base64_encode(const u8 *in, size_t len, u8 *out, size_t outlen, size_t li
|
|||
|
||||
int sc_base64_decode(const char *in, u8 *out, size_t outlen)
|
||||
{
|
||||
int len = 0, r, i, skip;
|
||||
|
||||
int len = 0, r, skip;
|
||||
unsigned int i;
|
||||
|
||||
while ((r = from_base64(in, &i, &skip)) > 0) {
|
||||
int finished = 0, s = 16;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ static int mflex_match_card(struct sc_card *card)
|
|||
|
||||
for (i = 0; mflex_atrs[i] != NULL; i++) {
|
||||
u8 defatr[SC_MAX_ATR_SIZE];
|
||||
int len = sizeof(defatr);
|
||||
size_t len = sizeof(defatr);
|
||||
const char *atrp = mflex_atrs[i];
|
||||
|
||||
if (sc_hex_to_bin(atrp, defatr, &len))
|
||||
|
@ -74,10 +74,15 @@ static int parse_flex_sf_reply(struct sc_context *ctx, const u8 *buf, int buflen
|
|||
struct sc_file *file)
|
||||
{
|
||||
const u8 *p = buf + 2;
|
||||
u8 b1, b2;
|
||||
int left;
|
||||
|
||||
file->size = (*p++ << 8) + *p++;
|
||||
file->id = (*p++ << 8) + *p++;
|
||||
b1 = *p++;
|
||||
b2 = *p++;
|
||||
file->size = (b1 << 8) + b2;
|
||||
b1 = *p++;
|
||||
b2 = *p++;
|
||||
file->id = (b1) + b2;
|
||||
switch (*p) {
|
||||
case 0x01:
|
||||
file->type = SC_FILE_TYPE_WORKING_EF;
|
||||
|
@ -119,7 +124,7 @@ static int mflex_select_file(struct sc_card *card, const struct sc_path *path,
|
|||
int r, i;
|
||||
struct sc_apdu apdu;
|
||||
u8 rbuf[MAX_BUFFER_SIZE];
|
||||
u8 *pathptr = path->value;
|
||||
const u8 *pathptr = path->value;
|
||||
size_t pathlen = path->len;
|
||||
|
||||
SC_FUNC_CALLED(card->ctx, 3);
|
||||
|
|
|
@ -44,7 +44,7 @@ static int setec_match_card(struct sc_card *card)
|
|||
|
||||
for (i = 0; setec_atrs[i] != NULL; i++) {
|
||||
u8 defatr[SC_MAX_ATR_SIZE];
|
||||
int len = sizeof(defatr);
|
||||
size_t len = sizeof(defatr);
|
||||
const char *atrp = setec_atrs[i];
|
||||
|
||||
if (sc_hex_to_bin(atrp, defatr, &len))
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _LIBOPENSC_H
|
||||
#define _LIBOPENSC_H
|
||||
#ifndef _SC_INTERNAL_H
|
||||
#define _SC_INTERNAL_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
|
|
|
@ -203,7 +203,7 @@ static int iso7816_select_file(struct sc_card *card,
|
|||
{
|
||||
struct sc_context *ctx;
|
||||
struct sc_apdu apdu;
|
||||
char buf[SC_MAX_APDU_BUFFER_SIZE];
|
||||
u8 buf[SC_MAX_APDU_BUFFER_SIZE];
|
||||
u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
|
||||
int r, pathlen;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ void error(struct sc_context *ctx, const char *format, ...)
|
|||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
do_log2(ctx, SC_LOG_TYPE_ERROR, "", format, ap);
|
||||
do_log2(ctx, SC_LOG_TYPE_ERROR, NULL, 0, "", format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ void debug(struct sc_context *ctx, const char *format, ...)
|
|||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
do_log2(ctx, SC_LOG_TYPE_DEBUG, "", format, ap);
|
||||
do_log2(ctx, SC_LOG_TYPE_DEBUG, NULL, 0, "", format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
@ -110,18 +110,18 @@ void do_log2(struct sc_context *ctx, int type, const char *file,
|
|||
if (do_color && !isatty(fileno(outf)))
|
||||
do_color = 0;
|
||||
if (do_color) {
|
||||
color_sfx = "\e[0m";
|
||||
color_sfx = "\\e[0m";
|
||||
switch (type) {
|
||||
case SC_LOG_TYPE_ERROR:
|
||||
color_pfx = "\e[01;31m";
|
||||
color_pfx = "\\e[01;31m";
|
||||
break;
|
||||
#if 0
|
||||
case SC_LOG_TYPE_NORMAL:
|
||||
color_pfx = "\e[01;33m";
|
||||
color_pfx = "\\e[01;33m";
|
||||
break;
|
||||
#endif
|
||||
case SC_LOG_TYPE_DEBUG:
|
||||
color_pfx = "\e[00;32m";
|
||||
color_pfx = "\\e[00;32m";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ void do_log2(struct sc_context *ctx, int type, const char *file,
|
|||
void sc_hex_dump(struct sc_context *ctx, const u8 *in, size_t count,
|
||||
char *buf, size_t len)
|
||||
{
|
||||
u8 *p = buf;
|
||||
char *p = buf;
|
||||
int lines = 0;
|
||||
|
||||
assert(buf != NULL && in != NULL);
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _SC_PKCS15_H
|
||||
#define _SC_PKCS15_H
|
||||
#ifndef _OPENSC_PKCS15_H
|
||||
#define _OPENSC_PKCS15_H
|
||||
|
||||
#include "opensc.h"
|
||||
|
||||
|
@ -42,7 +42,7 @@ extern "C" {
|
|||
|
||||
struct sc_pkcs15_id {
|
||||
u8 value[SC_PKCS15_MAX_ID_SIZE];
|
||||
int len;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct sc_pkcs15_common_obj_attr {
|
||||
|
|
|
@ -32,6 +32,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef __GNUC__
|
||||
#undef inline
|
||||
#define inline
|
||||
#endif
|
||||
|
||||
#define SC_ERROR_MIN -1000
|
||||
#define SC_ERROR_UNKNOWN -1000
|
||||
#define SC_ERROR_CMD_TOO_SHORT -1001
|
||||
|
|
|
@ -87,7 +87,7 @@ static int parse_x509_cert(struct sc_context *ctx, const u8 *buf, size_t buflen,
|
|||
{ NULL }
|
||||
};
|
||||
struct sc_asn1_struct asn1_pkinfo[] = {
|
||||
{ "algorithm", SC_ASN1_CALLBACK, ASN1_SEQUENCE | SC_ASN1_CONS, 0, parse_algorithm_id, &pk_alg },
|
||||
{ "algorithm", SC_ASN1_CALLBACK, ASN1_SEQUENCE | SC_ASN1_CONS, 0, (void *) parse_algorithm_id, &pk_alg },
|
||||
{ "subjectPublicKey", SC_ASN1_BIT_STRING_NI, ASN1_BIT_STRING, SC_ASN1_ALLOC, &pk, &pklen },
|
||||
{ NULL }
|
||||
};
|
||||
|
@ -103,7 +103,7 @@ static int parse_x509_cert(struct sc_context *ctx, const u8 *buf, size_t buflen,
|
|||
};
|
||||
struct sc_asn1_struct asn1_cert[] = {
|
||||
{ "tbsCertificate", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert },
|
||||
{ "signatureAlgorithm", SC_ASN1_CALLBACK, ASN1_SEQUENCE | SC_ASN1_CONS, 0, parse_algorithm_id, &sig_alg },
|
||||
{ "signatureAlgorithm", SC_ASN1_CALLBACK, ASN1_SEQUENCE | SC_ASN1_CONS, 0, (void *) parse_algorithm_id, &sig_alg },
|
||||
{ "signatureValue", SC_ASN1_BIT_STRING,ASN1_BIT_STRING, 0, NULL, 0 },
|
||||
{ NULL }
|
||||
};
|
||||
|
@ -139,7 +139,7 @@ static int generate_cert_filename(struct sc_pkcs15_card *p15card,
|
|||
char *fname, int len)
|
||||
{
|
||||
char *homedir;
|
||||
u8 cert_id[SC_PKCS15_MAX_ID_SIZE*2+1];
|
||||
char cert_id[SC_PKCS15_MAX_ID_SIZE*2+1];
|
||||
int i, r;
|
||||
|
||||
homedir = getenv("HOME");
|
||||
|
@ -166,7 +166,7 @@ static int find_cached_cert(struct sc_pkcs15_card *p15card,
|
|||
{
|
||||
int r;
|
||||
u8 *data;
|
||||
u8 fname[1024];
|
||||
char fname[1024];
|
||||
FILE *crtf;
|
||||
struct stat stbuf;
|
||||
|
||||
|
@ -204,7 +204,7 @@ static int store_cert_to_cache(struct sc_pkcs15_card *p15card,
|
|||
const struct sc_pkcs15_cert_info *info,
|
||||
u8 *data, int len)
|
||||
{
|
||||
u8 fname[1024];
|
||||
char fname[1024];
|
||||
FILE *crtf;
|
||||
int r;
|
||||
|
||||
|
|
|
@ -137,21 +137,21 @@ static int fineid_pkcs15_defaults(struct sc_pkcs15_card *arg,
|
|||
pin->magic = SC_PKCS15_PIN_MAGIC;
|
||||
|
||||
card->cert_count = 3;
|
||||
format_cert_struct(&card->cert_info[0], "todentamis- ja salausvarmenne", "\x45", 1, 0, "50154331");
|
||||
format_cert_struct(&card->cert_info[1], "allekirjoitusvarmenne", "\x46", 1, 0, "50154332");
|
||||
format_cert_struct(&card->cert_info[0], "todentamis- ja salausvarmenne", (const u8 *) "\x45", 1, 0, "50154331");
|
||||
format_cert_struct(&card->cert_info[1], "allekirjoitusvarmenne", (const u8 *) "\x46", 1, 0, "50154332");
|
||||
switch (type) {
|
||||
case 1:
|
||||
format_cert_struct(&card->cert_info[2], "FINSIGN CA for Citizen", "\x47", 1, 1, "50154333");
|
||||
format_cert_struct(&card->cert_info[2], "FINSIGN CA for Citizen", (const u8 *) "\x47", 1, 1, "50154333");
|
||||
break;
|
||||
case 2:
|
||||
format_cert_struct(&card->cert_info[2], "Test CA for S4-2", "\x47", 1, 1, "50154333");
|
||||
format_cert_struct(&card->cert_info[2], "Test CA for S4-2", (const u8 *) "\x47", 1, 1, "50154333");
|
||||
break;
|
||||
}
|
||||
|
||||
card->prkey_count = 2;
|
||||
format_prkey_struct(&card->prkey_info[0], "todentamis- ja salausavain", "\x45", 1, "\x01", 1,
|
||||
format_prkey_struct(&card->prkey_info[0], "todentamis- ja salausavain", (const u8 *) "\x45", 1, (const u8 *) "\x01", 1,
|
||||
0x26, 0x1d, 1024, "4B01");
|
||||
format_prkey_struct(&card->prkey_info[1], "allekirjoitusavain", "\x46", 1, "\x02", 1,
|
||||
format_prkey_struct(&card->prkey_info[1], "allekirjoitusavain", (const u8 *) "\x46", 1, (const u8 *) "\x02", 1,
|
||||
0x200, 0x1d, 1024, "4B02");
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -166,7 +166,7 @@ int sc_pkcs15_verify_pin(struct sc_pkcs15_card *p15card,
|
|||
int r;
|
||||
struct sc_file file;
|
||||
struct sc_card *card;
|
||||
char pinbuf[SC_MAX_PIN_SIZE];
|
||||
u8 pinbuf[SC_MAX_PIN_SIZE];
|
||||
|
||||
assert(p15card != NULL);
|
||||
if (pin->magic != SC_PKCS15_PIN_MAGIC)
|
||||
|
|
|
@ -55,7 +55,7 @@ void sc_pkcs15_print_card(const struct sc_pkcs15_card *card)
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
void parse_tokeninfo(struct sc_pkcs15_card *card, const u8 * buf, int buflen)
|
||||
void parse_tokeninfo(struct sc_pkcs15_card *card, const u8 * buf, size_t buflen)
|
||||
{
|
||||
int i, r;
|
||||
u8 serial[128];
|
||||
|
@ -97,7 +97,7 @@ void parse_tokeninfo(struct sc_pkcs15_card *card, const u8 * buf, int buflen)
|
|||
}
|
||||
if (card->manufacturer_id == NULL) {
|
||||
if (asn1_tokeninfo[2].flags & SC_ASN1_PRESENT)
|
||||
card->manufacturer_id = strdup(mnfid);
|
||||
card->manufacturer_id = strdup((char *) mnfid);
|
||||
else
|
||||
card->manufacturer_id = strdup("(unknown)");
|
||||
}
|
||||
|
@ -110,9 +110,9 @@ err:
|
|||
return;
|
||||
}
|
||||
|
||||
static int parse_dir(const u8 * buf, int buflen, struct sc_pkcs15_card *card)
|
||||
static int parse_dir(const u8 * buf, size_t buflen, struct sc_pkcs15_card *card)
|
||||
{
|
||||
const u8 *aidref = "\xA0\x00\x00\x00\x63PKCS-15";
|
||||
const u8 *aidref = (const u8 *) "\xA0\x00\x00\x00\x63PKCS-15";
|
||||
const int aidref_len = 12;
|
||||
int r;
|
||||
u8 aid[128], label[128], path[128];
|
||||
|
@ -150,7 +150,7 @@ static int parse_dir(const u8 * buf, int buflen, struct sc_pkcs15_card *card)
|
|||
return -1;
|
||||
}
|
||||
if (asn1_dir[1].flags & SC_ASN1_PRESENT)
|
||||
card->label = strdup(label);
|
||||
card->label = strdup((char *) label);
|
||||
else
|
||||
card->label = strdup("(unknown)");
|
||||
memcpy(card->file_app.path.value, path, path_len);
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _SC_PKCS15_H
|
||||
#define _SC_PKCS15_H
|
||||
#ifndef _OPENSC_PKCS15_H
|
||||
#define _OPENSC_PKCS15_H
|
||||
|
||||
#include "opensc.h"
|
||||
|
||||
|
@ -42,7 +42,7 @@ extern "C" {
|
|||
|
||||
struct sc_pkcs15_id {
|
||||
u8 value[SC_PKCS15_MAX_ID_SIZE];
|
||||
int len;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct sc_pkcs15_common_obj_attr {
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _LIBOPENSC_H
|
||||
#define _LIBOPENSC_H
|
||||
#ifndef _SC_INTERNAL_H
|
||||
#define _SC_INTERNAL_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# Process this file with automake to create Makefile.in
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/libopensc
|
||||
INCLUDES = -I../libopensc
|
||||
LDFLAGS = @LDFLAGS@ @LIBCRYPTO@ \
|
||||
$(top_srcdir)/src/libopensc/libopensc.la
|
||||
../libopensc/libopensc.la
|
||||
|
||||
EXTRA_DIST = openssh-3.0.2p1-patch.diff
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/evp.h>
|
||||
|
@ -37,7 +41,7 @@ struct sc_context *ctx = NULL;
|
|||
struct sc_card *card = NULL;
|
||||
struct sc_pkcs15_card *p15card = NULL;
|
||||
|
||||
void print_usage_and_die()
|
||||
void print_usage_and_die(void)
|
||||
{
|
||||
int i = 0;
|
||||
printf("Usage: sc-ssh [OPTIONS]\nOptions:\n");
|
||||
|
@ -127,7 +131,7 @@ int write_ssh_key(struct sc_pkcs15_cert_info *cinfo, RSA *rsa)
|
|||
|
||||
if (buf == NULL)
|
||||
return 1;
|
||||
put_string("ssh-rsa", 7, p, left, &skip);
|
||||
put_string((u8 *) "ssh-rsa", 7, p, left, &skip);
|
||||
left -= skip;
|
||||
p += skip;
|
||||
num = bignum_to_buf(rsa->e, &len, &skip);
|
||||
|
@ -168,7 +172,7 @@ int write_ssh_key(struct sc_pkcs15_cert_info *cinfo, RSA *rsa)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int extract_key()
|
||||
int extract_key(void)
|
||||
{
|
||||
int r, i;
|
||||
struct sc_pkcs15_id id;
|
||||
|
@ -180,7 +184,7 @@ int extract_key()
|
|||
EVP_PKEY *pubkey;
|
||||
|
||||
if (opt_cert) {
|
||||
if (strlen(opt_cert)/2 >= SC_PKCS15_MAX_ID_SIZE) {
|
||||
if (((strlen(opt_cert)/2) >= SC_PKCS15_MAX_ID_SIZE)) {
|
||||
fprintf(stderr, "Certificate id too long.\n");
|
||||
return 2;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
libdir = ${prefix}/lib/security
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/libopensc
|
||||
INCLUDES = -I../libopensc
|
||||
LDFLAGS = @LDFLAGS@ @LIBDL@ @LIBPAM@ @LIBCRYPTO@ \
|
||||
$(top_srcdir)/src/libopensc/libopensc.la
|
||||
../libopensc/libopensc.la
|
||||
|
||||
SRC = pam_pkcs15.c
|
||||
INC =
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -10,7 +12,48 @@
|
|||
|
||||
#include <security/pam_appl.h>
|
||||
#include <security/pam_modules.h>
|
||||
#ifdef HAVE_SECURITY__PAM_MACROS_H
|
||||
#include <security/_pam_macros.h>
|
||||
#else
|
||||
#define x_strdup(s) ((s) ? strdup(s):NULL)
|
||||
#define _pam_overwrite(x) \
|
||||
do { \
|
||||
register char *__xx__; \
|
||||
if ((__xx__=(x))) \
|
||||
while (*__xx__) \
|
||||
*__xx__++ = '\0'; \
|
||||
} while (0)
|
||||
#define _pam_drop(X) \
|
||||
do { \
|
||||
if (X) { \
|
||||
free(X); \
|
||||
X=NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
#define _pam_drop_reply(/* struct pam_response * */ reply, /* int */ replies) \
|
||||
do { \
|
||||
int reply_i; \
|
||||
\
|
||||
for (reply_i=0; reply_i<replies; ++reply_i) { \
|
||||
if (reply[reply_i].resp) { \
|
||||
_pam_overwrite(reply[reply_i].resp); \
|
||||
free(reply[reply_i].resp); \
|
||||
} \
|
||||
} \
|
||||
if (reply) \
|
||||
free(reply); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PAM_EXTERN
|
||||
#define PAM_EXTERN
|
||||
#endif
|
||||
|
||||
#ifdef PAM_SUN_CODEBASE
|
||||
#define PAM_CONST
|
||||
#else
|
||||
#define PAM_CONST const
|
||||
#endif
|
||||
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
@ -35,7 +78,6 @@ static const char *auth_cert_file = "authorized_certificates";
|
|||
|
||||
static int pamdebug = 1;
|
||||
|
||||
|
||||
static int format_eid_dir_path(const char *user, char **buf)
|
||||
{
|
||||
struct passwd *pwent = getpwnam(user);
|
||||
|
@ -152,11 +194,11 @@ static int get_password(pam_handle_t * pamh, char **password, const char *pinnam
|
|||
sprintf(buf, "Enter PIN [%s]: ", tmp);
|
||||
|
||||
DBG(printf("failed; Trying to get CONV object...\n"));
|
||||
r = pam_get_item(pamh, PAM_CONV, (const void **) &conv);
|
||||
r = pam_get_item(pamh, PAM_CONV, (PAM_CONST void **) &conv);
|
||||
if (r != PAM_SUCCESS)
|
||||
return r;
|
||||
DBG(printf("Conversing...\n"));
|
||||
r = conv->conv(1, pin_msg, &resp, conv->appdata_ptr);
|
||||
r = conv->conv(1, (PAM_CONST struct pam_message **) pin_msg, &resp, conv->appdata_ptr);
|
||||
if (r != PAM_SUCCESS)
|
||||
return r;
|
||||
if (resp) {
|
||||
|
@ -185,11 +227,12 @@ int verify_authenticity(struct sc_pkcs15_card *p15card,
|
|||
r = get_random(random_data, sizeof(random_data));
|
||||
if (r != PAM_SUCCESS)
|
||||
return -1;
|
||||
/* DBG(printf("Encrypting...\n"));
|
||||
#if 0
|
||||
DBG(printf("Encrypting...\n"));
|
||||
r = RSA_public_encrypt(117, random_data, chg, pubkey->pkey.rsa, RSA_PKCS1_PADDING);
|
||||
if (r != 128)
|
||||
goto end;
|
||||
*/
|
||||
#endif
|
||||
chglen = RSA_size(rsa);
|
||||
if (chglen > sizeof(chg)) {
|
||||
DBG(printf("Too large RSA key. Bailing out.\n"));
|
||||
|
@ -224,7 +267,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, con
|
|||
#endif
|
||||
{
|
||||
int r, i, err = PAM_AUTH_ERR, locked = 0;
|
||||
const char *user;
|
||||
PAM_CONST char *user = NULL;
|
||||
char *password = NULL;
|
||||
X509 *cert = NULL;
|
||||
EVP_PKEY *pubkey = NULL;
|
||||
|
@ -318,7 +361,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, con
|
|||
goto end;
|
||||
}
|
||||
DBG(printf("Verifying PIN code...\n"));
|
||||
r = sc_pkcs15_verify_pin(p15card, pinfo, password, strlen(password));
|
||||
r = sc_pkcs15_verify_pin(p15card, pinfo, (const u8 *) password, strlen(password));
|
||||
memset(password, 0, strlen(password));
|
||||
if (r) {
|
||||
DBG(printf("PIN code verification failed: %s\n", sc_strerror(r)));
|
||||
|
@ -329,12 +372,13 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, con
|
|||
DBG(printf("Awright! PIN code correct!\n"));
|
||||
/* FIXME: clear password? */
|
||||
DBG(printf("Deciphering...\n"));
|
||||
/* r = sc_pkcs15_decipher(p15card, prkinfo, chg, sizeof(chg), plain_text, sizeof(plain_text));
|
||||
#if 0
|
||||
r = sc_pkcs15_decipher(p15card, prkinfo, chg, sizeof(chg), plain_text, sizeof(plain_text));
|
||||
if (r <= 0) {
|
||||
DBG(printf("Decipher failed: %s\n", sc_strerror(r)));
|
||||
goto end;
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
if (verify_authenticity(p15card, prkinfo, pubkey->pkey.rsa) != 1)
|
||||
goto end;
|
||||
DBG(printf("You're in!\n"));
|
||||
|
|
|
@ -4,10 +4,10 @@ SUBDIRS = . pkcs11
|
|||
|
||||
libdir = ${prefix}/lib/pkcs11
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/libopensc
|
||||
INCLUDES = -I../libopensc
|
||||
|
||||
LDFLAGS = @LDFLAGS@ @LIBDL@ \
|
||||
$(top_srcdir)/src/libopensc/libopensc.la
|
||||
../libopensc/libopensc.la
|
||||
|
||||
SRC = function_table.c generic.c session.c object.c \
|
||||
endecrypt.c digestsign.c verify.c misc.c slot.c
|
||||
|
|
|
@ -239,7 +239,7 @@ CK_RV C_SetPIN(CK_SESSION_HANDLE hSession,
|
|||
card = slot[ses->slot].p15card;
|
||||
|
||||
LOG("Master PIN code update starts.\n");
|
||||
rc = sc_pkcs15_change_pin(card, &card->pin_info[0], (char *) pOldPin, ulOldLen, (char *) pNewPin, ulNewLen);
|
||||
rc = sc_pkcs15_change_pin(card, &card->pin_info[0], pOldPin, ulOldLen, pNewPin, ulNewLen);
|
||||
switch (rc) {
|
||||
case 0:
|
||||
LOG("Master PIN code CHANGED succesfully.\n");
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
# Process this file with automake to create Makefile.in
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/libopensc
|
||||
CFLAGS = @CFLAGS@ -Werror
|
||||
INCLUDES = -I../libopensc
|
||||
LDFLAGS = @LDFLAGS@ \
|
||||
$(top_srcdir)/src/libopensc/libopensc.la
|
||||
../libopensc/libopensc.la
|
||||
|
||||
noinst_PROGRAMS = base64 hst-test lottery p15dump \
|
||||
pintest prngtest
|
||||
|
|
|
@ -6,7 +6,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
int len;
|
||||
FILE *inf;
|
||||
char buf[8192];
|
||||
u8 buf[8192];
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: base64 <file>\n");
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
@ -42,7 +41,7 @@ int test()
|
|||
fprintf(stderr, "sc_select_file failed: %s\n", sc_strerror(r));
|
||||
goto err;
|
||||
}
|
||||
r = sc_pkcs15_verify_pin(p15card, &p15card->pin_info[0], "\x31\x32\x33\x34", 4);
|
||||
r = sc_pkcs15_verify_pin(p15card, &p15card->pin_info[0], (const u8 *) "\x31\x32\x33\x34", 4);
|
||||
if (r) {
|
||||
fprintf(stderr, "PIN code verification failed: %s\n", sc_strerror(r));
|
||||
goto err;
|
||||
|
@ -135,7 +134,7 @@ int test3()
|
|||
return -1;
|
||||
len = fread(buf, 1, sizeof(buf), inf);
|
||||
|
||||
r = sc_pkcs15_verify_pin(p15card, pin, "\x31\x32\x33\x34", 4);
|
||||
r = sc_pkcs15_verify_pin(p15card, pin, (const u8 *) "\x31\x32\x33\x34", 4);
|
||||
if (r) {
|
||||
fprintf(stderr, "PIN code verification failed: %s\n", sc_strerror(r));
|
||||
return -1;
|
||||
|
|
|
@ -37,25 +37,25 @@ int ask_and_verify_pin(struct sc_pkcs15_pin_info *pin)
|
|||
{
|
||||
int i = 0;
|
||||
char prompt[80];
|
||||
char *pass;
|
||||
u8 *pass;
|
||||
|
||||
while (1) {
|
||||
sprintf(prompt, "Please enter PIN code [%s]: ", pin->com_attr.label);
|
||||
pass = getpass(prompt);
|
||||
pass = (u8 *) getpass(prompt);
|
||||
|
||||
if (strlen(pass) == 0) {
|
||||
if (strlen((char *) pass) == 0) {
|
||||
printf("Not verifying PIN code.\n");
|
||||
return -1;
|
||||
}
|
||||
if (strlen(pass) < pin->min_length)
|
||||
if (strlen((char *) pass) < pin->min_length)
|
||||
break;
|
||||
if (strlen(pass) > pin->stored_length)
|
||||
if (strlen((char *) pass) > pin->stored_length)
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
sc_lock(card);
|
||||
i = sc_pkcs15_verify_pin(p15card, pin, pass, strlen(pass));
|
||||
i = sc_pkcs15_verify_pin(p15card, pin, pass, strlen((char *) pass));
|
||||
sc_unlock(card);
|
||||
if (i) {
|
||||
if (i == SC_ERROR_PIN_CODE_INCORRECT)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# Process this file with automake to create Makefile.in
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/libopensc
|
||||
INCLUDES = -I../libopensc
|
||||
LDFLAGS = @LDFLAGS@ \
|
||||
$(top_srcdir)/src/libopensc/libopensc.la
|
||||
../libopensc/libopensc.la
|
||||
|
||||
bin_PROGRAMS = opensc-crypt opensc-tool
|
||||
|
||||
|
|
|
@ -18,9 +18,15 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
@ -120,7 +126,7 @@ char * get_pin(struct sc_pkcs15_pin_info *pinfo)
|
|||
}
|
||||
}
|
||||
|
||||
int read_input(char *buf, int buflen)
|
||||
int read_input(u8 *buf, int buflen)
|
||||
{
|
||||
FILE *inf;
|
||||
int c;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* sc-tool.c: Tool for accessing SmartCards with libsc
|
||||
* sc-tool.c: Tool for accessing SmartCards with libopensc
|
||||
*
|
||||
* Copyright (C) 2001 Juha Yrjölä <juha.yrjola@iki.fi>
|
||||
*
|
||||
|
@ -18,9 +18,15 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
@ -88,7 +94,7 @@ struct sc_context *ctx = NULL;
|
|||
struct sc_card *card = NULL;
|
||||
struct sc_pkcs15_card *p15card = NULL;
|
||||
|
||||
void print_usage_and_die()
|
||||
void print_usage_and_die(void)
|
||||
{
|
||||
int i = 0;
|
||||
printf("Usage: sc-tool [OPTIONS]\nOptions:\n");
|
||||
|
@ -119,7 +125,7 @@ void print_usage_and_die()
|
|||
exit(2);
|
||||
}
|
||||
|
||||
int list_readers()
|
||||
int list_readers(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -134,7 +140,7 @@ int list_readers()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int list_drivers()
|
||||
int list_drivers(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -149,7 +155,7 @@ int list_drivers()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int list_certificates()
|
||||
int list_certificates(void)
|
||||
{
|
||||
int r, i;
|
||||
|
||||
|
@ -196,7 +202,7 @@ int print_pem_certificate(struct sc_pkcs15_cert *cert)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int read_certificate()
|
||||
int read_certificate(void)
|
||||
{
|
||||
int r, i;
|
||||
struct sc_pkcs15_id id;
|
||||
|
@ -232,7 +238,7 @@ int read_certificate()
|
|||
return 2;
|
||||
}
|
||||
|
||||
int list_private_keys()
|
||||
int list_private_keys(void)
|
||||
{
|
||||
int r, i;
|
||||
|
||||
|
@ -251,7 +257,7 @@ int list_private_keys()
|
|||
return 0;
|
||||
}
|
||||
|
||||
char * get_pin(const char *prompt, struct sc_pkcs15_pin_info **pin_out)
|
||||
u8 * get_pin(const char *prompt, struct sc_pkcs15_pin_info **pin_out)
|
||||
{
|
||||
int r;
|
||||
char buf[80];
|
||||
|
@ -299,11 +305,11 @@ char * get_pin(const char *prompt, struct sc_pkcs15_pin_info **pin_out)
|
|||
printf("PIN code too long, try again.\n");
|
||||
continue;
|
||||
}
|
||||
return strdup(pincode);
|
||||
return (u8 *) strdup(pincode);
|
||||
}
|
||||
}
|
||||
|
||||
int list_pins()
|
||||
int list_pins(void)
|
||||
{
|
||||
int r, i;
|
||||
|
||||
|
@ -322,30 +328,29 @@ int list_pins()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int change_pin()
|
||||
int change_pin(void)
|
||||
{
|
||||
char *pincode;
|
||||
char *newpin;
|
||||
struct sc_pkcs15_pin_info *pinfo = NULL;
|
||||
u8 *pincode, *newpin;
|
||||
int r;
|
||||
|
||||
pincode = get_pin("Enter old PIN", &pinfo);
|
||||
if (pincode == NULL)
|
||||
return 2;
|
||||
if (strlen(pincode) == 0) {
|
||||
if (strlen((char *) pincode) == 0) {
|
||||
fprintf(stderr, "No PIN code supplied.\n");
|
||||
return 2;
|
||||
}
|
||||
while (1) {
|
||||
char *newpin2;
|
||||
|
||||
u8 *newpin2;
|
||||
|
||||
newpin = get_pin("Enter new PIN", &pinfo);
|
||||
if (newpin == NULL || strlen(newpin) == 0)
|
||||
if (newpin == NULL || strlen((char *) newpin) == 0)
|
||||
return 2;
|
||||
newpin2 = get_pin("Enter new PIN again", &pinfo);
|
||||
if (newpin2 == NULL || strlen(newpin2) == 0)
|
||||
if (newpin2 == NULL || strlen((char *) newpin2) == 0)
|
||||
return 2;
|
||||
if (strcmp(newpin, newpin2) == 0) {
|
||||
if (strcmp((char *) newpin, (char *) newpin2) == 0) {
|
||||
free(newpin2);
|
||||
break;
|
||||
}
|
||||
|
@ -353,8 +358,8 @@ int change_pin()
|
|||
free(newpin);
|
||||
free(newpin2);
|
||||
}
|
||||
r = sc_pkcs15_change_pin(p15card, pinfo, pincode, strlen(pincode),
|
||||
newpin, strlen(newpin));
|
||||
r = sc_pkcs15_change_pin(p15card, pinfo, pincode, strlen((char *) pincode),
|
||||
newpin, strlen((char *) newpin));
|
||||
if (r == SC_ERROR_PIN_CODE_INCORRECT) {
|
||||
fprintf(stderr, "PIN code incorrect; tries left: %d\n", pinfo->tries_left);
|
||||
return 3;
|
||||
|
@ -513,7 +518,7 @@ int enum_dir(struct sc_path path, int depth)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int list_files()
|
||||
int list_files(void)
|
||||
{
|
||||
struct sc_path path;
|
||||
int r;
|
||||
|
@ -528,7 +533,7 @@ static int generate_cert_filename(struct sc_pkcs15_card *p15card,
|
|||
char *fname, int len)
|
||||
{
|
||||
char *homedir;
|
||||
u8 cert_id[SC_PKCS15_MAX_ID_SIZE*2+1];
|
||||
char cert_id[SC_PKCS15_MAX_ID_SIZE*2+1];
|
||||
int i, r;
|
||||
|
||||
homedir = getenv("HOME");
|
||||
|
@ -549,7 +554,7 @@ static int generate_cert_filename(struct sc_pkcs15_card *p15card,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int learn_card()
|
||||
int learn_card(void)
|
||||
{
|
||||
struct stat stbuf;
|
||||
char fname[512], *home;
|
||||
|
@ -606,12 +611,12 @@ int learn_card()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int send_apdu()
|
||||
int send_apdu(void)
|
||||
{
|
||||
struct sc_apdu apdu;
|
||||
u8 buf[MAX_BUFFER_SIZE], sbuf[MAX_BUFFER_SIZE],
|
||||
rbuf[MAX_BUFFER_SIZE], *p = buf;
|
||||
int len = sizeof(buf), len0, r;
|
||||
size_t len = sizeof(buf), len0, r;
|
||||
|
||||
sc_hex_to_bin(opt_apdu, buf, &len0);
|
||||
if (len < 4) {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
@ -53,4 +55,3 @@ void hex_dump_asc(FILE *f, const u8 *in, size_t count)
|
|||
lines++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue