本文整理汇总了C++中PEM_read_bio_X509_AUX函数的典型用法代码示例。如果您正苦于以下问题:C++ PEM_read_bio_X509_AUX函数的具体用法?C++ PEM_read_bio_X509_AUX怎么用?C++ PEM_read_bio_X509_AUX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PEM_read_bio_X509_AUX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BIO_new
X509* VSslServer::loadCrt(VError& error, QString fileName)
{
BIO* bio = BIO_new(BIO_s_file());
if (bio == NULL)
{
QString msg = "BIO_s_file return NULL";
LOG_ERROR("%s", qPrintable(msg));
error = VSslError(msg, VSslError::IN_BIO_S_FILE);
BIO_free(bio);
return NULL;
}
long res = BIO_read_filename(bio, qPrintable(fileName));
if (res <= 0)
{
QString msg = QString("BIO_read_filename(%1) %2").arg(fileName).arg(res);
LOG_ERROR("%s", qPrintable(msg));
error = VSslError(msg, VSslError::IN_BIO_READ_FILENAME);
BIO_free(bio);
return NULL;
}
X509* crt = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL);
if (crt == NULL)
{
QString msg = "PEM_read_bio_X509_AUX return NULL";
LOG_ERROR("%s", qPrintable(msg));
error = VSslError(msg, VSslError::IN_PEM_READ_BIO_X509_AUX);
BIO_free(bio);
return NULL;
}
BIO_free(bio);
return crt;
}
示例2: verify
static int verify(char *file,void *in,int ilen,void *sig,int slen)
{
int r=FILEFAIL;
BIO *cert;
X509 *x509;
EVP_PKEY *key;
EVP_MD_CTX *mdc;
if(!(cert=BIO_new(BIO_s_file())))goto err1;
if(BIO_read_filename(cert,file)<=0)goto err2;
r=CRYPTOFAIL;
if(!(x509=PEM_read_bio_X509_AUX(cert,NULL,NULL,NULL)))goto err2;
if(!(key=X509_get_pubkey(x509)))goto err3;
if(!(mdc=EVP_MD_CTX_create()))goto err4;
if(EVP_DigestInit_ex(mdc,EVP_sha256(),NULL)!=1)goto err5;
if(EVP_DigestVerifyInit(mdc,NULL,EVP_sha256(),NULL,key)!=1)goto err5;
if(EVP_DigestVerifyUpdate(mdc,in,ilen)!=1)goto err5;
if(EVP_DigestVerifyFinal(mdc,sig,slen)!=1)goto err5;
r=OK;
err5: EVP_MD_CTX_destroy(mdc);
err4: EVP_PKEY_free(key);
err3: X509_free(x509);
err2: BIO_free(cert);
err1: return r;
}
示例3: GetX509Certificate
/**
* Retrieves an X509 certificate from the specified file.
*
* @param pemfile The filename.
* @returns An X509 certificate.
*/
shared_ptr<X509> GetX509Certificate(const String& pemfile)
{
X509 *cert;
BIO *fpcert = BIO_new(BIO_s_file());
if (fpcert == NULL) {
BOOST_THROW_EXCEPTION(openssl_error()
<< boost::errinfo_api_function("BIO_new")
<< errinfo_openssl_error(ERR_get_error()));
}
if (BIO_read_filename(fpcert, pemfile.CStr()) < 0) {
BOOST_THROW_EXCEPTION(openssl_error()
<< boost::errinfo_api_function("BIO_read_filename")
<< errinfo_openssl_error(ERR_get_error())
<< boost::errinfo_file_name(pemfile));
}
cert = PEM_read_bio_X509_AUX(fpcert, NULL, NULL, NULL);
if (cert == NULL) {
BOOST_THROW_EXCEPTION(openssl_error()
<< boost::errinfo_api_function("PEM_read_bio_X509_AUX")
<< errinfo_openssl_error(ERR_get_error())
<< boost::errinfo_file_name(pemfile));
}
BIO_free(fpcert);
return shared_ptr<X509>(cert, X509_free);
}
示例4: reload_pem_cert
static int reload_pem_cert(struct openconnect_info *vpninfo)
{
BIO *b = BIO_new(BIO_s_file_internal());
char buf[200];
if (!b)
return -ENOMEM;
if (BIO_read_filename(b, vpninfo->cert) <= 0) {
err:
BIO_free(b);
vpn_progress(vpninfo, PRG_ERR,
_("Failed to reload X509 cert for expiry check\n"));
openconnect_report_ssl_errors(vpninfo);
return -EIO;
}
vpninfo->cert_x509 = PEM_read_bio_X509_AUX(b, NULL, NULL, NULL);
BIO_free(b);
if (!vpninfo->cert_x509)
goto err;
X509_NAME_oneline(X509_get_subject_name(vpninfo->cert_x509), buf, sizeof(buf));
vpn_progress(vpninfo, PRG_INFO,
_("Using client certificate '%s'\n"), buf);
return 0;
}
示例5: BIO_new
Certificate *Certificate::fromPEM(const char *pem)
{
X509 *x = NULL;
Certificate *c = NULL;
int ret = 0;
BIO *bp = BIO_new(BIO_s_mem());
if (!bp)
return NULL;
ret = BIO_puts(bp, pem);
if (!ret)
goto done;
x = PEM_read_bio_X509_AUX(bp, NULL, 0, NULL);
if (x) {
c = new Certificate(x);
}
done:
BIO_free(bp);
return c;
}
示例6: SSL_CTX_use_certificate_chain_mem
int
SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *data, int data_len)
{
pem_password_cb *psw_fn = ctx->default_passwd_callback;
void *psw_arg = ctx->default_passwd_callback_userdata;
X509 *cert;
BIO *bio = NULL;
int ok;
ERR_clear_error();
/* Read from memory */
bio = BIO_new_mem_buf(data, data_len);
if (!bio) {
SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_BUF_LIB);
goto failed;
}
/* Load primary cert */
cert = PEM_read_bio_X509_AUX(bio, NULL, psw_fn, psw_arg);
if (!cert) {
SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_PEM_LIB);
goto failed;
}
/* Increments refcount */
ok = SSL_CTX_use_certificate(ctx, cert);
X509_free(cert);
if (!ok || ERR_peek_error())
goto failed;
/* Load extra certs */
ok = SSL_CTX_clear_extra_chain_certs(ctx);
while (ok) {
cert = PEM_read_bio_X509(bio, NULL, psw_fn, psw_arg);
if (!cert) {
/* Is it EOF? */
unsigned long err = ERR_peek_last_error();
if (ERR_GET_LIB(err) != ERR_LIB_PEM)
break;
if (ERR_GET_REASON(err) != PEM_R_NO_START_LINE)
break;
/* On EOF do successful exit */
BIO_free(bio);
ERR_clear_error();
return 1;
}
/* Does not increment refcount */
ok = SSL_CTX_add_extra_chain_cert(ctx, cert);
if (!ok)
X509_free(cert);
}
failed:
if (bio)
BIO_free(bio);
return 0;
}
示例7: apr_jwk_rsa_bio_to_key
/*
* convert the RSA public key in the X.509 certificate in the BIO pointed to
* by "input" to a JSON Web Key object
*/
static apr_byte_t apr_jwk_rsa_bio_to_key(apr_pool_t *pool, BIO *input,
apr_jwk_key_rsa_t **jwk_key_rsa, int is_private_key) {
X509 *x509 = NULL;
EVP_PKEY *pkey = NULL;
apr_byte_t rv = FALSE;
if (is_private_key) {
/* get the private key struct from the BIO */
if ((pkey = PEM_read_bio_PrivateKey(input, NULL, NULL, NULL)) == NULL)
goto end;
} else {
/* read the X.509 struct */
if ((x509 = PEM_read_bio_X509_AUX(input, NULL, NULL, NULL)) == NULL)
goto end;
/* get the public key struct from the X.509 struct */
if ((pkey = X509_get_pubkey(x509)) == NULL)
goto end;
}
/* allocate space */
*jwk_key_rsa = apr_pcalloc(pool, sizeof(apr_jwk_key_rsa_t));
apr_jwk_key_rsa_t *key = *jwk_key_rsa;
/* get the RSA key from the public key struct */
RSA *rsa = EVP_PKEY_get1_RSA(pkey);
if (rsa == NULL)
goto end;
/* convert the modulus bignum in to a key/len */
key->modulus_len = BN_num_bytes(rsa->n);
key->modulus = apr_pcalloc(pool, key->modulus_len);
BN_bn2bin(rsa->n, key->modulus);
/* convert the exponent bignum in to a key/len */
key->exponent_len = BN_num_bytes(rsa->e);
key->exponent = apr_pcalloc(pool, key->exponent_len);
BN_bn2bin(rsa->e, key->exponent);
/* convert the private exponent bignum in to a key/len */
if (rsa->d != NULL) {
key->private_exponent_len = BN_num_bytes(rsa->d);
key->private_exponent = apr_pcalloc(pool, key->private_exponent_len);
BN_bn2bin(rsa->d, key->private_exponent);
}
rv = TRUE;
end:
if (pkey)
EVP_PKEY_free(pkey);
if (x509)
X509_free(x509);
return rv;
}
示例8: BIO_new_file
static X509 *load_cert(const char *pPath)
{
X509 *pCert;
BIO *bio = BIO_new_file(pPath, "r");
if (bio == NULL)
return NULL;
pCert = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL);
BIO_free(bio);
return pCert;
}
示例9: main
int main(int argc, char **argv)
{
X509 *x509 = NULL;
BIO *bio = NULL;
has_t *crt = NULL;
char *json = NULL;
size_t l;
openssl_init();
if ((bio = BIO_new(BIO_s_file())) == NULL) {
return -1;
}
if(argc < 2) {
BIO_set_fp(bio, stdin, BIO_NOCLOSE);
} else {
BIO_read_filename(bio, argv[1]);
}
/* Format DER */
if((x509 = d2i_X509_bio(bio, NULL)) == NULL) {
ERR_clear_error();
BIO_reset(bio);
/* Format PEM */
x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL);
}
if(!x509) {
fprintf(stderr, "Error loading certificate\n");
return -1;
}
if((crt = has_x509_new(x509)) == NULL) {
fprintf(stderr, "Error converting certificate\n");
return -1;
}
if(has_json_serialize(crt, &json, &l, HAS_JSON_SERIALIZE_PRETTY) == 0) {
printf("%s\n", json);
free(json);
} else {
fprintf(stderr, "Error serializing certificate\n");
return -1;
}
has_free(crt);
X509_free(x509);
BIO_free(bio);
openssl_cleanup();
return 0;
}
示例10: PEM_read_bio_X509_AUX
X509 *TS_CONF_load_cert(const char *file)
{
BIO *cert = NULL;
X509 *x = NULL;
if ((cert = BIO_new_file(file, "r")) == NULL) goto end;
x = PEM_read_bio_X509_AUX(cert, NULL, NULL, NULL);
end:
if (x == NULL)
TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "unable to load certificate: %s\n", file);
BIO_free(cert);
return x;
}
示例11: PEM_read_bio_X509_AUX
X509 *TS_CONF_load_cert(const char *file)
{
BIO *cert = NULL;
X509 *x = NULL;
if ((cert = BIO_new_file(file, "r")) == NULL)
goto end;
x = PEM_read_bio_X509_AUX(cert, NULL, NULL, NULL);
end:
if (x == NULL)
TSerr(TS_F_TS_CONF_LOAD_CERT, TS_R_CANNOT_LOAD_CERT);
BIO_free(cert);
return x;
}
示例12: load_pem_key
bool load_pem_key(const char *p_data, uint32_t p_length, RSA_KEYTYPE p_type, const char *p_passphrase, EVP_PKEY *&r_key)
{
bool t_success = true;
BIO *t_data = NULL;
EVP_PKEY *t_key = NULL;
t_data = BIO_new_mem_buf((void*)p_data, p_length);
t_success = t_data != NULL;
char t_empty_pass[] = "";
char *t_passphrase = (p_passphrase != NULL) ? (char*)p_passphrase : t_empty_pass;
if (t_success)
{
switch (p_type)
{
case RSAKEY_PUBKEY:
t_key = PEM_read_bio_PUBKEY(t_data, NULL, NULL, t_passphrase);
t_success = (t_key != NULL);
break;
case RSAKEY_PRIVKEY:
t_key = PEM_read_bio_PrivateKey(t_data, NULL, NULL, t_passphrase);
t_success = (t_key != NULL);
break;
case RSAKEY_CERT:
{
X509* t_cert = NULL;
t_cert = PEM_read_bio_X509_AUX(t_data, NULL, NULL, t_passphrase);
t_success = (t_cert != NULL);
if (t_success)
{
t_key = X509_get_pubkey(t_cert);
t_success = (t_key != NULL);
X509_free(t_cert);
}
}
break;
default:
// error: unknown key type
t_success = false;
}
}
if (t_data != NULL)
BIO_free(t_data);
if (t_success)
r_key = t_key;
return t_success;
}
示例13: return
static X509 *st_tls_load_cert(const char *file)
{
X509 *x=NULL;
BIO *cert;
if ((cert=BIO_new(BIO_s_file())) == NULL)
goto end;
if (BIO_read_filename(cert,file) <= 0)
goto end;
x=PEM_read_bio_X509_AUX(cert,NULL, NULL, NULL);
end:
if (cert != NULL) BIO_free(cert);
return(x);
}
示例14: BIO_new
// load certificate from file to a OpenSSL object
X509 *load_cert(char *filename)
{
BIO* f;
X509 *ret;
f = BIO_new(BIO_s_file());
BIO_read_filename(f, filename);
ret = PEM_read_bio_X509_AUX(f, NULL, 0, NULL);
if (ret == NULL)
fprintf(stderr, "Unable to load file %s as X509 certificate\n", filename);
BIO_free_all(f);
return ret;
}
示例15: BIO_new_mem_buf
// Adds a buffer containing one or more PEM-encoded
// root certificates to the X509PEMVerifier.
//
// If the certificate (or one of the certificates) could not be
// parsed AddPEM will return immediately, resulting in all of the
// certificates up to the bad certicate being added to the verifier.
bool X509PEMVerifier::AddPEM(const ByteArray &buf) {
BIO *mem = BIO_new_mem_buf(static_cast<void *>(const_cast<char *>(buf.ConstData())), buf.Length());
(void) BIO_set_close(mem, BIO_NOCLOSE);
int ncerts = 0;
while (1) {
X509 *x = PEM_read_bio_X509_AUX(mem, nullptr, nullptr, nullptr);
if (x == nullptr) {
return false;
}
X509_STORE_add_cert(store_, x);
X509_free(x);
ncerts++;
}
return true;
}