• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ASN1_OBJECT_free函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ASN1_OBJECT_free函数的典型用法代码示例。如果您正苦于以下问题:C++ ASN1_OBJECT_free函数的具体用法?C++ ASN1_OBJECT_free怎么用?C++ ASN1_OBJECT_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ASN1_OBJECT_free函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: cms_enveloped_data_init

static CMS_EnvelopedData *
cms_enveloped_data_init(CMS_ContentInfo *cms)
{
	if (cms->d.other == NULL) {
		cms->d.envelopedData = M_ASN1_new_of(CMS_EnvelopedData);
		if (!cms->d.envelopedData) {
			CMSerr(CMS_F_CMS_ENVELOPED_DATA_INIT,
			    ERR_R_MALLOC_FAILURE);
			return NULL;
		}
		cms->d.envelopedData->version = 0;
		cms->d.envelopedData->encryptedContentInfo->contentType =
		    OBJ_nid2obj(NID_pkcs7_data);
		ASN1_OBJECT_free(cms->contentType);
		cms->contentType = OBJ_nid2obj(NID_pkcs7_enveloped);
		return cms->d.envelopedData;
	}
	return cms_get0_enveloped(cms);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:19,代码来源:cms_env.c


示例2: X509_add1_trust_object

int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
{
    X509_CERT_AUX *aux;
    ASN1_OBJECT *objtmp = NULL;
    if (obj) {
        objtmp = OBJ_dup(obj);
        if (!objtmp)
            return 0;
    }
    if ((aux = aux_get(x)) == NULL)
        goto err;
    if (aux->trust == NULL
        && (aux->trust = sk_ASN1_OBJECT_new_null()) == NULL)
        goto err;
    if (!objtmp || sk_ASN1_OBJECT_push(aux->trust, objtmp))
        return 1;
 err:
    ASN1_OBJECT_free(objtmp);
    return 0;
}
开发者ID:Beatzevo,项目名称:openssl,代码行数:20,代码来源:x_x509a.c


示例3: gost94_param_decode

static int gost94_param_decode(EVP_PKEY *pkey, const unsigned char **pder,
                               int derlen)
{
    ASN1_OBJECT *obj = NULL;
    DSA *dsa = EVP_PKEY_get0(pkey);
    int nid;
    if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) {
        return 0;
    }
    nid = OBJ_obj2nid(obj);
    ASN1_OBJECT_free(obj);
    if (!dsa) {
        dsa = DSA_new();
        if (!EVP_PKEY_assign(pkey, NID_id_GostR3410_94, dsa))
            return 0;
    }
    if (!fill_GOST94_params(dsa, nid))
        return 0;
    return 1;
}
开发者ID:Adallom,项目名称:openssl,代码行数:20,代码来源:gost_ameth.c


示例4: gost2001_param_decode

static int gost2001_param_decode(EVP_PKEY *pkey, const unsigned char **pder,
                                 int derlen)
{
    ASN1_OBJECT *obj = NULL;
    int nid;
    EC_KEY *ec = EVP_PKEY_get0(pkey);
    if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) {
        return 0;
    }
    nid = OBJ_obj2nid(obj);
    ASN1_OBJECT_free(obj);
    if (!ec) {
        ec = EC_KEY_new();
        if (!EVP_PKEY_assign(pkey, NID_id_GostR3410_2001, ec))
            return 0;
    }
    if (!fill_GOST2001_params(ec, nid))
        return 0;
    return 1;
}
开发者ID:Adallom,项目名称:openssl,代码行数:20,代码来源:gost_ameth.c


示例5: M_ASN1_new_of

static CMS_SignedData *cms_signed_data_init(CMS_ContentInfo *cms)
	{
	if (cms->d.other == NULL)
		{
		cms->d.signedData = M_ASN1_new_of(CMS_SignedData);
		if (!cms->d.signedData)
			{
			CMSerr(CMS_F_CMS_SIGNED_DATA_INIT, ERR_R_MALLOC_FAILURE);
			return NULL;
			}
		cms->d.signedData->version = 1;
		cms->d.signedData->encapContentInfo->eContentType =
						OBJ_nid2obj(NID_pkcs7_data);
		cms->d.signedData->encapContentInfo->partial = 1;
		ASN1_OBJECT_free(cms->contentType);
		cms->contentType = OBJ_nid2obj(NID_pkcs7_signed);
		return cms->d.signedData;
		}
	return cms_get0_signed(cms);
	}
开发者ID:LucidOne,项目名称:Rovio,代码行数:20,代码来源:cms_sd.c


示例6: X509V3err

/* Create a generic extension: for now just handle DER type */
static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
	     int crit, int type)
	{
	unsigned char *ext_der=NULL;
	long ext_len;
	ASN1_OBJECT *obj=NULL;
	ASN1_OCTET_STRING *oct=NULL;
	X509_EXTENSION *extension=NULL;
	if (!(obj = OBJ_txt2obj(ext, 0)))
		{
		X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_NAME_ERROR);
		ERR_add_error_data(2, "name=", ext);
		goto err;
		}

	if (!(ext_der = string_to_hex(value, &ext_len)))
		{
		X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR);
		ERR_add_error_data(2, "value=", value);
		goto err;
		}

	if (!(oct = M_ASN1_OCTET_STRING_new()))
		{
		X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE);
		goto err;
		}

	oct->data = ext_der;
	oct->length = ext_len;
	ext_der = NULL;

	extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);

	err:
	ASN1_OBJECT_free(obj);
	M_ASN1_OCTET_STRING_free(oct);
	if(ext_der) OPENSSL_free(ext_der);
	return extension;

	}
开发者ID:xyzy,项目名称:mips-openssl_0.9.7,代码行数:42,代码来源:v3_conf.c


示例7: memcpy

ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
	     long len)
	{
	ASN1_OBJECT *ret=NULL;
	unsigned char *p;
	int i;

	/* only the ASN1_OBJECTs from the 'table' will have values
	 * for ->sn or ->ln */
	if ((a == NULL) || ((*a) == NULL) ||
		!((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC))
		{
		if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
		}
	else	ret=(*a);

	p= *pp;
	if ((ret->data == NULL) || (ret->length < len))
		{
		if (ret->data != NULL) OPENSSL_free(ret->data);
		ret->data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1);
		ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
		if (ret->data == NULL)
			{ i=ERR_R_MALLOC_FAILURE; goto err; }
		}
	memcpy(ret->data,p,(int)len);
	ret->length=(int)len;
	ret->sn=NULL;
	ret->ln=NULL;
	/* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
	p+=len;

	if (a != NULL) (*a)=ret;
	*pp=p;
	return(ret);
err:
	ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
	if ((ret != NULL) && ((a == NULL) || (*a != ret)))
		ASN1_OBJECT_free(ret);
	return(NULL);
	}
开发者ID:ahenroid,项目名称:ptptl-0.2,代码行数:41,代码来源:a_object.c


示例8: X509_add1_reject_object

int
X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
{
	X509_CERT_AUX *aux;
	ASN1_OBJECT *objtmp;
	int rc;

	if (!(objtmp = OBJ_dup(obj)))
		return 0;
	if (!(aux = aux_get(x)))
		goto err;
	if (!aux->reject && !(aux->reject = sk_ASN1_OBJECT_new_null()))
		goto err;
	rc = sk_ASN1_OBJECT_push(aux->reject, objtmp);
	if (rc != 0)
		return rc;

err:
	ASN1_OBJECT_free(objtmp);
	return 0;
}
开发者ID:2trill2spill,项目名称:nextgen,代码行数:21,代码来源:x_x509a.c


示例9: openssl_ts_req_policy_id

static int openssl_ts_req_policy_id(lua_State*L)
{
  TS_REQ* req = CHECK_OBJECT(1, TS_REQ, "openssl.ts_req");
  if (lua_isnone(L, 2))
  {
    ASN1_OBJECT* obj = TS_REQ_get_policy_id(req);
    openssl_push_asn1object(L, obj);
    ASN1_OBJECT_free(obj);
    return 1;
  }
  else
  {
    int nid = openssl_get_nid(L, 2);
    ASN1_OBJECT* obj;
    int ret;
    luaL_argcheck(L, nid != NID_undef, 2, "must be asn1_object object identified");
    obj = OBJ_nid2obj(nid);
    ret = TS_REQ_set_policy_id(req, obj);
    return openssl_pushresult(L, ret);
  }
}
开发者ID:Shaddy1884,项目名称:lua-openssl,代码行数:21,代码来源:ots.c


示例10: crypto_cert_get_public_key

CRYPTO_PUBLIC_KEY *
crypto_cert_get_public_key(CRYPTO_CERT * cert, uint32 * key_len)
{
#ifdef CRYPTO_OPENSSL
	
	int nid;
	CRYPTO_PUBLIC_KEY *lkey;
	EVP_PKEY *epk = NULL;

	/* For some reason, Microsoft sets the OID of the Public RSA key to
	   the oid for "MD5 with RSA Encryption" instead of "RSA Encryption"

	   Kudos to Richard Levitte for the following (intuitive)
	   lines of code that resets the OID and lets us extract the key. */
	
	nid = OBJ_obj2nid(cert->cert_info->key->algor->algorithm);
	
	if ((nid == NID_md5WithRSAEncryption) || (nid == NID_shaWithRSAEncryption))
	{
		ASN1_OBJECT_free(cert->cert_info->key->algor->algorithm);
		cert->cert_info->key->algor->algorithm = OBJ_nid2obj(NID_rsaEncryption);
	}
	
	epk = X509_get_pubkey(cert);
	
	if (NULL == epk)
		return NULL;

	lkey = RSAPublicKey_dup((RSA *) epk->pkey.ptr);
	*key_len = RSA_size(lkey);
	EVP_PKEY_free(epk);
	
	return lkey;

#else /* built-in crypto */

	return ssl_cert_get_public_key(cert, key_len);
	
#endif
}
开发者ID:ystk,项目名称:debian-freerdp,代码行数:40,代码来源:crypto.c


示例11: eckey_pub_encode

static int eckey_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) {
  EC_KEY *ec_key = pkey->pkey.ec;
  void *pval = NULL;
  int ptype;
  uint8_t *penc = NULL, *p;
  int penclen;

  if (!eckey_param2type(&ptype, &pval, ec_key)) {
    OPENSSL_PUT_ERROR(EVP, ERR_R_EC_LIB);
    return 0;
  }
  penclen = i2o_ECPublicKey(ec_key, NULL);
  if (penclen <= 0) {
    goto err;
  }
  penc = OPENSSL_malloc(penclen);
  if (!penc) {
    goto err;
  }
  p = penc;
  penclen = i2o_ECPublicKey(ec_key, &p);
  if (penclen <= 0) {
    goto err;
  }
  if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_EC), ptype, pval, penc,
                             penclen)) {
    return 1;
  }

err:
  if (ptype == V_ASN1_OBJECT) {
    ASN1_OBJECT_free(pval);
  } else {
    ASN1_STRING_free(pval);
  }
  if (penc) {
    OPENSSL_free(penc);
  }
  return 0;
}
开发者ID:bheesham,项目名称:boringssl,代码行数:40,代码来源:p_ec_asn1.c


示例12: has_voms_extension

int
has_voms_extension(const char *certfilepath)
{
    ASN1_OBJECT *acseq_oid = NULL;
    X509 *cert = NULL;
    int position = -1;
    int result = -1;

    assert (certfilepath != NULL);

    acseq_oid = OBJ_txt2obj(ACSEQ_OID, 1);
    if (acseq_oid == NULL) {
        return result;
    }

    cert = load_X509_from_file(certfilepath);
    if (cert == NULL) {
        goto error;
    }

    position = X509_get_ext_by_OBJ(cert, acseq_oid, -1);
    if (position >= 0) {
        result = 1;
    } else {
        result = 0;
    }

    if (cert != NULL) {
        X509_free(cert);
    }

  error:

    if (acseq_oid != NULL) {
        ASN1_OBJECT_free(acseq_oid);
    }

    return result;
}
开发者ID:eunsungc,项目名称:gt6-RAMSES_8_5,代码行数:39,代码来源:voms_utils.c


示例13: get_extension

static PyObject *
get_extension (certificate_x509 *self, PyObject *args, PyObject *keywords)
{
	const char *oid = NULL;
	const char *name = NULL;

	static char *keywordlist[] = { "oid", "name", NULL };

	if (!PyArg_ParseTupleAndKeywords (args, keywords, "|ss", keywordlist,
					  &oid, &name)) {
		return NULL;
	}

	char *value = NULL;
	size_t length;
	ASN1_OBJECT *obj = NULL;
	if (name != NULL) {
		obj = get_object_by_name (name);
	} else {
		obj = get_object_by_oid (oid);
	}

	if (obj == NULL) {
		Py_INCREF (Py_None);
		return Py_None;
	}

	length = get_extension_by_object (self->x509, obj, &value);
	ASN1_OBJECT_free (obj);
	if (value != NULL) {
		PyObject *extension = PyString_FromStringAndSize (value,
								  length);
		free (value);
		return extension;
	} else {
		Py_INCREF (Py_None);
		return Py_None;
	}
}
开发者ID:jlsherrill,项目名称:python-rhsm,代码行数:39,代码来源:certificate.c


示例14: X509_ALGOR_set0

int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
{
    if (!alg)
        return 0;
    if (ptype != V_ASN1_UNDEF) {
        if (alg->parameter == NULL)
            alg->parameter = ASN1_TYPE_new();
        if (alg->parameter == NULL)
            return 0;
    }
    if (alg) {
        ASN1_OBJECT_free(alg->algorithm);
        alg->algorithm = aobj;
    }
    if (ptype == 0)
        return 1;
    if (ptype == V_ASN1_UNDEF) {
        ASN1_TYPE_free(alg->parameter);
        alg->parameter = NULL;
    } else
        ASN1_TYPE_set(alg->parameter, ptype, pval);
    return 1;
}
开发者ID:1234-,项目名称:openssl,代码行数:23,代码来源:x_algor.c


示例15: TS_CONF_set_def_policy

int TS_CONF_set_def_policy(CONF *conf, const char *section,
                           const char *policy, TS_RESP_CTX *ctx)
{
    int ret = 0;
    ASN1_OBJECT *policy_obj = NULL;
    if (!policy)
        policy = NCONF_get_string(conf, section, ENV_DEFAULT_POLICY);
    if (!policy) {
        ts_CONF_lookup_fail(section, ENV_DEFAULT_POLICY);
        goto err;
    }
    if ((policy_obj = OBJ_txt2obj(policy, 0)) == NULL) {
        ts_CONF_invalid(section, ENV_DEFAULT_POLICY);
        goto err;
    }
    if (!TS_RESP_CTX_set_def_policy(ctx, policy_obj))
        goto err;

    ret = 1;
 err:
    ASN1_OBJECT_free(policy_obj);
    return ret;
}
开发者ID:1234-,项目名称:openssl,代码行数:23,代码来源:ts_conf.c


示例16: conv_eckey2gkey

int
conv_eckey2gkey(EC_KEY *key, TANG_KEY_USE use, TANG_KEY *gkey, BN_CTX *ctx)
{
    const EC_GROUP *grp = EC_KEY_get0_group(key);
    int r;

    if (!grp)
        return EINVAL;

    ASN1_OBJECT_free(gkey->grp);
    gkey->grp = OBJ_nid2obj(EC_GROUP_get_curve_name(grp));
    if (!gkey->grp)
        return ENOMEM;

    r = conv_point2os(grp, EC_KEY_get0_public_key(key), gkey->key, ctx);
    if (r != 0)
        return ENOMEM;

    if (ASN1_ENUMERATED_set(gkey->use, use) <= 0)
        return ENOMEM;

    return 0;
}
开发者ID:tiran,项目名称:tang,代码行数:23,代码来源:conv.c


示例17: _ext_key_usage_ext

// retrieve the extended key usage for the cert
LLSD _ext_key_usage_ext(X509* cert)
{
	LLSD result;
	EXTENDED_KEY_USAGE *eku = (EXTENDED_KEY_USAGE *)X509_get_ext_d2i(cert, NID_ext_key_usage, NULL, NULL);
	if(eku)
	{
		result = LLSD::emptyArray();
		while(sk_ASN1_OBJECT_num(eku))
		{
			ASN1_OBJECT *usage = sk_ASN1_OBJECT_pop(eku);
			if(usage)
			{
				int nid = OBJ_obj2nid(usage);
				if (nid)
				{
					std::string sn = OBJ_nid2sn(nid);
					result.append(sn);
				}
				ASN1_OBJECT_free(usage);
			}
		}
	}
	return result;
}
开发者ID:OS-Development,项目名称:VW.Zen,代码行数:25,代码来源:llsechandler_basic.cpp


示例18: TS_REQ_free

static TS_REQ *create_query(BIO *data_bio, char *digest, const EVP_MD *md,
                            const char *policy, int no_nonce, int cert)
{
    int ret = 0;
    TS_REQ *ts_req = NULL;
    int len;
    TS_MSG_IMPRINT *msg_imprint = NULL;
    X509_ALGOR *algo = NULL;
    unsigned char *data = NULL;
    ASN1_OBJECT *policy_obj = NULL;
    ASN1_INTEGER *nonce_asn1 = NULL;

    if (md == NULL && (md = EVP_get_digestbyname("sha1")) == NULL)
        goto err;
    if ((ts_req = TS_REQ_new()) == NULL)
        goto err;
    if (!TS_REQ_set_version(ts_req, 1))
        goto err;
    if ((msg_imprint = TS_MSG_IMPRINT_new()) == NULL)
        goto err;
    if ((algo = X509_ALGOR_new()) == NULL)
        goto err;
    if ((algo->algorithm = OBJ_nid2obj(EVP_MD_type(md))) == NULL)
        goto err;
    if ((algo->parameter = ASN1_TYPE_new()) == NULL)
        goto err;
    algo->parameter->type = V_ASN1_NULL;
    if (!TS_MSG_IMPRINT_set_algo(msg_imprint, algo))
        goto err;
    if ((len = create_digest(data_bio, digest, md, &data)) == 0)
        goto err;
    if (!TS_MSG_IMPRINT_set_msg(msg_imprint, data, len))
        goto err;
    if (!TS_REQ_set_msg_imprint(ts_req, msg_imprint))
        goto err;
    if (policy && (policy_obj = txt2obj(policy)) == NULL)
        goto err;
    if (policy_obj && !TS_REQ_set_policy_id(ts_req, policy_obj))
        goto err;

    /* Setting nonce if requested. */
    if (!no_nonce && (nonce_asn1 = create_nonce(NONCE_LENGTH)) == NULL)
        goto err;
    if (nonce_asn1 && !TS_REQ_set_nonce(ts_req, nonce_asn1))
        goto err;
    if (!TS_REQ_set_cert_req(ts_req, cert))
        goto err;

    ret = 1;
 err:
    if (!ret) {
        TS_REQ_free(ts_req);
        ts_req = NULL;
        BIO_printf(bio_err, "could not create query\n");
        ERR_print_errors(bio_err);
    }
    TS_MSG_IMPRINT_free(msg_imprint);
    X509_ALGOR_free(algo);
    OPENSSL_free(data);
    ASN1_OBJECT_free(policy_obj);
    ASN1_INTEGER_free(nonce_asn1);
    return ts_req;
}
开发者ID:Beatzevo,项目名称:openssl,代码行数:63,代码来源:ts.c


示例19: asn1_parse2


//.........这里部分代码省略.........
                        nl = 1;
                    }
                }
                ASN1_OCTET_STRING_free(os);
                os = NULL;
            } else if (tag == V_ASN1_INTEGER) {
                ASN1_INTEGER *bs;
                int i;

                opp = op;
                bs = d2i_ASN1_INTEGER(NULL, &opp, len + hl);
                if (bs != NULL) {
                    if (BIO_write(bp, ":", 1) <= 0)
                        goto end;
                    if (bs->type == V_ASN1_NEG_INTEGER)
                        if (BIO_write(bp, "-", 1) <= 0)
                            goto end;
                    for (i = 0; i < bs->length; i++) {
                        if (BIO_printf(bp, "%02X", bs->data[i]) <= 0)
                            goto end;
                    }
                    if (bs->length == 0) {
                        if (BIO_write(bp, "00", 2) <= 0)
                            goto end;
                    }
                } else {
                    if (BIO_puts(bp, ":BAD INTEGER") <= 0)
                        goto end;
                    dump_cont = 1;
                }
                ASN1_INTEGER_free(bs);
            } else if (tag == V_ASN1_ENUMERATED) {
                ASN1_ENUMERATED *bs;
                int i;

                opp = op;
                bs = d2i_ASN1_ENUMERATED(NULL, &opp, len + hl);
                if (bs != NULL) {
                    if (BIO_write(bp, ":", 1) <= 0)
                        goto end;
                    if (bs->type == V_ASN1_NEG_ENUMERATED)
                        if (BIO_write(bp, "-", 1) <= 0)
                            goto end;
                    for (i = 0; i < bs->length; i++) {
                        if (BIO_printf(bp, "%02X", bs->data[i]) <= 0)
                            goto end;
                    }
                    if (bs->length == 0) {
                        if (BIO_write(bp, "00", 2) <= 0)
                            goto end;
                    }
                } else {
                    if (BIO_puts(bp, ":BAD ENUMERATED") <= 0)
                        goto end;
                    dump_cont = 1;
                }
                ASN1_ENUMERATED_free(bs);
            } else if (len > 0 && dump) {
                if (!nl) {
                    if (BIO_write(bp, "\n", 1) <= 0)
                        goto end;
                }
                if (BIO_dump_indent(bp, (const char *)p,
                                    ((dump == -1 || dump > len) ? len : dump),
                                    dump_indent) <= 0)
                    goto end;
                nl = 1;
            }
            if (dump_cont) {
                int i;
                const unsigned char *tmp = op + hl;
                if (BIO_puts(bp, ":[") <= 0)
                    goto end;
                for (i = 0; i < len; i++) {
                    if (BIO_printf(bp, "%02X", tmp[i]) <= 0)
                        goto end;
                }
                if (BIO_puts(bp, "]") <= 0)
                    goto end;
            }

            if (!nl) {
                if (BIO_write(bp, "\n", 1) <= 0)
                    goto end;
            }
            p += len;
            if ((tag == V_ASN1_EOC) && (xclass == 0)) {
                ret = 2;        /* End of sequence */
                goto end;
            }
        }
        length -= len;
    }
    ret = 1;
 end:
    ASN1_OBJECT_free(o);
    ASN1_OCTET_STRING_free(os);
    *pp = p;
    return (ret);
}
开发者ID:2007750219,项目名称:openssl,代码行数:101,代码来源:asn1_par.c


示例20: saveKeys

static TokenError saveKeys(const CertReq *reqs, const char *hostname,
                           const char *password, FILE *file) {
    TokenError error = TokenError_Unknown;
    PKCS12 *p12 = NULL;
    
    // Add PKCS7 safes with the keys
    STACK_OF(PKCS7) *authsafes = NULL;
    uint32_t localKeyId = 0;
    size_t error_count = 0;
    while (reqs) {
        STACK_OF(PKCS12_SAFEBAG) *bags = NULL;
        X509 *cert = NULL;
        ASN1_OBJECT *objOwningHost = NULL;
        uint32_t keyid = htonl(localKeyId++);
        bool success = false;
        
        // Add private key
        PKCS12_SAFEBAG *bag = PKCS12_add_key(&bags, reqs->privkey,
            opensslKeyUsages[reqs->pkcs10->keyUsage], ENC_ITER, ENC_NID, (char*)password);
        if (!bag) goto loop_end;
        
        // Add name and localKeyId to the key bag
        // TODO extract name from subject DN
        char *name = "names are not implemented yet";
        if (!X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName, MBSTRING_UTF8,
                                     (unsigned char*)name, strlen(name)) ||
            !PKCS12_add_localkeyid(bag, (unsigned char*)&keyid, sizeof(keyid)))
            goto loop_end;
        
        // Add a certificate so we can find the key by the subject name
        cert = X509_REQ_to_X509(reqs->x509, 3650, reqs->privkey);
        if (!cert ||
            !X509_keyid_set1(cert, (unsigned char*)&keyid, sizeof(keyid)))
            goto loop_end;
        
        if (!X509_add_ext(cert, makeKeyUsageExt(reqs->pkcs10->keyUsage), -1))
            goto loop_end;
        
        if (!PKCS12_add_cert(&bags, cert))
            goto loop_end;
        
        // Add hostname (FriBID extension) so we can do same-origin checks
        // TODO maybe we should use document.domain instead of document.location.hostname?
        objOwningHost = OBJ_txt2obj(OID_OWNING_HOST, 1);
        if (!objOwningHost) goto loop_end;
        
        bag = sk_PKCS12_SAFEBAG_value(bags, sk_PKCS12_SAFEBAG_num(bags)-1);
        if (!X509at_add1_attr_by_OBJ(&bag->attrib, objOwningHost, MBSTRING_UTF8,
                                     (unsigned char*)hostname, strlen(hostname)))
            goto loop_end;
        
        
        // Add a new authsafe
        if (!PKCS12_add_safe(&authsafes, bags, -1, 0, NULL))
            goto loop_end;
        
        
        // Success!
        success = true;
        
      loop_end:
        if (!success) {
            error_count--;
            certutil_updateErrorString();
        }
        ASN1_OBJECT_free(objOwningHost);
        X509_free(cert);
        sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
        reqs = reqs->next;
    }
    
    if (error_count != 0)
        goto end;
    
    // Create the PKCS12 wrapper
    p12 = PKCS12_add_safes(authsafes, 0);
    if (!p12) {
        certutil_updateErrorString();
        goto end;
    }
    PKCS12_set_mac(p12, (char*)password, -1, NULL, 0, MAC_ITER, NULL);
    
    // Save file
    if (i2d_PKCS12_fp(file, p12)) {
        error = TokenError_Success;
    }
    
  end:
    sk_PKCS7_pop_free(authsafes, PKCS7_free);
    PKCS12_free(p12);
    return error;
}
开发者ID:xranby,项目名称:fribid,代码行数:92,代码来源:pkcs12.c



注:本文中的ASN1_OBJECT_free函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ASN1_OCTET_STRING_free函数代码示例发布时间:2022-05-30
下一篇:
C++ ASN1_MALLOC_ENCODE函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap