Skip to content
Snippets Groups Projects
Commit ba7539b3 authored by Yann Rimbaud's avatar Yann Rimbaud
Browse files

First commit.

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 609 additions and 0 deletions
.DS_Store
This diff is collapsed.
.content {
margin: 0 auto 50px auto;
}
.tab-pane {
border: 1px solid #ddd;
border-top: none;
padding: 20px;
}
.panel-title {
font-weight: bold;
}
body {
background-color: #f3f3f3;
}
.tab-content {
background-color: #fff;
}
.title {
font-weight: bold;
}
@media (max-width: 767px) {
.nav-tabs>li {
float: none;
border: 1px solid #dddddd;
}
.nav-tabs>li.active>a {
border: none;
}
.nav>li>a:hover,
.nav>li>a:focus,
.nav-tabs>li.active>a,
.nav-tabs>li.active>a:hover,
.nav-tabs>li.active>a:focus {
background: none;
border: none;
}
}
.cip-genpw-icon.cip-icon-key-small {
background-image: url(../fonts/key_16x16.png);
}
.cip-genpw-icon.cip-icon-key-big {
background-image: url(../fonts/key_24x24.png);
}
\ No newline at end of file
File added
File added
File added
File added
assets/fonts/key_16x16.png

471 B

assets/fonts/key_24x24.png

723 B

/* FileSaver.js
* A saveAs() FileSaver implementation.
* 2015-01-04
*
* By Eli Grey, http://eligrey.com
* License: X11/MIT
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
*/
/*global self */
/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs = saveAs
// IE 10+ (native saveAs)
|| (typeof navigator !== "undefined" &&
navigator.msSaveOrOpenBlob && navigator.msSaveOrOpenBlob.bind(navigator))
// Everyone else
|| (function(view) {
"use strict";
// IE <10 is explicitly unsupported
if (typeof navigator !== "undefined" &&
/MSIE [1-9]\./.test(navigator.userAgent)) {
return;
}
var
doc = view.document
// only get URL when necessary in case Blob.js hasn't overridden it yet
, get_URL = function() {
return view.URL || view.webkitURL || view;
}
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
, can_use_save_link = "download" in save_link
, click = function(node) {
var event = doc.createEvent("MouseEvents");
event.initMouseEvent(
"click", true, false, view, 0, 0, 0, 0, 0
, false, false, false, false, 0, null
);
node.dispatchEvent(event);
}
, webkit_req_fs = view.webkitRequestFileSystem
, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
, throw_outside = function(ex) {
(view.setImmediate || view.setTimeout)(function() {
throw ex;
}, 0);
}
, force_saveable_type = "application/octet-stream"
, fs_min_size = 0
// See https://code.google.com/p/chromium/issues/detail?id=375297#c7 and
// https://github.com/eligrey/FileSaver.js/commit/485930a#commitcomment-8768047
// for the reasoning behind the timeout and revocation flow
, arbitrary_revoke_timeout = 500 // in ms
, revoke = function(file) {
var revoker = function() {
if (typeof file === "string") { // file is an object URL
get_URL().revokeObjectURL(file);
} else { // file is a File
file.remove();
}
};
if (view.chrome) {
revoker();
} else {
setTimeout(revoker, arbitrary_revoke_timeout);
}
}
, dispatch = function(filesaver, event_types, event) {
event_types = [].concat(event_types);
var i = event_types.length;
while (i--) {
var listener = filesaver["on" + event_types[i]];
if (typeof listener === "function") {
try {
listener.call(filesaver, event || filesaver);
} catch (ex) {
throw_outside(ex);
}
}
}
}
, FileSaver = function(blob, name) {
// First try a.download, then web filesystem, then object URLs
var
filesaver = this
, type = blob.type
, blob_changed = false
, object_url
, target_view
, dispatch_all = function() {
dispatch(filesaver, "writestart progress write writeend".split(" "));
}
// on any filesys errors revert to saving with object URLs
, fs_error = function() {
// don't create more object URLs than needed
if (blob_changed || !object_url) {
object_url = get_URL().createObjectURL(blob);
}
if (target_view) {
target_view.location.href = object_url;
} else {
var new_tab = view.open(object_url, "_blank");
if (new_tab == undefined && typeof safari !== "undefined") {
//Apple do not allow window.open, see http://bit.ly/1kZffRI
view.location.href = object_url
}
}
filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
}
, abortable = function(func) {
return function() {
if (filesaver.readyState !== filesaver.DONE) {
return func.apply(this, arguments);
}
};
}
, create_if_not_found = {create: true, exclusive: false}
, slice
;
filesaver.readyState = filesaver.INIT;
if (!name) {
name = "download";
}
if (can_use_save_link) {
object_url = get_URL().createObjectURL(blob);
save_link.href = object_url;
save_link.download = name;
click(save_link);
filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
return;
}
// Object and web filesystem URLs have a problem saving in Google Chrome when
// viewed in a tab, so I force save with application/octet-stream
// http://code.google.com/p/chromium/issues/detail?id=91158
// Update: Google errantly closed 91158, I submitted it again:
// https://code.google.com/p/chromium/issues/detail?id=389642
if (view.chrome && type && type !== force_saveable_type) {
slice = blob.slice || blob.webkitSlice;
blob = slice.call(blob, 0, blob.size, force_saveable_type);
blob_changed = true;
}
// Since I can't be sure that the guessed media type will trigger a download
// in WebKit, I append .download to the filename.
// https://bugs.webkit.org/show_bug.cgi?id=65440
if (webkit_req_fs && name !== "download") {
name += ".download";
}
if (type === force_saveable_type || webkit_req_fs) {
target_view = view;
}
if (!req_fs) {
fs_error();
return;
}
fs_min_size += blob.size;
req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
var save = function() {
dir.getFile(name, create_if_not_found, abortable(function(file) {
file.createWriter(abortable(function(writer) {
writer.onwriteend = function(event) {
target_view.location.href = file.toURL();
filesaver.readyState = filesaver.DONE;
dispatch(filesaver, "writeend", event);
revoke(file);
};
writer.onerror = function() {
var error = writer.error;
if (error.code !== error.ABORT_ERR) {
fs_error();
}
};
"writestart progress write abort".split(" ").forEach(function(event) {
writer["on" + event] = filesaver["on" + event];
});
writer.write(blob);
filesaver.abort = function() {
writer.abort();
filesaver.readyState = filesaver.DONE;
};
filesaver.readyState = filesaver.WRITING;
}), fs_error);
}), fs_error);
};
dir.getFile(name, {create: false}, abortable(function(file) {
// delete file if it already exists
file.remove();
save();
}), abortable(function(ex) {
if (ex.code === ex.NOT_FOUND_ERR) {
save();
} else {
fs_error();
}
}));
}), fs_error);
}), fs_error);
}
, FS_proto = FileSaver.prototype
, saveAs = function(blob, name) {
return new FileSaver(blob, name);
}
;
FS_proto.abort = function() {
var filesaver = this;
filesaver.readyState = filesaver.DONE;
dispatch(filesaver, "abort");
};
FS_proto.readyState = FS_proto.INIT = 0;
FS_proto.WRITING = 1;
FS_proto.DONE = 2;
FS_proto.error =
FS_proto.onwritestart =
FS_proto.onprogress =
FS_proto.onwrite =
FS_proto.onabort =
FS_proto.onerror =
FS_proto.onwriteend =
null;
return saveAs;
}(
typeof self !== "undefined" && self
|| typeof window !== "undefined" && window
|| this.content
));
// `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
if (typeof module !== "undefined" && module.exports) {
module.exports.saveAs = saveAs;
} else if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) {
define([], function() {
return saveAs;
});
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* Debug msg handler.
*/
var _debug = function(msg) {
var dbg = false;
if (dbg) {
console.log(msg);
}
}
/**
* Generate a key pair and place base64 encoded values into specified DOM elements.
*/
var genKeyPair = function() {
// Get params from user input
var name = $('#name').val();
var email = $('#email').val() ? " <" + $('#email').val() + ">" : "";;
var comments = ($('#comments').val() != "") ? " (" + $('#comments').val() + ")" : "";
var bitlength = parseInt($('#bitlength').val());
var algorithm = $('#algorithm').val();
var expire = $('#expire').val();
var passphrase = $('#passphrase').val();
if (expire == "1") {
var expire = 86400 * 365 * 1;
} else if (expire == "2") {
var expire = 86400 * 365 * 2;
} else if (expire == "4") {
var expire = 86400 * 365 * 4;
} else if (expire == "8") {
var expire = 86400 * 365 * 8;
}
// Set ECC flag
var use_ecc = false;
if (algorithm == 'ecc') {
use_ecc = true;
}
// Calculate subkey size
var subkey_bitlength = calcSubkeySize(algorithm, bitlength);
_debug("Params:");
_debug("Name: " + name);
_debug("Email: " + email);
_debug("Comments: " + comments);
_debug("Bitlength: " + bitlength);
_debug("Subkey Bitlength: " + subkey_bitlength);
_debug("Algorithm: " + algorithm);
_debug("Expire: " + expire);
_debug("use_ecc flag: " + use_ecc);
_debug("Passphrase: " + passphrase);
// Disable/update the action button
_debug("Update buttons");
$('#generate_keys_btn').css('pointer-events', 'none');
$('#generate_keys_btn').addClass("disabled");
$('#generate_keys_btn').val("Generating .");
// Create a progress hook
var my_asp = new kbpgp.ASP({
progress_hook: function(o) {
_debug("progress_hook received: " + o);
var btn_update_ts = $('#btn_update_ts');
// If last button update was less than 500ms ago we skip
if ((Date.now() - btn_update_ts.val()) < 500) {
return;
}
// Else we continue to update button text
var btn = $('#generate_keys_btn');
if (btn.val() == 'Generating .') {
btn.val('Generating ..');
} else if (btn.val() == 'Generating ..') {
btn.val('Generating ...');
} else {
btn.val('Generating .');
}
// And we update the timestamp
btn_update_ts.val(Date.now());
}
});
var F = kbpgp["const"].openpgp;
var opts = {
asp: my_asp, // set progress hook
userid: name + comments + email,
ecc: use_ecc,
primary: {
nbits: bitlength,
flags: F.certify_keys | F.sign_data | F.auth | F.encrypt_comm | F.encrypt_storage,
expire_in: expire // never expires
},
subkeys: [{
nbits: subkey_bitlength,
flags: F.sign_data,
expire_in: expire
}, {
nbits: subkey_bitlength,
flags: F.encrypt_comm | F.encrypt_storage,
expire_in: expire
}, ]
};
_debug("Calling KeyManager.generate()");
kbpgp.KeyManager.generate(opts, function(err, alice) {
if (!err) {
_debug("Callback invoked()");
var _passphrase = $('#passphrase').val();
// sign alice's subkeys
alice.sign({}, function(err) {
_debug(alice);
$('#key_short_id').val(alice.get_pgp_short_key_id());
_debug("KeyID: " + alice.get_pgp_short_key_id());
// export; dump the private with a passphrase
alice.export_pgp_private_to_client({
passphrase: _passphrase
}, function(err, pgp_private) {
_debug("private key: " + pgp_private);
$('#privkey').val(pgp_private);
// Enable download buttons
$('#download_priv_key').removeClass('disabled');
});
alice.export_pgp_public({}, function(err, pgp_public) {
_debug("public key: " + pgp_public);
$('#pubkey').val(pgp_public);
// Enable download buttons
$('#download_pub_key').removeClass('disabled');
});
});
}
// Enable button once again (NOTE: user should refresh to re-gen)
$('#generate_keys_btn').removeClass("disabled");
$('#generate_keys_btn').removeClass("btn-primary").addClass("btn-success");
$('#generate_keys_btn').val("Finished");
$('#start_again_btn').removeClass("hide").fadeIn();
});
}
/**
* Download public key as a base64 encoded value.
*/
var calcSubkeySize = function(algo, bitlength) {
if (algo == 'rsa') {
// Return the same exact bitlength for RSA subkeys
return bitlength;
} else if (algo == 'ecc') {
// For ECC the subkeys should be smaller
switch (bitlength) {
case 256:
return 163;
case 384:
return 256;
case 512:
return 384;
default:
_debug("ERROR: Unexpected bitlength found for ECC algorithm!");
return 0;
}
} else {
_debug("ERROR: Unexpected algorithm found!");
return 0;
}
}
/**
* Populate dropdown key size menu.
*/
var populateKeysizeDropdown = function() {
/* Accepted RSA key sizes */
rsa_bitlengths = [{
"value": "",
"class": "disabled",
"text": "Select key size...",
"selected": "selected"
},
{
"value": "1024",
"class": null,
"text": "1024 bits (good for testing purposes)",
"selected": null
},
{
"value": "2048",
"class": null,
"text": "2048 bits (secure)",
"selected": null
},
{
"value": "4096",
"class": null,
"text": "4096 bits (more secure) [Recommended]",
"selected": null
},
{
"value": "8192",
"class": null,
"text": "8192 bits (super secure, super slow)",
"selected": null
},
]
/* Accepted ECC key sizes */
ecc_bitlengths = [{
"value": "",
"class": "disabled",
"text": "Select key size...",
"selected": "selected"
},
//{"value": "163", "class":null, "text":"163 bits (good for testing purposes)", "selected":null},
//{"value": "256", "class":null, "text":"256 bits (secure)", "selected":null},
{
"value": "384",
"class": null,
"text": "384 bits (secure)",
"selected": null
},
//{"value": "512", "class":null, "text":"512 bits (even more secure)", "selected":null},
]
/* Empty existing dropdown list */
$("#bitlength > option").each(function() {
$(this).remove();
});
/* Re-populate */
var option_list = $("#bitlength");
var picked_algorithm = $("#algorithm").val();
var option;
if (picked_algorithm == 'rsa') {
$.each(rsa_bitlengths, function(index, option) {
//console.log(option);
$('<option />', {
value: option['value'],
text: option['text'],
class: option['class'],
selected: option['selected']
}).appendTo(option_list);
});
} else if (picked_algorithm == 'ecc') {
$.each(ecc_bitlengths, function(index, option) {
//console.log(option);
$('<option />', {
value: option['value'],
text: option['text'],
class: option['class'],
selected: option['selected']
}).appendTo(option_list);
});
}
}
/**
* Download public key as a base64 encoded value.
*/
var downloadPubKey = function() {
var blob = new Blob([$('#pubkey').val()], {
type: "text/plain;charset=utf-8"
});
saveAs(blob, "0x" + $('#key_short_id').val() + "-pub.asc");
return false;
}
/**
* Download private key as a base64 encoded value.
*/
var downloadPrivKey = function() {
var blob = new Blob([$('#privkey').val()], {
type: "text/plain;charset=utf-8"
});
saveAs(blob, "0x" + $('#key_short_id').val() + "-sec.asc");
return false;
}
\ No newline at end of file
var i = document.createElement('input');
var html5 = 'placeholder' in i;
$(document).ready(function(){
if(!html5){
$('input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], textarea').each(function(){
if($(this).attr('placeholder'))
$(this).val($(this).attr('placeholder')).addClass('ie9-placeholder');
});
$('input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], textarea').bind('click focus', function(){
if($(this).attr('placeholder') && $(this).attr('placeholder') == $(this).val())
$(this).val(null).removeClass('ie9-placeholder');
});
$('input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], textarea').bind('blur', function(){
if($(this).attr('placeholder') && $.trim($(this).val()).length == 0)
$(this).val($(this).attr('placeholder')).addClass('ie9-placeholder');
});
}
});
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment