<commit_before>/**
 *	Copyright (C) 2014 3D Repo Ltd
*
*	This program is free software: you can redistribute it and/or modify
*	it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
*	You should have received a copy of the GNU Affero General Public License
*	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

"use strict";

const express = require("express");
const fs = require("fs");

const logger = require("./logger.js");
const systemLogger = logger.systemLogger;

const config = require("./config.js");

const https = require("https");
const http = require("http");
const tls  = require("tls");
const vhost = require("vhost");

const certs = {};
const certMap = {};
let sslOptions = {};

function setupSSL() {
	if ("ssl" in config) {

		for (const certGroup in config.ssl) {

			if (config.ssl.hasOwnProperty(certGroup)) {
				const certGroupOptions = {};

				certGroupOptions.key = fs.readFileSync(config.ssl[certGroup].key, "utf8");
				certGroupOptions.cert = fs.readFileSync(config.ssl[certGroup].cert, "utf8");

				if (config.ssl[certGroup].ca) {
					certGroupOptions.ca = fs.readFileSync(config.ssl[certGroup].ca, "utf8");
				}

				certs[certGroup] = tls.createSecureContext(certGroupOptions);

			}

		}

		sslOptions = {
			SNICallback: function(domain, callback) {
				const certGroup = certMap[domain];
				callback(null, certs[certGroup]);
			},
			key: fs.readFileSync(config.ssl["default"].key, "utf8"),
			cert: fs.readFileSync(config.ssl["default"].cert, "utf8"),
			ciphers: "ECDHE-ECDSA-AES128-GCM-SHA256|ECDHE-ECDSA-AES256-SHA:!RC4:!aNULL",
			// ciphers: "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PS:!SSLv3",
			honorCipherOrder: true,
			ecdhCurve: "secp384r1",
			secureOptions: tls.constants.SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION |
						tls.constants.SSL_OP_NO_SSLv2 |
						tls.constants.SSL_OP_NO_SSLv3
		};

		// This is the optional certificate authority<commit_msg>ISSUE #1106 fix SSL constants (#1113)<commit_after>/**
 *	Copyright (C) 2014 3D Repo Ltd
*
*	This program is free software: you can redistribute it and/or modify
*	it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
*	You should have received a copy of the GNU Affero General Public License
*	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

"use strict";

const express = require("express");
const fs = require("fs");

const logger = require("./logger.js");
const systemLogger = logger.systemLogger;

const config = require("./config.js");

const https = require("https");
const http = require("http");
const tls  = require("tls");
const vhost = require("vhost");
const crypto = require("crypto");

const certs = {};
const certMap = {};
let sslOptions = {};

function setupSSL() {
	if ("ssl" in config) {

		for (const certGroup in config.ssl) {

			if (config.ssl.hasOwnProperty(certGroup)) {
				const certGroupOptions = {};

				certGroupOptions.key = fs.readFileSync(config.ssl[certGroup].key, "utf8");
				certGroupOptions.cert = fs.readFileSync(config.ssl[certGroup].cert, "utf8");

				if (config.ssl[certGroup].ca) {
					certGroupOptions.ca = fs.readFileSync(config.ssl[certGroup].ca, "utf8");
				}

				certs[certGroup] = tls.createSecureContext(certGroupOptions);

			}

		}

		sslOptions = {
			SNICallback: function(domain, callback) {
				const certGroup = certMap[domain];
				callback(null, certs[certGroup]);
			},
			key: fs.readFileSync(config.ssl["default"].key, "utf8"),
			cert: fs.readFileSync(config.ssl["default"].cert, "utf8"),
			ciphers: "ECDHE-ECDSA-AES128-GCM-SHA256|ECDHE-ECDSA-AES256-SHA:!RC4:!aNULL",
			// ciphers: "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PS:!SSLv3",
			honorCipherOrder: true,
			ecdhCurve: "secp384r1",
			secureOptions: crypto.constants.SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION |
						crypto.constants.SSL_OP_NO_SSLv2 |
						crypto.constants.SSL_OP_NO_SSLv3
		};

		// This is the optional certificate authority
{'fraction_non_alphanumeric': 0.13841452453712025, 'fraction_numerical': 0.04278267122056444, 'mean_word_length': 4.631578947368421, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5585011', 'n_tokens_mistral': 2369, 'n_tokens_neox': 1963, 'n_words': 417}