本文整理汇总了C++中PKCS12_free函数的典型用法代码示例。如果您正苦于以下问题:C++ PKCS12_free函数的具体用法?C++ PKCS12_free怎么用?C++ PKCS12_free使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PKCS12_free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sk_X509_new_null
pki_pkcs12::pki_pkcs12(const QString fname, pem_password_cb *cb)
:pki_base(fname)
{
FILE *fp;
char pass[MAX_PASS_LENGTH];
EVP_PKEY *mykey = NULL;
X509 *mycert = NULL;
key=NULL; cert=NULL;
passcb = cb;
class_name="pki_pkcs12";
certstack = sk_X509_new_null();
pass_info p(XCA_TITLE, tr("Please enter the password to decrypt the PKCS#12 file.")
+ "\n'" + fname + "'");
fp = fopen(QString2filename(fname), "rb");
if (fp) {
PKCS12 *pkcs12 = d2i_PKCS12_fp(fp, NULL);
fclose(fp);
if (ign_openssl_error()) {
if (pkcs12)
PKCS12_free(pkcs12);
throw errorEx(tr("Unable to load the PKCS#12 (pfx) file %1.").arg(fname));
}
if (PKCS12_verify_mac(pkcs12, "", 0) || PKCS12_verify_mac(pkcs12, NULL, 0))
pass[0] = '\0';
else if (passcb(pass, MAX_PASS_LENGTH, 0, &p) < 0) {
/* cancel pressed */
PKCS12_free(pkcs12);
throw errorEx("","");
}
PKCS12_parse(pkcs12, pass, &mykey, &mycert, &certstack);
int error = ERR_peek_error();
if (ERR_GET_REASON(error) == PKCS12_R_MAC_VERIFY_FAILURE) {
ign_openssl_error();
PKCS12_free(pkcs12);
throw errorEx(getClassName(), tr("The supplied password was wrong (%1)").arg(ERR_reason_error_string(error)));
}
ign_openssl_error();
if (mycert) {
if (mycert->aux && mycert->aux->alias) {
alias = asn1ToQString(mycert->aux->alias);
alias = QString::fromUtf8(alias.toAscii());
}
cert = new pki_x509(mycert);
if (alias.isEmpty()) {
cert->autoIntName();
} else {
cert->setIntName(alias);
}
alias = cert->getIntName();
}
if (mykey) {
key = new pki_evp(mykey);
key->setIntName(alias + "_key");
key->bogusEncryptKey();
}
PKCS12_free(pkcs12);
} else
fopen_error(fname);
}
示例2: useCertFile
int
useCertFile(SSL_CTX* ctx, const char* path, const char* passphrase, const char* cacertfile)
{
FILE *p12_file;
PKCS12 *p12_cert = NULL;
EVP_PKEY *pkey;
X509 *x509_cert;
p12_file = fopen(path, "r");
if (!p12_file)
{
timestamp_f(stderr);
perror(path);
return -1;
}
d2i_PKCS12_fp(p12_file, &p12_cert);
fclose(p12_file);
if (!PKCS12_parse(p12_cert, passphrase, &pkey, &x509_cert, NULL))
{
int error = ERR_get_error();
timestamp_f(stderr);
fprintf(stderr, "failed to parse p12 file; error %d\n", error);
PKCS12_free(p12_cert);
return -1;
}
PKCS12_free(p12_cert);
if (!SSL_CTX_use_certificate(ctx, x509_cert))
{
int error = ERR_get_error();
timestamp_f(stderr);
fprintf(stderr, "failed to set cert for SSL context; error %d\n", error);
X509_free(x509_cert);
EVP_PKEY_free(pkey);
return -1;
}
X509_free(x509_cert);
if (!SSL_CTX_use_PrivateKey(ctx, pkey))
{
int error = ERR_get_error();
timestamp_f(stderr);
fprintf(stderr, "failed to set private key for SSL context; error %d\n", error);
EVP_PKEY_free(pkey);
return -1;
}
EVP_PKEY_free(pkey);
if (cacertfile && *cacertfile && !SSL_CTX_load_verify_locations(ctx, cacertfile, NULL))
{
timestamp_f(stderr);
fprintf(stderr, "failed to load root cert for verification from %s\n", cacertfile);
return -1;
}
return 0;
}
示例3: _parcPkcs12KeyStore_ParseFile
static int
_parcPkcs12KeyStore_ParseFile(PARCPkcs12KeyStore *keystore, const char *filename, const char *password)
{
parcSecurity_AssertIsInitialized();
FILE *fp = fopen(filename, "rb");
assertNotNull(fp, "Error opening %s: %s", filename, strerror(errno));
if (fp == NULL) {
return -1;
}
PKCS12 *p12Keystore = NULL;
d2i_PKCS12_fp(fp, &p12Keystore);
fclose(fp);
int success = PKCS12_parse(p12Keystore, password, &keystore->private_key, &keystore->x509_cert, NULL);
PKCS12_free(p12Keystore);
if (!success) {
unsigned long errcode;
while ((errcode = ERR_get_error()) != 0) {
fprintf(stderr, "openssl error: %s\n", ERR_error_string(errcode, NULL));
}
return -1;
}
keystore->public_key = X509_get_pubkey(keystore->x509_cert);
return 0;
}
示例4: PKCS12_init
PKCS12 *
PKCS12_init(int mode)
{
PKCS12 *pkcs12;
if (!(pkcs12 = PKCS12_new())) {
PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE);
return NULL;
}
ASN1_INTEGER_set(pkcs12->version, 3);
pkcs12->authsafes->type = OBJ_nid2obj(mode);
switch (mode) {
case NID_pkcs7_data:
if (!(pkcs12->authsafes->d.data =
ASN1_OCTET_STRING_new())) {
PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE);
goto err;
}
break;
default:
PKCS12err(PKCS12_F_PKCS12_INIT,
PKCS12_R_UNSUPPORTED_PKCS12_MODE);
goto err;
}
return pkcs12;
err:
if (pkcs12 != NULL)
PKCS12_free(pkcs12);
return NULL;
}
示例5: pkcs12_release
/**
* Releases a shared PKCS12 object. If nobody else is using the object then
* it's freed.
*/
static void pkcs12_release(SharedPKCS12 *sharedP12) {
if (--sharedP12->refCount == 0) {
// We're the last reference holder to release the P12
PKCS12_free(sharedP12->data);
free(sharedP12);
}
}
示例6: p
void pki_pkcs12::writePKCS12(const QString fname)
{
Passwd pass;
pass_info p(XCA_TITLE, tr("Please enter the password to encrypt the PKCS#12 file"));
if (cert == NULL || key == NULL) {
my_error(tr("No key or no Cert and no pkcs12"));
}
FILE *fp = fopen(QString2filename(fname), "wb");
if (fp != NULL) {
if (PwDialog::execute(&p, &pass, true) != 1) {
fclose(fp);
return;
}
PKCS12 *pkcs12 = PKCS12_create(pass.data(),
getIntName().toUtf8().data(),
key->decryptKey(),
cert->getCert(), certstack, 0, 0, 0, 0, 0);
i2d_PKCS12_fp(fp, pkcs12);
fclose (fp);
openssl_error();
PKCS12_free(pkcs12);
}
else fopen_error(fname);
}
示例7: IsPKCS12
static Bool
IsPKCS12(const char *file)
{
Bool ret = TRUE;
EVP_PKEY *key = NULL;
X509 *cert = NULL;
BIO *input;
PKCS12 *p12;
int err_reason;
if ((input = BIO_new_file(file, "r")) == NULL){
if (d2i_PKCS12_bio(input, &p12) == NULL) return FALSE;
}
p12 = d2i_PKCS12_bio(input, NULL);
BIO_free(input);
if (p12 == NULL) return FALSE;
err_reason = PKCS12_parse(p12, "", &key, &cert, NULL);
if (err_reason == PKCS12_R_MAC_VERIFY_FAILURE){
ret = FALSE;
}
if (cert){ X509_free(cert); cert = NULL; }
if (key){ EVP_PKEY_free(key); key = NULL; }
ERR_clear_error();
PKCS12_free(p12);
return ret;
}
示例8: LUA_FUNCTION
static LUA_FUNCTION(openssl_pkcs12_export)
{
X509 * cert = CHECK_OBJECT(1, X509, "openssl.x509");
EVP_PKEY *priv_key = CHECK_OBJECT(2, EVP_PKEY, "openssl.evp_pkey");
char * pass = (char*)luaL_checkstring(L, 3);
int top = lua_gettop(L);
BIO * bio_out = NULL;
PKCS12 * p12 = NULL;
const char * friendly_name = NULL;
STACK_OF(X509) *ca = NULL;
int ret = 0;
luaL_argcheck(L, openssl_pkey_is_private(priv_key), 2, "must be private key");
if (top > 3)
{
if (lua_isstring(L, 4))
friendly_name = lua_tostring(L, 4);
else if (lua_isuserdata(L, 4))
ca = CHECK_OBJECT(4, STACK_OF(X509), "openssl.stack_of_x509");
else
luaL_argerror(L, 4, "must be string as friendly_name or openssl.stack_of_x509 object as cacets");
if (top > 4)
ca = CHECK_OBJECT(5, STACK_OF(X509), "openssl.stack_of_x509");
}
if (cert && !X509_check_private_key(cert, priv_key))
{
luaL_error(L, "private key does not correspond to cert");
}
/* end parse extra config */
/*PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, STACK_OF(X509) *ca,
int nid_key, int nid_cert, int iter, int mac_iter, int keytype);*/
p12 = PKCS12_create(pass, (char*)friendly_name, priv_key, cert, ca, 0, 0, 0, 0, 0);
if (!p12)
luaL_error(L, "PKCS12_careate failed,pleases get more error info");
bio_out = BIO_new(BIO_s_mem());
if (i2d_PKCS12_bio(bio_out, p12))
{
BUF_MEM *bio_buf;
BIO_get_mem_ptr(bio_out, &bio_buf);
lua_pushlstring(L, bio_buf->data, bio_buf->length);
ret = 1;
}
BIO_free(bio_out);
PKCS12_free(p12);
return ret;
}
示例9: util_to_p12
int __fastcall util_to_p12(struct util_cert cert, char *password, char** data)
{
PKCS12 *p12;
int len;
p12 = PKCS12_create(password, "Certificate", cert.pkey, cert.x509, NULL, 0, 0, 0, 0, 0);
*data = NULL;
len = i2d_PKCS12(p12, (unsigned char**)data);
PKCS12_free(p12);
return len;
}
示例10: OpenSSL_add_all_algorithms
void SafetPKCS12Private::init( const QByteArray &data, const QByteArray &pin )
{
OpenSSL_add_all_algorithms();
qDebug("... SafetPKCS12Private::init ... 1");
BIO *bio = BIO_new_mem_buf( const_cast<char*>(data.constData()), data.size() );
if( !bio ){
return setLastError();
/*
qDebug("!bio");
qDebug(qPrintable(errorString));
SafetYAWL::streamlog << SafetLog::Error << QObject::tr("Error al inicializar objeto PKCS12: BIO no valida");
return;
*/
}
PKCS12 *p12 = d2i_PKCS12_bio( bio, NULL );
BIO_free( bio );
if( !p12 ){
return setLastError();
/*
qDebug("!p12");
qDebug(qPrintable(errorString));
SafetYAWL::streamlog << SafetLog::Debug << errorString;
SafetYAWL::streamlog << SafetLog::Error << QObject::tr("Error al inicializar objeto PKCS12: PKCS12 no valida");
return;
*/
}
X509 *c = NULL;
EVP_PKEY *k = NULL;
int ret = PKCS12_parse( p12, pin.constData(), &k, &c, NULL );
PKCS12_free( p12 );
if( !ret ){
return setLastError();
/*
setLastError();
qDebug("!ret");
qDebug(qPrintable(errorString));
SafetYAWL::streamlog << SafetLog::Error << QObject::tr("Error al inicializar objeto PKCS12: EVP_PKEY no valida");
return;
*/
}
SafetYAWL::streamlog << SafetLog::Debug << QObject::tr("Analizada correctamente la estructura PKCS12");
cert = SafetPKCS12::fromX509( c );
key = SafetPKCS12::keyFromEVP( k );
X509_free( c );
EVP_PKEY_free( k );
qDebug("... SafetPKCS12Private::init ... 2");
SafetYAWL::streamlog << SafetLog::Action << QObject::tr("Inicializado objeto SafetPKCS12 correctamente!");
}
示例11: util_from_p12
int __fastcall util_from_p12(char* data, int datalen, char* password, struct util_cert* cert)
{
int r = 0;
PKCS12 *p12 = NULL;
if (data == NULL || datalen ==0) return 0;
cert->x509 = NULL;
cert->pkey = NULL;
p12 = d2i_PKCS12(&p12, (const unsigned char**)&data, datalen);
r = PKCS12_parse(p12, password, &(cert->pkey), &(cert->x509), NULL);
PKCS12_free(p12);
return r;
}
示例12: ne_ssl_clicert_free
void ne_ssl_clicert_free(ne_ssl_client_cert *cc)
{
if (cc->p12)
PKCS12_free(cc->p12);
if (cc->decrypted) {
if (cc->cert.identity) ne_free(cc->cert.identity);
EVP_PKEY_free(cc->pkey);
X509_free(cc->cert.subject);
}
if (cc->friendly_name) ne_free(cc->friendly_name);
ne_free(cc);
}
示例13: sign_with_rsa_sha256
int sign_with_rsa_sha256(const char *input, const char *private_key, unsigned char *buffer_out, int *buffer_out_len) {
FILE *fp;
EVP_PKEY *pkey = 0;
EVP_MD_CTX *ctx = 0;
const EVP_MD *sha256_md = 0;
unsigned int s = 0;
PKCS12 *p12 = 0;
X509 *cert = 0;
OpenSSL_add_all_ciphers();
OpenSSL_add_all_digests();
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
ctx = EVP_MD_CTX_create();
EVP_MD_CTX_init(ctx);
sha256_md = EVP_sha256();
EVP_SignInit(ctx, sha256_md);
EVP_SignUpdate(ctx, input, strlen(input));
ERR_load_crypto_strings();
if (!(fp = fopen(private_key, "rb"))) {
perror("Error opening file with private key");
return -1;
}
p12 = d2i_PKCS12_fp(fp, NULL);
fclose (fp);
if (!p12) {
perror("Error reading PKCS#12 file");
return -1;
}
if (!PKCS12_parse(p12, "notasecret", &pkey, &cert, NULL)) {
perror("Error parsing PKCS#12 file");
return -1;
}
s = EVP_PKEY_size(pkey);
EVP_SignFinal(ctx, buffer_out, &s, pkey);
*buffer_out_len = s;
PKCS12_free(p12);
EVP_MD_CTX_destroy(ctx);
X509_free(cert);
EVP_cleanup();
return 0;
}
示例14: PKCS12_free
Pkcs12::~Pkcs12()
{
if(this->privKey != NULL)
{
delete this->privKey;
}
if(this->cert != NULL)
{
delete this->cert;
}
for(unsigned int i = 0 ; i < this->ca.size() ; i++)
{
delete ca.at(i);
}
PKCS12_free(this->pkcs12);
}
示例15: d2i_PKCS12
/**
* Parses a P12 file and returns a parsed representation of the file, with
* a reference count so it can be shared by multiple tokens.
*/
static SharedPKCS12 *pkcs12_parse(const char *p12Data, int p12Length) {
const unsigned char *temp = (const unsigned char*)p12Data;
PKCS12 *data;
// Parse P12 data
data = d2i_PKCS12(NULL, &temp, p12Length);
if (!data) return NULL;
// Create a reference counted object
SharedPKCS12 *sharedP12 = malloc(sizeof(SharedPKCS12));
if (!sharedP12) {
PKCS12_free(data);
return NULL;
}
sharedP12->refCount = 1;
sharedP12->data = data;
return sharedP12;
}