12#include <openssl/x509.h>
13#include <openssl/x509v3.h>
14#include <openssl/asn1.h>
160 membuf = BIO_new(BIO_s_mem());
163 (
errcode(ERRCODE_OUT_OF_MEMORY),
164 errmsg(
"could not create OpenSSL BIO structure")));
165 (void) BIO_set_close(membuf, BIO_CLOSE);
166 ASN1_STRING_print_ex(membuf,
str,
167 ((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
168 | ASN1_STRFLGS_UTF8_CONVERT));
171 BIO_write(membuf, &nullterm, 1);
172 size = BIO_get_mem_data(membuf, &sp);
177 if (BIO_free(membuf) != 1)
178 elog(
ERROR,
"could not free OpenSSL BIO structure");
199 char *string_fieldname;
205 nid = OBJ_txt2nid(string_fieldname);
206 if (nid == NID_undef)
208 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
209 errmsg(
"invalid X.509 field name: \"%s\"",
211 pfree(string_fieldname);
212 index = X509_NAME_get_index_by_NID(
name, nid, -1);
215 data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(
name,
index));
382 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
383 errmsg(
"function returning record called in context that cannot accept type record")));
387 max_calls = cert != NULL ? X509_get_ext_count(cert) : 0;
416 if (call_cntr < max_calls)
430 membuf = BIO_new(BIO_s_mem());
433 (
errcode(ERRCODE_OUT_OF_MEMORY),
434 errmsg(
"could not create OpenSSL BIO structure")));
437 ext = X509_get_ext(cert, call_cntr);
438 obj = X509_EXTENSION_get_object(ext);
441 nid = OBJ_obj2nid(obj);
442 if (nid == NID_undef)
444 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
445 errmsg(
"unknown OpenSSL extension in certificate at position %d",
451 if (X509V3_EXT_print(membuf, ext, 0, 0) <= 0)
453 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
454 errmsg(
"could not print extension value in certificate at position %d",
456 len = BIO_get_mem_data(membuf, &
buf);
468 if (BIO_free(membuf) != 1)
469 elog(
ERROR,
"could not free OpenSSL BIO structure");
Datum numeric_in(PG_FUNCTION_ARGS)
const char * be_tls_get_version(Port *port)
const char * be_tls_get_cipher(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)
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 MemoryContext MemoryContextSwitchTo(MemoryContext context)
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)
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)
PG_MODULE_MAGIC_EXT(.name="sslinfo",.version=PG_VERSION)
Datum ssl_is_used(PG_FUNCTION_ARGS)
MemoryContext multi_call_memory_ctx
text * cstring_to_text_with_len(const char *s, int len)
text * cstring_to_text(const char *s)
char * text_to_cstring(const text *t)