[lxc-devel] [pylxd/master] Fix the cert handling.

rockstar on Github lxc-bot at linuxcontainers.org
Sun Jun 26 00:06:38 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 617 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160626/90591573/attachment.bin>
-------------- next part --------------
From ba63defee76fb3a429076ea584ac4ba1e98c9a14 Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Sat, 25 Jun 2016 18:04:18 -0600
Subject: [PATCH] Fix the cert handling.

---
 pylxd/certificate.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/pylxd/certificate.py b/pylxd/certificate.py
index d116b63..5b395a1 100644
--- a/pylxd/certificate.py
+++ b/pylxd/certificate.py
@@ -50,9 +50,13 @@ def all(cls, client):
     def create(cls, client, password, cert_data):
         """Create a new certificate."""
         cert = x509.load_pem_x509_certificate(cert_data, default_backend())
+        base64_cert = cert.public_bytes(Encoding.PEM).decode('utf-8')
+        if base64_cert.startswith('-----BEGIN CERTIFICATE-----'):
+            base64_cert = '\n'.join(
+                base64_cert.split('\n')[1:-2])
         data = {
             'type': 'client',
-            'certificate': cert.public_bytes(Encoding.PEM).decode('utf-8'),
+            'certificate': base64_cert,
             'password': password,
         }
         client.api.certificates.post(json=data)


More information about the lxc-devel mailing list