pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0049-ipaldap.py-fix-method-creating-a-ldap-filter-for-IPA.patch

ad1545
From 896c438f1dd7e4aa316503fbf68fef13963d7463 Mon Sep 17 00:00:00 2001
ad1545
From: Florence Blanc-Renaud <flo@redhat.com>
ad1545
Date: Thu, 22 Nov 2018 18:31:38 +0100
ad1545
Subject: [PATCH] ipaldap.py: fix method creating a ldap filter for
ad1545
 IPACertificate
ad1545
ad1545
ipa user-find --certificate and ipa host-find --certificate
ad1545
fail to return matching entries, because the method transforming
ad1545
the attribute into a LDAP filter does not properly handle
ad1545
IPACertificate objects.
ad1545
Directory Server logs show a filter with
ad1545
(usercertificate=ipalib.x509.IPACertificate object at 0x7fc0a5575b90>)
ad1545
ad1545
When the attribute contains a cryptography.x509.Certificate,
ad1545
the method needs to extract the public bytes instead of calling str(value).
ad1545
ad1545
Fixes https://pagure.io/freeipa/issue/7770
ad1545
ad1545
Reviewed-By: Christian Heimes <cheimes@redhat.com>
ad1545
Reviewed-By: Christian Heimes <cheimes@redhat.com>
ad1545
---
ad1545
 ipapython/ipaldap.py | 3 +++
ad1545
 1 file changed, 3 insertions(+)
ad1545
ad1545
diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py
ad1545
index 53fdf4967868961effea7f3f64dfb3c0edfc75f3..a44246e3ee0de5a78de77a593718ecad1aaa0f67 100644
ad1545
--- a/ipapython/ipaldap.py
ad1545
+++ b/ipapython/ipaldap.py
ad1545
@@ -36,6 +36,7 @@ from six.moves.urllib.parse import urlparse
ad1545
 # pylint: enable=import-error
ad1545
 
ad1545
 from cryptography import x509 as crypto_x509
ad1545
+from cryptography.hazmat.primitives import serialization
ad1545
 
ad1545
 import ldap
ad1545
 import ldap.sasl
ad1545
@@ -1276,6 +1277,8 @@ class LDAPClient(object):
ad1545
             ]
ad1545
             return cls.combine_filters(flts, rules)
ad1545
         elif value is not None:
ad1545
+            if isinstance(value, crypto_x509.Certificate):
ad1545
+                value = value.public_bytes(serialization.Encoding.DER)
ad1545
             if isinstance(value, bytes):
ad1545
                 value = binascii.hexlify(value).decode('ascii')
ad1545
                 # value[-2:0] is empty string for the initial '\\'
ad1545
-- 
ad1545
2.17.2
ad1545