How to use the pkijs.Certificate function in pkijs

To help you get started, we’ve selected a few pkijs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github YuryStrozhevsky / CTjs / src / TimestampedEntry.js View on Github external
// } TimestampedEntry;

		this.timestamp = new Date(utilFromBase(new Uint8Array(stream.getBlock(8)), 8));
		this.entryType = stream.getUint16();
		
		switch(this.entryType)
		{
			case LogEntryType.constants("x509_entry"):
				{
					const certificateLength = stream.getUint24();
					
					const asn1 = asn1js.fromBER((new Uint8Array(stream.getBlock(certificateLength))).buffer.slice(0));
					if(asn1.offset === (-1))
						throw new Error("Object's stream was not correct for TimestampedEntry");
					
					this.signedEntry = new Certificate({ schema: asn1.result });
				}
				break;
			case LogEntryType.constants("precert_entry"):
				this.signedEntry = new PreCert({ stream });
				break;
			default:
				throw new Error("Object's stream was not correct for TimestampedEntry");
		}
		
		const extensionsLength = stream.getUint16();
		
		if(extensionsLength)
			this.extensions = (new Uint8Array(stream.getBlock(extensionsLength))).buffer.slice(0);
	}
	//**********************************************************************************
github PeculiarVentures / fortify / src / main / main.ts View on Github external
function CheckSSL() {
  if (fs.existsSync(APP_SSL_CERT) && fs.existsSync(APP_SSL_KEY)) {
    const sslCert = fs.readFileSync(APP_SSL_CERT, "utf8").replace(/-{5}[\w\s]+-{5}/ig, "").replace(/\r/g, "").replace(/\n/g, "");

    // Parse cert

    const asn1 = asn1js.fromBER(new Uint8Array(Buffer.from(sslCert, "base64")).buffer);
    const cert = new pkijs.Certificate({ schema: asn1.result });

    // Check date
    if (cert.notAfter.value < new Date()) {
      winston.info(`SSL certificate is expired`);
      return false;
    }
    return true;
  }
  winston.info(`SSL certificate is not found`);
  return false;
}
github YuryStrozhevsky / CTjs / src / LogV1.js View on Github external
if(asn1.offset === (-1))
							throw new Error("Object's stream was not correct for MerkleTreeLeaf extra_data");
						
						const preCertificate = new Certificate({ schema: asn1.result });
						//endregion
						
						//region Get information about "precertificate_chain" array
						const preCertificateChain = [];
						
						for(const preCertificateChainElement of entry.extra_data.precertificate_chain)
						{
							const asn1 = asn1js.fromBER(preCertificateChainElement);
							if(asn1.offset === (-1))
								throw new Error("Object's stream was not correct for MerkleTreeLeaf extra_data");
							
							preCertificateChain.push(new Certificate({ schema: asn1.result }));
						}
						//endregion
						
						extraData = {
							pre_certificate: preCertificate,
							precertificate_chain: preCertificateChain
						};
					}
					break;
				default:
			}
			
			result.push({
				leaf: entry.leaf,
				extra_data: extraData
			});
github PeculiarVentures / xmldsigjs / src / pki / x509.ts View on Github external
protected LoadRaw(rawData: BufferSource) {
        this.raw = new Uint8Array(rawData as ArrayBuffer);
        const asn1 = Asn1Js.fromBER(this.raw.buffer);
        this.simpl = new Certificate({ schema: asn1.result });
    }
    //#endregion
github PeculiarVentures / CAdES.js / examples / CAdESComplexExample / es6.js View on Github external
dataView[5] = 0x05;
	
	let cmsSignedSimpl;

	const signatureTimeStamp = new SignatureTimeStamp();
	const cadesCTimeStamp = new CAdESCTimestamp();
	
	const completeCertificateReferences = new CompleteCertificateReferences();
	const completeRevocationReferences = new CompleteRevocationReferences();
	
	const ocspRequest = new OCSPRequest();
	
	let ocspResponse;
	
	let asn1 = asn1js.fromBER(stringToArrayBuffer(atob(User10cert)));
	const certSimpl = new Certificate({ schema: asn1.result });
	
	asn1 = asn1js.fromBER(stringToArrayBuffer(atob(CAcert)));
	const caCertSimpl = new Certificate({ schema: asn1.result });
	//endregion
	
	//region Get a "crypto" extension
	const crypto = getCrypto();
	if(typeof crypto === "undefined")
		return Promise.reject("No WebCrypto extension found");
	//endregion
	
	
	sequence = sequence.then(() => certSimpl.getPublicKey());
	
	sequence = sequence.then(result =>
	{
github PeculiarVentures / CAdES.js / examples / CAdESComplexExample / es6.js View on Github external
const dataView = new Uint8Array(dataBuffer);
	dataView[0] = 0x00;
	dataView[1] = 0x01;
	dataView[2] = 0x02;
	dataView[3] = 0x03;
	dataView[4] = 0x04;
	dataView[5] = 0x05;
	
	let cmsSignedSimpl;
	
	const ocspRequest = new OCSPRequest();
	
	const aTSHashIndex = new ATSHashIndex();
	
	let asn1 = asn1js.fromBER(stringToArrayBuffer(atob(User10cert)));
	const certSimpl = new Certificate({ schema: asn1.result });
	
	asn1 = asn1js.fromBER(stringToArrayBuffer(atob(CAcert)));
	const caCertSimpl = new Certificate({ schema: asn1.result });
	//endregion
	
	//region Get a "crypto" extension
	const crypto = getCrypto();
	if(typeof crypto === "undefined")
		return Promise.reject("No WebCrypto extension found");
	//endregion

	sequence = sequence.then(() => certSimpl.getPublicKey());
	
	sequence = sequence.then(result =>
	{
		userPublicKey = result;
github YuryStrozhevsky / CTjs / src / PreCert.js View on Github external
get certificate()
	{
		return (new Certificate({
			schema: new asn1js.Sequence({
				value: [
					this.tbsCertificate,
					(new AlgorithmIdentifier({
						algorithmId: "1.2.840.113549.1.1.11",
						algorithmParams: new asn1js.Null()
					})).toSchema(),
					new asn1js.BitString({
						valueHex: new ArrayBuffer(2),
						unusedBits: 0
					})
				]
			})
		}));
	}
	//**********************************************************************************

pkijs

Public Key Infrastructure (PKI) is the basis of how identity and key management is performed on the web today. PKIjs is a pure JavaScript library implementing the formats that are used in PKI applications. It is built on WebCrypto and aspires to make it p

BSD-3-Clause
Latest version published 4 months ago

Package Health Score

78 / 100
Full package analysis