Hello,

patch for https://fedorahosted.org/freeipa/ticket/5311 is attached.

--
Pavel^3 Vomacka


>From 01d99f2a8b576c48ccf31c8dbccb293021104f5e Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvoma...@redhat.com>
Date: Tue, 15 Mar 2016 11:51:35 +0100
Subject: [PATCH] Show certificate in useful format

Certificates are shown in PEM format which includes BEGIN and END CERTIFICATE string
and all lines are wrapped at 64 characters.

https://fedorahosted.org/freeipa/ticket/5311
---
 install/ui/src/freeipa/certificate.js | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/install/ui/src/freeipa/certificate.js b/install/ui/src/freeipa/certificate.js
index ae05ebb3d45974cd1df50c16e19d0ab9fd27a19b..ef36f5c08c7d3e5674fcd2aa671ed0d0b579547a 100755
--- a/install/ui/src/freeipa/certificate.js
+++ b/install/ui/src/freeipa/certificate.js
@@ -182,6 +182,29 @@ IPA.cert.pem_csr_format = function(text) {
            IPA.cert.END_CERTIFICATE_REQUEST;
 };
 
+IPA.cert.cert_to_html_format = function(text) {
+    /*
+     * Input is assumed to be eihter PEM formatted data or the base64
+     * encoding of DER binary certificate data. Return data in PEM
+     * format is prepared for using in html. All line breaks are
+     * substituted with <br> element. The function checks if the input
+     * is PEM formatted, if so it parses base64 part and then it uses
+     * this part for creating PEM formated certificate. This is done
+     * because of possibility of missing new lines in base64 encoded
+     * part. Otherwise the input is in the base64 format and it is
+     * retransformed into PEM format with HTML new lines.
+     */
+    if (text.match(IPA.cert.PEM_CERT_REGEXP)) {
+        var matched_groups = IPA.cert.PEM_CERT_REGEXP.exec(text);
+        var base64 = matched_groups[2];
+        text = base64;
+    }
+
+    var formatted = IPA.cert.pem_cert_format(text);
+
+    return formatted.replace(/\n+/g,"<br>");
+};
+
 IPA.cert.download_dialog = function(spec) {
 
     spec = spec || {};
@@ -1056,10 +1079,11 @@ IPA.cert.cert_widget = function(spec) {
 
         if (l && that.certs_visible) {
             for (var i=0; i<l; i++) {
+                var cert = IPA.cert.cert_to_html_format(that.certificates[i]);
                 $('<div/>', {
-                    'class': 'certificate',
-                    text: that.certificates[i]
-                }).appendTo(that.content_el);
+                    'class': 'certificate'
+                }).html(cert)
+                  .appendTo(that.content_el);
             }
             $('<div/>').append(
                 IPA.button({
-- 
2.5.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to