• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PEM_write_bio_X509函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PEM_write_bio_X509函数的典型用法代码示例。如果您正苦于以下问题:C++ PEM_write_bio_X509函数的具体用法?C++ PEM_write_bio_X509怎么用?C++ PEM_write_bio_X509使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PEM_write_bio_X509函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: flatten_X509

struct X509_flat *
flatten_X509(X509 *x)
{
	struct X509_flat *out = NULL;
	int ret;
	BUF_MEM *bptr = NULL;
	BIO *mem = NULL;

	if (x == NULL) {
		return NULL;
	}

	mem = BIO_new(BIO_s_mem());
	if (mem == NULL) {
		return NULL;
	}
	ret = PEM_write_bio_X509(mem, x);
	if (ret == 0) {
		BIO_free(mem);
		return NULL;
	}
	out = new_X509_flat();
	if (out == NULL)  {
		BIO_free(mem);
		return NULL;
	}
	BIO_get_mem_ptr(mem, &bptr);
	assert(BIO_set_close(mem, BIO_NOCLOSE) == 1);
	BIO_free(mem);
	out->len = bptr->length;
	if (bptr->length != 0
	    && (size_t) bptr->length <= SIZE_MAX/sizeof(*(out->data))) {
		out->data = malloc(bptr->length*sizeof(*(out->data)));
	}
	if (out->data == NULL) {
		BUF_MEM_free(bptr);
		return NULL;
	}
	memcpy(out->data, bptr->data, bptr->length);
	BUF_MEM_free(bptr);

	return out;
}
开发者ID:Crashdowns,项目名称:phantom,代码行数:43,代码来源:x509_flat.c


示例2: print_certificate

static void print_certificate(BIO *out, cert_format_e format, X509 *cert)
{
	if (out == NULL)
		return;
	switch (format) {
		default:
		case CERT_FORMAT_TEXT:
			X509_print(out, cert);
			break;
		case CERT_FORMAT_PEM:
			PEM_write_bio_X509(out, cert);
			break;
		case CERT_FORMAT_DER:
			EXIT_ERROR("DER format is not yet supported for output");
			break;
	}
}
开发者ID:Jonnyliu,项目名称:pev,代码行数:17,代码来源:pesec.c


示例3: capi_dump_cert

void capi_dump_cert(CAPI_CTX *ctx, BIO *out, PCCERT_CONTEXT cert)
	{
	X509 *x;
	unsigned char *p;
	unsigned long flags = ctx->dump_flags;
	if (flags & CAPI_DMP_FNAME)
		{
		char *fname;
		fname = capi_cert_get_fname(ctx, cert);
		if (fname)
			{
			BIO_printf(out, "  Friendly Name \"%s\"\n", fname);
			OPENSSL_free(fname);
			}
		else
			BIO_printf(out, "  <No Friendly Name>\n");
		}

	p = cert->pbCertEncoded;
	x = d2i_X509(NULL, &p, cert->cbCertEncoded);
	if (!x)
		BIO_printf(out, "  <Can't parse certificate>\n");
	if (flags & CAPI_DMP_SUMMARY)
		{
		BIO_printf(out, "  Subject: ");
		X509_NAME_print_ex(out, X509_get_subject_name(x), 0, XN_FLAG_ONELINE);
		BIO_printf(out, "\n  Issuer: ");
		X509_NAME_print_ex(out, X509_get_issuer_name(x), 0, XN_FLAG_ONELINE);
		BIO_printf(out, "\n");
		}
	if (flags & CAPI_DMP_FULL)
		X509_print_ex(out, x, XN_FLAG_ONELINE,0);

	if (flags & CAPI_DMP_PKEYINFO)
		{
		CRYPT_KEY_PROV_INFO *pinfo;
		pinfo = capi_get_prov_info(ctx, cert);
		capi_dump_prov_info(ctx, out, pinfo);
		if (pinfo)
			OPENSSL_free(pinfo);
		}

	if (flags & CAPI_DMP_PEM)
		PEM_write_bio_X509(out, x);
	X509_free(x);
	}
开发者ID:LucidOne,项目名称:Rovio,代码行数:46,代码来源:e_capi.c


示例4: z_py_zorp_certificate_getattr

static PyObject *
z_py_zorp_certificate_getattr(PyObject *o, char *name)
{
  ZorpCertificate *self = (ZorpCertificate *) 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(bio, self->cert);
      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_get_issuer_name(self->cert), buf, sizeof(buf));
      res = PyString_FromString(buf);
    }
  else if (strcmp(name, "subject") == 0)
    {
      X509_NAME_oneline(X509_get_subject_name(self->cert), buf, sizeof(buf));
      res = PyString_FromString(buf);
    }
  else if (strcmp(name, "serial") == 0)
    {
      ASN1_INTEGER *cert_serial;

      cert_serial = X509_get_serialNumber(self->cert);
      if (cert_serial)
        {
          res = PyInt_FromLong(ASN1_INTEGER_get(cert_serial));
        }
    }
  else
    {
      PyErr_SetString(PyExc_AttributeError, "Attribute not found");
    }
  return res;
}
开发者ID:VPetyaa,项目名称:zorp,代码行数:46,代码来源:pyx509.c


示例5: pemCert

unsigned char* pemCert(X509* cert)
{
    BIO * bio_out = BIO_new(BIO_s_mem());
    PEM_write_bio_X509(bio_out, cert);
    BUF_MEM *bio_buf;
    BIO_get_mem_ptr(bio_out, &bio_buf);
    string pemStr = string(bio_buf->data, bio_buf->length);
    unsigned char* pem;
    char* cstr = const_cast<char*>(pemStr.c_str());
    pem = reinterpret_cast<unsigned char*>(cstr);
    BIO_free(bio_out);

    unsigned char* retPem = new unsigned char[pemStr.length()];
    memcpy(retPem, cstr, pemStr.length());

    return retPem;
}
开发者ID:Aquila63,项目名称:FYP-SSLChain-Backend,代码行数:17,代码来源:xcert.cpp


示例6: OCSP_REQUEST_print

int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags)
        {
	int i;
	long l;
	OCSP_CERTID* cid = NULL;
	OCSP_ONEREQ *one = NULL;
	OCSP_REQINFO *inf = o->tbsRequest;
	OCSP_SIGNATURE *sig = o->optionalSignature;

	if (BIO_write(bp,"OCSP Request Data:\n",19) <= 0) goto err;
	l=ASN1_INTEGER_get(inf->version);
	if (BIO_printf(bp,"    Version: %lu (0x%lx)",l+1,l) <= 0) goto err;
	if (inf->requestorName != NULL)
	        {
		if (BIO_write(bp,"\n    Requestor Name: ",21) <= 0) 
		        goto err;
		GENERAL_NAME_print(bp, inf->requestorName);
		}
	if (BIO_write(bp,"\n    Requestor List:\n",21) <= 0) goto err;
	for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++)
	        {
		one = sk_OCSP_ONEREQ_value(inf->requestList, i);
		cid = one->reqCert;
		ocsp_certid_print(bp, cid, 8);
		if (!X509V3_extensions_print(bp,
					"Request Single Extensions",
					one->singleRequestExtensions, flags, 8))
							goto err;
		}
	if (!X509V3_extensions_print(bp, "Request Extensions",
			inf->requestExtensions, flags, 4))
							goto err;
	if (sig)
	        {
		X509_signature_print(bp, sig->signatureAlgorithm, sig->signature);
		for (i=0; i<sk_X509_num(sig->certs); i++)
			{
			X509_print(bp, sk_X509_value(sig->certs,i));
			PEM_write_bio_X509(bp,sk_X509_value(sig->certs,i));
			}
		}
	return 1;
err:
	return 0;
	}
开发者ID:AustinWise,项目名称:Netduino-Micro-Framework,代码行数:45,代码来源:ocsp_prn.cpp


示例7: pki_write_certificate

int pki_write_certificate(X509 *certificate, const char *filename)
{
	int ret = 0;
	BIO *bio_file = NULL;

	bio_file = BIO_new_file(filename, "w");
	if (bio_file == NULL) {
		ret = -1;
		goto out;
	}
	ret = PEM_write_bio_X509(bio_file, certificate);
	if (ret != 1) {
		ret = -1;
	}
	BIO_free(bio_file);
out:
	return ret;
}
开发者ID:gvsurenderreddy,项目名称:netvirt,代码行数:18,代码来源:pki.c


示例8: meth_pem

/**
 * Convert the certificate to PEM format.
 */
static int meth_pem(lua_State* L)
{
  char* data;
  long bytes;
  X509* cert = lsec_checkx509(L, 1);
  BIO *bio = BIO_new(BIO_s_mem());
  if (!PEM_write_bio_X509(bio, cert)) {
    lua_pushnil(L);
    return 1;
  }
  bytes = BIO_get_mem_data(bio, &data);
  if (bytes > 0)
    lua_pushlstring(L, data, bytes);
  else
    lua_pushnil(L);
  BIO_free(bio);
  return 1;
}
开发者ID:horazont,项目名称:luasec,代码行数:21,代码来源:x509.c


示例9: BIO_new

//
// retrieve the pem using the openssl functionality
std::string LLBasicCertificate::getPem() const
{ 
	char * pem_bio_chars = NULL;
	// a BIO is the equivalent of a 'std::stream', and
	// can be a file, mem stream, whatever.  Grab a memory based
	// BIO for the result
	BIO *pem_bio = BIO_new(BIO_s_mem());
	if (!pem_bio)
	{
		LL_WARNS("SECAPI") << "Could not allocate an openssl memory BIO." << LL_ENDL;		
		return std::string();
	}
	PEM_write_bio_X509(pem_bio, mCert);
	int length = BIO_get_mem_data(pem_bio, &pem_bio_chars);
	std::string result = std::string(pem_bio_chars, length);
	BIO_free(pem_bio);
	return result;
}
开发者ID:OS-Development,项目名称:VW.Zen,代码行数:20,代码来源:llsechandler_basic.cpp


示例10: exportToPem

    std::string exportToPem(X509 *x509)
    {
      std::string bio;
      
      if (!x509)
	return bio;

      BIO *bioMem = BIO_new(BIO_s_mem());
      if (!PEM_write_bio_X509(bioMem, x509)) {
	// error
      } else {
	char *thePem;
	int pemLength = BIO_get_mem_data(bioMem, &thePem);
	bio = std::string(thePem, thePem + pemLength);
      }
      BIO_free_all(bioMem);
      return bio;
    }
开发者ID:913862627,项目名称:wt,代码行数:18,代码来源:SslUtils.C


示例11: as_pem

static PyObject *
as_pem (certificate_x509 *self, PyObject *args)
{
	if (!PyArg_ParseTuple (args, "")) {
		return NULL;
	}

	BIO *bio = BIO_new (BIO_s_mem ());
	PEM_write_bio_X509 (bio, self->x509);

	size_t size = BIO_ctrl_pending (bio);
	char *buf = malloc (sizeof (char) * size);
	BIO_read (bio, buf, size);
	BIO_free (bio);

	PyObject *pem = PyString_FromStringAndSize (buf, size);
	free (buf);
	return pem;
}
开发者ID:jlsherrill,项目名称:python-rhsm,代码行数:19,代码来源:certificate.c


示例12: print_peer_certificate

void print_peer_certificate(SSL *ssl)
{
    X509* cert= NULL;
    X509_NAME *name=NULL;
    char buf[8192]={0};
    BIO *bio_cert = NULL;
    cert = SSL_get_peer_certificate(ssl);
    name = X509_get_subject_name(cert);
    X509_NAME_oneline(name,buf,8191);
    printf("Verified Peer Name:%s\n",buf);
    memset(buf,0,sizeof(buf));
    bio_cert = BIO_new(BIO_s_mem());
    PEM_write_bio_X509(bio_cert, cert);
    BIO_read( bio_cert, buf, 8191);
   
    printf("SERVER CERT:\n%s\n",buf);
    if(bio_cert)BIO_free(bio_cert);
    if(cert)X509_free(cert);
}
开发者ID:tianwenwvk,项目名称:workspace,代码行数:19,代码来源:client3.c


示例13: write_pem

bool write_pem(char *path, uint8_t *passwd, size_t len, EVP_PKEY *key, EC_GROUP *group, size_t certs, ...) {
    const EVP_CIPHER *cipher = passwd ? EVP_aes_256_cbc() : NULL;
    va_list ap;
    BIO *out = NULL;

    int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
    if (fd >= 0 && (out = BIO_new_fd(fd, BIO_CLOSE))) {
        PEM_write_bio_ECPKParameters(out, group);
        PEM_write_bio_PKCS8PrivateKey(out, key, cipher, (char *) passwd, len, NULL, NULL);

        va_start(ap, certs);
        for (size_t i = 0; i < certs; i++) {
            X509 *cert = va_arg(ap, X509 *);
            PEM_write_bio_X509(out, cert);
        }
        va_end(ap);

        BIO_free(out);
    }
开发者ID:10xEngineer,项目名称:My-Wallet-iPhone,代码行数:19,代码来源:pki.c


示例14: x509_to_string

/*
 * Convert X509 to string.
 */
static char * x509_to_string(const X509 *cert) {
	BIO *bio;
	int len;
	char *ptr, *result;

	// write X509 into buffer
	bio = BIO_new(BIO_s_mem());
	PEM_write_bio_X509(bio, (X509 *) cert);

	// create results.
	len = BIO_number_written(bio);
	BIO_get_mem_data(bio, &ptr);
	result = palloc(len + 1);
	strncpy(result, ptr, len);
	result[len] = '\0';
	BIO_free(bio);

	return result;
}
开发者ID:beargiles,项目名称:pgopenssltypes,代码行数:22,代码来源:x509.c


示例15: x509buf

/*
 * Convert an X509 certificate to a buffer of "sz".
 * We don't guarantee that it's nil-terminated.
 * Returns NULL on failure.
 */
static char *
x509buf(X509 *x, size_t *sz)
{
	BIO	*bio;
	char	*p;
	int	 ssz;

	/* Convert X509 to PEM in BIO. */

	if (NULL == (bio = BIO_new(BIO_s_mem()))) {
		warnx("BIO_new");
		return(NULL);
	} else if ( ! PEM_write_bio_X509(bio, x)) {
		warnx("PEM_write_bio_X509");
		BIO_free(bio);
		return(NULL);
	}

	/* 
	 * Now convert bio to string. 
	 * Make into nil-terminated, just in case.
	 */

	if (NULL == (p = calloc(1, bio->num_write + 1))) {
		warn("calloc");
		BIO_free(bio);
		return(NULL);
	} 

	ssz = BIO_read(bio, p, bio->num_write);
	if (ssz < 0 || (unsigned)ssz != bio->num_write) {
		warnx("BIO_read");
		BIO_free(bio);
		return(NULL);
	}

	*sz = ssz;
	BIO_free(bio);
	return(p);
}
开发者ID:ehasting,项目名称:letskencrypt-portable,代码行数:45,代码来源:certproc.c


示例16: assert

int SocketClient::pinCertCallback(int pok, X509_STORE_CTX *ctx)
{
    std::cout << "Checking pinned certificate" << std::endl;

    X509 *cert = NULL;
    BIO *b64 = NULL;
    BUF_MEM *bptr = NULL;
    char *szCert = NULL;

    cert = ctx->current_cert;
    assert(cert != NULL);

    b64 = BIO_new(BIO_s_mem());
    assert(b64 != NULL);
    assert(1 == PEM_write_bio_X509(b64, cert));

    BIO_get_mem_ptr(b64, &bptr);

    assert(NULL != (szCert = (char*)malloc(bptr->length + 1)));
    assert(0 < BIO_read(b64, szCert, bptr->length));

    int ret = strncmp(szCert, AUTH_CERTIFICATE, strlen(AUTH_CERTIFICATE));

    free(szCert);
    if (b64)
    {
        BIO_free(b64);
    }

    if(ret == 0)
    {
        std::cout << "pinned certificate verification passed..." << std::endl;
        return 1;
    }
    else
    {
        std::cout << "pinned certificate verification failed..." << std::endl;
        return 0;
    }
}
开发者ID:marcb1,项目名称:ssl_socket,代码行数:40,代码来源:SocketClient.cpp


示例17: render_pem

      std::string render_pem() const
      {
	if (x509_)
	  {
	    BIO *bio = BIO_new(BIO_s_mem());
	    const int ret = PEM_write_bio_X509(bio, x509_);
	    if (ret == 0)
	      {
		BIO_free(bio);
		throw OpenSSLException("X509::render_pem");
	      }

	    {
	      char *temp;
	      const int buf_len = BIO_get_mem_data(bio, &temp);
	      std::string ret = std::string(temp, buf_len);
	      BIO_free(bio);
	      return ret;
	    }
	  }
	else
	  return "";
      }
开发者ID:akoshelnik,项目名称:openvpn3,代码行数:23,代码来源:x509.hpp


示例18: hr_https_add_vars

int hr_https_add_vars(struct http_session *hr, struct corerouter_peer *peer, struct uwsgi_buffer *out) {
// HTTPS (adapted from nginx)
        if (hr->session.ugs->mode == UWSGI_HTTP_SSL) {
                if (uwsgi_buffer_append_keyval(out, "HTTPS", 5, "on", 2)) return -1;
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
			const char *servername = SSL_get_servername(hr->ssl, TLSEXT_NAMETYPE_host_name);
                        if (servername && strlen(servername) <= 0xff) {
				peer->key_len = strlen(servername);
                        	memcpy(peer->key, servername, peer->key_len) ;
                        }
#endif
                hr->ssl_client_cert = SSL_get_peer_certificate(hr->ssl);
                if (hr->ssl_client_cert) {
                        X509_NAME *name = X509_get_subject_name(hr->ssl_client_cert);
                        if (name) {
                                hr->ssl_client_dn = X509_NAME_oneline(name, NULL, 0);
                                if (uwsgi_buffer_append_keyval(out, "HTTPS_DN", 8, hr->ssl_client_dn, strlen(hr->ssl_client_dn))) return -1;
                        }
                        if (uhttp.https_export_cert) {
                        hr->ssl_bio = BIO_new(BIO_s_mem());
                        if (hr->ssl_bio) {
                                if (PEM_write_bio_X509(hr->ssl_bio, hr->ssl_client_cert) > 0) {
                                        size_t cc_len = BIO_pending(hr->ssl_bio);
                                        hr->ssl_cc = uwsgi_malloc(cc_len);
                                        BIO_read(hr->ssl_bio, hr->ssl_cc, cc_len);
                                        if (uwsgi_buffer_append_keyval(out, "HTTPS_CC", 8, hr->ssl_cc, cc_len)) return -1;
                                }
                        }
                        }
                }
        }
        else if (hr->session.ugs->mode == UWSGI_HTTP_FORCE_SSL) {
                hr->force_https = 1;
        }

	return 0;
}
开发者ID:wangmingfu,项目名称:G7Platform,代码行数:37,代码来源:https.c


示例19: print_client_cert

void print_client_cert(char* path)
{
    X509 *cert =NULL;
    FILE *fp = NULL;
    fp = fopen(path,"rb");
    
    cert = PEM_read_X509(fp, NULL, NULL, "900820");
    X509_NAME *name=NULL;
    char buf[8192]={0};
    BIO *bio_cert = NULL;

    name = X509_get_subject_name(cert);
    X509_NAME_oneline(name,buf,8191);
    printf("ClientSubjectName:%s\n",buf);
    memset(buf,0,sizeof(buf));
    bio_cert = BIO_new(BIO_s_mem());
    PEM_write_bio_X509(bio_cert, cert);

    BIO_read( bio_cert, buf, 8191);
    printf("CLIENT CERT:\n%s\n",buf);
    if(bio_cert)BIO_free(bio_cert);
    fclose(fp);
    if(cert) X509_free(cert);
}
开发者ID:tianwenwvk,项目名称:workspace,代码行数:24,代码来源:client3.c


示例20: STACK_OF

/* Return a PEM-formatted buffer containing the peer's certificate chain.
 *
 * NULL is returned if there is no certificate chain, or if memory allocation fails.
 */
char *async_ssl__pem_peer_certificate_chain(const SSL *con) {
    STACK_OF(X509) *cert_stack = NULL;
    BIO *bio = NULL;
    char *certs = NULL;
    int i = 0, pending_bytes = 0;

    /* [cert_stack] is not to be freed; [SSL_get_peer_cert_chain] simply returns an
     * internal pointer and no reference count is incremented. */
    if ((cert_stack = SSL_get_peer_cert_chain(con)) == NULL) {
        return NULL;
    }

    if ((bio = BIO_new(BIO_s_mem())) == NULL) {
        return NULL;
    }
    for (i = 0; i < sk_X509_num(cert_stack); i++) {
        if ((PEM_write_bio_X509(bio, sk_X509_value(cert_stack, i))) == 0) {
            goto cleanup;
        }
    }
    pending_bytes = BIO_ctrl_pending(bio);
    if ((certs = malloc((pending_bytes + 1) * sizeof(char))) == NULL) {
        goto cleanup;
    }
    if ((BIO_read(bio, certs, pending_bytes)) < pending_bytes) {
        free(certs);
        goto cleanup;
    }
    certs[pending_bytes] = '\0';

  cleanup:
    BIO_set_close(bio, BIO_CLOSE);
    BIO_free(bio);

    return certs;
}
开发者ID:janestreet,项目名称:async_ssl,代码行数:40,代码来源:openssl_helpers.c



注:本文中的PEM_write_bio_X509函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PEMerr函数代码示例发布时间:2022-05-30
下一篇:
C++ PEM_read_bio_X509_AUX函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap