/* Authors: * Endi Sukma Dewata * Petr Vobornik * * 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, either version 3 of the License, or * (at your option) any later version. * * 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, see . */ define([ 'dojo/_base/lang', './metadata', './ipa', './jquery', './menu', './phases', './reg', './rpc', './text', './dialog'], function(lang, metadata_provider, IPA, $, menu, phases, reg, rpc, text) { var exp = IPA.cert = {}; IPA.cert.BEGIN_CERTIFICATE = '-----BEGIN CERTIFICATE-----'; IPA.cert.END_CERTIFICATE = '-----END CERTIFICATE-----'; IPA.cert.BEGIN_CERTIFICATE_REQUEST = '-----BEGIN CERTIFICATE REQUEST-----'; IPA.cert.END_CERTIFICATE_REQUEST = '-----END CERTIFICATE REQUEST-----'; /* * Pre-compiled regular expression to match a PEM cert. * * regexp group 1: entire canonical cert (delimiters plus base64) * regexp group 2: base64 data inside PEM delimiters */ IPA.cert.PEM_CERT_REGEXP = RegExp('(-----BEGIN CERTIFICATE-----([^-]*)-----END CERTIFICATE-----)'); /* * Pre-compiled regular expression to match a CSR (Certificate Signing Request). * The delimiter "CERTIFICATE REQUEST" is the cononical standard, however some legacy * software will produce a delimiter with "NEW" in it, i.e. "NEW CERTIFICATE REQUEST" * This regexp will work with either form. * * regexp group 1: entire canonical CSR (delimiters plus base64) * regexp group 2: base64 data inside canonical CSR delimiters * regexp group 3: entire legacy CSR (delimiters plus base64) * regexp group 4: base64 data inside legacy CSR delimiters */ IPA.cert.PEM_CSR_REGEXP = RegExp('(-----BEGIN CERTIFICATE REQUEST-----([^-]*)-----END CERTIFICATE REQUEST-----)|(-----BEGIN NEW CERTIFICATE REQUEST-----([^-]*)-----END NEW CERTIFICATE REQUEST-----)'); IPA.cert.CERTIFICATE_STATUS_MISSING = 0; IPA.cert.CERTIFICATE_STATUS_VALID = 1; IPA.cert.CERTIFICATE_STATUS_REVOKED = 2; IPA.cert.CRL_REASON = [ 'unspecified', 'key_compromise', 'ca_compromise', 'affiliation_changed', 'superseded', 'cessation_of_operation', 'certificate_hold', null, 'remove_from_crl', 'privilege_withdrawn', 'aa_compromise' ]; IPA.cert.parse_dn = function(dn) { var result = {}; if (!dn) return result; // TODO: Use proper LDAP DN parser var rdns = dn.split(','); for (var i=0; i */ /* * Does the text already have the PEM delimiters? * If so just return the text unmodified. */ if (text.match(IPA.cert.PEM_CERT_REGEXP)) { return text; } /* No PEM delimiters so format the base64 & add the delimiters. */ return IPA.cert.BEGIN_CERTIFICATE + "\n" + IPA.cert.pem_format_base64(text) + "\n" + IPA.cert.END_CERTIFICATE; }; IPA.cert.pem_csr_format = function(text) { /* * Input is assumed to be either PEM formated data or the base64 * encoding of DER binary certificate request (csr) data. Return * data in PEM format. The function checks if the input text is * PEM formatted, if so it just returns the input text. Otherwise * the input is treated as base64 which is formatted to be PEM> */ /* * Does the text already have the PEM delimiters? * If so just return the text unmodified. */ if (text.match(IPA.cert.PEM_CSR_REGEXP)) { return text; } /* No PEM delimiters so format the base64 & add the delimiters. */ return IPA.cert.BEGIN_CERTIFICATE_REQUEST + "\n" + IPA.cert.pem_format_base64(text) + "\n" + IPA.cert.END_CERTIFICATE_REQUEST; }; IPA.cert.download_dialog = function(spec) { spec = spec || {}; var that = IPA.dialog(spec); that.width = spec.width || 500; that.height = spec.height || 380; that.add_pem_delimiters = typeof spec.add_pem_delimiters == 'undefined' ? true : spec.add_pem_delimiters; that.certificate = spec.certificate || ''; that.create_button({ name: 'close', label: '@i18n:buttons.close', click: function() { that.close(); } }); that.create_content = function() { var textarea = $('