// returns NULL if CSR doesn't contain the extension, the commitment C value otherwise BIGNUM *getCommitmentValueFromCSR(char *req_filename) { /* read in the request */ X509_REQ *req; FILE *fp; if (!(fp = fopen(req_filename, "r"))) critical_error("Error reading request file"); if (!(req = PEM_read_X509_REQ(fp, NULL, NULL, NULL))) critical_error("Error reading request in file"); fclose(fp); BIGNUM *toret = NULL; // enable the extension handling (retrieve/print as string) int nid = _commitmentExt_start(); // get extensions stack of request STACK_OF(X509_EXTENSION) *extlist = X509_REQ_get_extensions(req); if (extlist!=NULL) { // if there are extensions int extpos = X509v3_get_ext_by_NID(extlist, nid, -1); // try to locate extension if (extpos!=-1) { // if found X509_EXTENSION *ext = X509v3_get_ext(extlist, extpos); toret = _commitmentExt2BN(ext); } } X509_REQ_free(req); _commitmentExt_end(); return toret; }
X509_EXTENSION * OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc) { return X509v3_get_ext(x->singleExtensions, loc); }
X509_EXTENSION * OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc) { return X509v3_get_ext(x->tbsResponseData->responseExtensions, loc); }
X509_EXTENSION * OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc) { return X509v3_get_ext(x->singleRequestExtensions, loc); }
X509_EXTENSION * OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc) { return X509v3_get_ext(x->tbsRequest->requestExtensions, loc); }
X509_EXTENSION * TS_REQ_get_ext(TS_REQ *a, int loc) { return X509v3_get_ext(a->extensions, loc); }
X509_EXTENSION *X509_get_ext(const X509 *x, int loc) { return (X509v3_get_ext(x->cert_info.extensions, loc)); }
X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc) { return (X509v3_get_ext(x->crl.extensions, loc)); }
X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc) { return (X509v3_get_ext(x->extensions, loc)); }
X509_EXTENSION * TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc) { return X509v3_get_ext(a->extensions, loc); }
EXPORT_C X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc) { return(X509v3_get_ext(x->crl->extensions,loc)); }
EXPORT_C X509_EXTENSION *X509_get_ext(X509 *x, int loc) { return(X509v3_get_ext(x->cert_info->extensions,loc)); }