URL: https://github.com/freeipa/freeipa/pull/1107
Author: tomaskrizek
 Title: #1107: [Backport][ipa-4-6] py3: fix pkcs7 file processing
Action: opened

PR body:
"""
This PR was opened automatically because PR #1102 was pushed to master and 
backport to ipa-4-6 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1107/head:pr1107
git checkout pr1107
From e3543b1459126d04514efaf0e8508c0199da6e7c Mon Sep 17 00:00:00 2001
From: Fraser Tweedale <ftwee...@redhat.com>
Date: Wed, 20 Sep 2017 18:38:24 +1000
Subject: [PATCH] py3: fix pkcs7 file processing

https://pagure.io/freeipa/issue/7131
---
 ipalib/x509.py                    |  2 +-
 ipatests/test_ipalib/test_x509.py | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/ipalib/x509.py b/ipalib/x509.py
index 0b3a423ce3..9f7a3c3115 100644
--- a/ipalib/x509.py
+++ b/ipalib/x509.py
@@ -475,7 +475,7 @@ def pkcs7_to_certs(data, datatype=PEM):
     """
     if datatype == PEM:
         match = re.match(
-            r'-----BEGIN PKCS7-----(.*?)-----END PKCS7-----',
+            br'-----BEGIN PKCS7-----(.*?)-----END PKCS7-----',
             data,
             re.DOTALL)
         if not match:
diff --git a/ipatests/test_ipalib/test_x509.py b/ipatests/test_ipalib/test_x509.py
index 904152aac1..09b3933892 100644
--- a/ipatests/test_ipalib/test_x509.py
+++ b/ipatests/test_ipalib/test_x509.py
@@ -60,6 +60,31 @@
     b'-----END CERTIFICATE-----'
 )
 
+good_pkcs7 = (
+    b'-----BEGIN PKCS7-----\n'
+    b'MIIDvAYJKoZIhvcNAQcCoIIDrTCCA6kCAQExADALBgkqhkiG9w0BBwGgggOPMIID\n'
+    b'izCCAnOgAwIBAgIBATANBgkqhkiG9w0BAQsFADA2MRQwEgYDVQQKDAtFWEFNUExF\n'
+    b'LkNPTTEeMBwGA1UEAwwVQ2VydGlmaWNhdGUgQXV0aG9y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CLKmvQkotn6UJd8N1X0R2J3\n'
+    b'4/qv0rUtcCnyEBNSgpTGCRlYM4kd98Dqc5W7wUpMcsQMFxQMSYY7pFQkdLPfJEx2\n'
+    b'Mg63SPawxfAgUeukrdsF3wTIKkIBu1TVse+kvRvgmRRrfF2a4ZOv5qORe2uhADEA\n'
+    b'-----END PKCS7-----'
+)
+
 
 class test_x509(object):
     """
@@ -119,3 +144,10 @@ def test_3_cert_contents(self):
         assert cert.serial_number == 1093
         assert cert.not_valid_before == not_before
         assert cert.not_valid_after == not_after
+
+    def test_load_pkcs7_pem(self):
+        certlist = x509.pkcs7_to_certs(good_pkcs7, datatype=x509.PEM)
+        assert len(certlist) == 1
+        cert = certlist[0]
+        assert DN(cert.subject) == DN('CN=Certificate Authority,O=EXAMPLE.COM')
+        assert cert.serial_number == 1
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to