{"size": 2383, "ext": "js", "max_stars_repo_path": "node_modules/node-opcua/node_modules/node-opcua-pki/lib/pki/obsolete.js", "max_stars_repo_name": "MPPilon/RasPiNode-HistoricalAccess", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/node-opcua/node_modules/node-opcua-pki/lib/pki/obsolete.js", "max_issues_repo_name": "MPPilon/RasPiNode-HistoricalAccess", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/node-opcua/node_modules/node-opcua-pki/lib/pki/obsolete.js", "max_forks_repo_name": "MPPilon/RasPiNode-HistoricalAccess", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 44.1296296296, "max_line_length": 152, "alphanum_fraction": 0.6793957197}
"use strict"
/**
 *
 * @param certificate_file       {String} the certificate filename to generate
 * @param csr_file               {String} the certificate signing request
 * @param params                 {Object}
 * @param params.applicationUri  {String} the applicationUri
 * @param params.startDate       {Date}   startDate of the certificate
 * @param params.duration        {Number} duration in date
 * @param callback               {Function}
 */
exports.signCertificateRequestInCA = function signCertificateRequestInCA(certificate_file, csr_file, params, callback) {

    assert(fs.existsSync(params.configFile));
    if (!check_certificate_filename(certificate_file)){ return callback(); }

    toolbox.adjustDate(params);
    toolbox.adjustApplicationUri(params);
    toolbox.processAltNames(params);

    var options = {cwd: params.rootDir } ;
    var configOption = " -config " + n(params.configFile);
    // this require OPENSSL_CONF to be set
    assert(fs.existsSync(process.env.OPENSSL_CONF));

    var tasks = [];

    tasks.push(displaySubtitle.bind(null, "- then we ask the authority to sign the certificate signing request"));
    tasks.push(execute_openssl.bind(null, "ca " + configOption +
        " -startdate " + toolbox.x509Date(params.startDate) +
        " -enddate " + toolbox.x509Date(params.endDate) +
        " -batch -out " + q(n(certificate_file)) + " -in " + q(n(csr_file)), options));



    tasks.push(displaySubtitle.bind(null, "- dump the certificate for a check"));
    tasks.push(execute_openssl.bind(null, "x509 -in " + certificate_file + "  -dates -fingerprint -purpose -noout", {}));

    tasks.push(displaySubtitle.bind(null, "- construct CA certificate with CRL"));
    tasks.push(constructCACertificateWithCRL.bind(null));

    // construct certificate chain
    //   concatenate certificate with CA Certificate and revocation list
    tasks.push(displaySubtitle.bind(null, "- construct certificate chain"));
    tasks.push(constructCertificateChain.bind(null, false, certificate_file));


    // todo
    // tasks.push(displaySubtitle.bind(null, "- verify certificate against the root CA"));
    // tasks.push(execute_openssl_no_failure.bind(null, "verify -verbose -CAfile " + config.caCertificate_With_CRL + " " + certificate_file, options));

    async.series(tasks, callback);
};
