Example #1
0
        it("load root ca times", () => {
            function count(ca) {
                var cnt = 1;
                var ca1;

                while (ca1 = ca.next) {
                    cnt++;
                    ca = ca1;
                }

                return cnt;
            }

            cert.clear();
            assert.deepEqual(cert.dump(), []);

            cert.loadRootCerts();
            var cnt1 = count(cert);

            cert.loadRootCerts();
            assert.equal(cnt1, count(cert));

            cert.clear();
            assert.deepEqual(cert.dump(), []);

            cert.loadRootCerts();
            assert.equal(cnt1, count(cert));
        });
Example #2
0
		it("load file", function() {
			var s = cert.dump();
			cert.clear();
			assert.deepEqual(cert.dump(), []);

			var fl = fs.readdir('cert_files/');
			fl.forEach(function(s) {
				if (!s.isDirectory() && s.name.match(/\.crt/))
					cert.loadFile('cert_files/' + s.name);
			});

			assert.deepEqual(cert.dump(), s);
		});
Example #3
0
        it("load file", () => {
            var s = cert.dump();
            cert.clear();
            assert.deepEqual(cert.dump(), []);

            var fl = fs.readdir('cert_files/');
            fl.forEach((s) => {
                if (s.match(/\.crt/))
                    cert.loadFile('cert_files/' + s);
            });

            assert.deepEqual(cert.dump(), s);
        });
Example #4
0
        it("root ca", () => {
            cert.clear();
            assert.deepEqual(cert.dump(), []);

            cert.load(fs.readTextFile('cert_files/ca-bundle.crt'));
            var s = cert.dump();

            cert.clear();
            assert.deepEqual(cert.dump(), []);

            cert.loadRootCerts();
            var s1 = cert.dump();

            assert.deepEqual(s, s1.slice(s1.length - s.length));
        });
Example #5
0
		it("root ca", function() {
			cert.clear();
			assert.deepEqual(cert.dump(), []);

			cert.load(fs.readFile('cert_files/ca-bundle.crt'));
			var s = cert.dump();

			cert.clear();
			assert.deepEqual(cert.dump(), []);

			cert.loadRootCerts();
			var s1 = cert.dump();

			assert.deepEqual(s, s1.slice(29));
		});
Example #6
0
        it("info", () => {
            cert.clear();
            assert.deepEqual(cert.dump(), []);

            cert.load(ca1);
            assert.equal(cert.version, 3);
            assert.equal(cert.serial, "17");
            assert.equal(cert.issuer, "C=NL, O=PolarSSL, CN=PolarSSL Test CA");
            assert.equal(cert.subject, "C=NL, O=PolarSSL, CN=www.example.com");
            assert.deepEqual(cert.notBefore, new Date("May 10 13:23:41 2012 GMT"));
            assert.deepEqual(cert.notAfter, new Date("May 11 13:23:41 2022 GMT"));
            assert.equal(cert.ca, false);
            assert.equal(cert.pathlen, 0);
            assert.equal(cert.usage, "");
            assert.equal(cert.type, "");
            assert.equal(cert.publicKey, pk);

            cert.load(ca2);

            var cert1 = cert.next;
            assert.equal(cert1.issuer, "C=NL, O=PolarSSL, CN=PolarSSL Test CA");
            assert.equal(cert1.subject, "C=NL, O=PolarSSL, CN=PolarSSL Cert SHA224");
            assert.deepEqual(cert1.notBefore, new Date("Feb 12 14:44:07 2011 GMT"));
            assert.deepEqual(cert1.notAfter, new Date("Feb 12 14:44:07 2021 GMT"));
            assert.equal(cert1.ca, false);
            assert.equal(cert1.pathlen, 0);
            assert.equal(cert1.usage, "");
            assert.equal(cert1.type, "");
            assert.equal(cert1.publicKey, pk);
        });
Example #7
0
        it("certdata.txt", () => {
            cert.clear();
            assert.deepEqual(cert.dump(), []);

            cert.load(fs.readTextFile('cert_files/certdata.txt'));
            var s = cert.dump();
            assert.notDeepEqual(s, []);

            cert.clear();
            assert.deepEqual(cert.dump(), []);

            cert.load(fs.readTextFile('cert_files/ca-bundle.crt'));
            var s1 = cert.dump();

            assert.deepEqual(s.slice(s.length - s1.length), s1);
        });
Example #8
0
        it("clear/export", () => {
            var s = cert.dump();
            cert.clear();
            assert.deepEqual(cert.dump(), []);

            s.forEach((c) => {
                cert.load(c);
            });

            assert.deepEqual(cert.dump(), s);

            cert.clear();
            cert.load(s.join('\n'));

            assert.deepEqual(cert.dump(), s);
        });
Example #9
0
		it("certdata.txt", function() {
			cert.clear();
			assert.deepEqual(cert.dump(), []);

			cert.load(fs.readFile('cert_files/certdata.txt'));
			var s = cert.dump();
			assert.notDeepEqual(s, []);

			cert.clear();
			assert.deepEqual(cert.dump(), []);

			cert.load(fs.readFile('cert_files/ca-bundle.crt'));
			var s1 = cert.dump();

			assert.deepEqual(s.slice(29), s1);
		});
Example #10
0
		it("clear/export", function() {
			var s = cert.dump();
			cert.clear();
			assert.deepEqual(cert.dump(), []);

			s.forEach(function(c) {
				cert.load(c);
			});

			assert.deepEqual(cert.dump(), s);

			cert.clear();
			cert.load(s.join('\n'));

			assert.deepEqual(cert.dump(), s);
		});
Example #11
0
var crypto = require("crypto");
var fs = require("fs");

var cert = new crypto.X509Cert();
cert.loadFile('certdata.txt');
var a = cert.dump();
var a1 = [];

for (var i = 0; i < a.length; i++) {
	var txt = a[i];
	cert.clear();
	cert.load(txt);
	txt = txt.replace('-----BEGIN CERTIFICATE-----', '').replace('-----END CERTIFICATE-----', '');

	var buf = new Buffer(txt, 'base64');
	txt = buf.hex();
	var b = txt.match(/(.{1,2})/g);
	txt = '\\x' + b.join('\\x');
	var b = txt.match(/(.{1,80})/g);
	txt = '        "' + b.join('"\n        "') + '"';

	a1.push('    {');
	a1.push('        ' + buf.length + ',');
	a1.push(txt);
	a1.push('    },');
}

var txts = ['/***************************************************************************',
	' *                                                                         *',
	' *   This file was automatically generated using gen_root.js               *',
	' *   PLEASE DO NOT EDIT!!!!                                                *',