extern "C" X509Stack* CryptoNative_X509StoreCtxGetChain(X509_STORE_CTX* ctx) { return X509_STORE_CTX_get1_chain(ctx); }
// success of certificates extraction bool pemData(X509_STORE_CTX* ctx, ListHashSet<String>& certificates) { bool ok = true; STACK_OF(X509)* certs = X509_STORE_CTX_get1_chain(ctx); for (int i = 0; i < sk_X509_num(certs); i++) { X509* uCert = sk_X509_value(certs, i); BIO* bio = BIO_new(BIO_s_mem()); int res = PEM_write_bio_X509(bio, uCert); if (!res) { ok = false; BIO_free(bio); break; } unsigned char* certificateData; long length = BIO_get_mem_data(bio, &certificateData); if (length < 0) { ok = false; BIO_free(bio); break; } certificateData[length] = '\0'; String certificate = certificateData; certificates.add(certificate); BIO_free(bio); } sk_X509_pop_free(certs, X509_free); return ok; }