本文整理汇总了C++中BIO_read_filename函数的典型用法代码示例。如果您正苦于以下问题:C++ BIO_read_filename函数的具体用法?C++ BIO_read_filename怎么用?C++ BIO_read_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BIO_read_filename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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);
}
示例3: STACK_OF
int SSLContext::setCertificateChainFile( const char * pFile )
{
BIO *bio;
X509 *x509;
STACK_OF(X509) * pExtraCerts;
unsigned long err;
int n;
if ((bio = BIO_new(BIO_s_file_internal())) == NULL)
return 0;
if (BIO_read_filename(bio, pFile) <= 0) {
BIO_free(bio);
return 0;
}
pExtraCerts=m_pCtx->extra_certs;
if ( pExtraCerts != NULL)
{
sk_X509_pop_free((STACK_OF(X509) *)pExtraCerts, X509_free);
m_pCtx->extra_certs = NULL;
}
示例4: LOGGER_FN
Handle<CertificationRequest> Provider_System::getCSRFromURI(Handle<std::string> uri, Handle<std::string> format){
LOGGER_FN();
try{
BIO *bioFile = NULL;
X509_REQ *hreq = 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_REQ);
hreq = PEM_read_bio_X509_REQ(bioFile, NULL, NULL, NULL);
}
else if (strcmp(format->c_str(), "DER") == 0){
LOGGER_OPENSSL(d2i_X509_REQ_bio);
hreq = d2i_X509_REQ_bio(bioFile, NULL);
}
else{
THROW_EXCEPTION(0, Provider_System, NULL, "Unsupported format. Only PEM | DER");
}
}
LOGGER_OPENSSL(BIO_free);
BIO_free(bioFile);
if (!hreq){
THROW_EXCEPTION(0, Provider_System, NULL, "Unable decode csr from PEM/DER");
}
else{
return new CertificationRequest(hreq);
}
}
catch (Handle<Exception> e){
THROW_EXCEPTION(0, Provider_System, e, "getCSRFromURI");
}
}
示例5: 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);
}
示例6: apr_jwk_parse_rsa_key
static apr_byte_t apr_jwk_parse_rsa_key(apr_pool_t *pool, int is_private_key,
const char *filename, apr_jwk_t **j_jwk, apr_jwt_error_t *err) {
BIO *input = NULL;
apr_jwk_key_rsa_t *key = NULL;
apr_byte_t rv = FALSE;
if ((input = BIO_new(BIO_s_file())) == NULL) {
apr_jwt_error_openssl(err, "BIO_new/BIO_s_file");
goto end;
}
if (BIO_read_filename(input, filename) <= 0) {
apr_jwt_error_openssl(err, "BIO_read_filename");
goto end;
}
if (apr_jwk_rsa_bio_to_key(pool, input, &key, is_private_key, err) == FALSE)
goto end;
/* allocate memory for the JWK */
*j_jwk = apr_pcalloc(pool, sizeof(apr_jwk_t));
apr_jwk_t *jwk = *j_jwk;
jwk->type = APR_JWK_KEY_RSA;
jwk->key.rsa = key;
/* calculate a unique key identifier (kid) by fingerprinting the key params */
// TODO: based just on sha1 hash of modulus "n" now..., could do this based on jwk->value.str
if (apr_jwk_hash_and_base64urlencode(pool, key->modulus, key->modulus_len,
&jwk->kid, err) == FALSE)
goto end;
rv = TRUE;
end:
if (input)
BIO_free(input);
return rv;
}
示例7: ERR_print_errors
static SSL_SESSION *load_sess_id(char *infile, int format)
{
SSL_SESSION *x=NULL;
BIO *in=NULL;
in=BIO_new(BIO_s_file());
if (in == NULL)
{
ERR_print_errors(bio_err);
goto end;
}
if (infile == NULL)
BIO_set_fp(in,stdin,BIO_NOCLOSE);
else
{
if (BIO_read_filename(in,infile) <= 0)
{
perror(infile);
goto end;
}
}
if (format == FORMAT_ASN1)
x=d2i_SSL_SESSION_bio(in,NULL);
else if (format == FORMAT_PEM)
x=PEM_read_bio_SSL_SESSION(in,NULL,NULL,NULL);
else {
BIO_printf(bio_err,"bad input format specified for input crl\n");
goto end;
}
if (x == NULL)
{
BIO_printf(bio_err,"unable to load SSL_SESSION\n");
ERR_print_errors(bio_err);
goto end;
}
end:
if (in != NULL) BIO_free(in);
return(x);
}
示例8: ERR_print_errors
static X509_CRL *load_crl(char *infile, int format)
{
X509_CRL *x=NULL;
BIO *in=NULL;
in=BIO_new(BIO_s_file());
if (in == NULL)
{
ERR_print_errors(bio_err);
goto end;
}
if (infile == NULL)
BIO_set_fp(in,OPENSSL_TYPE__FILE_STDIN,BIO_NOCLOSE);
else
{
if (BIO_read_filename(in,infile) <= 0)
{
TINYCLR_SSL_PERROR(infile);
goto end;
}
}
if (format == FORMAT_ASN1)
x=d2i_X509_CRL_bio(in,NULL);
else if (format == FORMAT_PEM)
x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL);
else {
BIO_printf(bio_err,"bad input format specified for input crl\n");
goto end;
}
if (x == NULL)
{
BIO_printf(bio_err,"unable to load CRL\n");
ERR_print_errors(bio_err);
goto end;
}
end:
BIO_free(in);
return(x);
}
示例9: SSL_use_RSAPrivateKey_file
int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type) {
int reason_code, ret = 0;
BIO *in;
RSA *rsa = 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;
rsa = d2i_RSAPrivateKey_bio(in, NULL);
} else if (type == SSL_FILETYPE_PEM) {
reason_code = ERR_R_PEM_LIB;
rsa =
PEM_read_bio_RSAPrivateKey(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 (rsa == NULL) {
OPENSSL_PUT_ERROR(SSL, reason_code);
goto end;
}
ret = SSL_use_RSAPrivateKey(ssl, rsa);
RSA_free(rsa);
end:
BIO_free(in);
return ret;
}
示例10: SSL_CTX_use_PrivateKey_file
int
SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
{
int j, ret = 0;
BIO *in;
EVP_PKEY *pkey = NULL;
in = BIO_new(BIO_s_file_internal());
if (in == NULL) {
SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE, ERR_R_BUF_LIB);
goto end;
}
if (BIO_read_filename(in, file) <= 0) {
SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE, ERR_R_SYS_LIB);
goto end;
}
if (type == SSL_FILETYPE_PEM) {
j = ERR_R_PEM_LIB;
pkey = PEM_read_bio_PrivateKey(in, NULL,
ctx->default_passwd_callback,
ctx->default_passwd_callback_userdata);
} else if (type == SSL_FILETYPE_ASN1) {
j = ERR_R_ASN1_LIB;
pkey = d2i_PrivateKey_bio(in, NULL);
} else {
SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,
SSL_R_BAD_SSL_FILETYPE);
goto end;
}
if (pkey == NULL) {
SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE, j);
goto end;
}
ret = SSL_CTX_use_PrivateKey(ctx, pkey);
EVP_PKEY_free(pkey);
end:
BIO_free(in);
return (ret);
}
示例11: SSL_use_RSAPrivateKey_file
int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type)
{
int j, ret = 0;
BIO *in;
RSA *rsa = NULL;
in = BIO_new(BIO_s_file_internal());
if (in == NULL) {
SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE, ERR_R_BUF_LIB);
goto end;
}
if (BIO_read_filename(in, file) <= 0) {
SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE, ERR_R_SYS_LIB);
goto end;
}
if (type == SSL_FILETYPE_ASN1) {
j = ERR_R_ASN1_LIB;
rsa = d2i_RSAPrivateKey_bio(in, NULL);
} else if (type == SSL_FILETYPE_PEM) {
j = ERR_R_PEM_LIB;
rsa = PEM_read_bio_RSAPrivateKey(in, NULL,
ssl->ctx->default_passwd_callback,
ssl->
ctx->default_passwd_callback_userdata);
} else {
SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE, SSL_R_BAD_SSL_FILETYPE);
goto end;
}
if (rsa == NULL) {
SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE, j);
goto end;
}
ret = SSL_use_RSAPrivateKey(ssl, rsa);
RSA_free(rsa);
end:
if (in != NULL)
BIO_free(in);
return (ret);
}
示例12: us894_test16
/*
* Null Server certificate when initializing server
*/
static void us894_test16 (void)
{
unsigned char *cacerts = NULL;
int cacerts_len = 0;
BIO *keyin;
EVP_PKEY *priv_key;
int rv;
EST_CTX *ctx;
LOG_FUNC_NM;
/*
* Read in the CA certificates
*/
cacerts_len = read_binary_file(US894_CACERT, &cacerts);
CU_ASSERT(cacerts_len > 0);
/*
* 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 server key
*/
est_init_logger(EST_LOG_LVL_INFO, NULL);
ctx = est_proxy_init(cacerts, cacerts_len, cacerts, cacerts_len,
EST_CERT_FORMAT_PEM,
"testrealm", NULL, priv_key,
"estuser", "estpwd");
CU_ASSERT(ctx == NULL);
EVP_PKEY_free(priv_key);
}
示例13: SSL_CTX_use_PrivateKey_file
int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type) {
int reason_code, ret = 0;
BIO *in;
EVP_PKEY *pkey = 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_PEM) {
reason_code = ERR_R_PEM_LIB;
pkey = PEM_read_bio_PrivateKey(in, NULL, ctx->default_passwd_callback,
ctx->default_passwd_callback_userdata);
} else if (type == SSL_FILETYPE_ASN1) {
reason_code = ERR_R_ASN1_LIB;
pkey = d2i_PrivateKey_bio(in, NULL);
} else {
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE);
goto end;
}
if (pkey == NULL) {
OPENSSL_PUT_ERROR(SSL, reason_code);
goto end;
}
ret = SSL_CTX_use_PrivateKey(ctx, pkey);
EVP_PKEY_free(pkey);
end:
BIO_free(in);
return ret;
}
示例14: read_requestorstuff
/*
* read requestor data
*
* for version 2 requests, the requestor and the SCEP client can be different
* and the request does not need to be a PKCS#10
*/
static int read_requestorstuff(scep_t *scep, int type, char *filename) {
BIO *bio;
NETSCAPE_SPKI *spki = NULL;
X509_REQ *req = NULL;
bio = BIO_new(BIO_s_file());
if (BIO_read_filename(bio, filename) < 0) {
BIO_printf(bio_err, "%s:%d: cannot read request file '%s'\n",
__FILE__, __LINE__, filename);
goto err;
}
switch (type) {
case 0:
scep->requestorreq = d2i_X509_REQ_bio(bio, &req);
if (scep->requestorreq == NULL) {
BIO_printf(bio_err, "%s:%d: cannot decode X509_REQ\n",
__FILE__, __LINE__);
goto err;
}
scep->requestorpubkey
= X509_REQ_get_pubkey(scep->requestorreq);
break;
case 1:
scep->requestorspki = d2i_NETSCAPE_SPKI_bio(bio, &spki);
if (scep->requestorspki == NULL) {
BIO_printf(bio_err, "%s:%d: cannot decode SPKI\n",
__FILE__, __LINE__);
goto err;
}
scep->requestorpubkey
= NETSCAPE_SPKI_get_pubkey(scep->requestorspki);
break;
default:
goto err;
}
return 0;
err:
ERR_print_errors(bio_err);
return -1;
}
示例15: us894_test17
/*
* Null Server certificate private key when initializing server
*/
static void us894_test17 (void)
{
unsigned char *cacerts = NULL;
int cacerts_len = 0;
BIO *certin;
X509 *x;
int rv;
EST_CTX *ctx;
LOG_FUNC_NM;
/*
* Read in the CA certificates
*/
cacerts_len = read_binary_file(US894_CACERT, &cacerts);
CU_ASSERT(cacerts_len > 0);
/*
* 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);
/*
* Attempt to init EST proxy using NULL private key
*/
est_init_logger(EST_LOG_LVL_INFO, NULL);
ctx = est_proxy_init(cacerts, cacerts_len, cacerts, cacerts_len,
EST_CERT_FORMAT_PEM,
"testrealm", x, NULL,
"estuser", "estpwd");
CU_ASSERT(ctx == NULL);
X509_free(x);
}