本文整理匯總了C++中BIO_new_mem_buf函數的典型用法代碼示例。如果您正苦於以下問題:C++ BIO_new_mem_buf函數的具體用法?C++ BIO_new_mem_buf怎麽用?C++ BIO_new_mem_buf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BIO_new_mem_buf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}