Skip to content

Commit e73ab55

Browse files
committed
support OPT_X_TLS_PEERCERT
1 parent 2fb97af commit e73ab55

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Doc/reference/ldap.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ TLS options
383383

384384
.. py:data:: OPT_X_TLS_PEERCERT
385385
386-
Get peer's certificate as binary ASN.1 data structure (not supported)
386+
Get peer's certificate as binary ASN.1 data structure
387387

388388
.. py:data:: OPT_X_TLS_PROTOCOL_MIN
389389

Modules/options.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "LDAPObject.h"
66
#include "ldapcontrol.h"
77
#include "options.h"
8+
#include "berval.h"
89

910
void
1011
set_timeval_from_double(struct timeval *tv, double d)
@@ -235,6 +236,7 @@ LDAP_get_option(LDAPObject *self, int option)
235236
{
236237
int res;
237238
int intval;
239+
struct berval *bv;
238240
struct timeval *tv;
239241
LDAPAPIInfo apiinfo;
240242
LDAPControl **lcs;
@@ -399,7 +401,20 @@ LDAP_get_option(LDAPObject *self, int option)
399401
v = LDAPControls_to_List(lcs);
400402
ldap_controls_free(lcs);
401403
return v;
402-
404+
#ifdef LDAP_OPT_X_TLS_PEERCERT
405+
case LDAP_OPT_X_TLS_PEERCERT:
406+
#endif
407+
/* Berval-valued options */
408+
res = LDAP_int_get_option(self, option, &bv);
409+
if (res != LDAP_OPT_SUCCESS)
410+
return option_error(res, "ldap_get_option");
411+
if (bv == NULL) {
412+
Py_INCREF(Py_None);
413+
return Py_None;
414+
}
415+
v = LDAPberval_to_object(bv);
416+
ldap_memfree(bv);
417+
return v;
403418
default:
404419
PyErr_Format(PyExc_ValueError, "unknown option %d", option);
405420
return NULL;

Tests/t_ldapobject.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ def test_multiple_starttls(self):
395395
l.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
396396
l.start_tls_s()
397397
l.simple_bind_s(self.server.root_dn, self.server.root_pw)
398+
self.assertEqual(l.get_option(ldap.OPT_X_TLS_PEERCERT), b"eg")
398399
self.assertEqual(l.whoami_s(), 'dn:' + self.server.root_dn)
399400

400401
def test_dse(self):

0 commit comments

Comments
 (0)