Пример #1
0
	return Promise.resolve().then(() => createOCSPReqInternal()).then(() =>
	{
		let resultString = "";
		
		resultString = `${resultString}\r\n-----BEGIN OCSP REQUEST-----\r\n`;
		resultString = `${resultString}${formatPEM(toBase64(arrayBufferToString(ocspReqBuffer)))}`;
		resultString = `${resultString}\r\n-----END OCSP REQUEST-----\r\n\r\n`;
		
		// noinspection InnerHTMLJS
		document.getElementById("new_signed_data").innerHTML = resultString;
		
		parseOCSPReq();
		
		alert("OCSP request has created successfully!");
	});
Пример #2
0
	return Promise.resolve().then(() => createTSPRespInternal()).then(() =>
	{
		let resultString = "-----BEGIN CERTIFICATE-----\r\n";
		resultString = `${resultString}${formatPEM(toBase64(arrayBufferToString(certificateBuffer)))}`;
		resultString = `${resultString}\r\n-----END CERTIFICATE-----\r\n`;
		
		alert("Certificate created successfully!");
		
		resultString = `${resultString}\r\n-----BEGIN PRIVATE KEY-----\r\n`;
		resultString = `${resultString}${formatPEM(toBase64(arrayBufferToString(privateKeyBuffer)))}`;
		resultString = `${resultString}\r\n-----END PRIVATE KEY-----\r\n`;
		
		alert("Private key exported successfully!");
		
		resultString = `${resultString}\r\n-----BEGIN TSP RESPONSE-----\r\n`;
		resultString = `${resultString}${formatPEM(toBase64(arrayBufferToString(tspResponseBuffer)))}`;
		resultString = `${resultString}\r\n-----END TSP RESPONSE-----\r\n\r\n`;
		
		document.getElementById("new_signed_data").innerHTML = resultString;
		
		parseTSPResp();
		
		alert("TSP response has created successfully!");
	});
Пример #3
0
	//**********************************************************************************
	/**
	 * Convertion for the class to JSON object
	 * @returns {Object}
	 */
	toJSON()
	{
		if((("namedCurve" in this) === false) || (ECPrivateKey.compareWithDefault("namedCurve", this.namedCurve)))
			throw new Error("Not enough information for making JSON: absent \"namedCurve\" value");

		let crvName = "";

		switch(this.namedCurve)
		{
			case "1.2.840.10045.3.1.7": // P-256
				crvName = "P-256";
				break;
			case "1.3.132.0.34": // P-384
				crvName = "P-384";
				break;
			case "1.3.132.0.35": // P-521
				crvName = "P-521";
				break;
			default:
		}

		const privateKeyJSON = {
			crv: crvName,
			d: toBase64(arrayBufferToString(this.privateKey.valueBlock.valueHex), true, true, false)
		};

		if("publicKey" in this)
		{
			const publicKeyJSON = this.publicKey.toJSON();

			privateKeyJSON.x = publicKeyJSON.x;
			privateKeyJSON.y = publicKeyJSON.y;
		}

		return privateKeyJSON;
	}
Пример #4
0
//*********************************************************************************
async function parseOpenSSLPrivateKey()
{
	let keyLength = 0;
	let base64 = "";

	const headerExp = /([\x21-\x7e]+):\s*([\x21-\x7e\s^:]+)/;

	const stringPEM = document.getElementById("openssl_data").value.replace(/(-----(BEGIN|END) RSA PRIVATE KEY-----)/g, "");
	const lines = stringPEM.split(/\r?\n/);

	let dekFound = false;
	let iv = new ArrayBuffer(0);

	for(let i = 0; i < lines.length; i++)
	{
		const lineMatch = lines[i].match(headerExp);
		if(lineMatch !== null)
		{
			if(lineMatch[1] === "DEK-Info")
			{
				dekFound = true;

				const values = lineMatch[2].split(",");

				for(let j = 0; j < values.length; j++)
					values[j] = values[j].trim();

				switch(values[0].toLocaleUpperCase())
				{
					case "AES-128-CBC":
						keyLength = 16;
						break;
					case "AES-192-CBC":
						keyLength = 24;
						break;
					case "AES-256-CBC":
						keyLength = 32;
						break;
					default:
						throw new Error(`Unsupported apgorithm ${values[0].toLocaleUpperCase()}`);
				}

				iv = hex2b(values[1]);
			}
		}
		else
		{
			if(dekFound)
				base64 += lines[i];
		}
	}

	if(dekFound === false)
		throw new Error("Can not find DEK-Info section!");

	const dataBuffer = await decryptOpenSSLPrivateKey(stringToArrayBuffer(fromBase64(base64.trim())), stringToArrayBuffer(document.getElementById("password").value), "AES-CBC", keyLength, iv);

	const asn1 = asn1js.fromBER(dataBuffer);
	if(asn1.offset === (-1))
		throw new Error("Incorect encrypted key");

	//const privateKeyInfo = new PrivateKeyInfo({ schema: asn1.result });
	const rsaPrivateKey = new RSAPrivateKey({ schema: asn1.result });

	let resultString = "-----BEGIN RSA PRIVATE KEY-----\r\n";
	//resultString = `${resultString}${formatPEM(toBase64(arrayBufferToString(privateKeyInfo.toSchema().toBER(false))))}`;
	resultString = `${resultString}${formatPEM(toBase64(arrayBufferToString(rsaPrivateKey.toSchema().toBER(false))))}`;
	//resultString = `${resultString}${formatPEM(toBase64(arrayBufferToString(dataBuffer)))}`;
	resultString = `${resultString}\r\n-----END RSA PRIVATE KEY-----\r\n`;

	document.getElementById("pkijs_data").value = resultString;
}