result_t X509Req::create(const char *subject, PKey_base *key, int32_t hash) { clear(); x509write_csr csr; int ret; x509write_csr_init(&csr); if (hash < POLARSSL_MD_MD2 || hash > POLARSSL_MD_RIPEMD160) return CHECK_ERROR(CALL_E_INVALIDARG); x509write_csr_set_md_alg(&csr, (md_type_t)hash); x509write_csr_set_subject_name(&csr, subject); pk_context *k = &((PKey *)(PKey_base *)key)->m_key; x509write_csr_set_key(&csr, k); std::string buf; buf.resize(pk_get_size(k) * 8 + 128); ret = x509write_csr_pem(&csr, (unsigned char *)&buf[0], buf.length(), ctr_drbg_random, &g_ssl.ctr_drbg); x509write_csr_free(&csr); if (ret != 0) return CHECK_ERROR(_ssl::setError(ret)); ret = x509_csr_parse(&m_csr, (const unsigned char *)buf.c_str(), qstrlen(buf.c_str())); if (ret != 0) return CHECK_ERROR(_ssl::setError(ret)); return 0; }
result_t X509Req::load(const char *pemReq) { int ret; clear(); ret = x509_csr_parse(&m_csr, (const unsigned char *)pemReq, qstrlen(pemReq)); if (ret != 0) return CHECK_ERROR(_ssl::setError(ret)); return 0; }
/* * Load a CSR into the structure */ int x509_csr_parse_file( x509_csr *csr, const char *path ) { int ret; size_t n; unsigned char *buf; if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 ) return( ret ); ret = x509_csr_parse( csr, buf, n ); memset( buf, 0, n + 1 ); polarssl_free( buf ); return( ret ); }
result_t X509Req::load(Buffer_base *derReq) { int ret; clear(); std::string csr; derReq->toString(csr); ret = x509_csr_parse(&m_csr, (const unsigned char *)csr.c_str(), csr.length()); if (ret != 0) return CHECK_ERROR(_ssl::setError(ret)); return 0; }
result_t X509Req::loadFile(const char *filename) { result_t hr; std::string data; int ret; clear(); hr = fs_base::ac_readFile(filename, data); if (hr < 0) return hr; ret = x509_csr_parse(&m_csr, (const unsigned char *)data.c_str(), data.length()); if (ret != 0) return CHECK_ERROR(_ssl::setError(ret)); std::string buf; buf.resize(8192); return 0; }