-/* engines/e_capi.c */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
GETCONSWIN getconswindow;
};
-static CAPI_CTX *capi_ctx_new();
+static CAPI_CTX *capi_ctx_new(void);
static void capi_ctx_free(CAPI_CTX * ctx);
static int capi_ctx_set_provname(CAPI_CTX * ctx, LPSTR pname, DWORD type,
int check);
case CAPI_CMD_STORE_NAME:
OPENSSL_free(ctx->storename);
- ctx->storename = BUF_strdup(p);
+ ctx->storename = OPENSSL_strdup(p);
CAPI_trace(ctx, "Setting store name to %s\n", p);
break;
break;
case CAPI_CMD_DEBUG_FILE:
- ctx->debug_file = BUF_strdup(p);
+ ctx->debug_file = OPENSSL_strdup(p);
CAPI_trace(ctx, "Setting debug file to %s\n", ctx->debug_file);
break;
0, /* bn_mod_exp */
0, /* init */
capi_rsa_free, /* finish */
- RSA_FLAG_SIGN_VER, /* flags */
+ 0, /* flags */
NULL, /* app_data */
capi_rsa_sign, /* rsa_sign */
0 /* rsa_verify */
/* Setup RSA_METHOD */
rsa_capi_idx = RSA_get_ex_new_index(0, NULL, NULL, NULL, 0);
- ossl_rsa_meth = RSA_PKCS1_SSLeay();
+ ossl_rsa_meth = RSA_PKCS1_OpenSSL();
capi_rsa_method.rsa_pub_enc = ossl_rsa_meth->rsa_pub_enc;
capi_rsa_method.rsa_pub_dec = ossl_rsa_meth->rsa_pub_dec;
capi_rsa_method.rsa_mod_exp = ossl_rsa_meth->rsa_mod_exp;
}
ctx = capi_ctx_new();
- if (!ctx)
+ if (ctx == NULL)
goto memerr;
ENGINE_set_ex_data(e, capi_idx, ctx);
static ENGINE *engine_capi(void)
{
ENGINE *ret = ENGINE_new();
- if (!ret)
+ if (ret == NULL)
return NULL;
if (!bind_capi(ret)) {
ENGINE_free(ret);
pubkey = OPENSSL_malloc(len);
- if (!pubkey)
+ if (pubkey == NULL)
goto memerr;
if (!CryptExportKey(key->key, 0, PUBLICKEYBLOB, 0, pubkey, &len)) {
rkey->e = BN_new();
rkey->n = BN_new();
- if (!rkey->e || !rkey->n)
+ if (rkey->e == NULL || rkey->n == NULL)
goto memerr;
if (!BN_set_word(rkey->e, rp->pubexp))
dkey->q = BN_new();
dkey->g = BN_new();
dkey->pub_key = BN_new();
- if (!dkey->p || !dkey->q || !dkey->g || !dkey->pub_key)
+ if (dkey->p == NULL || dkey->q == NULL || dkey->g == NULL
+ || dkey->pub_key == NULL)
goto memerr;
if (!lend_tobn(dkey->p, btmp, dsa_plen))
goto memerr;
dkey = NULL;
} else {
char algstr[10];
- BIO_snprintf(algstr, 10, "%lx", bh->aiKeyAlg);
+ BIO_snprintf(algstr, 10, "%ux", bh->aiKeyAlg);
CAPIerr(CAPI_F_CAPI_GET_PKEY,
CAPI_R_UNSUPPORTED_PUBLIC_KEY_ALGORITHM);
ERR_add_error_data(2, "aiKeyAlg=0x", algstr);
default:
{
char algstr[10];
- BIO_snprintf(algstr, 10, "%lx", dtype);
+ BIO_snprintf(algstr, 10, "%x", dtype);
CAPIerr(CAPI_F_CAPI_RSA_SIGN, CAPI_R_UNSUPPORTED_ALGORITHM_NID);
ERR_add_error_data(2, "NID=0x", algstr);
return -1;
unsigned char *tmpbuf;
CAPI_KEY *capi_key;
CAPI_CTX *ctx;
+ DWORD dlen;
+
+ if (flen <= 0)
+ return flen;
+
ctx = ENGINE_get_ex_data(rsa->engine, capi_idx);
CAPI_trace(ctx, "Called capi_rsa_priv_dec()\n");
tmpbuf[flen - i - 1] = from[i];
/* Finally decrypt it */
- if (!CryptDecrypt(capi_key->key, 0, TRUE, 0, tmpbuf, &flen)) {
+ dlen = flen;
+ if (!CryptDecrypt(capi_key->key, 0, TRUE, 0, tmpbuf, &dlen)) {
CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, CAPI_R_DECRYPT_ERROR);
capi_addlasterror();
OPENSSL_free(tmpbuf);
return -1;
} else
- memcpy(to, tmpbuf, flen);
+ memcpy(to, tmpbuf, (flen = (int)dlen));
OPENSSL_free(tmpbuf);
goto err;
} else {
ret = DSA_SIG_new();
- if (!ret)
+ if (ret == NULL)
goto err;
ret->r = BN_new();
ret->s = BN_new();
- if (!ret->r || !ret->s)
+ if (ret->r == NULL || ret->s == NULL)
goto err;
if (!lend_tobn(ret->r, csigbuf, 20)
|| !lend_tobn(ret->s, csigbuf + 20, 20)) {
return NULL;
}
str = OPENSSL_malloc(sz);
- if (!str) {
+ if (str == NULL) {
CAPIerr(CAPI_F_WIDE_TO_ASC, ERR_R_MALLOC_FAILURE);
return NULL;
}
break;
if (ret == 0)
break;
- BIO_printf(out, "%d. %s, type %d\n", idx, provname, ptype);
+ BIO_printf(out, "%lu. %s, type %lu\n", idx, provname, ptype);
OPENSSL_free(provname);
}
return 1;
if (buflen == 0)
buflen = 1024;
cname = OPENSSL_malloc(buflen);
- if (!cname) {
+ if (cname == NULL) {
CAPIerr(CAPI_F_CAPI_LIST_CONTAINERS, ERR_R_MALLOC_FAILURE);
goto err;
}
CAPI_trace(ctx, "Enumerate bug: using workaround\n");
goto done;
}
- BIO_printf(out, "%d. %s\n", idx, cname);
+ BIO_printf(out, "%lu. %s\n", idx, cname);
}
err:
return ret;
}
-CRYPT_KEY_PROV_INFO *capi_get_prov_info(CAPI_CTX * ctx, PCCERT_CONTEXT cert)
+static CRYPT_KEY_PROV_INFO *capi_get_prov_info(CAPI_CTX * ctx, PCCERT_CONTEXT cert)
{
DWORD len;
CRYPT_KEY_PROV_INFO *pinfo;
(cert, CERT_KEY_PROV_INFO_PROP_ID, NULL, &len))
return NULL;
pinfo = OPENSSL_malloc(len);
- if (!pinfo) {
+ if (pinfo == NULL) {
CAPIerr(CAPI_F_CAPI_GET_PROV_INFO, ERR_R_MALLOC_FAILURE);
return NULL;
}
goto err;
BIO_printf(out, " Private Key Info:\n");
- BIO_printf(out, " Provider Name: %s, Provider Type %d\n", provname,
+ BIO_printf(out, " Provider Name: %s, Provider Type %lu\n", provname,
pinfo->dwProvType);
- BIO_printf(out, " Container Name: %s, Key Type %d\n", contname,
+ BIO_printf(out, " Container Name: %s, Key Type %lu\n", contname,
pinfo->dwKeySpec);
err:
OPENSSL_free(provname);
OPENSSL_free(contname);
}
-char *capi_cert_get_fname(CAPI_CTX * ctx, PCCERT_CONTEXT cert)
+static char *capi_cert_get_fname(CAPI_CTX * ctx, PCCERT_CONTEXT cert)
{
LPWSTR wfname;
DWORD dlen;
return NULL;
}
-void capi_dump_cert(CAPI_CTX * ctx, BIO *out, PCCERT_CONTEXT cert)
+static void capi_dump_cert(CAPI_CTX * ctx, BIO *out, PCCERT_CONTEXT cert)
{
X509 *x;
- unsigned char *p;
+ const unsigned char *p;
unsigned long flags = ctx->dump_flags;
if (flags & CAPI_DMP_FNAME) {
char *fname;
X509_free(x);
}
-HCERTSTORE capi_open_store(CAPI_CTX * ctx, char *storename)
+static HCERTSTORE capi_open_store(CAPI_CTX * ctx, char *storename)
{
HCERTSTORE hstore;
/* Initialize a CAPI_CTX structure */
-static CAPI_CTX *capi_ctx_new()
+static CAPI_CTX *capi_ctx_new(void)
{
- CAPI_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
+ CAPI_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
- if (!ctx) {
+ if (ctx == NULL) {
CAPIerr(CAPI_F_CAPI_CTX_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
}
- ctx->cspname = NULL;
ctx->csptype = PROV_RSA_FULL;
ctx->dump_flags = CAPI_DMP_SUMMARY | CAPI_DMP_FNAME;
ctx->keytype = AT_KEYEXCHANGE;
- ctx->storename = NULL;
- ctx->ssl_client_store = NULL;
ctx->store_flags = CERT_STORE_OPEN_EXISTING_FLAG |
CERT_STORE_READONLY_FLAG | CERT_SYSTEM_STORE_CURRENT_USER;
ctx->lookup_method = CAPI_LU_SUBSTR;
- ctx->debug_level = 0;
- ctx->debug_file = NULL;
ctx->client_cert_select = cert_select_simple;
return ctx;
}
CryptReleaseContext(hprov, 0);
}
OPENSSL_free(ctx->cspname);
- ctx->cspname = BUF_strdup(pname);
+ ctx->cspname = OPENSSL_strdup(pname);
ctx->csptype = type;
return 1;
}
STACK_OF(X509) *certs = NULL;
X509 *x;
char *storename;
- const char *p;
+ const unsigned char *p;
int i, client_cert_idx;
HCERTSTORE hstore;
PCCERT_CONTEXT cert = NULL, excert = NULL;