当前位置: 首页>>代码示例>>C++>>正文


C++ PEM_write_bio_X509函数代码示例

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


在下文中一共展示了PEM_write_bio_X509函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例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


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