
work correctly with utf8 strings. Fixeda visibility issue with the testing suite and added relevant unit tests.
241 lines
14 KiB
HTML
241 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>JSDoc: Source: openpgp.msg.privatekey.js</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"> </script>
|
|
<script src="scripts/prettify/lang-css.js"> </script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">Source: openpgp.msg.privatekey.js</h1>
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source"><code>// GPG4Browsers - An OpenPGP implementation in javascript
|
|
// Copyright (C) 2011 Recurity Labs GmbH
|
|
//
|
|
// This library is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
// License as published by the Free Software Foundation; either
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
//
|
|
// This library 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
|
|
// Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
// License along with this library; if not, write to the Free Software
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
/**
|
|
* @class
|
|
* @classdesc Class that represents a decoded private key for internal openpgp.js use
|
|
*/
|
|
|
|
function openpgp_msg_privatekey() {
|
|
this.subKeys = new Array();
|
|
this.privateKeyPacket = null;
|
|
this.userIds = new Array();
|
|
this.userAttributes = new Array();
|
|
this.revocationSignatures = new Array();
|
|
this.subKeys = new Array();
|
|
|
|
/**
|
|
*
|
|
* @return last position
|
|
*/
|
|
function read_nodes(parent_node, input, position, len) {
|
|
this.privateKeyPacket = parent_node;
|
|
|
|
var pos = position;
|
|
while (input.length > pos) {
|
|
var result = openpgp_packet.read_packet(input, pos, input.length - pos);
|
|
if (result == null) {
|
|
util.print_error("openpgp.msg.messge decrypt:\n"+'[pub/priv_key]parsing ends here @:' + pos + " l:" + len);
|
|
break;
|
|
} else {
|
|
switch (result.tagType) {
|
|
case 2: // public key revocation signature
|
|
if (result.signatureType == 32)
|
|
this.revocationSignatures[this.revocationSignatures.length] = result;
|
|
else if (result.signatureType > 15 && result.signatureType < 20) {
|
|
if (this.certificationsignatures == null)
|
|
this.certificationSignatures = new Array();
|
|
this.certificationSignatures[this.certificationSignatures.length] = result;
|
|
} else
|
|
util.print_error("openpgp.msg.messge decrypt:\n"+"unknown signature type directly on key "+result.signatureType+" @"+pos);
|
|
pos += result.packetLength + result.headerLength;
|
|
break;
|
|
case 7: // PrivateSubkey Packet
|
|
this.subKeys[this.subKeys.length] = result;
|
|
pos += result.packetLength + result.headerLength;
|
|
pos += result.read_nodes(this.privateKeyPacket,input, pos, input.length - pos);
|
|
break;
|
|
case 17: // User Attribute Packet
|
|
this.userAttributes[this.userAttributes.length] = result;
|
|
pos += result.packetLength + result.headerLength;
|
|
pos += result.read_nodes(this.privateKeyPacket,input, pos, input.length - pos);
|
|
break;
|
|
case 13: // User ID Packet
|
|
this.userIds[this.userIds.length] = result;
|
|
pos += result.packetLength + result.headerLength;
|
|
pos += result.read_nodes(this.privateKeyPacket, input, pos, input.length - pos);
|
|
break;
|
|
default:
|
|
this.position = position - this.privateKeyPacket.packetLength - this.privateKeyPacket.headerLength;
|
|
this.len = pos - position;
|
|
return this.len;
|
|
}
|
|
}
|
|
}
|
|
this.position = position - this.privateKeyPacket.packetLength - this.privateKeyPacket.headerLength;
|
|
this.len = pos - position;
|
|
|
|
return this.len;
|
|
}
|
|
|
|
function getKeyId() {
|
|
return this.privateKeyPacket.publicKey.getKeyId();
|
|
}
|
|
|
|
|
|
function getSubKeyIds() {
|
|
if (this.privateKeyPacket.publicKey.version == 4) // V3 keys MUST NOT have subkeys.
|
|
var result = new Array();
|
|
for (var i = 0; i < this.subKeys.length; i++) {
|
|
result[i] = str_sha1(this.subKeys[i].publicKey.header+this.subKeys[i].publicKey.data).substring(12,20);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
function getSigningKey() {
|
|
if ((this.privateKeyPacket.publicKey.publicKeyAlgorithm == 17 ||
|
|
this.privateKeyPacket.publicKey.publicKeyAlgorithm != 2)
|
|
&& this.privateKeyPacket.publicKey.verifyKey() == 3)
|
|
return this.privateKeyPacket;
|
|
else if (this.privateKeyPacket.publicKey.version == 4) // V3 keys MUST NOT have subkeys.
|
|
for (var j = 0; j < this.privateKeyPacket.subKeys.length; j++) {
|
|
if ((this.privateKeyPacket.subKeys[j].publicKey.publicKeyAlgorithm == 17 ||
|
|
this.privateKeyPacket.subKeys[j].publicKey.publicKeyAlgorithm != 2) &&
|
|
this.privateKeyPacket.subKeys[j].publicKey.verifyKey() == 3)
|
|
return this.privateKeyPacket.subKeys[j];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function getPreferredSignatureHashAlgorithm() {
|
|
var pkey = this.getSigningKey();
|
|
if (pkey == null) {
|
|
util.print_error("private key is for encryption only! Cannot create a signature.")
|
|
return null;
|
|
}
|
|
if (pkey.publicKey.publicKeyAlgorithm == 17) {
|
|
var dsa = new DSA();
|
|
return dsa.select_hash_algorithm(pkey.publicKey.MPIs[1].toBigInteger()); // q
|
|
}
|
|
return openpgp.config.config.prefer_hash_algorithm;
|
|
|
|
}
|
|
|
|
function decryptSecretMPIs(str_passphrase) {
|
|
return this.privateKeyPacket.decryptSecretMPIs(str_passphrase);
|
|
}
|
|
|
|
function getFingerprint() {
|
|
return this.privateKeyPacket.publicKey.getFingerprint();
|
|
}
|
|
|
|
// TODO need to implement this
|
|
function revoke() {
|
|
|
|
}
|
|
|
|
/**
|
|
* extracts the public key part
|
|
* @return {String} OpenPGP armored text containing the public key
|
|
* returns null if no sufficient data to extract public key
|
|
*/
|
|
function extractPublicKey() {
|
|
// add public key
|
|
var key = this.privateKeyPacket.publicKey.header + this.privateKeyPacket.publicKey.data;
|
|
for (var i = 0; i < this.userIds.length; i++) {
|
|
// verify userids
|
|
if (this.userIds[i].certificationSignatures.length === 0) {
|
|
util.print_error("extractPublicKey - missing certification signatures");
|
|
return null;
|
|
}
|
|
var userIdPacket = new openpgp_packet_userid();
|
|
// add userids
|
|
key += userIdPacket.write_packet(this.userIds[i].text);
|
|
for (var j = 0; j < this.userIds[i].certificationSignatures.length; j++) {
|
|
var certSig = this.userIds[i].certificationSignatures[j];
|
|
// add signatures
|
|
key += openpgp_packet.write_packet_header(2, certSig.data.length) + certSig.data;
|
|
}
|
|
}
|
|
for (var k = 0; k < this.subKeys.length; k++) {
|
|
var pubSubKey = this.subKeys[k].publicKey;
|
|
// add public subkey package
|
|
key += openpgp_packet.write_old_packet_header(14, pubSubKey.data.length) + pubSubKey.data;
|
|
var subKeySig = this.subKeys[k].subKeySignature;
|
|
if (subKeySig !== null) {
|
|
// add subkey signature
|
|
key += openpgp_packet.write_packet_header(2, subKeySig.data.length) + subKeySig.data;
|
|
} else {
|
|
util.print_error("extractPublicKey - missing subkey signature");
|
|
return null;
|
|
}
|
|
}
|
|
var publicArmored = openpgp_encoding_armor(4, key);
|
|
return publicArmored;
|
|
}
|
|
|
|
this.extractPublicKey = extractPublicKey;
|
|
this.getSigningKey = getSigningKey;
|
|
this.getFingerprint = getFingerprint;
|
|
this.getPreferredSignatureHashAlgorithm = getPreferredSignatureHashAlgorithm;
|
|
this.read_nodes = read_nodes;
|
|
this.decryptSecretMPIs = decryptSecretMPIs;
|
|
this.getSubKeyIds = getSubKeyIds;
|
|
this.getKeyId = getKeyId;
|
|
|
|
}
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<nav>
|
|
<h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="_openpgp_packet.html">_openpgp_packet</a></li><li><a href="JXG.Util.html">Util</a></li><li><a href="openpgp.html">openpgp</a></li><li><a href="openpgp_config.html">openpgp_config</a></li><li><a href="openpgp_keyring.html">openpgp_keyring</a></li><li><a href="openpgp_msg_message.html">openpgp_msg_message</a></li><li><a href="openpgp_msg_privatekey.html">openpgp_msg_privatekey</a></li><li><a href="openpgp_msg_publickey.html">openpgp_msg_publickey</a></li><li><a href="openpgp_packet_compressed.html">openpgp_packet_compressed</a></li><li><a href="openpgp_packet_encrypteddata.html">openpgp_packet_encrypteddata</a></li><li><a href="openpgp_packet_encryptedintegrityprotecteddata.html">openpgp_packet_encryptedintegrityprotecteddata</a></li><li><a href="openpgp_packet_encryptedsessionkey.html">openpgp_packet_encryptedsessionkey</a></li><li><a href="openpgp_packet_keymaterial.html">openpgp_packet_keymaterial</a></li><li><a href="openpgp_packet_literaldata.html">openpgp_packet_literaldata</a></li><li><a href="openpgp_packet_marker.html">openpgp_packet_marker</a></li><li><a href="openpgp_packet_modificationdetectioncode.html">openpgp_packet_modificationdetectioncode</a></li><li><a href="openpgp_packet_onepasssignature.html">openpgp_packet_onepasssignature</a></li><li><a href="openpgp_packet_signature.html">openpgp_packet_signature</a></li><li><a href="openpgp_packet_userattribute.html">openpgp_packet_userattribute</a></li><li><a href="openpgp_packet_userid.html">openpgp_packet_userid</a></li><li><a href="openpgp_type_keyid.html">openpgp_type_keyid</a></li><li><a href="openpgp_type_mpi.html">openpgp_type_mpi</a></li><li><a href="openpgp_type_s2k.html">openpgp_type_s2k</a></li></ul><h3>Global</h3><ul><li><a href="global.html#bin2str">bin2str</a></li><li><a href="global.html#calc_checksum">calc_checksum</a></li><li><a href="global.html#crc_table">crc_table</a></li><li><a href="global.html#decode_utf8">decode_utf8</a></li><li><a href="global.html#encode_utf8">encode_utf8</a></li><li><a href="global.html#get_hashAlgorithmString">get_hashAlgorithmString</a></li><li><a href="global.html#getCheckSum">getCheckSum</a></li><li><a href="global.html#getPGPMessageType">getPGPMessageType</a></li><li><a href="global.html#hash_headers">hash_headers</a></li><li><a href="global.html#hex2bin">hex2bin</a></li><li><a href="global.html#hexidump">hexidump</a></li><li><a href="global.html#hexstrdump">hexstrdump</a></li><li><a href="global.html#MD5">MD5</a></li><li><a href="global.html#openpgp_cfb_decrypt">openpgp_cfb_decrypt</a></li><li><a href="global.html#openpgp_cfb_encrypt">openpgp_cfb_encrypt</a></li><li><a href="global.html#openpgp_cfb_mdc">openpgp_cfb_mdc</a></li><li><a href="global.html#openpgp_crypto_asymetricDecrypt">openpgp_crypto_asymetricDecrypt</a></li><li><a href="global.html#openpgp_crypto_asymetricEncrypt">openpgp_crypto_asymetricEncrypt</a></li><li><a href="global.html#openpgp_crypto_generateKeyPair">openpgp_crypto_generateKeyPair</a></li><li><a href="global.html#openpgp_crypto_generateSessionKey">openpgp_crypto_generateSessionKey</a></li><li><a href="global.html#openpgp_crypto_getHashByteLength">openpgp_crypto_getHashByteLength</a></li><li><a href="global.html#openpgp_crypto_getPrefixRandom">openpgp_crypto_getPrefixRandom</a></li><li><a href="global.html#openpgp_crypto_getPseudoRandom">openpgp_crypto_getPseudoRandom</a></li><li><a href="global.html#openpgp_crypto_getRandomBigInteger">openpgp_crypto_getRandomBigInteger</a></li><li><a href="global.html#openpgp_crypto_getRandomBytes">openpgp_crypto_getRandomBytes</a></li><li><a href="global.html#openpgp_crypto_getSecureRandom">openpgp_crypto_getSecureRandom</a></li><li><a href="global.html#openpgp_crypto_hashData">openpgp_crypto_hashData</a></li><li><a href="global.html#openpgp_crypto_MDCSystemBytes">openpgp_crypto_MDCSystemBytes</a></li><li><a href="global.html#openpgp_crypto_signData">openpgp_crypto_signData</a></li><li><a href="global.html#openpgp_crypto_symmetricDecrypt">openpgp_crypto_symmetricDecrypt</a></li><li><a href="global.html#openpgp_crypto_symmetricEncrypt">openpgp_crypto_symmetricEncrypt</a></li><li><a href="global.html#openpgp_crypto_verifySignature">openpgp_crypto_verifySignature</a></li><li><a href="global.html#openpgp_encoding_armor">openpgp_encoding_armor</a></li><li><a href="global.html#openpgp_encoding_armor_addheader">openpgp_encoding_armor_addheader</a></li><li><a href="global.html#openpgp_encoding_base64_decode">openpgp_encoding_base64_decode</a></li><li><a href="global.html#openpgp_encoding_base64_encode">openpgp_encoding_base64_encode</a></li><li><a href="global.html#openpgp_encoding_deArmor">openpgp_encoding_deArmor</a></li><li><a href="global.html#openpgp_encoding_eme_pkcs1_decode">openpgp_encoding_eme_pkcs1_decode</a></li><li><a href="global.html#openpgp_encoding_eme_pkcs1_encode">openpgp_encoding_eme_pkcs1_encode</a></li><li><a href="global.html#openpgp_encoding_emsa_pkcs1_decode">openpgp_encoding_emsa_pkcs1_decode</a></li><li><a href="global.html#openpgp_encoding_emsa_pkcs1_encode">openpgp_encoding_emsa_pkcs1_encode</a></li><li><a href="global.html#openpgp_encoding_html_encode">openpgp_encoding_html_encode</a></li><li><a href="global.html#print_debug">print_debug</a></li><li><a href="global.html#print_debug_hexstr_dump">print_debug_hexstr_dump</a></li><li><a href="global.html#print_error">print_error</a></li><li><a href="global.html#print_info">print_info</a></li><li><a href="global.html#shiftRight">shiftRight</a></li><li><a href="global.html#str2bin">str2bin</a></li><li><a href="global.html#str2Uint8Array">str2Uint8Array</a></li><li><a href="global.html#Uint8Array2str">Uint8Array2str</a></li><li><a href="global.html#util">util</a></li><li><a href="global.html#verifyCheckSum">verifyCheckSum</a></li></ul>
|
|
</nav>
|
|
|
|
<br clear="both">
|
|
|
|
<footer>
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Tue Apr 16 2013 10:42:39 GMT+0200 (CEST)
|
|
</footer>
|
|
|
|
<script> prettyPrint(); </script>
|
|
</body>
|
|
</html>
|