12 #include <openssl/x509.h>
13 #include <openssl/x509v3.h>
14 #include <openssl/asn1.h>
168 membuf = BIO_new(BIO_s_mem());
171 (
errcode(ERRCODE_OUT_OF_MEMORY),
172 errmsg(
"could not create OpenSSL BIO structure")));
173 (void) BIO_set_close(membuf, BIO_CLOSE);
174 ASN1_STRING_print_ex(membuf,
str,
175 ((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
176 | ASN1_STRFLGS_UTF8_CONVERT));
179 BIO_write(membuf, &nullterm, 1);
180 size = BIO_get_mem_data(membuf, &sp);
185 if (BIO_free(membuf) != 1)
186 elog(
ERROR,
"could not free OpenSSL BIO structure");
207 char *string_fieldname;
213 nid = OBJ_txt2nid(string_fieldname);
214 if (nid == NID_undef)
216 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
217 errmsg(
"invalid X.509 field name: \"%s\"",
219 pfree(string_fieldname);
220 index = X509_NAME_get_index_by_NID(
name, nid, -1);
223 data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(
name,
index));
390 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
391 errmsg(
"function returning record called in context that cannot accept type record")));
395 max_calls = cert != NULL ? X509_get_ext_count(cert) : 0;
424 if (call_cntr < max_calls)
438 membuf = BIO_new(BIO_s_mem());
441 (
errcode(ERRCODE_OUT_OF_MEMORY),
442 errmsg(
"could not create OpenSSL BIO structure")));
445 ext = X509_get_ext(cert, call_cntr);
446 obj = X509_EXTENSION_get_object(ext);
449 nid = OBJ_obj2nid(obj);
450 if (nid == NID_undef)
452 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
453 errmsg(
"unknown OpenSSL extension in certificate at position %d",
459 if (X509V3_EXT_print(membuf, ext, 0, 0) <= 0)
461 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
462 errmsg(
"could not print extension value in certificate at position %d",
464 len = BIO_get_mem_data(membuf, &
buf);
476 if (BIO_free(membuf) != 1)
477 elog(
ERROR,
"could not free OpenSSL BIO structure");
Datum numeric_in(PG_FUNCTION_ARGS)
const char * be_tls_get_version(Port *port)
void be_tls_get_peer_serial(Port *port, char *ptr, size_t len)
void be_tls_get_peer_issuer_name(Port *port, char *ptr, size_t len)
const char * be_tls_get_cipher(Port *port)
void be_tls_get_peer_subject_name(Port *port, char *ptr, size_t len)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_TEXT_P(x)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_RETURN_BOOL(x)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define SRF_RETURN_DONE(_funcctx)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
char * pg_any_to_server(const char *s, int len, int encoding)
void pfree(void *pointer)
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
MemoryContextSwitchTo(old_ctx)
static pg_noinline void Size size
static Datum X509_NAME_field_to_text(X509_NAME *name, text *fieldName)
Datum ssl_version(PG_FUNCTION_ARGS)
Datum ssl_client_serial(PG_FUNCTION_ARGS)
Datum ssl_issuer_field(PG_FUNCTION_ARGS)
static Datum ASN1_STRING_to_text(ASN1_STRING *str)
Datum ssl_issuer_dn(PG_FUNCTION_ARGS)
Datum ssl_client_dn(PG_FUNCTION_ARGS)
Datum ssl_extension_info(PG_FUNCTION_ARGS)
Datum ssl_cipher(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(ssl_is_used)
Datum ssl_client_dn_field(PG_FUNCTION_ARGS)
Datum ssl_client_cert_present(PG_FUNCTION_ARGS)
Datum ssl_is_used(PG_FUNCTION_ARGS)
MemoryContext multi_call_memory_ctx
char * text_to_cstring(const text *t)
text * cstring_to_text_with_len(const char *s, int len)
text * cstring_to_text(const char *s)