本文整理汇总了C++中BIO_new_mem_buf函数的典型用法代码示例。如果您正苦于以下问题:C++ BIO_new_mem_buf函数的具体用法?C++ BIO_new_mem_buf怎么用?C++ BIO_new_mem_buf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BIO_new_mem_buf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: calcDecodeLength
int utils::Base64Decode(char* b64message, size_t* length, unsigned char** buffer) { //Decodes a base64 encoded string
BIO *bio, *b64;
int decodeLen = calcDecodeLength(b64message);
*buffer = (unsigned char*)malloc(decodeLen + 1);
(*buffer)[decodeLen] = '\0';
bio = BIO_new_mem_buf(b64message, -1);
b64 = BIO_new(BIO_f_base64());
bio = BIO_push(b64, bio);
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Do not use newlines to flush buffer
*length = BIO_read(bio, *buffer, strlen(b64message));
//length should equal decodeLen, else something went horribly wrong
BIO_free_all(bio);
return (*length == decodeLen); //success
}
开发者ID:athongintel,项目名称:irm5-ec_crypto,代码行数:18,代码来源:utils.cpp
示例2: memset
char* CryptoHandler::base64decode(unsigned char *input, int length)
{
BIO *b64, *bmem;
char *buffer = (char *)malloc(length);
memset(buffer, 0, length);
b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
bmem = BIO_new_mem_buf(input, length);
bmem = BIO_push(b64, bmem);
BIO_read(bmem, buffer, length);
BIO_free_all(bmem);
return buffer;
}
开发者ID:OlegUA,项目名称:ffead-cpp,代码行数:18,代码来源:CryptoHandler.cpp
示例3: load_dh_buffer
/*
* Load hardcoded DH parameters.
*
* To prevent problems if the DH parameters files don't even
* exist, we can load DH parameters hardcoded into this file.
*/
static DH *
load_dh_buffer(const char *buffer, size_t len)
{
BIO *bio;
DH *dh = NULL;
bio = BIO_new_mem_buf((char *) buffer, len);
if (bio == NULL)
return NULL;
dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
if (dh == NULL)
ereport(DEBUG2,
(errmsg_internal("DH load buffer: %s",
SSLerrmessage())));
BIO_free(bio);
return dh;
}
开发者ID:Deepakkothandan,项目名称:postgres,代码行数:24,代码来源:be-secure.c
示例4: getkey
static EVP_PKEY *
getkey(void)
{
EVP_PKEY *key;
BIO *bio;
/* new read-only BIO backed by KEY. */
bio = BIO_new_mem_buf((char*)KEY, -1);
tt_assert(bio);
key = PEM_read_bio_PrivateKey(bio,NULL,NULL,NULL);
BIO_free(bio);
tt_assert(key);
return key;
end:
return NULL;
}
开发者ID:Cue,项目名称:Pincaster,代码行数:18,代码来源:regress_ssl.c
示例5: tls_ctx_load_extra_certs
void
tls_ctx_load_extra_certs (struct tls_root_ctx *ctx, const char *extra_certs_file,
const char *extra_certs_file_inline
)
{
BIO *in;
if (!strcmp (extra_certs_file, INLINE_FILE_TAG) && extra_certs_file_inline)
in = BIO_new_mem_buf ((char *)extra_certs_file_inline, -1);
else
in = BIO_new_file (extra_certs_file, "r");
if (in == NULL)
msg (M_SSLERR, "Cannot load extra-certs file: %s", extra_certs_file);
else
tls_ctx_add_extra_certs (ctx, in);
BIO_free (in);
}
开发者ID:kruton,项目名称:openvpn,代码行数:18,代码来源:ssl_openssl.c
示例6: SSL_CTX_use_certificate_chain_mem
int
SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len)
{
BIO *in;
int ret = 0;
in = BIO_new_mem_buf(buf, len);
if (in == NULL) {
SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_BUF_LIB);
goto end;
}
ret = ssl_ctx_use_certificate_chain_bio(ctx, in);
end:
BIO_free(in);
return (ret);
}
开发者ID:Heratom,项目名称:Firefly-project,代码行数:18,代码来源:ssl_rsa.c
示例7: defined
bool TLSEncryption::load_certificate(const char* certificate_buf)
{
if (!certificate_buf) return false;
bool result = false;
#if defined(SSL_LIB_OPENSSL)
X509 *cert = NULL;
EVP_PKEY *pkey = NULL;
BIO *bio_buffer;
//create readonly memory BIO
if (!(bio_buffer = BIO_new_mem_buf((void*)certificate_buf, -1))) return false; //certificate_buf should be null terminated;
//load PEM cert from buffer
if(PEM_read_bio_X509(bio_buffer, &cert, 0, NULL))
{
result = (SSL_CTX_use_certificate(m_ctx, cert) == SSL_SUCCESS);
X509_free(cert);
BIO_reset(bio_buffer);
}
//load PEM private key from buffer
if(result && PEM_read_bio_PrivateKey(bio_buffer, &pkey, 0, NULL))
{
result = (SSL_CTX_use_PrivateKey(m_ctx, pkey) == SSL_SUCCESS);
EVP_PKEY_free(pkey);
}
BIO_free(bio_buffer);
#elif defined(SSL_LIB_CYASSL)
uint certificate_buf_len = strlen(certificate_buf);
if (CyaSSL_CTX_use_certificate_buffer(m_ctx, (const unsigned char*)certificate_buf,
certificate_buf_len, SSL_FILETYPE_PEM) == SSL_SUCCESS) {
result = (CyaSSL_CTX_use_PrivateKey_buffer(m_ctx, (const unsigned char*)certificate_buf,
certificate_buf_len, SSL_FILETYPE_PEM) == SSL_SUCCESS);
}
#endif
return result;
}
开发者ID:goodinges,项目名称:Ciao-Chat,代码行数:44,代码来源:SidTLSEncryption.cpp
示例8: countBetaVersionSignature
QString countBetaVersionSignature(quint64 version) { // duplicated in autoupdate.cpp
QByteArray cBetaPrivateKey(BetaPrivateKey);
if (cBetaPrivateKey.isEmpty()) {
cout << "Error: Trying to count beta version signature without beta private key!\n";
return QString();
}
QByteArray signedData = (QLatin1String("TelegramBeta_") + QString::number(version, 16).toLower()).toUtf8();
static const int32 shaSize = 20, keySize = 128;
uchar sha1Buffer[shaSize];
hashSha1(signedData.constData(), signedData.size(), sha1Buffer); // count sha1
uint32 siglen = 0;
RSA *prKey = PEM_read_bio_RSAPrivateKey(BIO_new_mem_buf(const_cast<char*>(cBetaPrivateKey.constData()), -1), 0, 0, 0);
if (!prKey) {
cout << "Error: Could not read beta private key!\n";
return QString();
}
if (RSA_size(prKey) != keySize) {
cout << "Error: Bad beta private key size: " << RSA_size(prKey) << "\n";
RSA_free(prKey);
return QString();
}
QByteArray signature;
signature.resize(keySize);
if (RSA_sign(NID_sha1, (const uchar*)(sha1Buffer), shaSize, (uchar*)(signature.data()), &siglen, prKey) != 1) { // count signature
cout << "Error: Counting beta version signature failed!\n";
RSA_free(prKey);
return QString();
}
RSA_free(prKey);
if (siglen != keySize) {
cout << "Error: Bad beta version signature length: " << siglen << "\n";
return QString();
}
signature = signature.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
signature = signature.replace('-', '8').replace('_', 'B');
return QString::fromUtf8(signature.mid(19, 32));
}
开发者ID:MobinRanjbar,项目名称:tdesktop,代码行数:44,代码来源:packer.cpp
示例9: SSL_get_SSL_CTX
/**
* Call Lua user function to get the DH key.
*/
static DH *dhparam_cb(SSL *ssl, int is_export, int keylength)
{
BIO *bio;
lua_State *L;
DH *dh_tmp = NULL;
SSL_CTX *ctx = SSL_get_SSL_CTX(ssl);
p_context pctx = (p_context)SSL_CTX_get_app_data(ctx);
L = pctx->L;
/* Get the callback */
luaL_getmetatable(L, "SSL:DH:Registry");
lua_pushlightuserdata(L, (void*)ctx);
lua_gettable(L, -2);
/* Invoke the callback */
lua_pushboolean(L, is_export);
lua_pushnumber(L, keylength);
lua_call(L, 2, 1);
/* Load parameters from returned value */
if (lua_type(L, -1) != LUA_TSTRING) {
lua_pop(L, 2); /* Remove values from stack */
return NULL;
}
bio = BIO_new_mem_buf((void*)lua_tostring(L, -1),
lua_rawlen(L, -1));
if (bio) {
dh_tmp = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
BIO_free(bio);
}
/*
* OpenSSL exepcts the callback to maintain a reference to the DH*. So,
* cache it here, and clean up the previous set of parameters. Any remaining
* set is cleaned up when destroying the LuaSec context.
*/
if (pctx->dh_param)
DH_free(pctx->dh_param);
pctx->dh_param = dh_tmp;
lua_pop(L, 2); /* Remove values from stack */
return dh_tmp;
}
开发者ID:armatys,项目名称:luasec,代码行数:47,代码来源:context.c
示例10: put_key_pem
int
put_key_pem(int is_public_only, PyObject *py_key_pem,
PyObject **py_private_key_ccn, PyObject **py_public_key_ccn,
PyObject **py_public_key_digest)
{
unsigned char *key_pem;
Py_ssize_t pem_len;
RSA *key_rsa = NULL;
BIO *bio = NULL;
int r;
unsigned long err;
r = PyBytes_AsStringAndSize(py_key_pem, (char **) &key_pem, &pem_len);
JUMP_IF_NEG(r, error);
bio = BIO_new_mem_buf(key_pem, pem_len);
JUMP_IF_NULL(bio, openssl_error);
if (is_public_only)
key_rsa = PEM_read_bio_RSAPublicKey(bio, NULL, NULL, NULL);
else
key_rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL);
JUMP_IF_NULL(key_rsa, openssl_error);
r = ccn_keypair_from_rsa(is_public_only, key_rsa, py_private_key_ccn,
py_public_key_ccn);
JUMP_IF_NEG(r, error);
r = create_public_key_digest(key_rsa, py_public_key_digest, NULL);
JUMP_IF_NEG(r, error);
RSA_free(key_rsa);
return 0;
openssl_error:
err = ERR_get_error();
PyErr_Format(g_PyExc_CCNKeyError, "Unable to parse key: %s",
ERR_reason_error_string(err));
error:
RSA_free(key_rsa);
BIO_free(bio);
return -1;
}
开发者ID:Emat12,项目名称:PyCCN,代码行数:44,代码来源:key_utils.c
示例11: PKCS7_VerifySign
/*
功能:验证签名
入口:
char*certFile 证书(含匙)
char* plainText 明文
char* cipherText 签名
出口:
bool true 签名验证成功
bool false 验证失败
*/
bool PKCS7_VerifySign(char*certFile,char* plainText,char* cipherText )
{
/* Get X509 */
FILE* fp = fopen (certFile, "r");
if (fp == NULL)
return false;
X509* x509 = PEM_read_X509(fp, NULL, NULL, NULL);
fclose (fp);
if (x509 == NULL) {
ERR_print_errors_fp (stderr);
return false;
}
//BASE64解码
unsigned char *retBuf[1024*8];
int retBufLen = sizeof(retBuf);
memset(retBuf,0,sizeof(retBuf));
decodeBase64(cipherText,(void *)retBuf,&retBufLen);
//从签名中取PKCS7对象
BIO* vin = BIO_new_mem_buf(retBuf,retBufLen);
PKCS7 *p7 = d2i_PKCS7_bio(vin,NULL);
//取STACK_OF(X509)对象
STACK_OF(X509) *stack=sk_X509_new_null();//X509_STORE_new()
sk_X509_push(stack,x509);
//明码数据转为BIO
BIO *bio = BIO_new(BIO_s_mem());
BIO_puts(bio,plainText);
//验证签名
int err = PKCS7_verify(p7, stack, NULL,bio, NULL, PKCS7_NOVERIFY);
if (err != 1) {
ERR_print_errors_fp (stderr);
return false;
}
return true;
}
开发者ID:keyidadi,项目名称:asuwrt,代码行数:54,代码来源:afc.c
示例12: load_cert
static CURLcode load_cert(const char* mypem,void * sslctx) {
X509_STORE * store = NULL;
X509 * cert = NULL;
BIO * bio = NULL;
bio = BIO_new_mem_buf((void*)mypem, -1);
if (bio == NULL)
{
return CURLE_SSL_CACERT;
}
/* use it to read the PEM formatted certificate from memory into an X509
* structure that SSL can use
*/
PEM_read_bio_X509(bio, &cert, 0, NULL);
if (cert == NULL)
{
BIO_free(bio);
return CURLE_SSL_CACERT;
}
/* get a pointer to the X509 certificate store (which may be empty!) */
store = SSL_CTX_get_cert_store((SSL_CTX*)sslctx);
if (store == NULL)
{
X509_free(cert);
BIO_free(bio);
return CURLE_SSL_CACERT;
}
/* add our certificate to this store */
if (X509_STORE_add_cert(store, cert)==0)
{
X509_free(cert);
BIO_free(bio);
return CURLE_SSL_CACERT;
}
/* decrease reference counts */
X509_free(cert);
BIO_free(bio);
return CURLE_OK;
}
开发者ID:dlf412,项目名称:thunderCopyright,代码行数:44,代码来源:sslcert.cpp
示例13: BIO_new_mem_buf
static PyObject *load_key(PyObject *self, PyObject *args)
{
Py_buffer data;
BIO *bio = NULL;
RSA *rsa = NULL;
RSAObject *result = NULL;
#if PY_MAJOR_VERSION >= 3
if (!PyArg_ParseTuple(args, "y*:load_key", &data))
return NULL;
#else
if (!PyArg_ParseTuple(args, "s*:load_key", &data))
return NULL;
#endif
bio = BIO_new_mem_buf(data.buf, data.len);
if (bio == NULL)
{
PyErr_SetString(PyExc_RuntimeError, "BIO_new_mem_buf");
goto cleanup;
}
if (PEM_read_bio_RSAPublicKey(bio, &rsa, NULL, NULL) == NULL)
{
PyErr_SetString(PyExc_ValueError, "invalid PKCS1 key");
goto cleanup;
}
result = PyObject_NEW(RSAObject, &RSAType);
if (result == NULL)
goto cleanup;
result->rsa = rsa;
rsa = NULL;
cleanup:
if (rsa)
RSA_free(rsa);
if (bio)
BIO_free(bio);
PyBuffer_Release(&data);
return (PyObject *) result;
}
开发者ID:eric-wieser,项目名称:python-raven,代码行数:44,代码来源:rsa.c
示例14: BIO_new_mem_buf
LLBasicCertificate::LLBasicCertificate(const std::string& pem_cert)
{
// BIO_new_mem_buf returns a read only bio, but takes a void* which isn't const
// so we need to cast it.
BIO * pem_bio = BIO_new_mem_buf((void*)pem_cert.c_str(), pem_cert.length());
if(pem_bio == NULL)
{
LL_WARNS("SECAPI") << "Could not allocate an openssl memory BIO." << LL_ENDL;
throw LLInvalidCertificate(this);
}
mCert = NULL;
PEM_read_bio_X509(pem_bio, &mCert, 0, NULL);
BIO_free(pem_bio);
if (!mCert)
{
throw LLInvalidCertificate(this);
}
}
开发者ID:OS-Development,项目名称:VW.Zen,代码行数:19,代码来源:llsechandler_basic.cpp
示例15: ddocDecodeOCSPResponseData
//============================================================
// Decodes binary (DER) OCSP_RESPONSE data and returns a OCSP_RESPONSE object
// ppResp - pointer to a buffer to receive newly allocated OCSP_RESPONSE pointer
// data - (DER) OCSP_RESPONSE data
// len - length of data in bytes
//============================================================
EXP_OPTION int ddocDecodeOCSPResponseData(OCSP_RESPONSE **ppResp, const byte* data, int len)
{
BIO* b1 = 0;
// check input params
RETURN_IF_NULL_PARAM(data);
RETURN_IF_NULL_PARAM(ppResp);
// mark as not read yet
*ppResp = 0;
// create BIO
b1 = BIO_new_mem_buf((void*)data, len);
RETURN_IF_NOT(b1, ERR_NULL_POINTER);
// decode OCSP
*ppResp = d2i_OCSP_RESPONSE_bio(b1, NULL);
BIO_free(b1);
ddocDebug(3, "ddocDecodeOCSPResponseData", "Decoding %d bytes DER data - OCSP_RESPONSE %s", len, (*ppResp ? "OK" : "ERROR"));
RETURN_IF_NOT(*ppResp, ERR_OCSP_UNKNOWN_TYPE);
return ERR_OK;
}
开发者ID:Miguel-J,项目名称:eneboo-core,代码行数:25,代码来源:DigiDocOCSP.c
示例16: BIO_new_mem_buf
OpenSSLCertificate* OpenSSLCertificate::FromPEMString(
const std::string& pem_string, int* pem_length) {
BIO* bio = BIO_new_mem_buf(const_cast<char*>(pem_string.c_str()), -1);
if (!bio)
return NULL;
(void)BIO_set_close(bio, BIO_NOCLOSE);
BIO_set_mem_eof_return(bio, 0);
X509 *x509 = PEM_read_bio_X509(bio, NULL, NULL,
const_cast<char*>("\0"));
char *ptr;
int remaining_length = BIO_get_mem_data(bio, &ptr);
BIO_free(bio);
if (pem_length)
*pem_length = pem_string.length() - remaining_length;
if (x509)
return new OpenSSLCertificate(x509);
else
return NULL;
}
开发者ID:Abhi347,项目名称:s3eTxmpp,代码行数:19,代码来源:opensslidentity.cpp
示例17: base64_decode
char* base64_decode(char *input, int length, bool with_new_line)
{
BIO * b64 = NULL;
BIO * bmem = NULL;
char * buffer = (char *)malloc(length);
memset(buffer, 0, length);
b64 = BIO_new(BIO_f_base64());
if (!with_new_line) {
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
}
bmem = BIO_new_mem_buf(input, length);
bmem = BIO_push(b64, bmem);
BIO_read(bmem, buffer, length);
BIO_free_all(bmem);
return buffer;
}
开发者ID:longshadian,项目名称:estl,代码行数:19,代码来源:Base64.cpp
示例18: ossl_init_cert_store_from_raw
/*
* This function is used to load an X509_STORE using raw
* data from a buffer. The data is expected to be PEM
* encoded.
*
* Returns the number of certs added to the store
*/
static int ossl_init_cert_store_from_raw (X509_STORE *store,
unsigned char *raw, int size)
{
STACK_OF(X509_INFO) * sk = NULL;
X509_INFO *xi;
BIO *in;
int cert_cnt = 0;
in = BIO_new_mem_buf(raw, size);
if (in == NULL) {
EST_LOG_ERR("Unable to open the raw CA cert buffer");
return 0;
}
/* This loads from a file, a stack of x509/crl/pkey sets */
sk = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
if (sk == NULL) {
EST_LOG_ERR("Unable to read PEM encoded certs from BIO");
BIO_free(in);
return 0;
}
BIO_free(in);
/* scan over it and pull out the CRL's */
while (sk_X509_INFO_num(sk)) {
xi = sk_X509_INFO_shift(sk);
if (xi->x509 != NULL) {
EST_LOG_INFO("Adding cert to store (%s)", xi->x509->name);
X509_STORE_add_cert(store, xi->x509);
cert_cnt++;
}
if (xi->crl != NULL) {
EST_LOG_INFO("Adding CRL to store");
X509_STORE_add_crl(store, xi->crl);
}
X509_INFO_free(xi);
}
if (sk != NULL) {
sk_X509_INFO_pop_free(sk, X509_INFO_free);
}
return (cert_cnt);
}
开发者ID:DDvO,项目名称:libest,代码行数:50,代码来源:est_ossl_util.c
示例19: read_x509_from_x509_flat
X509 *
read_x509_from_x509_flat(const struct X509_flat *fx)
{
BIO *in = NULL;
X509 *x = NULL;
if (fx == NULL) {
return NULL;
}
in = BIO_new_mem_buf(fx->data, fx->len);
if (in == NULL) {
return NULL;
}
x = PEM_read_bio_X509(in, NULL, 0, NULL);
BIO_free(in);
return x;
}
开发者ID:Crashdowns,项目名称:phantom,代码行数:19,代码来源:x509_flat.c
示例20: return
RSA *zt_rsa_new(const char *key, bool is_public)
{
RSA *rsa;
BIO *bio;
if (key == NULL)
return (NULL);
rsa = NULL;
bio = NULL;
if ((bio = BIO_new_mem_buf((void *)key, -1)) == NULL)
return (NULL);
if (is_public)
rsa = PEM_read_bio_RSA_PUBKEY(bio, &rsa, NULL, NULL);
else
rsa = PEM_read_bio_RSAPrivateKey(bio, &rsa, NULL, NULL);
if (rsa == NULL)
BIO_free_all(bio);
return (rsa);
}
开发者ID:Raphy,项目名称:zappy,代码行数:19,代码来源:zt_rsa_new.c
注:本文中的BIO_new_mem_buf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论