本文整理汇总了C++中PEM_read_bio_X509函数的典型用法代码示例。如果您正苦于以下问题:C++ PEM_read_bio_X509函数的具体用法?C++ PEM_read_bio_X509怎么用?C++ PEM_read_bio_X509使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PEM_read_bio_X509函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: SSL_use_certificate_file
int SSL_use_certificate_file(SSL *ssl, const char *file, int type) {
int reason_code;
BIO *in;
int ret = 0;
X509 *x = NULL;
in = BIO_new(BIO_s_file());
if (in == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
goto end;
}
if (BIO_read_filename(in, file) <= 0) {
OPENSSL_PUT_ERROR(SSL, ERR_R_SYS_LIB);
goto end;
}
if (type == SSL_FILETYPE_ASN1) {
reason_code = ERR_R_ASN1_LIB;
x = d2i_X509_bio(in, NULL);
} else if (type == SSL_FILETYPE_PEM) {
reason_code = ERR_R_PEM_LIB;
x = PEM_read_bio_X509(in, NULL, ssl->ctx->default_passwd_callback,
ssl->ctx->default_passwd_callback_userdata);
} else {
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE);
goto end;
}
if (x == NULL) {
OPENSSL_PUT_ERROR(SSL, reason_code);
goto end;
}
ret = SSL_use_certificate(ssl, x);
end:
X509_free(x);
BIO_free(in);
return ret;
}
开发者ID:a397871706,项目名称:plug,代码行数:42,代码来源:ssl_rsa.c
示例2: us894_test18
/*
* Null trusted CA chain when initializing server
*/
static void us894_test18 (void)
{
BIO *certin, *keyin;
X509 *x;
EVP_PKEY *priv_key;
int rv;
EST_CTX *ctx;
LOG_FUNC_NM;
/*
* Read the server cert
*/
certin = BIO_new(BIO_s_file_internal());
rv = BIO_read_filename(certin, US894_SERVER_CERT);
CU_ASSERT(rv > 0);
x = PEM_read_bio_X509(certin, NULL, NULL, NULL);
CU_ASSERT(x != NULL);
BIO_free(certin);
/*
* Read the server key
*/
keyin = BIO_new(BIO_s_file_internal());
rv = BIO_read_filename(keyin, US894_SERVER_KEY);
CU_ASSERT(rv > 0);
priv_key = PEM_read_bio_PrivateKey(keyin, NULL, NULL, NULL);
CU_ASSERT(priv_key != NULL);
BIO_free(keyin);
/*
* Attempt to init EST proxy using NULL local CA chain
*/
est_init_logger(EST_LOG_LVL_INFO, NULL);
ctx = est_proxy_init(NULL, 0, NULL, 0, EST_CERT_FORMAT_PEM,
"testrealm", x, priv_key,
"estuser", "estpwd");
CU_ASSERT(ctx == NULL);
X509_free(x);
EVP_PKEY_free(priv_key);
}
开发者ID:DDvO,项目名称:libest,代码行数:45,代码来源:us894.c
示例3: ssl_ctx_use_certificate_chain_bio
/*
* Read a bio that contains our certificate in "PEM" format,
* possibly followed by a sequence of CA certificates that should be
* sent to the peer in the Certificate message.
*/
static int
ssl_ctx_use_certificate_chain_bio(SSL_CTX *ctx, BIO *in)
{
X509 *ca, *x = NULL;
unsigned long err;
int ret = 0;
if ((x = PEM_read_bio_X509_AUX(in, NULL, ctx->default_passwd_callback,
ctx->default_passwd_callback_userdata)) == NULL) {
SSLerrorx(ERR_R_PEM_LIB);
goto err;
}
if (!SSL_CTX_use_certificate(ctx, x))
goto err;
if (!ssl_cert_set0_chain(ctx->internal->cert, NULL))
goto err;
/* Process any additional CA certificates. */
while ((ca = PEM_read_bio_X509(in, NULL,
ctx->default_passwd_callback,
ctx->default_passwd_callback_userdata)) != NULL) {
if (!ssl_cert_add0_chain_cert(ctx->internal->cert, ca)) {
X509_free(ca);
goto err;
}
}
/* When the while loop ends, it's usually just EOF. */
err = ERR_peek_last_error();
if (ERR_GET_LIB(err) == ERR_LIB_PEM &&
ERR_GET_REASON(err) == PEM_R_NO_START_LINE) {
ERR_clear_error();
ret = 1;
}
err:
X509_free(x);
return (ret);
}
开发者ID:libressl-portable,项目名称:openbsd,代码行数:47,代码来源:ssl_rsa.c
示例4: SSL_use_certificate_file
int SSL_use_certificate_file(SSL *ssl, const char *file, int type)
{
int j;
BIO *in;
int ret = 0;
X509 *x = NULL;
in = BIO_new(BIO_s_file_internal());
if (in == NULL) {
SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE, ERR_R_BUF_LIB);
goto end;
}
if (BIO_read_filename(in, file) <= 0) {
SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE, ERR_R_SYS_LIB);
goto end;
}
if (type == SSL_FILETYPE_ASN1) {
j = ERR_R_ASN1_LIB;
x = d2i_X509_bio(in, NULL);
} else if (type == SSL_FILETYPE_PEM) {
j = ERR_R_PEM_LIB;
x = PEM_read_bio_X509(in, NULL, ssl->ctx->default_passwd_callback,
ssl->ctx->default_passwd_callback_userdata);
} else {
SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE, SSL_R_BAD_SSL_FILETYPE);
goto end;
}
if (x == NULL) {
SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE, j);
goto end;
}
ret = SSL_use_certificate(ssl, x);
end:
if (x != NULL)
X509_free(x);
if (in != NULL)
BIO_free(in);
return (ret);
}
开发者ID:johnjohnsp1,项目名称:opensgx,代码行数:42,代码来源:ssl_rsa.c
示例5: BIO_new_file
X509 *https_open_cert(s8 *filepath)
{
X509 *cert = NULL;
BIO *bio_cert = NULL;
bio_cert = BIO_new_file(filepath, "r");
if (!bio_cert)
{
return NULL;
}
cert = PEM_read_bio_X509(bio_cert, NULL, NULL, NULL);
if (!cert)
{
(void)BIO_reset(bio_cert);
cert = d2i_X509_bio(bio_cert, NULL);
}
BIO_free(bio_cert);
return cert;
}
开发者ID:millken,项目名称:zhuxianB30,代码行数:20,代码来源:parse_cacert.c
示例6: BIO_new_file
X509 *fileio_read_cert(const char *filename)
{
X509 *cert = NULL;
BIO *bio;
bio = BIO_new_file(filename, "r");
if (!bio)
goto out;
cert = PEM_read_bio_X509(bio, NULL, NULL, NULL);
out:
BIO_free_all(bio);
if (!cert) {
fprintf(stderr, "Can't load certificate from file '%s'\n",
filename);
ERR_print_errors_fp(stderr);
}
return cert;
}
开发者ID:inorton,项目名称:sbsigntool,代码行数:20,代码来源:fileio.c
示例7: BIO_new
static EVP_PKEY *extract_pkey_from_x509(const char *x509_str) {
X509 *x509 = NULL;
EVP_PKEY *result = NULL;
BIO *bio = BIO_new(BIO_s_mem());
BIO_write(bio, x509_str, strlen(x509_str));
x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL);
if (x509 == NULL) {
gpr_log(GPR_ERROR, "Unable to parse x509 cert.");
goto end;
}
result = X509_get_pubkey(x509);
if (result == NULL) {
gpr_log(GPR_ERROR, "Cannot find public key in X509 cert.");
}
end:
BIO_free(bio);
if (x509 != NULL) X509_free(x509);
return result;
}
开发者ID:rootusr,项目名称:grpc,代码行数:20,代码来源:jwt_verifier.c
示例8: throw
/**
* Parses X.509 PEM formatted certificate from file.
* NB! This struct must be freed using X509_free() function from OpenSSL or
* with X509_scope struct.
*
* @param path PEM formatted X.509 certificate file path.
* @return returns certificate parsed from file.
* @throws IOException throws exception if the file does not contain X.509
* PEM formatted certificate.
*/
X509* digidoc::X509Cert::loadX509(const std::string& path) throw(IOException)
{
// Initialize OpenSSL file.
BIO* file = BIO_new_file(path.c_str(), "rb"); BIO_scope fileScope(&file);
if(file == NULL)
{
THROW_IOEXCEPTION("Failed to open X.509 certificate file '%s': %s",
path.c_str(), ERR_reason_error_string(ERR_get_error()));
}
// Parse X.509 certificate from file.
X509* cert = PEM_read_bio_X509(file, NULL, NULL, NULL);
if(cert == NULL)
{
THROW_IOEXCEPTION("Failed to load X.509 certificate from file '%s': %s",
path.c_str(), ERR_reason_error_string(ERR_get_error()));
}
return cert;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:30,代码来源:X509Cert.cpp
示例9: SSL_CTX_use_certificate_file
int
SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type)
{
int j;
BIO *in;
int ret = 0;
X509 *x = NULL;
in = BIO_new(BIO_s_file_internal());
if (in == NULL) {
SSLerrorx(ERR_R_BUF_LIB);
goto end;
}
if (BIO_read_filename(in, file) <= 0) {
SSLerrorx(ERR_R_SYS_LIB);
goto end;
}
if (type == SSL_FILETYPE_ASN1) {
j = ERR_R_ASN1_LIB;
x = d2i_X509_bio(in, NULL);
} else if (type == SSL_FILETYPE_PEM) {
j = ERR_R_PEM_LIB;
x = PEM_read_bio_X509(in, NULL, ctx->default_passwd_callback,
ctx->default_passwd_callback_userdata);
} else {
SSLerrorx(SSL_R_BAD_SSL_FILETYPE);
goto end;
}
if (x == NULL) {
SSLerrorx(j);
goto end;
}
ret = SSL_CTX_use_certificate(ctx, x);
end:
X509_free(x);
BIO_free(in);
return (ret);
}
开发者ID:libressl-portable,项目名称:openbsd,代码行数:41,代码来源:ssl_rsa.c
示例10: LOGGER_FN
Handle<Certificate> Provider_System::getCertFromURI(Handle<std::string> uri, Handle<std::string> format){
LOGGER_FN();
try{
BIO *bioFile = NULL;
X509 *hcert = NULL;
LOGGER_OPENSSL(BIO_new);
bioFile = BIO_new(BIO_s_file());
LOGGER_OPENSSL(BIO_read_filename);
if (BIO_read_filename(bioFile, uri->c_str()) > 0){
LOGGER_OPENSSL(BIO_seek);
BIO_seek(bioFile, 0);
if (strcmp(format->c_str(), "PEM") == 0){
LOGGER_OPENSSL(PEM_read_bio_X509);
hcert = PEM_read_bio_X509(bioFile, NULL, NULL, NULL);
}
else if (strcmp(format->c_str(), "DER") == 0){
LOGGER_OPENSSL(d2i_X509_bio);
hcert = d2i_X509_bio(bioFile, NULL);
}
else{
THROW_EXCEPTION(0, Provider_System, NULL, "Unsupported format. Only PEM | DER");
}
}
LOGGER_OPENSSL(BIO_free);
BIO_free(bioFile);
if (!hcert){
THROW_EXCEPTION(0, Provider_System, NULL, "Unable decode cert from PEM/DER");
}
else{
return new Certificate(hcert);
}
}
catch (Handle<Exception> e){
THROW_EXCEPTION(0, Provider_System, e, "Error get certificate from URI");
}
}
开发者ID:algv,项目名称:trusted-crypto,代码行数:41,代码来源:provider_system.cpp
示例11: setCertFile
static int setCertFile(SSL_CTX *ctx, cchar *certFile)
{
X509 *cert;
BIO *bio;
char *buf;
int rc;
assert(ctx);
assert(certFile);
rc = -1;
bio = 0;
buf = 0;
cert = 0;
if (ctx == NULL) {
return rc;
}
if ((buf = mprReadPathContents(certFile, NULL)) == 0) {
mprLog("error openssl", 0, "Unable to read certificate %s", certFile);
} else if ((bio = BIO_new_mem_buf(buf, -1)) == 0) {
mprLog("error openssl", 0, "Unable to allocate memory for certificate %s", certFile);
} else if ((cert = PEM_read_bio_X509(bio, NULL, 0, NULL)) == 0) {
mprLog("error openssl", 0, "Unable to parse certificate %s", certFile);
} else if (SSL_CTX_use_certificate(ctx, cert) != 1) {
mprLog("error openssl", 0, "Unable to use certificate %s", certFile);
} else {
rc = 0;
}
if (bio) {
BIO_free(bio);
}
if (cert) {
X509_free(cert);
}
return rc;
}
开发者ID:leemit,项目名称:ejscript,代码行数:41,代码来源:mpr-openssl.c
示例12: DirCliPEMToX509
DWORD
DirCliPEMToX509(
PCSTR pszCert,
X509** ppCert
)
{
DWORD dwError = 0;
BIO *pBioMem = NULL;
X509* pCert = NULL;
pBioMem = BIO_new_mem_buf((PVOID) pszCert, -1);
if ( pBioMem == NULL)
{
dwError = ERROR_OUTOFMEMORY;
BAIL_ON_VMAFD_ERROR(dwError);
}
pCert = PEM_read_bio_X509(pBioMem, NULL, NULL, NULL);
if (pCert == NULL)
{
dwError = ERROR_OPEN_FAILED;
BAIL_ON_VMAFD_ERROR(dwError);
}
*ppCert = pCert;
cleanup:
if (pBioMem)
{
BIO_free(pBioMem);
}
return dwError;
error:
*ppCert = NULL;
goto cleanup;
}
开发者ID:Dan-McGee,项目名称:lightwave,代码行数:41,代码来源:cert.c
示例13: InitializeDefaultCredentials
static void InitializeDefaultCredentials()
{
BIO *bio = BIO_new_mem_buf (PrivateMaterials, -1);
assert (bio);
if (DefaultPrivateKey) {
// we may come here in a restart.
EVP_PKEY_free (DefaultPrivateKey);
DefaultPrivateKey = NULL;
}
PEM_read_bio_PrivateKey (bio, &DefaultPrivateKey, builtin_passwd_cb, 0);
if (DefaultCertificate) {
// we may come here in a restart.
X509_free (DefaultCertificate);
DefaultCertificate = NULL;
}
PEM_read_bio_X509 (bio, &DefaultCertificate, NULL, 0);
BIO_free (bio);
}
开发者ID:Ag565,项目名称:eventmachine,代码行数:21,代码来源:ssl.cpp
示例14: BIO_new_mem_buf
static X509 *ssl_load_cert(const char *cert_str)
{
X509 *cert = NULL;
BIO *in = NULL;
if (!cert_str) {
return NULL;
}
in = BIO_new_mem_buf((void *)cert_str, -1);
if (!in) {
return NULL;
}
cert = PEM_read_bio_X509(in, NULL, NULL, NULL);
if (in) {
BIO_free(in);
}
return cert;
}
开发者ID:Cean1024,项目名称:iotkit-embedded,代码行数:21,代码来源:HAL_TLS_openssl.c
示例15: main
int main(int argc, char **argv)
{
ERR_load_crypto_strings();
OpenSSL_add_all_algorithms();
#if !defined(OPENSSL_NO_ENGINE)
/* Load all compiled-in ENGINEs */
ENGINE_load_builtin_engines();
ENGINE_register_all_ciphers();
ENGINE_register_all_digests();
#endif
{
BIO *bio = BIO_new_mem_buf(RSA_CERTIFICATE, strlen(RSA_CERTIFICATE));
X509 *x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL);
assert(x509 != NULL || !!"failed to load certificate");
BIO_free(bio);
cert.len = i2d_X509(x509, &cert.base);
X509_free(x509);
}
{
BIO *bio = BIO_new_mem_buf(RSA_PRIVATE_KEY, strlen(RSA_PRIVATE_KEY));
EVP_PKEY *pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
assert(pkey != NULL || !"failed to load private key");
BIO_free(bio);
ptls_openssl_init_sign_certificate(&cert_signer, pkey);
EVP_PKEY_free(pkey);
}
subtest("next-packet-number", test_next_packet_number);
subtest("ranges", test_ranges);
subtest("frame", test_frame);
subtest("maxsender", test_maxsender);
subtest("ack", test_ack);
subtest("simple", test_simple);
subtest("stream-concurrency", test_stream_concurrency);
subtest("loss", test_loss);
return done_testing();
}
开发者ID:deweerdt,项目名称:quicly,代码行数:40,代码来源:test.c
示例16: X509_STORE_load_bio
/**
* Read from a BIO, adding to the x509 store.
*/
static int
X509_STORE_load_bio(X509_STORE *ca_store, BIO *in) {
int ret = 1;
X509 *ca;
int r;
int found = 0;
unsigned long err;
while ((ca = PEM_read_bio_X509(in, NULL, NULL, NULL))) {
r = X509_STORE_add_cert(ca_store, ca);
if (r == 0) {
X509_free(ca);
ret = 0;
break;
}
found++;
/**
* The x509 cert object is reference counted by OpenSSL, so the STORE
* keeps it alive after its been added.
*/
X509_free(ca);
}
/* When the while loop ends, it's usually just EOF. */
err = ERR_peek_last_error();
if (found != 0 &&
ERR_GET_LIB(err) == ERR_LIB_PEM &&
ERR_GET_REASON(err) == PEM_R_NO_START_LINE) {
ERR_clear_error();
} else {
/* some real error */
ret = 0;
}
return ret;
}
开发者ID:xming,项目名称:luvit,代码行数:43,代码来源:luv_tls.c
示例17: PEM_read_bio_X509
X509 *SSL_read_X509(char* filename, X509 **x509, pem_password_cb *cb)
{
X509 *rc;
BIO *bioS;
BIO *bioF;
/* 1. try PEM (= DER+Base64+headers) */
if ((bioS=BIO_new_file(filename, "r")) == NULL)
return NULL;
rc = PEM_read_bio_X509 (bioS, x509, cb, NULL);
BIO_free(bioS);
if (rc == NULL) {
/* 2. try DER+Base64 */
if ((bioS=BIO_new_file(filename, "r")) == NULL)
return NULL;
if ((bioF = BIO_new(BIO_f_base64())) == NULL) {
BIO_free(bioS);
return NULL;
}
bioS = BIO_push(bioF, bioS);
rc = d2i_X509_bio(bioS, NULL);
BIO_free_all(bioS);
if (rc == NULL) {
/* 3. try plain DER */
if ((bioS=BIO_new_file(filename, "r")) == NULL)
return NULL;
rc = d2i_X509_bio(bioS, NULL);
BIO_free(bioS);
}
}
if (rc != NULL && x509 != NULL) {
if (*x509 != NULL)
X509_free(*x509);
*x509 = rc;
}
return rc;
}
开发者ID:Aimbot2,项目名称:apache2,代码行数:40,代码来源:ssl_util_ssl.c
示例18: ssl_ctx_use_certificate_chain
/* Loads an in-memory PEM certificate chain into the SSL context. */
static tsi_result ssl_ctx_use_certificate_chain(
SSL_CTX* context, const unsigned char* pem_cert_chain,
size_t pem_cert_chain_size) {
tsi_result result = TSI_OK;
X509* certificate = NULL;
BIO* pem = BIO_new_mem_buf((void*)pem_cert_chain, pem_cert_chain_size);
if (pem == NULL) return TSI_OUT_OF_RESOURCES;
do {
certificate = PEM_read_bio_X509_AUX(pem, NULL, NULL, "");
if (certificate == NULL) {
result = TSI_INVALID_ARGUMENT;
break;
}
if (!SSL_CTX_use_certificate(context, certificate)) {
result = TSI_INVALID_ARGUMENT;
break;
}
while (1) {
X509* certificate_authority = PEM_read_bio_X509(pem, NULL, NULL, "");
if (certificate_authority == NULL) {
ERR_clear_error();
break; /* Done reading. */
}
if (!SSL_CTX_add_extra_chain_cert(context, certificate_authority)) {
X509_free(certificate_authority);
result = TSI_INVALID_ARGUMENT;
break;
}
/* We don't need to free certificate_authority as its ownership has been
transfered to the context. That is not the case for certificate though.
*/
}
} while (0);
if (certificate != NULL) X509_free(certificate);
BIO_free(pem);
return result;
}
开发者ID:Infixz,项目名称:grpc,代码行数:40,代码来源:ssl_transport_security.c
示例19: ssl_ctx_function
static CURLcode ssl_ctx_function(CURL *curl, void *sslctx, void *parm)
{
X509_STORE *store;
X509 *cert = nullptr;
BIO *bio;
bio = BIO_new_mem_buf(const_cast<char*>(NinjaParty::Cacerts), -1);
while((cert = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr)) != nullptr)
{
store = SSL_CTX_get_cert_store(static_cast<SSL_CTX*>(sslctx));
if(X509_STORE_add_cert(store, cert) == 0)
{
// todo: log error adding certificate
BIO_free(bio);
return CURLE_SSL_CACERT;
}
}
BIO_free(bio);
return CURLE_OK;
}
开发者ID:ThirdPartyNinjas,项目名称:NinjaParty,代码行数:22,代码来源:HttpRequestManager.cpp
示例20: calloc
embassy_t *pki_embassy_load_from_memory(char *certificate, char *privatekey, uint32_t serial)
{
BIO *bio_memory = NULL;
embassy_t *embassy;
// create an empty embassy
embassy = calloc(1, sizeof(embassy_t));
// fetch the certificate in PEM format and convert to X509
bio_memory = BIO_new_mem_buf(certificate, strlen(certificate));
embassy->certificate = PEM_read_bio_X509(bio_memory, NULL, NULL, NULL);
BIO_free(bio_memory);
// fetch the private key in PEM format and convert to EVP
bio_memory = BIO_new_mem_buf(privatekey, strlen(privatekey));
embassy->keyring = PEM_read_bio_PrivateKey(bio_memory, NULL, NULL, NULL);
BIO_free(bio_memory);
embassy->serial = serial;
return embassy;
}
开发者ID:gvsurenderreddy,项目名称:DNDS,代码行数:22,代码来源:pki.c
注:本文中的PEM_read_bio_X509函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论