fork-openpgpjs/plugins/chrome/options.html
2012-06-25 20:48:46 -04:00

447 lines
19 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>OpenPGP.js - PGP Message Options</title>
</head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="js/ciphers/hash/sha.js"></script>
<script type="text/javascript" src="js/ciphers/hash/md5.js"></script>
<script type="text/javascript" src="js/ciphers/hash/ripe-md.js"></script>
<!-- crypto libs -->
<script type="text/javascript" src="js/ciphers/symmetric/aes.js"></script>
<script type="text/javascript" src="js/ciphers/symmetric/cast5.js"></script>
<script type="text/javascript" src="js/ciphers/symmetric/dessrc.js"></script>
<script type="text/javascript" src="js/ciphers/symmetric/twofish.js"></script>
<script type="text/javascript" src="js/ciphers/symmetric/blowfish.js"></script>
<script type="text/javascript" src="js/ciphers/asymmetric/jsbn.js"></script>
<script type="text/javascript" src="js/ciphers/asymmetric/jsbn2.js"></script>
<script type="text/javascript" src="js/ciphers/asymmetric/dsa.js"></script>
<script type="text/javascript" src="js/ciphers/asymmetric/elgamal.js"></script>
<script type="text/javascript" src="js/ciphers/asymmetric/rsa.js"></script>
<script type="text/javascript" src="js/ciphers/openpgp.crypto.js"></script>
<script type="text/javascript" src="js/ciphers/openpgp.cfb.js"></script>
<!-- compression -->
<!-- encoding -->
<script type="text/javascript" src="js/encoding/base64.js"></script>
<script type="text/javascript" src="js/encoding/openpgp.encoding.asciiarmor.js"></script>
<script type="text/javascript" src="js/encoding/openpgp.encoding.js"></script>
<!-- openpgp types -->
<script type="text/javascript" src="js/type/openpgp.type.keyid.js"></script>
<script type="text/javascript" src="js/type/openpgp.type.mpi.js"></script>
<script type="text/javascript" src="js/type/openpgp.type.s2k.js"></script>
<!-- openpgp packets -->
<script type="text/javascript" src="js/packet/openpgp.packet.compressed.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.encrypteddata.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.encryptedintegrityprotecteddata.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.encryptedsessionkey.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.keymaterial.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.literaldata.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.marker.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.modificationdetectioncode.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.onepasssignature.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.signature.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.userattribute.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.userid.js"></script>
<script type="text/javascript" src="js/packet/openpgp.packet.js"></script>
<!-- openpgp impl. -->
<script type="text/javascript" src="js/openpgp.js"></script>
<script type="text/javascript" src="js/config/openpgp.config.js"></script>
<script type="text/javascript" src="js/openpgp.keyring.js"></script>
<script type="text/javascript" src="js/openpgp.msg.message.js"></script>
<script type="text/javascript" src="js/openpgp.msg.privatekey.js"></script>
<script type="text/javascript" src="js/openpgp.msg.publickey.js"></script>
<script type="text/javascript" src="js/util/util.js"></script>
<script type="text/javascript">
// Saves options to localStorage.
function save_options() {
openpgp.keyring.store();
}
function getAlgorithmString(publicKey) {
var result = publicKey.publicKeyPacket.MPIs[0].mpiByteLength*8+"/";
switch (publicKey.publicKeyPacket.publicKeyAlgorithm) {
case 1:
result += "RSA(S/E)";
break;
case 2:
result +="RSA(E)";
break;
case 3:
result += "RSA(S)";
break;
case 16:
result += "Elg";
break;
case 17:
result += "DSA";
break;
}
if (publicKey.subKeys.length > 0) {
result += ", "+(publicKey.subKeys[0].MPIs[0].mpiByteLength * 8)+"/";
switch (publicKey.subKeys[0].publicKeyAlgorithm) {
case 1:
result += "(RSA(S/E)";
break;
case 2:
result +="RSA(E)";
break;
case 3:
result += "RSA(S)";
break;
case 16:
result += "Elg.";
break;
case 17:
result += "DSA";
break;
}
}
return result;
}
function encodeForHtml(text) {
if (text == null)
return "";
return $('<div/>').text(text+"").html();
}
function importPublicKey(key) {
openpgp.keyring.importPublicKey(key);
save_options();
update_tables();
}
function importPrivateKey(key) {
openpgp.keyring.importPrivateKey(key);
save_options();
update_tables();
}
// Restores select box state to saved value from localStorage.
function restore_options() {
openpgp.init();
update_tables();
$('#cipher_alg_select').val(""+openpgp.config.config.encryption_cipher);
$('#hash_alg_select').val(""+openpgp.config.config.prefer_hash_algorithm);
$('#compression_alg_select').val(""+openpgp.config.config.compression);
$('#integrity').attr("checked", openpgp.config.config.integrity_protect);
$('#aaversion').attr("checked", openpgp.config.config.show_version);
$('#keyserver').val(""+openpgp.config.config.keyserver);
show_tab(0);
}
function show_userIds(k) {
var publicKey = openpgp.keyring.publicKeys[k];
var certsigs = publicKey.obj.verifyCertificationSignatures();
$('#show_ids_'+k).empty();
for (var i = 0; i < publicKey.obj.userIds.length; i++) {
if (certsigs[i].indexOf(6) != -1)
$('#show_ids_'+k).append("<tr style=\"background-color: #fdd\"><td>rev</td><td class=\"uid_revoked\" colspan=\"2\"><s>"+encodeForHtml(publicKey.obj.userIds[i].text)+"</s></td></tr>");
else if (certsigs[i].indexOf(5) != -1)
$('#show_ids_'+k).append("<tr style=\"background-color: #ffd\"><td>exp</td><td class=\"uid_expired\" colspan=\"2\"><i>"+encodeForHtml(publicKey.obj.userIds[i].text)+"</i></td></tr>");
else
$('#show_ids_'+k).append("<tr style=\"background-color: #dfd\"><td>uid</td><td class=\"uid_normal\" colspan=\"2\"><b>"+encodeForHtml(publicKey.obj.userIds[i].text)+"</b></td></tr>");
for (var j = 0; j < publicKey.obj.userIds[i].certificationSignatures.length; j++) {
var istr = util.hexstrdump(publicKey.obj.userIds[i].certificationSignatures[j].getIssuer());
var issuer = publicKey.obj.userIds[i].certificationSignatures[j].getIssuerKey();
var sigclass = publicKey.obj.userIds[i].certificationSignatures[j].signatureType - 0x10;
if (issuer != null)
istr = issuer.obj.userIds[0].text;
if (certsigs[i][j] == 0)
$('#show_ids_'+k).append("<tr><td>sig"+(sigclass == 0 ? "" : sigclass)+"</td><td>BAD</td><td class=\"sig_bad\">"+encodeForHtml(istr)+"</td></tr>");
if (certsigs[i][j] == 1)
$('#show_ids_'+k).append("<tr><td>sig"+(sigclass == 0 ? "" : sigclass)+"</td><td>exp</td><td class=\"sig_exp\"><i>"+encodeForHtml(istr)+"</i></td></tr>");
if (certsigs[i][j] == 2)
$('#show_ids_'+k).append("<tr><td>sig"+(sigclass == 0 ? "" : sigclass)+"</td><td>unk</td><td class=\"sig_unk\">"+encodeForHtml(istr)+"</td></tr>");
if (certsigs[i][j] == 3)
$('#show_ids_'+k).append("<tr><td>sig"+(sigclass == 0 ? "" : sigclass)+"</td><td>rev</td><td class=\"sig_unk\"><s>"+encodeForHtml(istr)+"</s></td></tr>");
if (certsigs[i][j] == 4)
$('#show_ids_'+k).append("<tr><td>sig"+(sigclass == 0 ? "" : sigclass)+"</td><td></td><td class=\"sig_normal\">"+encodeForHtml(istr)+"</td></tr>");
}
}
$('#show_ids_'+k).toggle();
}
function update_tables() {
$('#publicKeyTable').empty();
$('#publicKeyTable').append("<tr><th>Key ID</th><th>Person</th><th>Length/Alg.</th><th>Status</th><th>Action</th></tr>");
for (var i = 0; i < openpgp.keyring.publicKeys.length; i++) {
var status = openpgp.keyring.publicKeys[i].obj.verifyBasicSignatures();
var result = "<tr><td>0x"+
util.hexstrdump(openpgp.keyring.publicKeys[i].obj.getKeyId()).toUpperCase().substring(8)+ "</td>";
result += "<td><button id=\"show_button"+i+"\" onmousedown=\"show_userIds("+i+");\">+</button>"+encodeForHtml(openpgp.keyring.publicKeys[i].obj.userIds[0].text)+"<table style=\"display: none;\" id=\"show_ids_"+i+"\"></table></td>";
result += "<td>"+getAlgorithmString(openpgp.keyring.publicKeys[i].obj)+"</td>";
result += "<td>"+(status ? "valid" : "invalid")+"</td>";
result += "<td><a href=\"#\" onmousedown=\"openpgp.keyring.removePublicKey("+i+"); update_tables();\">remove</a></td>";
$("#publicKeyTable").append(result+"</tr>");
}
$('#privateKeyTable').empty();
$('#privateKeyTable').append("<tr><th>Key ID</th><th>Person</th><th>Length/Alg.</th><th>Expires on</th><th>Action</th></tr>");
for (var i = 0; i < openpgp.keyring.privateKeys.length; i++) {
for (var j = 0; j < openpgp.keyring.privateKeys[i].obj.userIds.length; j++) {
$("#privateKeyTable").append("<tr><td>"
+util.hexstrdump(openpgp.keyring.privateKeys[i].obj.getKeyId())+ "</td><td>"+
": "+encodeForHtml(openpgp.keyring.privateKeys[i].obj.userIds[j].text)+"</td></tr>");
}
}
}
var current_tab = -1;
function show_tab(num) {
if (current_tab != num) {
$("#tab_"+current_tab).hide();
$('#tabref_'+current_tab).attr("class","tabref");
$("#tab_"+num).show();
$('#tabref_'+num).attr("class","tabref-select");
}
current_tab = num;
}
function importKeyId(string) {
var xhr = new XMLHttpRequest();
var searchtext = $('#searchKeyText').val();
xhr.open("GET", "http://"+encodeURIComponent(openpgp.config.config.keyserver)+"/pks/lookup?op=get&search=0x"+encodeURIComponent(string)+"&options=mr",true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var key = xhr.responseText.split('<pre>')[1];
importPublicKey(key);
}
};
xhr.send();
}
function showMessages(html) {
$('#debug').append(html);
}
function show_search_results() {
$('#searchKeyResults').empty();
var xhr = new XMLHttpRequest();
var searchtext = $('#searchKeyText').val();
xhr.open("GET", "http://"+encodeURIComponent(openpgp.config.config.keyserver)+"/pks/lookup?op=index&search="+encodeURIComponent(searchtext)+"&options=mr",true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
$('#searchKeyResults').append("<tr><th>Key ID</th><th>Person</th><th>Length/Alg.</th><th>CreatedOn</th><th>Action</th></tr>");
var text = xhr.responseText.split('\n');
for (var i =1; i < text.length; i++) {
var col = text[i].split(":");
var keyId = null;
var created = null;
var algorithm = null;
var length = null;
var uids = null;
var revoked = null;
var r = 1;
if (col[0] == "pub") {
keyId = col[1];
algorithm = col[2];
length = col[3];
created = new Date(parseInt(col[4]+"000"));
revoked = !(col[6].indexOf('r') < 0);
} else {
continue;
}
uids = "";
while (text[i+r].split(":")[0] == "uid") {
uids += encodeForHtml(text[i+r].split(":")[1])+"<br>";
r++;
}
i += r-1;
$('#searchKeyResults').append("<tr><td>"+keyId+"</td>"+
"<td>"+uids+"</td>"+
"<td>"+length+"/"+(algorithm == "1" ? "RSA" : "DSA-Elgamal")+"</td>"+
"<td>"+created+"</td>"+
"<td>"+
(!revoked ? "<a href=\"#\" onclick=\"importKeyId('"+encodeForHtml(keyId).trim()+"');\"> Import Key</a>" : "key is revoked")+"</td></tr>");
}
$('#searchKeyResults').show();
}
};
xhr.send();
}
</script>
<style>
body {
background-color: #efefef;
}
* {
font-size: 98%;
font-family: sans-serif;
}
.tabref, .tabref-select {
border: 1px solid #aaa;
border-bottom: none;
padding-left: 10px;
padding-right: 10px;
padding-top: 2px;
padding-bottom: 2px;
margin-left: 3px;
margin-bottom: 0px;
z-index: 1;
}
th {
text-align: left;
}
.tabref {
background-color: #eee;
border: 1px solid #aaa;
}
#options_header {
margin-left: 5px;
}
#publicKeyTable, #privateKeyTable, #searchKeyResults {
border: 1px solid #aaa;
}
#publicKeyTable th, #privateKeyTable th, #searchKeyResults th {
background-color: #eee;
border-bottom: 1px solid #000;
padding: 3px;
}
#publicKeyTable td, #privateKeyTable td, #searchKeyResults td {
padding: 3px;
border-bottom: 1px solid #aaa;
vertical-align: top;
}
.tabref-select {
background-color: #fff;
border-bottom: 1px solid #fff;
}
h2 {
font: 1.5em;
width: 100%;
border-bottom: 1px solid #888;
}
h1, h2 {
font: 1.5em "Impact";
}
#tab_1, #tab_2, #tab_3, #tab_0 {
margin-top: 2px;
border: 1px solid #aaa;
background-color: #fff;
box-shadow: 2px 2px 5px #888;
z-index: 2;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
border-radius: 5px;
}
</style>
<body onload="restore_options()">
<div id="options_header">
<a href="#" class="tabref" id="tabref_0" onmousedown="show_tab(0);">Settings</a>
<a href="#" class="tabref" id="tabref_1" onmousedown="show_tab(1);">Public Keys</a>
<a href="#" class="tabref" id="tabref_2" onmousedown="show_tab(2);">Private Keys</a>
</div>
<div id="tab_0" style="display: none">
<h2>Composition Settings</h2>
<ul><li><select id="composition_behavior" onchange="openpgp.config.config.composition_behavior = parseInt($('#composition_behavior').val()); openpgp.config.write();">
<option value="0"> Sign &amp; Encrypt</option>
<option value="1"> Sign only</option>
<option value="2"> Encrypt only</option>
</select> when creating messages </li>
<li><input type="checkbox" id="integrity" onchange="openpgp.config.config.integrity_protect = ($('#integrity').attr('checked') ? true: false); openpgp.config.write();">Generate integrity protected messages<br></li>
<li><input type="checkbox" id="aaversion" onchange="openpgp.config.config.show_version = ($('#aaversion').attr('checked') ? true: false); openpgp.config.write();">Insert version into ASCII Armor<br></li>
<li>PGP Key Server Host (no slashes): http://<input type="text" id="keyserver"><button type="submit" onclick="openpgp.config.config.keyserver = $('#keyserver').val(); openpgp.config.write();">Save</button></li>
</ul>
<h2>Encryption Algorithms</h2>
<table><tr><td>Preferred Hash Algorithm:</td>
<td><select id="hash_alg_select" onchange=" openpgp.config.config.prefer_hash_algorithm = parseInt($('#hash_alg_select').val()); openpgp.config.write();">
<option value="1">MD5 (deprecated)</option>
<option value="3">RIPE-MD/160</option>
<option value="2">SHA-1 (GnuPG default)</option>
<option value="11">SHA224</option>
<option value="8">SHA256</option>
<option value="9">SHA384</option>
<option value="10">SHA512</option>
</select></td></tr>
<tr><td>Symmetric Cipher Algorithm:</td>
<td><select id="cipher_alg_select" onchange="openpgp.config.config.encryption_cipher = parseInt($('#cipher_alg_select').val()); openpgp.config.write();">
<option value="2">TripleDES (compatible mode)</option>
<option value="3">CAST5</option>
<option value="4">Blowfish</option>
<option value="7">AES with 128-bit key</option>
<option value="8">AES with 192-bit key</option>
<option value="9">AES with 256-bit key (GnuPG default)</option>
<option value="10">Twofish</option>
</select></td></tr>
<tr><td>Message Compression:</td>
<td><select id="compression_alg_select" onchange="openpgp.config.config.compression = parseInt($('#compression_alg_select').val()); openpgp.config.write();">
<option value="0">Plaintext (no compression)</option>
<!-- <option value="1">ZIP </option> -->
</select></td></tr>
</table>
</div>
<div id="tab_1" style="display: none">
<h2>Public Keys in Keyring</h2>
<table id="publicKeyTable">
<tr><th>Key ID</th><th>Person</th><th>Length/Alg.</th><th>Status</th><th>Action</th></tr>
</table>
<h2>Import a Public Key</h2>
<b><a href="#" onclick="$('#importSearchedKey').toggle();">Search Key</a></b><br>
<div id="importSearchedKey" style="display: none;margin-left: 5px; border-left: 1px solid #aaa; padding-left: 5px;">
KeyID or UserId: <input type="text" id="searchKeyText"></input><button type="submit" onclick="show_search_results();">search</button>
<table id="searchKeyResults" style="display: none">
<tr><th>Key ID</th><th>Person</th><th>Length/Alg.</th><th>CreatedOn</th><th>Action</th></tr>
</table>
</div>
<b><a href="#" onclick="$('#importPastedPublicKey').toggle();">Import pasted public key</a></b><br>
<div id="importPastedPublicKey" style="display: none; margin-left: 5px; border-left: 1px solid #aaa; padding-left: 5px;">
<textarea rows="25" cols="80" id="importKeyTextfield"></textarea>
<button onclick="importPublicKey($('#importKeyTextfield').val());">Import</button>
</div>
</div>
<div id="tab_2" style="display: none; ">
<h2>Private Keys in Keyring</h2>
<table id="privateKeyTable">
<tr><th>Key ID</th><th>Person</th><th>Length/Alg.</th><th>Expires on</th></tr>
</table>
<h2>Add a Private Key</h2>
<b><a href="#" onclick="$('#generatePrivateKey').toggle();">Generate a new private key</a></b><br>
<div id="generatePrivateKey" style="display: none; margin-left: 5px; border-left: 1px solid #aaa; padding-left: 5px;">
<table>
<tr><td>Length in Bits:</td>
<td><select><option value="1024">1024</option><option value="2048" selected="selected">2048</option><option value="4096">4096</option></select></td></tr>
<tr><td>Algorithm:</td>
<td><input type="radio" checked="checked" name="algorithm" value="16"> DSA / Elgamal (Sign & Encrypt)<br>
<input type="radio" name="algorithm" value="17"> DSA (Sign Only)<br>
<input type="radio" name="algorithm" value="1"> RSA (Sign & Encrypt)<br></td></tr>
<tr><td>Username:</td><td><input type="text" name="username"></input> (e.g "John Doe")</td></tr>
<tr><td>Alias:</td><td><input type="text" name="alias"></input> (e.g "Johns Company")</td></tr>
<tr><td>Email Address:</td><td><input type="text" name="email"></input> (e.g "john@doe.com")</td></tr>
<tr><td>Expires on:</td><td><input type="radio" name="expiry" value="0" onclick="$('#expiryDate').attr('disabled','disabled');" checked="checked"></input>Never | <input type="radio" name="expiry" value="1" onclick="$('#expiryDate').removeAttr('disabled');">Date: <input type="text" id="expiryDate" disabled="disabled"></td></tr>
<tr><td></td><td><button type="submit" onclick="generateKey();">Generate Key</button></td></tr>
</table>
</div>
<b><a href="#" onclick="$('#pastePrivateKey').toggle();">Paste a private key</a></b><br>
<div id="pastePrivateKey" style="display: none; margin-left: 5px; border-left: 1px solid #aaa; padding-left: 5px;">
<textarea rows="30" cols="80" id="importPrivateKeyTextfield"></textarea>
<button onclick="importPrivateKey($('#importPrivateKeyTextfield').val()); $('#generatePrivateKey').toggle();">Import Key</button>
</div>
</div>
<br/>
<div id="debug"></div>
</body>
</html>