diff options
author | Endi S. Dewata <edewata@redhat.com> | 2010-10-15 12:22:01 -0500 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2010-10-15 14:26:07 -0400 |
commit | 4c24581b5cffaffbb200152e1d43931c0d674102 (patch) | |
tree | 2f9aa6c8b7a2875804e1af834c7fc8e02d0a7973 /install/static/certificate.js | |
parent | acf5f9cad7438268148dff6c6b74d8c63048409a (diff) | |
download | freeipa-4c24581b5cffaffbb200152e1d43931c0d674102.tar.gz freeipa-4c24581b5cffaffbb200152e1d43931c0d674102.tar.xz freeipa-4c24581b5cffaffbb200152e1d43931c0d674102.zip |
Service certificate UI.
The service.py has been modified to include certificate info in
the service-show result if the service contains usercertificate.
A new file certificate.js has been added to store codes related
to certificates (e.g. revocation reasons, dialog boxes). The
service.js has been modified to provide the UI for certificate
management. The certificate.js can also be used for host
certificate management.
The Makefile.am and index.xhtml has been modified to include
certificate.js. New test data files have been added for certificate
operations.
To test revoke and restore operations the server needs to be
installed with dogtag CA instead of self-signed CA.
The certificate status and revocation reason in the details page
will be implemented in subsequent patches. Unit tests will also
be added in subsequent patches.
Diffstat (limited to 'install/static/certificate.js')
-rwxr-xr-x | install/static/certificate.js | 381 |
1 files changed, 381 insertions, 0 deletions
diff --git a/install/static/certificate.js b/install/static/certificate.js new file mode 100755 index 000000000..4302e2f81 --- /dev/null +++ b/install/static/certificate.js @@ -0,0 +1,381 @@ +/* Authors: + * Endi Sukma Dewata <edewata@redhat.com> + * + * Copyright (C) 2010 Red Hat + * see file 'COPYING' for use and warranty information + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 only + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +var BEGIN_CERTIFICATE_REQUEST = '-----BEGIN CERTIFICATE REQUEST-----'; +var END_CERTIFICATE_REQUEST = '-----END CERTIFICATE REQUEST-----'; + +var CRL_REASON = [ + 'Unspecified', + 'Key Compromise', + 'CA Compromise', + 'Affiliation Changed', + 'Superseded', + 'Cessation of Operation', + 'Certificate Hold', + null, + 'Remove from CRL', + 'Privilege Withdrawn', + 'AA Compromise' +]; + +function certificate_parse_dn(dn) { + + var result = {}; + + // TODO: Use proper LDAP DN parser + var rdns = dn.split(','); + for (var i=0; i<rdns.length; i++) { + var rdn = rdns[i]; + var parts = rdn.split('='); + var name = parts[0].toLowerCase(); + var value = parts[1]; + + result[name] = value; + } + + return result; +} + +function certificate_confirmation_dialog(spec) { + var that = {}; + spec = spec || {}; + + var dialog = $('<div/>', { + 'title': spec.title + }); + + dialog.append(spec.message); + + that.open = function() { + dialog.dialog({ + modal: true, + width: 300, + height: 150, + buttons: { + 'Close': function() { + dialog.dialog('destroy'); + } + } + }); + }; + + return that; +} + +function certificate_get_dialog(spec) { + var that = {}; + spec = spec || {}; + + var dialog = $('<div/>', { + 'title': spec.title + }); + + var textarea = $('<textarea/>', { + readonly: 'yes', + style: 'width: 100%; height: 275px;' + }).appendTo(dialog); + + textarea.val( + BEGIN_CERTIFICATE_REQUEST+'\n'+ + spec.usercertificate+'\n'+ + END_CERTIFICATE_REQUEST + ); + + that.open = function() { + dialog.dialog({ + modal: true, + width: 500, + height: 400, + buttons: { + 'Close': function() { + dialog.dialog('destroy'); + } + } + }); + }; + + return that; +} + +function certificate_revoke_dialog(spec) { + var that = {}; + spec = spec || {}; + + var dialog = $('<div/>', { + 'title': spec.title + }); + + var table = $('<table/>').appendTo(dialog); + + var tr = $('<tr/>').appendTo(table); + + var td = $('<td/>').appendTo(tr); + td.append('Note:'); + + td = $('<td/>').appendTo(tr); + td.append( + 'To confirm your intention to revoke this certificate, '+ + 'select a reason from the pull-down list, and click '+ + 'the "Revoke" button.'); + + tr = $('<tr/>').appendTo(table); + + td = $('<td/>').appendTo(tr); + td.append('Reason for Revocation:'); + + td = $('<td/>').appendTo(tr); + + var select = $('<select/>').appendTo(td); + for (var i=0; i<CRL_REASON.length; i++) { + if (!CRL_REASON[i]) continue; + $('<option/>', { + 'value': i, + 'html': CRL_REASON[i] + }).appendTo(select); + } + + that.open = function() { + dialog.dialog({ + modal: true, + width: 500, + height: 300, + buttons: { + 'Revoke': function() { + var values = {}; + values['reason'] = select.val(); + if (spec.revoke) { + spec.revoke(values); + } + dialog.dialog('destroy'); + }, + 'Cancel': function() { + dialog.dialog('destroy'); + } + } + }); + }; + + return that; +} + +function certificate_restore_dialog(spec) { + var that = {}; + spec = spec || {}; + + var dialog = $('<div/>', { + 'title': spec.title + }); + + dialog.append( + 'To confirm your intention to restore this certificate, '+ + 'click the "Restore" button.'); + + that.open = function() { + dialog.dialog({ + modal: true, + width: 400, + height: 200, + buttons: { + 'Restore': function() { + var values = {}; + if (spec.restore) { + spec.restore(values); + } + dialog.dialog('destroy'); + }, + 'Cancel': function() { + dialog.dialog('destroy'); + } + } + }); + }; + + return that; +} + +function certificate_view_dialog(spec) { + var that = {}; + spec = spec || {}; + + that.subject = certificate_parse_dn(spec.subject); + that.issuer = certificate_parse_dn(spec.issuer); + + var dialog = $('<div/>', { + 'title': spec.title + }); + + var table = $('<table/>').appendTo(dialog); + + var tr = $('<tr/>').appendTo(table); + $('<td/>', { + 'colspan': 2, + 'html': '<h3>Issued To</h3>' + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Common Name:</td>').appendTo(tr); + $('<td/>', { + 'html': that.subject.cn + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Organization:</td>').appendTo(tr); + $('<td/>', { + 'html': that.subject.o + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Organizational Unit:</td>').appendTo(tr); + $('<td/>', { + 'html': that.subject.ou + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Serial Number:</td>').appendTo(tr); + $('<td/>', { + 'html': spec.serial_number + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td/>', { + 'colspan': 2, + 'html': '<h3>Issued By</h3>' + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Common Name:</td>').appendTo(tr); + $('<td/>', { + 'html': that.issuer.cn + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Organization:</td>').appendTo(tr); + $('<td/>', { + 'html': that.issuer.o + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Organizational Unit:</td>').appendTo(tr); + $('<td/>', { + 'html': that.issuer.ou + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td/>', { + 'colspan': 2, + 'html': '<h3>Validity</h3>' + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Issued On:</td>').appendTo(tr); + $('<td/>', { + 'html': spec.issued_on + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Expires On:</td>').appendTo(tr); + $('<td/>', { + 'html': spec.expires_on + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td/>', { + 'colspan': 2, + 'html': '<h3>Fingerprints</h3>' + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>SHA1 Fingerprint:</td>').appendTo(tr); + $('<td/>', { + 'html': spec.sha1_fingerprint + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>MD5 Fingerprint:</td>').appendTo(tr); + $('<td/>', { + 'html': spec.md5_fingerprint + }).appendTo(tr); + + that.open = function() { + dialog.dialog({ + modal: true, + width: 600, + height: 500, + buttons: { + 'Close': function() { + dialog.dialog('destroy'); + } + } + }); + }; + + return that; +} + +function certificate_request_dialog(spec) { + var that = {}; + spec = spec || {}; + + var dialog = $('<div/>', { + 'title': spec.title + }); + + dialog.append('Copy and paste the Base64-encoded CSR below:'); + dialog.append('<br/>'); + dialog.append('<br/>'); + + dialog.append(BEGIN_CERTIFICATE_REQUEST); + dialog.append('<br/>'); + + var textarea = $('<textarea/>', { + style: 'width: 100%; height: 225px;' + }).appendTo(dialog); + + dialog.append('<br/>'); + dialog.append(END_CERTIFICATE_REQUEST); + + that.open = function() { + dialog.dialog({ + modal: true, + width: 500, + height: 400, + buttons: { + 'Issue': function() { + var values = {}; + var request = textarea.val(); + request = + BEGIN_CERTIFICATE_REQUEST+'\n'+ + $.trim(request)+'\n'+ + END_CERTIFICATE_REQUEST+'\n'; + values['request'] = request; + if (spec.request) { + spec.request(values); + } + dialog.dialog('destroy'); + }, + 'Cancel': function() { + dialog.dialog('destroy'); + } + } + }); + }; + + return that; +} |