本文整理匯總了C++中BIO_get_mem_data函數的典型用法代碼示例。如果您正苦於以下問題:C++ BIO_get_mem_data函數的具體用法?C++ BIO_get_mem_data怎麽用?C++ BIO_get_mem_data使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BIO_get_mem_data函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: GenerateRSAKeyPair
bool GenerateRSAKeyPair(int numBits, std::string& privKey, std::string& pubKey)
{
// TODO: add some error checking
RSA* rsa = RSA_new();
BIGNUM* bn = BN_new();
BN_GENCB cb;
BIO* bio_err = NULL;
BN_GENCB_set(&cb, genrsa_cb, bio_err);
BN_set_word(bn, RSA_F4);
RSA_generate_key_ex(rsa, numBits, bn, &cb);
BIO* privKeyBuff = BIO_new(BIO_s_mem());
BIO* pubKeyBuff = BIO_new(BIO_s_mem());
PEM_write_bio_RSAPrivateKey(privKeyBuff, rsa, 0, 0, 0, 0, 0);
PEM_write_bio_RSA_PUBKEY(pubKeyBuff, rsa); // RSA_PUBKEY includes some data that RSAPublicKey doesn't have
char* privKeyData;
char* pubKeyData;
auto privKeySize = BIO_get_mem_data(privKeyBuff, &privKeyData);
auto pubKeySize = BIO_get_mem_data(pubKeyBuff, &pubKeyData);
privKey = std::string(privKeyData, privKeySize);
pubKey = std::string(pubKeyData, pubKeySize);
BIO_free_all(privKeyBuff);
BIO_free_all(pubKeyBuff);
BN_free(bn);
RSA_free(rsa);
return true;
}
示例2: BIO_new
bool X509Certificate_OpenSSL::checkIssuer(ref <const X509Certificate> cert_) const
{
ref <const X509Certificate_OpenSSL> cert =
cert_.dynamicCast <const X509Certificate_OpenSSL>();
// Get issuer for this cert
BIO *out;
unsigned char *issuer;
out = BIO_new(BIO_s_mem());
X509_NAME_print_ex(out, X509_get_issuer_name(m_data->cert), 0, XN_FLAG_RFC2253);
int n = BIO_get_mem_data(out, &issuer);
vmime::string thisIssuerName((char*)issuer, n);
BIO_free(out);
// Get subject of issuer
unsigned char *subject;
out = BIO_new(BIO_s_mem());
X509_NAME_print_ex(out, X509_get_subject_name(cert->m_data->cert), 0, XN_FLAG_RFC2253);
n = BIO_get_mem_data(out, &subject);
vmime::string subjOfIssuer((char*)subject, n);
BIO_free(out);
return subjOfIssuer == thisIssuerName;
}
示例3: BIO_new
char *PICA_id_to_base64(const unsigned char *id, char *buf)
{
BIO *biomem, *b64;
static char localbuf[PICA_ID_SIZE * 2];
char *sourcebuf, *outputbuf = buf;
long b64len;
b64 = BIO_new(BIO_f_base64());
biomem = BIO_new(BIO_s_mem());
biomem = BIO_push(b64, biomem);
BIO_write(biomem, id, PICA_ID_SIZE);
BIO_flush(biomem);
b64len = BIO_get_mem_data(biomem, &sourcebuf);
if (outputbuf == NULL)
outputbuf = localbuf;
memcpy(outputbuf, sourcebuf, b64len);
*strchr(outputbuf, '\n') = '\0';
outputbuf[b64len] = '\0';
BIO_free_all(biomem);
return outputbuf;
}
示例4: rsautil_rsa_to_privkeyblob
BOOL rsautil_rsa_to_privkeyblob(RSA *rsa, PBYTE *blob, DWORD *cbBlob)
{
BOOL status = FALSE;
BIO *out;
EVP_PKEY *pk;
int ret;
char *ptr;
if(pk = EVP_PKEY_new())
{
if(out = BIO_new(BIO_s_mem()))
{
EVP_PKEY_set1_RSA(pk, rsa);
ret = i2b_PrivateKey_bio(out, pk);
if(ret > 0)
{
*cbBlob = BIO_get_mem_data(out, &ptr);
if(*blob = (PBYTE) LocalAlloc(LPTR, *cbBlob))
{
status = TRUE;
RtlCopyMemory(*blob, ptr, *cbBlob);
}
}
else /**/;
BIO_free(out);
}
EVP_PKEY_free(pk);
}
return status;
}
示例5: PEM_From_P12
void PEM_From_P12(PA_PluginParameters params)
{
sLONG_PTR *pResult = (sLONG_PTR *)params->fResult;
PackagePtr pParams = (PackagePtr)params->fParameters;
C_BLOB Param1;
C_BLOB Param2;
C_TEXT Param3;
C_TEXT returnValue;
Param1.fromParamAtIndex(pParams, 1);
Param3.fromParamAtIndex(pParams, 3);
BIO *bio = BIO_new_mem_buf((void *)Param1.getBytesPtr(), Param1.getBytesLength());
if(bio){
PKCS12 *p12 = d2i_PKCS12_bio(bio, NULL);
if(p12){
EVP_PKEY *key = NULL;
X509 *cert = NULL;
STACK_OF(X509) *ca = NULL;
CUTF8String pass;
Param3.copyUTF8String(&pass);
if(PKCS12_parse(p12, (const char *)pass.c_str(), &key, &cert, &ca)){
BIO *pem = BIO_new(BIO_s_mem());
if(pem){
PEM_write_bio_PrivateKey(pem, key, NULL, NULL, NULL, NULL, (void *)pass.c_str());
char *buf = NULL;
int len = BIO_get_mem_data(pem, &buf);
if(len){
Param2.setBytes((const uint8_t *)buf, len);
Param2.toParamAtIndex(pParams, 2);
CUTF8String pemStr = CUTF8String((const uint8_t *)buf, len);
returnValue.setUTF8String(&pemStr);
}
BIO_free(pem);
}
}
}
BIO_free(bio);
}
Param2.toParamAtIndex(pParams, 2);
returnValue.setReturn(pResult);
}
示例6: dump_X509_cert
u2fs_rc dump_X509_cert(const u2fs_X509_t * cert, char **output)
{
//input: openssl X509 certificate
//output: PEM-formatted char buffer
if (cert == NULL || output == NULL)
return U2FS_MEMORY_ERROR;
*output = NULL;
BIO *bio = BIO_new(BIO_s_mem());
if (bio == NULL)
return U2FS_MEMORY_ERROR;
if(!PEM_write_bio_X509(bio, (X509 *)cert)) {
BIO_free(bio);
return U2FS_CRYPTO_ERROR;
}
char *PEM_data;
int length = BIO_get_mem_data(bio, &PEM_data);
*output = malloc(length);
if (*output == NULL) {
BIO_free(bio);
return U2FS_MEMORY_ERROR;
}
memcpy(*output, PEM_data, length);
BIO_free(bio);
return U2FS_OK;
}
示例7: ASN1_STRING_to_text
/*
* Converts OpenSSL ASN1_STRING structure into text
*
* Converts ASN1_STRING into text, converting all the characters into
* current database encoding if possible. Any invalid characters are
* replaced by question marks.
*
* Parameter: str - OpenSSL ASN1_STRING structure. Memory management
* of this structure is responsibility of caller.
*
* Returns Datum, which can be directly returned from a C language SQL
* function.
*/
static Datum
ASN1_STRING_to_text(ASN1_STRING *str)
{
BIO *membuf;
size_t size;
char nullterm;
char *sp;
char *dp;
text *result;
membuf = BIO_new(BIO_s_mem());
if (membuf == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("could not create OpenSSL BIO structure")));
(void) BIO_set_close(membuf, BIO_CLOSE);
ASN1_STRING_print_ex(membuf, str,
((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
| ASN1_STRFLGS_UTF8_CONVERT));
/* ensure null termination of the BIO's content */
nullterm = '\0';
BIO_write(membuf, &nullterm, 1);
size = BIO_get_mem_data(membuf, &sp);
dp = pg_any_to_server(sp, size - 1, PG_UTF8);
result = cstring_to_text(dp);
if (dp != sp)
pfree(dp);
if (BIO_free(membuf) != 1)
elog(ERROR, "could not free OpenSSL BIO structure");
PG_RETURN_TEXT_P(result);
}
示例8: BIO_new
char *EstEID_base64Encode(const char *input, int length) {
BIO *memBio;
BIO *b64Bio;
char *b;
int len;
char *result;
LOG_LOCATION;
memBio = BIO_new(BIO_s_mem());
b64Bio = BIO_new(BIO_f_base64());
b64Bio = BIO_push(b64Bio, memBio);
BIO_write(b64Bio, input, length);
(void)BIO_flush(b64Bio);
len = BIO_get_mem_data(memBio, &b);
result = (char *)malloc(len + 1);
strncpy(result, b, len);
result[len] = 0;
BIO_free_all(b64Bio);
while (result[--len] == '\n') result[len] = 0;
return result;
}
示例9: ASN1_STRING_to_text
/*
* Converts OpenSSL ASN1_STRING structure into text
*
* Converts ASN1_STRING into text, converting all the characters into
* current database encoding if possible. Any invalid characters are
* replaced by question marks.
*
* Parameter: str - OpenSSL ASN1_STRING structure. Memory managment
* of this structure is responsibility of caller.
*
* Returns Datum, which can be directly returned from a C language SQL
* function.
*/
Datum
ASN1_STRING_to_text(ASN1_STRING *str)
{
BIO *membuf = NULL;
size_t size,
outlen;
char *sp;
char *dp;
text *result;
membuf = BIO_new(BIO_s_mem());
(void) BIO_set_close(membuf, BIO_CLOSE);
ASN1_STRING_print_ex(membuf, str,
((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
| ASN1_STRFLGS_UTF8_CONVERT));
outlen = 0;
BIO_write(membuf, &outlen, 1);
size = BIO_get_mem_data(membuf, &sp);
dp = (char *) pg_do_encoding_conversion((unsigned char *) sp,
size - 1,
PG_UTF8,
GetDatabaseEncoding());
outlen = strlen(dp);
result = palloc(VARHDRSZ + outlen);
memcpy(VARDATA(result), dp, outlen);
if (dp != sp)
pfree(dp);
BIO_free(membuf);
VARATT_SIZEP(result) = outlen + VARHDRSZ;
PG_RETURN_TEXT_P(result);
}
示例10: verify_certificate_chain
static int verify_certificate_chain(X509_STORE_CTX * x509_ctx, void * ignored) {
qeo_platform_custom_certificate_validator custom_cert_validator_cb = qeo_platform_get_custom_certificate_validator();
qeo_der_certificate certificate_chain[10];
BIO* bios[10];
int rc = 0;
/** We need access to unchecked chain of certificates
* No obvious API is found to get a hold of it. The API's available to get certificates
* expect to do the verification first and only then you can get the chain.
* As we want to do the validation ourselves, we just pull them out the struct to get
* the untrusted chain.
*/
STACK_OF(X509) *sk = x509_ctx->untrusted;
if (sk) {
//Lets check the stack.
qeo_util_retcode_t retcode = QEO_UTIL_EFAIL;
int certs = sk_X509_num(sk);
int i;
if (certs > 10) { //to many certificates;
//there is also a limit of 10 in openssl for the maximum certificate chain length. We should not hit this; Still better safe then sorry.
return 0;
}
memset(bios, 0, sizeof(BIO*) * 10);
for (i = 0; i < certs ; i++) {
int result;
X509* cert = sk_X509_value(sk, i);
//create a memory BIO
BIO *mem = BIO_new(BIO_s_mem());
if (NULL == mem) {
goto out; //failed to create BIO
}
bios[i] = mem;
//write to bio int i2d_X509_bio(BIO *bp, X509 *x);
result = i2d_X509_bio(mem, cert);
if (result < 0) {
qeo_log_e("Failed to write certificate data to mem bio %d\n", result);
goto out;
}
// add to array
certificate_chain[i].size = BIO_get_mem_data(mem, &certificate_chain[i].cert_data);
}
//call the callback
retcode = custom_cert_validator_cb(certificate_chain, certs);
if (retcode == QEO_UTIL_OK) {
rc = 1;
} else {
qeo_log_e("Custom certificate verification callback returned %d - Treating this as a verification error\n", retcode);
}
out:
//free memory
for (i = 0; i < certs ; i++) {
if (bios[i])
BIO_vfree(bios[i]); //we take the void version; not much we can do if the free fails
}
}
return rc;
}
示例11: BIO_new
/** Base64-encode data
* @param[in] data The data to be encoded
* @param[in] len The length of the data
* @return A pointer to the base64-encoded data. The data is stored in a dynamically-allocated buffer.
*/
char *cl_base64_encode(void *data, size_t len)
{
BIO *bio, *b64;
char *buf, *p;
size_t elen;
b64 = BIO_new(BIO_f_base64());
if (!(b64))
return NULL;
bio = BIO_new(BIO_s_mem());
if (!(bio)) {
BIO_free(b64);
return NULL;
}
bio = BIO_push(b64, bio);
BIO_write(bio, data, len);
BIO_flush(bio);
elen = (size_t)BIO_get_mem_data(bio, &buf);
/* Ensure we're dealing with a NULL-terminated string */
p = (char *)malloc(elen+1);
if (NULL == p) {
BIO_free(b64);
return NULL;
}
memcpy((void *)p, (void *)buf, elen);
p[elen] = 0x00;
buf = p;
BIO_free_all(bio);
return buf;
}
示例12: clone_mem_bio
static void clone_mem_bio(BIO *bio, void **buf, size_t *buflen)
{
char *internal_buf;
size_t len;
*buf=NULL;
len = BIO_get_mem_data(bio, &internal_buf);
if (!internal_buf) {
return;
}
if(buflen) {
*buflen=len;
}
*buf = malloc(len+1); /* always allocate an extra space for a null
character, but leave it to caller to
actually set it if needed */
if(!*buf) {
return;
}
memcpy(*buf, internal_buf, len);
return;
}
示例13: z_py_zorp_crl_getattr
static PyObject *
z_py_zorp_crl_getattr(PyObject *o, char *name)
{
ZorpCRL *self = (ZorpCRL *) o;
PyObject *res = NULL;
BIO *bio;
guint len;
gchar *mem;
gchar buf[512];
if (strcmp(name, "blob") == 0)
{
bio = BIO_new(BIO_s_mem());
PEM_write_bio_X509_CRL(bio, self->crl);
len = BIO_get_mem_data(bio, &mem);
res = PyString_FromStringAndSize(mem, len);
BIO_free(bio);
}
else if (strcmp(name, "issuer") == 0)
{
X509_NAME_oneline(X509_CRL_get_issuer(self->crl), buf, sizeof(buf));
res = PyString_FromString(buf);
}
else
{
PyErr_SetString(PyExc_AttributeError, "Attribute not found");
}
return res;
}
示例14: ASN1_STRING_to_text
/*
* Converts OpenSSL ASN1_STRING structure into text
*
* Converts ASN1_STRING into text, converting all the characters into
* current database encoding if possible. Any invalid characters are
* replaced by question marks.
*
* Parameter: str - OpenSSL ASN1_STRING structure. Memory management
* of this structure is responsibility of caller.
*
* Returns Datum, which can be directly returned from a C language SQL
* function.
*/
static Datum
ASN1_STRING_to_text(ASN1_STRING *str)
{
BIO *membuf;
size_t size;
char nullterm;
char *sp;
char *dp;
text *result;
membuf = BIO_new(BIO_s_mem());
(void) BIO_set_close(membuf, BIO_CLOSE);
ASN1_STRING_print_ex(membuf, str,
((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
| ASN1_STRFLGS_UTF8_CONVERT));
/* ensure null termination of the BIO's content */
nullterm = '\0';
BIO_write(membuf, &nullterm, 1);
size = BIO_get_mem_data(membuf, &sp);
dp = pg_any_to_server(sp, size - 1, PG_UTF8);
result = cstring_to_text(dp);
if (dp != sp)
pfree(dp);
BIO_free(membuf);
PG_RETURN_TEXT_P(result);
}
示例15: af_update_seg_frombio
/* Requires no locking */
int af_update_seg_frombio(AFFILE *af,const char *segname,unsigned long arg,BIO *bio)
{
/* Get the buffer to write out */
u_char *buf=0;
size_t buflen = BIO_get_mem_data(bio,&buf);
return af_update_seg(af,segname,0,buf,buflen);
}