12 #include <openssl/x509.h> 13 #include <openssl/x509v3.h> 14 #include <openssl/asn1.h> 157 membuf = BIO_new(BIO_s_mem());
160 (
errcode(ERRCODE_OUT_OF_MEMORY),
161 errmsg(
"could not create OpenSSL BIO structure")));
162 (void) BIO_set_close(membuf, BIO_CLOSE);
163 ASN1_STRING_print_ex(membuf, str,
164 ((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
165 | ASN1_STRFLGS_UTF8_CONVERT));
168 BIO_write(membuf, &nullterm, 1);
169 size = BIO_get_mem_data(membuf, &sp);
174 if (BIO_free(membuf) != 1)
175 elog(
ERROR,
"could not free OpenSSL BIO structure");
196 char *string_fieldname;
202 nid = OBJ_txt2nid(string_fieldname);
203 if (nid == NID_undef)
205 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
206 errmsg(
"invalid X.509 field name: \"%s\"",
208 pfree(string_fieldname);
209 index = X509_NAME_get_index_by_NID(name, nid, -1);
212 data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, index));
379 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
380 errmsg(
"function returning record called in context that cannot accept type record")));
384 max_calls = cert != NULL ? X509_get_ext_count(cert) : 0;
413 if (call_cntr < max_calls)
427 membuf = BIO_new(BIO_s_mem());
430 (
errcode(ERRCODE_OUT_OF_MEMORY),
431 errmsg(
"could not create OpenSSL BIO structure")));
434 ext = X509_get_ext(cert, call_cntr);
435 obj = X509_EXTENSION_get_object(ext);
438 nid = OBJ_obj2nid(obj);
439 if (nid == NID_undef)
441 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
442 errmsg(
"unknown OpenSSL extension in certificate at position %d",
448 if (X509V3_EXT_print(membuf, ext, 0, 0) <= 0)
450 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
451 errmsg(
"could not print extension value in certificate at position %d",
453 len = BIO_get_mem_data(membuf, &buf);
458 values[2] =
BoolGetDatum(X509_EXTENSION_get_critical(ext));
465 if (BIO_free(membuf) != 1)
466 elog(
ERROR,
"could not free OpenSSL BIO structure");
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
static Datum X509_NAME_field_to_text(X509_NAME *name, text *fieldName)
#define SRF_IS_FIRSTCALL()
#define PointerGetDatum(X)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
int errcode(int sqlerrcode)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Datum ssl_client_serial(PG_FUNCTION_ARGS)
#define SRF_PERCALL_SETUP()
Datum ssl_extension_info(PG_FUNCTION_ARGS)
#define PG_GETARG_TEXT_PP(n)
#define SRF_RETURN_NEXT(_funcctx, _result)
Datum ssl_is_used(PG_FUNCTION_ARGS)
static Datum ASN1_STRING_to_text(ASN1_STRING *str)
void pfree(void *pointer)
#define ObjectIdGetDatum(X)
Datum ssl_client_cert_present(PG_FUNCTION_ARGS)
Datum ssl_client_dn_field(PG_FUNCTION_ARGS)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
text * cstring_to_text_with_len(const char *s, int len)
#define CStringGetDatum(X)
Datum numeric_in(PG_FUNCTION_ARGS)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Datum ssl_issuer_dn(PG_FUNCTION_ARGS)
#define PG_RETURN_BOOL(x)
Datum ssl_version(PG_FUNCTION_ARGS)
#define ereport(elevel,...)
Datum ssl_client_dn(PG_FUNCTION_ARGS)
#define PG_RETURN_TEXT_P(x)
text * cstring_to_text(const char *s)
Datum ssl_issuer_field(PG_FUNCTION_ARGS)
MemoryContext multi_call_memory_ctx
#define HeapTupleGetDatum(tuple)
const char * be_tls_get_version(Port *port)
void be_tls_get_peer_issuer_name(Port *port, char *ptr, size_t len)
static Datum values[MAXATTR]
char * text_to_cstring(const text *t)
Datum ssl_cipher(PG_FUNCTION_ARGS)
void be_tls_get_peer_subject_name(Port *port, char *ptr, size_t len)
int errmsg(const char *fmt,...)
void be_tls_get_peer_serial(Port *port, char *ptr, size_t len)
#define CStringGetTextDatum(s)
const char * be_tls_get_cipher(Port *port)
PG_FUNCTION_INFO_V1(ssl_is_used)
char * pg_any_to_server(const char *s, int len, int encoding)
#define SRF_RETURN_DONE(_funcctx)
#define SRF_FIRSTCALL_INIT()