예제 #1
0
파일: X509Crl.cpp 프로젝트: ngot/fibjs
result_t X509Crl::dump(v8::Local<v8::Array> &retVal)
{
    Isolate* isolate = holder();
    retVal = v8::Array::New(isolate->m_isolate);

    const mbedtls_x509_crl *pCrl = &m_crl;
    int32_t ret, n = 0;
    exlib::string buf;
    size_t olen;

    while (pCrl)
    {
        if (pCrl->raw.len > 0)
        {
            buf.resize(pCrl->raw.len * 2 + 64);
            ret = mbedtls_pem_write_buffer(PEM_BEGIN_CRL, PEM_END_CRL,
                                           pCrl->raw.p, pCrl->raw.len,
                                           (unsigned char *)&buf[0], buf.length(), &olen);
            if (ret != 0)
                return CHECK_ERROR(_ssl::setError(ret));

            retVal->Set(n ++, isolate->NewFromUtf8(buf.c_str(), (int32_t) olen - 1));
        }
        pCrl = pCrl->next;
    }

    return 0;
}
예제 #2
0
파일: pkwrite.c 프로젝트: Comojs/comojs
int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *key, unsigned char *buf, size_t size )
{
    int ret;
    unsigned char output_buf[PUB_DER_MAX_BYTES];
    size_t olen = 0;

    if( ( ret = mbedtls_pk_write_pubkey_der( key, output_buf,
                sizeof(output_buf) ) ) < 0 )
    {
        return( ret );
    }

    if( ( ret = mbedtls_pem_write_buffer( PEM_BEGIN_PUBLIC_KEY, PEM_END_PUBLIC_KEY,
                                          output_buf + sizeof(output_buf) - ret,
                                          ret, buf, size, &olen ) ) != 0 )
    {
        return( ret );
    }

    return( 0 );
}
예제 #3
0
int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt, unsigned char *buf, size_t size,
                       int (*f_rng)(void *, unsigned char *, size_t),
                       void *p_rng )
{
    int ret;
    unsigned char output_buf[4096];
    size_t olen = 0;

    if( ( ret = mbedtls_x509write_crt_der( crt, output_buf, sizeof(output_buf),
                                   f_rng, p_rng ) ) < 0 )
    {
        return( ret );
    }

    if( ( ret = mbedtls_pem_write_buffer( PEM_BEGIN_CRT, PEM_END_CRT,
                                  output_buf + sizeof(output_buf) - ret,
                                  ret, buf, size, &olen ) ) != 0 )
    {
        return( ret );
    }

    return( 0 );
}
예제 #4
0
파일: pkwrite.c 프로젝트: Comojs/comojs
int mbedtls_pk_write_key_pem( mbedtls_pk_context *key, unsigned char *buf, size_t size )
{
    int ret;
    unsigned char output_buf[PRV_DER_MAX_BYTES];
    const char *begin, *end;
    size_t olen = 0;

    if( ( ret = mbedtls_pk_write_key_der( key, output_buf, sizeof(output_buf) ) ) < 0 )
        return( ret );

#if defined(MBEDTLS_RSA_C)
    if( mbedtls_pk_get_type( key ) == MBEDTLS_PK_RSA )
    {
        begin = PEM_BEGIN_PRIVATE_KEY_RSA;
        end = PEM_END_PRIVATE_KEY_RSA;
    }
    else
#endif
#if defined(MBEDTLS_ECP_C)
        if( mbedtls_pk_get_type( key ) == MBEDTLS_PK_ECKEY )
        {
            begin = PEM_BEGIN_PRIVATE_KEY_EC;
            end = PEM_END_PRIVATE_KEY_EC;
        }
        else
#endif
            return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );

    if( ( ret = mbedtls_pem_write_buffer( begin, end,
                                          output_buf + sizeof(output_buf) - ret,
                                          ret, buf, size, &olen ) ) != 0 )
    {
        return( ret );
    }

    return( 0 );
}