int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) { EVP_PKEY *pkey; ASN1_IA5STRING *chal; int i, n; char *s; BIO_printf(out, "Netscape SPKI:\n"); i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm); BIO_printf(out," Public Key Algorithm: %s\n", (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); pkey = X509_PUBKEY_get(spki->spkac->pubkey); if(!pkey) BIO_printf(out, " Unable to load public key\n"); else { #ifndef OPENSSL_NO_RSA if (pkey->type == EVP_PKEY_RSA) { BIO_printf(out," RSA Public Key: (%d bit)\n", BN_num_bits(pkey->pkey.rsa->n)); RSA_print(out,pkey->pkey.rsa,2); } else #endif #ifndef OPENSSL_NO_DSA if (pkey->type == EVP_PKEY_DSA) { BIO_printf(out," DSA Public Key:\n"); DSA_print(out,pkey->pkey.dsa,2); } else #endif #ifndef OPENSSL_NO_EC if (pkey->type == EVP_PKEY_EC) { BIO_printf(out, " EC Public Key:\n"); EC_KEY_print(out, pkey->pkey.ec,2); } else #endif BIO_printf(out," Unknown Public Key:\n"); EVP_PKEY_free(pkey); } chal = spki->spkac->challenge; if(chal->length) BIO_printf(out, " Challenge String: %s\n", chal->data); i=OBJ_obj2nid(spki->sig_algor->algorithm); BIO_printf(out," Signature Algorithm: %s", (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); n=spki->signature->length; s=(char *)spki->signature->data; for (i=0; i<n; i++) { if ((i%18) == 0) BIO_write(out,"\n ",7); BIO_printf(out,"%02x%s",(unsigned char)s[i], ((i+1) == n)?"":":"); } BIO_write(out,"\n",1); return 1; }
int EVP_add_digest(const EVP_MD *md) { int r; const char *name; OPENSSL_init(); name = OBJ_nid2sn(md->type); r = OBJ_NAME_add(name, OBJ_NAME_TYPE_MD_METH, (const char *)md); if (r == 0) return (0); check_defer(md->type); r = OBJ_NAME_add(OBJ_nid2ln(md->type), OBJ_NAME_TYPE_MD_METH, (const char *)md); if (r == 0) return (0); if (md->pkey_type && md->type != md->pkey_type) { r = OBJ_NAME_add(OBJ_nid2sn(md->pkey_type), OBJ_NAME_TYPE_MD_METH | OBJ_NAME_ALIAS, name); if (r == 0) return (0); check_defer(md->pkey_type); r = OBJ_NAME_add(OBJ_nid2ln(md->pkey_type), OBJ_NAME_TYPE_MD_METH | OBJ_NAME_ALIAS, name); } return (r); }
static int check_nid(const char *name, int expected_nid, int nid) { if (expected_nid == 0 || expected_nid == nid) return 1; TEST_error("%s type mismatch, %s vs %s\n", name, OBJ_nid2ln(expected_nid), nid == NID_undef ? "absent" : OBJ_nid2ln(nid)); return 0; }
static int check_tmp_key(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx) { if (test_ctx->expected_tmp_key_type == 0 || test_ctx->expected_tmp_key_type == result->tmp_key_type) return 1; fprintf(stderr, "Tmp key type mismatch, %s vs %s\n", OBJ_nid2ln(test_ctx->expected_tmp_key_type), OBJ_nid2ln(result->tmp_key_type)); return 0; }
dbheaderList db_x509req::getHeaders() { dbheaderList h = db_x509super::getHeaders(); h << new dbheader(HD_req_signed, true, tr("Signed"), tr("whether the request is already signed or not")) << new dbheader(HD_req_unstr_name, false, tr("Unstructured name"), QString(OBJ_nid2ln(NID_pkcs9_unstructuredName))) << new dbheader(HD_req_chall_pass, false, tr("Challenge password"), QString(OBJ_nid2ln(NID_pkcs9_challengePassword))); return h; }
db_x509req::db_x509req(QString DBfile, MainWindow *mw) :db_x509super(DBfile, mw) { allHeaders << new dbheader(HD_req_signed, true, tr("Signed"), tr("whether the request is already signed or not")) << new dbheader(HD_req_unstr_name, false, tr("Unstructured name"), QString(OBJ_nid2ln(NID_pkcs9_unstructuredName))) << new dbheader(HD_req_chall_pass, false, tr("Challenge password"), QString(OBJ_nid2ln(NID_pkcs9_challengePassword))); class_name = "requests"; pkitype << x509_req; loadContainer(); }
static int param_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { int param_nid = EC_GROUP_get_curve_name(GOST_KEY_get0_group(pkey->pkey.gost)); if (BIO_indent(out, indent, 128) == 0) return 0; BIO_printf(out, "Parameter set: %s\n", OBJ_nid2ln(param_nid)); if (BIO_indent(out, indent, 128) == 0) return 0; BIO_printf(out, "Digest Algorithm: %s\n", OBJ_nid2ln(GOST_KEY_get_digest(pkey->pkey.gost))); return 1; }
static int print_unsupported(BIO *out, const EVP_PKEY *pkey, int indent, const char *kstr) { BIO_indent(out, indent, 128); BIO_printf(out, "%s algorithm \"%s\" unsupported\n", kstr, OBJ_nid2ln(pkey->type)); return 1; }
int main(int argc, char **argv) { ASN1_OBJECT *obj = NULL; int tmp_size = 0; int oid_len = 0; if (argc < 2) { usage(argv[0]); return 0; } char *oid = NULL; char *sn = NULL; char *ln = NULL; oid = (char *) malloc(STRSIZE + 1); if (oid == NULL) { printf("Error allocating %i bytes for oid string\n", STRSIZE + 1); } oid[STRSIZE] = '\0'; int nid = atoi(argv[1]); printf("searching for nid shortname for %i\n", nid); sn = (char *) OBJ_nid2sn(nid); ln = (char *) OBJ_nid2ln(nid); obj = OBJ_nid2obj(nid); if (obj != NULL) { oid_len = OBJ_obj2txt(oid, STRSIZE, obj, 1); if (oid_len > 0) { oid[oid_len] = '\0'; } else { strncpy(oid, "Unkown", STRSIZE); } } else { oid = strncpy(oid, "Unknown", STRSIZE); } printf("sb=\"%s\" ln=\"%s\" oid=\"%s\"\n", sn, ln, oid); free(oid); return 0; }
static int test_tbl_standard(void) { const ASN1_STRING_TABLE *tmp; int last_nid = -1; size_t i; for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) { if (tmp->nid < last_nid) { last_nid = 0; break; } last_nid = tmp->nid; } if (TEST_int_ne(last_nid, 0)) { TEST_info("asn1 tbl_standard: Table order OK"); return 1; } TEST_info("asn1 tbl_standard: out of order"); for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) TEST_note("asn1 tbl_standard: Index %zu, NID %d, Name=%s", i, tmp->nid, OBJ_nid2ln(tmp->nid)); return 0; }
IoObject *IoCertificate_attributes(IoCertificate *self, IoObject *locals, IoMessage *m) { IoObject *map = IoObject_new(IoObject_state(self)); const EVP_PKEY *pkey = X509_extract_key(X509(self)); int i; for(i = 0; i < EVP_PKEY_get_attr_count(pkey); i++) { IoList *list = IoList_new(IoObject_state(self)); X509_ATTRIBUTE *attr = EVP_PKEY_get_attr(pkey, i); const char *key = (const char *)OBJ_nid2ln(OBJ_obj2nid(X509_ATTRIBUTE_get0_object(attr))); int j; for(j = 0; j < X509_ATTRIBUTE_count(attr); j++) { ASN1_TYPE *attrType = X509_ATTRIBUTE_get0_type(attr, j); ASN1_OBJECT *attrData = X509_ATTRIBUTE_get0_data(attr, j, attrType->type, NULL); //consider switching on attrType instead; //really, that would be wiser, so that dates, //numbers, etc can be happy /* switch(attrType->type) { case V_ASN1_OCTET_STRING: ... */ int len = i2t_ASN1_OBJECT(NULL, 0, attrData); char *value = calloc(len, sizeof(char)); i2t_ASN1_OBJECT(value, len, attrData); IoList_rawAppend_(list, IoSeq_newWithCString_(IoObject_state(self), value)); } IoObject_setSlot_to_(map, IOSYMBOL(key), list); } return map; }
int main(int argc, char **argv) { X509 *cert; FILE *inf; int i, count; X509_EXTENSION *ext; X509V3_add_standard_extensions(); ERR_load_crypto_strings(); if(!argv[1]) { fprintf(stderr, "Usage v3prin cert.pem\n"); exit(1); } if(!(inf = fopen(argv[1], "r"))) { fprintf(stderr, "Can't open %s\n", argv[1]); exit(1); } if(!(cert = PEM_read_X509(inf, NULL, NULL))) { fprintf(stderr, "Can't read certificate %s\n", argv[1]); ERR_print_errors_fp(stderr); exit(1); } fclose(inf); count = X509_get_ext_count(cert); printf("%d extensions\n", count); for(i = 0; i < count; i++) { ext = X509_get_ext(cert, i); printf("%s\n", OBJ_nid2ln(OBJ_obj2nid(ext->object))); if(!X509V3_EXT_print_fp(stdout, ext, 0, 0)) ERR_print_errors_fp(stderr); printf("\n"); } return 0; }
main() { ASN1_STRING_TABLE *tmp; int i, last_nid = -1; for (tmp = tbl_standard, i = 0; i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { if (tmp->nid < last_nid) { last_nid = 0; break; } last_nid = tmp->nid; } if (last_nid != 0) { printf("Table order OK\n"); exit(0); } for (tmp = tbl_standard, i = 0; i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, OBJ_nid2ln(tmp->nid)); }
/* Test of EVP_PKEY_METHOD ordering */ static int test_pkey_meths(void) { size_t i; int prev = -1; int good = 1; int pkey_id; const EVP_PKEY_METHOD *pmeth; for (i = 0; i < EVP_PKEY_meth_get_count(); i++) { pmeth = EVP_PKEY_meth_get0(i); EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth); if (pkey_id < prev) good = 0; prev = pkey_id; } if (!good) { TEST_error("EVP_PKEY_METHOD table out of order"); for (i = 0; i < EVP_PKEY_meth_get_count(); i++) { pmeth = EVP_PKEY_meth_get0(i); EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth); TEST_note("%d : %s", pkey_id, OBJ_nid2ln(pkey_id)); } } return good; }
X509_PKEY * d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) { int i; M_ASN1_D2I_vars(a, X509_PKEY *, X509_PKEY_new); M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get_x(X509_ALGOR, ret->enc_algor, d2i_X509_ALGOR); M_ASN1_D2I_get_x(ASN1_OCTET_STRING, ret->enc_pkey, d2i_ASN1_OCTET_STRING); ret->cipher.cipher = EVP_get_cipherbyname( OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); if (ret->cipher.cipher == NULL) { c.error = ASN1_R_UNSUPPORTED_CIPHER; c.line = __LINE__; goto err; } if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) { i = ret->enc_algor->parameter->value.octet_string->length; if (i > EVP_MAX_IV_LENGTH) { c.error = ASN1_R_IV_TOO_LARGE; c.line = __LINE__; goto err; } memcpy(ret->cipher.iv, ret->enc_algor->parameter->value.octet_string->data, i); } else memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH); M_ASN1_D2I_Finish(a, X509_PKEY_free, ASN1_F_D2I_X509_PKEY); }
static int test_tbl_standard() { const ASN1_STRING_TABLE *tmp; int last_nid = -1; size_t i; for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) { if (tmp->nid < last_nid) { last_nid = 0; break; } last_nid = tmp->nid; } if (last_nid != 0) { fprintf(stderr, "asn1 tbl_standard: Table order OK\n"); return 1; } for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) fprintf(stderr, "asn1 tbl_standard: Index %" OSSLzu ", NID %d, Name=%s\n", i, tmp->nid, OBJ_nid2ln(tmp->nid)); return 0; }
/* Test of EVP_PKEY_ASN1_METHOD ordering */ static int test_asn1_meths(void) { int i; int prev = -1; int good = 1; int pkey_id; const EVP_PKEY_ASN1_METHOD *ameth; for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) { ameth = EVP_PKEY_asn1_get0(i); EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth); if (pkey_id < prev) good = 0; prev = pkey_id; } if (!good) { TEST_error("EVP_PKEY_ASN1_METHOD table out of order"); for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) { const char *info; ameth = EVP_PKEY_asn1_get0(i); EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, &info, NULL, ameth); if (info == NULL) info = "<NO NAME>"; TEST_note("%d : %s : %s", pkey_id, OBJ_nid2ln(pkey_id), info); } } return good; }
/* --------- printing keys --------------------------------*/ static int print_gost_94(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx, int type) { int param_nid = NID_undef; if (type == 2) { BIGNUM *key; if (!BIO_indent(out,indent,128)) return 0; BIO_printf(out,"Private key: "); key = gost_get0_priv_key(pkey); if (!key) BIO_printf(out,"<undefined>"); else BN_print(out,key); BIO_printf(out,"\n"); } if (type >= 1) { BIGNUM *pubkey; pubkey = ((DSA *)EVP_PKEY_get0((EVP_PKEY *)pkey))->pub_key; BIO_indent(out,indent,128); BIO_printf(out,"Public key: "); BN_print(out,pubkey); BIO_printf(out,"\n"); } param_nid = gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)pkey)); BIO_indent(out,indent,128); BIO_printf(out, "Parameter set: %s\n",OBJ_nid2ln(param_nid)); return 1; }
static int print_gost_01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx, int type) { int param_nid = NID_undef; if (type == 2) { BIGNUM *key; if (!BIO_indent(out,indent,128)) return 0; BIO_printf(out,"Private key: "); key = gost_get0_priv_key(pkey); if (!key) BIO_printf(out,"<undefined)"); else BN_print(out,key); BIO_printf(out,"\n"); } if (type >= 1) { BN_CTX *ctx = BN_CTX_new(); BIGNUM *X,*Y; const EC_POINT *pubkey; const EC_GROUP *group; if (!ctx) { GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_MALLOC_FAILURE); return 0; } BN_CTX_start(ctx); X = BN_CTX_get(ctx); Y = BN_CTX_get(ctx); pubkey = EC_KEY_get0_public_key((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey)); group = EC_KEY_get0_group((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey)); if (!EC_POINT_get_affine_coordinates_GFp(group,pubkey,X,Y,ctx)) { GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_EC_LIB); BN_CTX_free(ctx); return 0; } if (!BIO_indent(out,indent,128)) return 0; BIO_printf(out,"Public key:\n"); if (!BIO_indent(out,indent+3,128)) return 0; BIO_printf(out,"X:"); BN_print(out,X); BIO_printf(out,"\n"); BIO_indent(out,indent+3,128); BIO_printf(out,"Y:"); BN_print(out,Y); BIO_printf(out,"\n"); BN_CTX_end(ctx); BN_CTX_free(ctx); } param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey))); if (!BIO_indent(out,indent,128)) return 0; BIO_printf(out,"Parameter set: %s\n",OBJ_nid2ln(param_nid)); return 1; }
std::string genAlgProperty(const X509* cert) { int pub_key_alg_nid = OBJ_obj2nid(cert->cert_info->key->algor->algorithm); if (pub_key_alg_nid == NID_undef) { // Unknown algorithm OID. return ""; } return std::string(OBJ_nid2ln(pub_key_alg_nid)); }
NOEXPORT int init_ecdh(SERVICE_OPTIONS *section) { EC_KEY *ecdh; s_log(LOG_DEBUG, "ECDH initialization"); ecdh=EC_KEY_new_by_curve_name(section->curve); if(!ecdh) { sslerror("EC_KEY_new_by_curve_name"); s_log(LOG_ERR, "Cannot create curve %s", OBJ_nid2ln(section->curve)); return 1; /* FAILED */ } SSL_CTX_set_tmp_ecdh(section->ctx, ecdh); EC_KEY_free(ecdh); s_log(LOG_DEBUG, "ECDH initialized with curve %s", OBJ_nid2ln(section->curve)); return 0; /* OK */ }
int main(int argc, char **argv) { LHASH *conf; X509 *cert; FILE *inf; char *conf_file; int i; int count; X509_EXTENSION *ext; X509V3_add_standard_extensions(); ERR_load_crypto_strings(); if(!argv[1]) { fprintf(stderr, "Usage: v3conf cert.pem [file.cnf]\n"); exit(1); } conf_file = argv[2]; if(!conf_file) conf_file = "test.cnf"; conf = CONF_load(NULL, "test.cnf", NULL); if(!conf) { fprintf(stderr, "Error opening Config file %s\n", conf_file); ERR_print_errors_fp(stderr); exit(1); } inf = fopen(argv[1], "r"); if(!inf) { fprintf(stderr, "Can't open certificate file %s\n", argv[1]); exit(1); } cert = PEM_read_X509(inf, NULL, NULL); if(!cert) { fprintf(stderr, "Error reading certificate file %s\n", argv[1]); exit(1); } fclose(inf); sk_pop_free(cert->cert_info->extensions, X509_EXTENSION_free); cert->cert_info->extensions = NULL; if(!X509V3_EXT_add_conf(conf, NULL, "test_section", cert)) { fprintf(stderr, "Error adding extensions\n"); ERR_print_errors_fp(stderr); exit(1); } count = X509_get_ext_count(cert); printf("%d extensions\n", count); for(i = 0; i < count; i++) { ext = X509_get_ext(cert, i); printf("%s", OBJ_nid2ln(OBJ_obj2nid(ext->object))); if(ext->critical) printf(",critical:\n"); else printf(":\n"); X509V3_EXT_print_fp(stdout, ext, 0, 0); printf("\n"); } return 0; }
static void SCT_signature_algorithms_print(const SCT *sct, BIO *out) { int nid = SCT_get_signature_nid(sct); if (nid == NID_undef) BIO_printf(out, "%02X%02X", sct->hash_alg, sct->sig_alg); else BIO_printf(out, "%s", OBJ_nid2ln(nid)); }
/* * Equivalent of X509_NAME_oneline that respects encoding * * This function converts X509_NAME structure to the text variable * converting all textual data into current database encoding. * * Parameter: X509_NAME *name X509_NAME structure to be converted * * Returns: text datum which contains string representation of * X509_NAME */ static Datum X509_NAME_to_text(X509_NAME *name) { BIO *membuf = BIO_new(BIO_s_mem()); int i, nid, count = X509_NAME_entry_count(name); X509_NAME_ENTRY *e; ASN1_STRING *v; const char *field_name; size_t size; char nullterm; char *sp; char *dp; text *result; if (membuf == NULL) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("could not create OpenSSL BIO structure"))); (void) BIO_set_close(membuf, BIO_CLOSE); for (i = 0; i < count; i++) { e = X509_NAME_get_entry(name, i); nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(e)); if (nid == NID_undef) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("could not get NID for ASN1_OBJECT object"))); v = X509_NAME_ENTRY_get_data(e); field_name = OBJ_nid2sn(nid); if (field_name == NULL) field_name = OBJ_nid2ln(nid); if (field_name == NULL) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("could not convert NID %d to an ASN1_OBJECT structure", nid))); BIO_printf(membuf, "/%s=", field_name); ASN1_STRING_print_ex(membuf, v, ((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB) | ASN1_STRFLGS_UTF8_CONVERT)); } /* ensure null termination of the BIO's content */ nullterm = '\0'; BIO_write(membuf, &nullterm, 1); size = BIO_get_mem_data(membuf, &sp); dp = pg_any_to_server(sp, size - 1, PG_UTF8); result = cstring_to_text(dp); if (dp != sp) pfree(dp); if (BIO_free(membuf) != 1) elog(ERROR, "could not free OpenSSL BIO structure"); PG_RETURN_TEXT_P(result); }
int EVP_add_cipher(const EVP_CIPHER *c) { int r; r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c); if (r == 0) return(0); r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c); return(r); }
QString pki_x509req::getSigAlg() { ASN1_OBJECT *o; if (spki) { o = spki->spkac->pubkey->algor->algorithm; } else { o = request->sig_alg->algorithm; } return QString(OBJ_nid2ln(OBJ_obj2nid(o))); }
void pki_x509req::addAttribute(int nid, QString content) { if (content.isEmpty()) return; ASN1_STRING *a = QStringToAsn1(content, nid); X509_REQ_add1_attr_by_NID(request, nid, a->type, a->data, a->length); ASN1_STRING_free(a); openssl_error(QString("'%1' (%2)").arg(content).arg(OBJ_nid2ln(nid))); }
/* * Equivalent of X509_NAME_oneline that respects encoding * * This function converts X509_NAME structure to the text variable * converting all textual data into current database encoding. * * Parameter: X509_NAME *name X509_NAME structure to be converted * * Returns: text datum which contains string representation of * X509_NAME */ Datum X509_NAME_to_text(X509_NAME *name) { BIO *membuf = BIO_new(BIO_s_mem()); int i, nid, count = X509_NAME_entry_count(name); X509_NAME_ENTRY *e; ASN1_STRING *v; const char *field_name; size_t size, outlen; char *sp; char *dp; text *result; (void) BIO_set_close(membuf, BIO_CLOSE); for (i = 0; i < count; i++) { e = X509_NAME_get_entry(name, i); nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(e)); v = X509_NAME_ENTRY_get_data(e); field_name = OBJ_nid2sn(nid); if (!field_name) field_name = OBJ_nid2ln(nid); BIO_printf(membuf, "/%s=", field_name); ASN1_STRING_print_ex(membuf, v, ((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB) | ASN1_STRFLGS_UTF8_CONVERT)); } i = 0; BIO_write(membuf, &i, 1); size = BIO_get_mem_data(membuf, &sp); dp = (char *) pg_do_encoding_conversion((unsigned char *) sp, size - 1, PG_UTF8, GetDatabaseEncoding()); BIO_free(membuf); outlen = strlen(dp); result = palloc(VARHDRSZ + outlen); memcpy(VARDATA(result), dp, outlen); /* * pg_do_encoding_conversion has annoying habit of returning source * pointer */ if (dp != sp) pfree(dp); VARATT_SIZEP(result) = outlen + VARHDRSZ; PG_RETURN_TEXT_P(result); }
std::string genAlgProperty(const X509* cert) { int nid = 0; OSX_OPENSSL(nid = OBJ_obj2nid(cert->cert_info->key->algor->algorithm)); if (nid == NID_undef) { // Unknown algorithm OID. return ""; } std::string property; OSX_OPENSSL(property = std::string(OBJ_nid2ln(nid))); return property; }
int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) { EVP_PKEY *pkey; ASN1_IA5STRING *chal; int i, n; char *s; BIO_printf(out, "Netscape SPKI:\n"); i = OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm); BIO_printf(out, " Public Key Algorithm: %s\n", (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i)); pkey = X509_PUBKEY_get(spki->spkac->pubkey); if (!pkey) BIO_printf(out, " Unable to load public key\n"); else { EVP_PKEY_print_public(out, pkey, 4, NULL); EVP_PKEY_free(pkey); } chal = spki->spkac->challenge; if (chal->length) BIO_printf(out, " Challenge String: %s\n", chal->data); i = OBJ_obj2nid(spki->sig_algor.algorithm); BIO_printf(out, " Signature Algorithm: %s", (i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i)); n = spki->signature->length; s = (char *)spki->signature->data; for (i = 0; i < n; i++) { if ((i % 18) == 0) BIO_write(out, "\n ", 7); BIO_printf(out, "%02x%s", (unsigned char)s[i], ((i + 1) == n) ? "" : ":"); } BIO_write(out, "\n", 1); return 1; }