Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse multiple certificates in CA chain #28

Open
tracend opened this issue Jun 22, 2019 · 0 comments
Open

Parse multiple certificates in CA chain #28

tracend opened this issue Jun 22, 2019 · 0 comments

Comments

@tracend
Copy link
Member

tracend commented Jun 22, 2019

CA certs may be many in number, in which case they can be parsed and served as an array of certs, as noted in this article:
http://nodejs.md/blog/https-server-with-multiple-domains-on-same-port-and-instance/

This is the relevant code:

function sslCAdecode(source) {
	var ca		= [];
	if (!source || typeof(source) !== "string")
		return ca;
		ca = source.split(/-----END CERTIFICATE-----[\s\n]+-----BEGIN CERTIFICATE-----/).map(function (v, k, arr) {
			if (k) {
				v = '-----BEGIN CERTIFICATE-----' + v;
			}
			if (k !== arr.length - 1) {
				v = v + '-----END CERTIFICATE-----';
			}
			v = v.replace(/^\n+/,'').replace(/\n+$/,'');
			return v;
		});
	return ca;
};

Use:

creds.ca = sslCAdecode( fs.readFileSync( site.credentials.ca, 'utf8') );
@tracend tracend changed the title Parse multiple certificates in CA chain #enhancement Parse multiple certificates in CA chain Jun 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant