pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone
Blob Blame History Raw
From be6eedde5a5aaf7ad1b527c0cfb9699ccb98a6b5 Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvomacka@redhat.com>
Date: Mon, 27 Mar 2017 14:14:32 +0200
Subject: [PATCH] WebUI: Allow to add certs to certmapping with CERT LINES
 around

The certificate to the certmapping might be inserted as
base64 encoded blob. This patch allows to also insert the certificate
blob with surrounding "-----BEGIN CERTIFICATE-----" and
"-----END CERTIFICATE-----" lines. This behavior is the same in
widget for assigning certificates to users, so the change helps
WebUI to be more consistent.

https://pagure.io/freeipa/issue/6772

Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
---
 install/ui/src/freeipa/plugins/certmap.js | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/install/ui/src/freeipa/plugins/certmap.js b/install/ui/src/freeipa/plugins/certmap.js
index ecbe095b9ead5c3dad70380202836608d564cd58..c613601e989f065a3d6289b02b60563020acf978 100644
--- a/install/ui/src/freeipa/plugins/certmap.js
+++ b/install/ui/src/freeipa/plugins/certmap.js
@@ -8,6 +8,7 @@ define([
         'dojo/_base/declare',
         'dojo/Evented',
         'dojo/on',
+        '../certificate',
         '../navigation',
         '../field',
         '../ipa',
@@ -19,8 +20,8 @@ define([
         // plain imports
         '../search',
         '../entity'],
-            function(lang, declare, Evented, on, navigation, mod_field, IPA,
-                     phases, reg, widget_mod, text, util) {
+            function(lang, declare, Evented, on, certificate, navigation,
+                 mod_field, IPA, phases, reg, widget_mod, text, util) {
 /**
  * Certificate map module
  * @class
@@ -312,6 +313,12 @@ certmap.certmap_multivalued_widget = function (spec) {
         var widget = widgets[0];
         var inner_widgets = widget.widgets.get_widgets();
 
+        var normalize_certs = function(certs) {
+            for (var k = 0, l = certs.length; k<l; k++) {
+                certs[k] = certificate.get_base64(certs[k]);
+            }
+        };
+
         for (var i = 0, l = inner_widgets.length; i<l; i++) {
             var w = inner_widgets[i];
 
@@ -321,6 +328,8 @@ certmap.certmap_multivalued_widget = function (spec) {
 
                 if (field.name === 'issuer' || field.name === 'subject') {
                     value = value[0];
+                } else if (field.name === 'certificate') {
+                    normalize_certs(value);
                 }
 
                 if (!util.is_empty(value)) options[field.name] = value;
-- 
2.12.1