为什么要实现密码自动填充?
密码多了记不住怎么办?每次录入太麻烦怎么办?
自己动手丰衣足食!根据应用场景不同,高度定制密码自动填充策略。在这里我将介绍如何使用Firefox的Greasemonkey插件完成这个任务。
Greasemonkey
Greasemonkey,简称GM,中文俗称为“油猴子”,是Mozilla Firefox的一个附加组件。它让用户安装一些脚本使大部分HTML为主的网页于用户端直接改变得更方便易用。随着Greasemonkey脚本常驻于浏览器,每次随着目的网页打开而自动做修改,使得运行脚本的用户印象深刻地享受其固定便利性。
上面的解释来自于度娘。正是Greasemonkey这个可以随着网页打开而执行JavaScript的功能,给了我们执行密码自动填充策略的机会。
用户脚本
执行策略的机会已经有了,接下来就是如何规划了。策略的执行主要还得依靠Greasemonkey,因为它可以让我们执行属于我们自己的用户脚本,而且是可以在网页加载的时候执行。所以基本思路就是恰好在页面加载完成的时候立即用我们自己的JavaScript程序为网页中的密码框填充密码。
具体的操作流程如下:
通过导航菜单Tools/Greasemonkey/Manage User Scripts
打开Greasemonkey插件。
在主画面的上面点击New User Script...
,填写好Name
和Namespace
,再点击OK
按钮进行确认。这时新的用户脚本就创建好了,其中的内容应该与下面的例子差不多。
// ==UserScript==
// @name autoPasswd
// @namespace KNIGHTRCOM
// @version 1
// @grant none
// ==/UserScript==
快速测试
接下来我们可以快速测试一下,录入下面的语句:
alert('test');
脚本保存之后,请随意访问一个网站,这时你会发现无论访问什么网站,总是会弹出一个消息对话框,其中的文本内容便是上门代码中的测试字符串test
。如果你的情形与现在描述的一样,那么恭喜你啦,中奖了哦!
自动化程序
测试成功后要做的就是实现自动化程序,用它来完成密码自动填充。这里需要编写JavaScript程序了,先是要定位网页中的密码输入框元素,然后再填写事先配置好的密码。我们先实现一个简单的,运行成功后可以进一步重构,请参考下面的代码:
// ==UserScript==
// @name autoPasswd
// @namespace KNIGHTRCOM
// @version 1
// @grant none
// @include /^https?:\/\/localhost:900\d\/.*$/
// ==/UserScript==
try {
if (/^https?:\/\/localhost:900\d\/.*$/.test(window.location)) {
var inputs = document.body.getElementsByTagName('input');
for (var i in inputs) {
var input = inputs[i];
if (input.name == 'j_username') {
input.value = 'admin';
} else if (input.name == 'j_password') {
input.value = 'nimda';
}
}
}
} catch (e) { console.error(e); }
这就是我们的第一个工作版本的程序。在此请让我对代码稍作一下解释。最上方的注释里的@include
后面跟随的是JavaScript语法支持的正则表达式,这表示只有满足该表达式样式的网站URL才可以执行我们这段程序。例子中的注释里只有一行@include
,而实际上你可以根据需要增加更多的@include
,如果你放弃使用它的话,那就跟我们在快速测试里实现的效果一样,无论访问哪个网站,脚本程序都会无条件执行。
@include
所处于的注释块被称为metadata,是配置脚本相关信息的地方,详情请见:http://wiki.greasespot.net/Metadata_Block
接下来是程序代码部分,第一行用于检测当前URL地址是否满足执行条件,这里可能会引起一些歧义,既然@include
已经做了类似的排他处理,为什么还需要多此一举的重复检查呢?这种做法的真实原因其实是为了对不同的URL地址定制不同的密码填充策略。@include
只是为脚本执行规划了一个白名单,而符合白名单样式的每一个网站都可能有他们自己的密码填充策略,所以我们需要用不同的样式作为匹配条件来分别实现具体的程序代码。稍后从后面的完整代码中可以更好的体会到这个好处。
代码再往下一些,我们获取了整个网页中所有的输入框控件,并循环遍历这些控件找出符合条件的用户名和密码输入框,然后分别进行赋值操作。至此,自动化脚本程序已经全部完成。不过为了防止一些意外发生,我在程序一开始就买了保险,try
且catch
。
重构 —— 分离数据与行为
现在程序基本上已经可以按照设定那样开始工作了,但为了可以让它看起来更清晰更合理,我们需要对它做进一步重构,基本思想就是把数据从行为中分离出来。
下面让我们看看经过重构之后的第一个程序版本:
// ==UserScript==
// @name autoPasswd
// @namespace KNIGHTRCOM
// @version 1
// @include /^https?://localhost:900[0-9]/.*$/
// @include /^http://epub.ituring.com.cn/Account/Login.*$/
// @include /^https?://.*/(hmc/hybris|hac)([?/].*)?$/
// @grant none
// ==/UserScript==
var globalConfig = {
'stocks': [
{
targetUrlRegex: new RegExp("^http://epub.ituring.com.cn/Account/Login.*$"),
attributeName: 'id',
usernameKey: 'UserName',
usernameVal: 'xxxxxxxxx',
passwordKey: 'Password',
passwordVal: 'xxxxxxxxx'
},
{
targetUrlRegex: new RegExp("^https?://localhost:900[0-9]/(hac)?.*$"),
attributeName: 'name',
usernameKey: 'j_username',
usernameVal: 'xxxxxxxxx',
passwordKey: 'j_password',
passwordVal: 'xxxxxxxxx'
},
{
targetUrlRegex: new RegExp("^https?://localhost:900[0-9]/hmc/hybris.*$"),
attributeName: 'id',
usernameKey: 'Main_user',
usernameVal: 'xxxxxxxxx',
passwordKey: 'Main_password',
passwordVal: 'xxxxxxxxx'
},
{
targetUrlRegex: new RegExp("^https?://(admin-)?prod-.*/(hmc/hybris|hac)/?.*$"),
attributeName: 'id',
usernameKey: 'UserName',
usernameVal: 'xxxxxxxxx',
passwordKey: 'Password',
passwordVal: 'xxxxxxxxx'
},
{
targetUrlRegex: new RegExp("^https?://(admin-)?preprod-.*/(hmc/hybris|hac)/?.*$"),
attributeName: 'id',
usernameKey: 'UserName',
usernameVal: 'xxxxxxxxx',
passwordKey: 'Password',
passwordVal: 'xxxxxxxxx'
},
{
targetUrlRegex: new RegExp("^https?://(admin-)?con-.*/(hmc/hybris|hac)/?.*$"),
attributeName: 'id',
usernameKey: 'UserName',
usernameVal: 'xxxxxxxxx',
passwordKey: 'Password',
passwordVal: 'xxxxxxxxx'
},
{
targetUrlRegex: new RegExp("^https?://(admin-)?qas-.*/(hmc/hybris|hac)/?.*$"),
attributeName: 'id',
usernameKey: 'UserName',
usernameVal: 'xxxxxxxxx',
passwordKey: 'Password',
passwordVal: 'xxxxxxxxx'
},
{
targetUrlRegex: new RegExp("^https?://(admin-)?dev-.*/(hmc/hybris|hac)/?.*$"),
attributeName: 'id',
usernameKey: 'UserName',
usernameVal: 'xxxxxxxxx',
passwordKey: 'Password',
passwordVal: 'xxxxxxxxx'
},
]
};
function autoit() {
try {
var stocks = globalConfig.stocks;
if (!stocks.length) {
return;
}
for (var idx in stocks) {
if (!stocks[idx].targetUrlRegex.test(window.location)) {
continue;
}
var inputs = document.body.getElementsByTagName('input');
for (var i in inputs) {
var input = inputs[i];
if (input[stocks[idx].attributeName] == stocks[idx].usernameKey) {
input.value = stocks[idx].usernameVal;
} else if (input[stocks[idx].attributeName] == stocks[idx].passwordKey) {
input.value = stocks[idx].passwordVal;
}
}
}
} catch (e) {
alert(e.message);
}
}
setTimeout(autoit, 100);
从代码中我们可以看出,所有的配置信息都已经完全从行为逻辑中分离出来了,以配置信息形式存在,并且经过重构之后的行为逻辑较之未重构之前的代码更为灵活通用。另外还有一点要提的是,我们在前面曾经解释过为什么在已经设置了@include
网站URL的情况下,仍要对程序中的网址做二次校验,观察重构后的代码可以发现,实际校验的网址和@include
中配置的网址并不相同,我们可以说程序中的网址更为详细,是@include
网址样式的子集,是一种更为细致的控制。
现在数据和行为逻辑已经分离了,但看起来感觉好像还差点什么似的。
- 密码竟然是明文的,太儿戏了吧?!
- 配置看起来有些繁琐,是否还有优化的空间呢?
好吧,既然还有问题,那就让我们继续开启下一个任务吧!
信息加密与简化配置
明文密码当然要加密,但我并不对自己实现加密功能有信心,那怎么办,总不能等着天上掉馅饼吧?还真别说,馅饼年年有,今年特别多!开源喽 —— SJCL库,详情请见:https://github.com/bitwiseshiftleft/sjcl/wiki
。
The Stanford Javascript Crypto Library is a project by the Stanford Computer Security Lab to build a secure, powerful, fast, small, easy-to-use, cross-browser library for cryptography in Javascript.
下面是代码加密解密的示例代码,我们可以把这段逻辑直接引入密码自动填充功能里。
var sjcl = require('./sjcl.js')
var ciphertext = sjcl.encrypt("any_encrypt_key_string", "Hello World!")
var plaintext = sjcl.decrypt("any_encrypt_key_string", ciphertext)
console.log(ciphertext)
console.log(plaintext)
程序输出结果:
{"iv":"mfzPs58R3vonO0tLZyyDTg==","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"gOLZzYQ6sHI=","ct":"yhiREfrAFIu99e1WEVPG7VCKQUA="}
Hello World!
下面是二次重构后的代码,一方面引入了SJCL库,为密码实现了加密,另一方面重构了数据配置,使得配置更简单。整体结构一共有四部分组成,分别为SJCL库引用、配置信息、配置结构定义和自动化处理。
SJCL库加载 —— 为了实现脚本的快速执行,这里直接把SJCL库的源码粘贴进来,这样就节省了从网络中加载SJCL库的时间。
信息配置 —— 经过再次重构之后的配置内容与初次重构里的差不多,只是密码设置需要稍作调整。这里采用的密码看起来就是一个字符串类型的JSON数据,这种数据是经过加密处理得出的,具体加密操作请参考上面的例子。
配置结构定义 —— 新的结构可以让我们只关注配置的内容,无需考虑配置结构,以及密码解密的细节。
自动化处理 —— 和第一次重构时一样,没有任何变化。
-
其他要点 —— ENCRYPTION_KEY和setTimeout
ENCRYPTION_KEY:这个是密码加密和解密时默认使用的密匙,如果有必要的话,你可以使用你自己的专属密匙来对密码进行加密和解密。如果使用了自定义密匙,在做内容配置的时候就需要为函数
pwdbox
额外再多传入一个密匙参数,这个参数已经在pwdbox
函数中预留出来了,只是在现有的例子中没有使用罢了。setTimeout:为了防止与其他一些自动化程序冲突,这里使用setTimeout来实现延时处理。另外还请注意一下
setTimeout
语句上面的注释内容alert(ENCRYPTION_KEY);
,打开它可以方便我们调试,因为使用Greasemonkey不方便的是,当脚本发生了什么语法错误导致程序无法运行,程序不会有任何表现,所以在这里我用一个alert
来作为程序能过正确通过语法检查的一个信号。
// ==UserScript==
// @name autoPasswd
// @namespace KNIGHTRCOM
// @version 1
// @include /^https?://localhost:900[0-9]/.*$/
// @include /^http://epub.ituring.com.cn/Account/Login.*$/
// @include /^https?://.*/(hmc/hybris|hac)([?/].*)?$/
// @grant none
// ==/UserScript==
"use strict";var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message};this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message};this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message};this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message};this.message=a}}};
"undefined"!==typeof module&&module.exports&&(module.exports=sjcl);"function"===typeof define&&define([],function(){return sjcl});
sjcl.cipher.aes=function(a){this.s[0][0][0]||this.O();var b,c,d,e,g=this.s[0][4],f=this.s[1];b=a.length;var h=1;if(4!==b&&6!==b&&8!==b)throw new sjcl.exception.invalid("invalid aes key size");this.b=[d=a.slice(0),e=[]];for(a=b;a<4*b+28;a++){c=d[a-1];if(0===a%b||8===b&&4===a%b)c=g[c>>>24]<<24^g[c>>16&255]<<16^g[c>>8&255]<<8^g[c&255],0===a%b&&(c=c<<8^c>>>24^h<<24,h=h<<1^283*(h>>7));d[a]=d[a-b]^c}for(b=0;a;b++,a--)c=d[b&3?a:a-4],e[b]=4>=a||4>b?c:f[0][g[c>>>24]]^f[1][g[c>>16&255]]^f[2][g[c>>8&255]]^f[3][g[c&
255]]};
sjcl.cipher.aes.prototype={encrypt:function(a){return u(this,a,0)},decrypt:function(a){return u(this,a,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var a=this.s[0],b=this.s[1],c=a[4],d=b[4],e,g,f,h=[],l=[],k,m,n,p;for(e=0;0x100>e;e++)l[(h[e]=e<<1^283*(e>>7))^e]=e;for(g=f=0;!c[g];g^=k||1,f=l[f]||1)for(n=f^f<<1^f<<2^f<<3^f<<4,n=n>>8^n&255^99,c[g]=n,d[n]=g,m=h[e=h[k=h[g]]],p=0x1010101*m^0x10001*e^0x101*k^0x1010100*g,m=0x101*h[n]^0x1010100*n,e=0;4>e;e++)a[e][g]=m=m<<24^m>>>8,b[e][n]=p=p<<24^p>>>8;for(e=
0;5>e;e++)a[e]=a[e].slice(0),b[e]=b[e].slice(0)}};
function u(a,b,c){if(4!==b.length)throw new sjcl.exception.invalid("invalid aes block size");var d=a.b[c],e=b[0]^d[0],g=b[c?3:1]^d[1],f=b[2]^d[2];b=b[c?1:3]^d[3];var h,l,k,m=d.length/4-2,n,p=4,r=[0,0,0,0];h=a.s[c];a=h[0];var q=h[1],t=h[2],w=h[3],x=h[4];for(n=0;n<m;n++)h=a[e>>>24]^q[g>>16&255]^t[f>>8&255]^w[b&255]^d[p],l=a[g>>>24]^q[f>>16&255]^t[b>>8&255]^w[e&255]^d[p+1],k=a[f>>>24]^q[b>>16&255]^t[e>>8&255]^w[g&255]^d[p+2],b=a[b>>>24]^q[e>>16&255]^t[g>>8&255]^w[f&255]^d[p+3],p+=4,e=h,g=l,f=k;for(n=
0;4>n;n++)r[c?3&-n:n]=x[e>>>24]<<24^x[g>>16&255]<<16^x[f>>8&255]<<8^x[b&255]^d[p++],h=e,e=g,g=f,f=b,b=h;return r}
sjcl.bitArray={bitSlice:function(a,b,c){a=sjcl.bitArray.$(a.slice(b/32),32-(b&31)).slice(1);return void 0===c?a:sjcl.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<<c)-1},concat:function(a,b){if(0===a.length||0===b.length)return a.concat(b);var c=a[a.length-1],d=sjcl.bitArray.getPartial(c);return 32===d?a.concat(b):sjcl.bitArray.$(b,d,c|0,a.slice(0,a.length-1))},bitLength:function(a){var b=a.length;return 0===
b?0:32*(b-1)+sjcl.bitArray.getPartial(a[b-1])},clamp:function(a,b){if(32*a.length<b)return a;a=a.slice(0,Math.ceil(b/32));var c=a.length;b=b&31;0<c&&b&&(a[c-1]=sjcl.bitArray.partial(b,a[c-1]&2147483648>>b-1,1));return a},partial:function(a,b,c){return 32===a?b:(c?b|0:b<<32-a)+0x10000000000*a},getPartial:function(a){return Math.round(a/0x10000000000)||32},equal:function(a,b){if(sjcl.bitArray.bitLength(a)!==sjcl.bitArray.bitLength(b))return!1;var c=0,d;for(d=0;d<a.length;d++)c|=a[d]^b[d];return 0===
c},$:function(a,b,c,d){var e;e=0;for(void 0===d&&(d=[]);32<=b;b-=32)d.push(c),c=0;if(0===b)return d.concat(a);for(e=0;e<a.length;e++)d.push(c|a[e]>>>b),c=a[e]<<32-b;e=a.length?a[a.length-1]:0;a=sjcl.bitArray.getPartial(e);d.push(sjcl.bitArray.partial(b+a&31,32<b+a?c:d.pop(),1));return d},i:function(a,b){return[a[0]^b[0],a[1]^b[1],a[2]^b[2],a[3]^b[3]]},byteswapM:function(a){var b,c;for(b=0;b<a.length;++b)c=a[b],a[b]=c>>>24|c>>>8&0xff00|(c&0xff00)<<8|c<<24;return a}};
sjcl.codec.utf8String={fromBits:function(a){var b="",c=sjcl.bitArray.bitLength(a),d,e;for(d=0;d<c/8;d++)0===(d&3)&&(e=a[d/4]),b+=String.fromCharCode(e>>>24),e<<=8;return decodeURIComponent(escape(b))},toBits:function(a){a=unescape(encodeURIComponent(a));var b=[],c,d=0;for(c=0;c<a.length;c++)d=d<<8|a.charCodeAt(c),3===(c&3)&&(b.push(d),d=0);c&3&&b.push(sjcl.bitArray.partial(8*(c&3),d));return b}};
sjcl.codec.hex={fromBits:function(a){var b="",c;for(c=0;c<a.length;c++)b+=((a[c]|0)+0xf00000000000).toString(16).substr(4);return b.substr(0,sjcl.bitArray.bitLength(a)/4)},toBits:function(a){var b,c=[],d;a=a.replace(/\s|0x/g,"");d=a.length;a=a+"00000000";for(b=0;b<a.length;b+=8)c.push(parseInt(a.substr(b,8),16)^0);return sjcl.bitArray.clamp(c,4*d)}};
sjcl.codec.base32={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",X:"0123456789ABCDEFGHIJKLMNOPQRSTUV",BITS:32,BASE:5,REMAINING:27,fromBits:function(a,b,c){var d=sjcl.codec.base32.BASE,e=sjcl.codec.base32.REMAINING,g="",f=0,h=sjcl.codec.base32.B,l=0,k=sjcl.bitArray.bitLength(a);c&&(h=sjcl.codec.base32.X);for(c=0;g.length*d<k;)g+=h.charAt((l^a[c]>>>f)>>>e),f<d?(l=a[c]<<d-f,f+=e,c++):(l<<=d,f-=d);for(;g.length&7&&!b;)g+="=";return g},toBits:function(a,b){a=a.replace(/\s|=/g,"").toUpperCase();var c=sjcl.codec.base32.BITS,
d=sjcl.codec.base32.BASE,e=sjcl.codec.base32.REMAINING,g=[],f,h=0,l=sjcl.codec.base32.B,k=0,m,n="base32";b&&(l=sjcl.codec.base32.X,n="base32hex");for(f=0;f<a.length;f++){m=l.indexOf(a.charAt(f));if(0>m){if(!b)try{return sjcl.codec.base32hex.toBits(a)}catch(p){}throw new sjcl.exception.invalid("this isn't "+n+"!");}h>e?(h-=e,g.push(k^m>>>h),k=m<<c-h):(h+=d,k^=m<<c-h)}h&56&&g.push(sjcl.bitArray.partial(h&56,k,1));return g}};
sjcl.codec.base32hex={fromBits:function(a,b){return sjcl.codec.base32.fromBits(a,b,1)},toBits:function(a){return sjcl.codec.base32.toBits(a,1)}};
sjcl.codec.base64={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(a,b,c){var d="",e=0,g=sjcl.codec.base64.B,f=0,h=sjcl.bitArray.bitLength(a);c&&(g=g.substr(0,62)+"-_");for(c=0;6*d.length<h;)d+=g.charAt((f^a[c]>>>e)>>>26),6>e?(f=a[c]<<6-e,e+=26,c++):(f<<=6,e-=6);for(;d.length&3&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c=[],d,e=0,g=sjcl.codec.base64.B,f=0,h;b&&(g=g.substr(0,62)+"-_");for(d=0;d<a.length;d++){h=g.indexOf(a.charAt(d));
if(0>h)throw new sjcl.exception.invalid("this isn't base64!");26<e?(e-=26,c.push(f^h>>>e),f=h<<32-e):(e+=6,f^=h<<32-e)}e&56&&c.push(sjcl.bitArray.partial(e&56,f,1));return c}};sjcl.codec.base64url={fromBits:function(a){return sjcl.codec.base64.fromBits(a,1,1)},toBits:function(a){return sjcl.codec.base64.toBits(a,1)}};sjcl.hash.sha256=function(a){this.b[0]||this.O();a?(this.F=a.F.slice(0),this.A=a.A.slice(0),this.l=a.l):this.reset()};sjcl.hash.sha256.hash=function(a){return(new sjcl.hash.sha256).update(a).finalize()};
sjcl.hash.sha256.prototype={blockSize:512,reset:function(){this.F=this.Y.slice(0);this.A=[];this.l=0;return this},update:function(a){"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));var b,c=this.A=sjcl.bitArray.concat(this.A,a);b=this.l;a=this.l=b+sjcl.bitArray.bitLength(a);for(b=512+b&-512;b<=a;b+=512)v(this,c.splice(0,16));return this},finalize:function(){var a,b=this.A,c=this.F,b=sjcl.bitArray.concat(b,[sjcl.bitArray.partial(1,1)]);for(a=b.length+2;a&15;a++)b.push(0);b.push(Math.floor(this.l/
4294967296));for(b.push(this.l|0);b.length;)v(this,b.splice(0,16));this.reset();return c},Y:[],b:[],O:function(){function a(a){return 0x100000000*(a-Math.floor(a))|0}var b=0,c=2,d;a:for(;64>b;c++){for(d=2;d*d<=c;d++)if(0===c%d)continue a;8>b&&(this.Y[b]=a(Math.pow(c,.5)));this.b[b]=a(Math.pow(c,1/3));b++}}};
function v(a,b){var c,d,e,g=b.slice(0),f=a.F,h=a.b,l=f[0],k=f[1],m=f[2],n=f[3],p=f[4],r=f[5],q=f[6],t=f[7];for(c=0;64>c;c++)16>c?d=g[c]:(d=g[c+1&15],e=g[c+14&15],d=g[c&15]=(d>>>7^d>>>18^d>>>3^d<<25^d<<14)+(e>>>17^e>>>19^e>>>10^e<<15^e<<13)+g[c&15]+g[c+9&15]|0),d=d+t+(p>>>6^p>>>11^p>>>25^p<<26^p<<21^p<<7)+(q^p&(r^q))+h[c],t=q,q=r,r=p,p=n+d|0,n=m,m=k,k=l,l=d+(k&m^n&(k^m))+(k>>>2^k>>>13^k>>>22^k<<30^k<<19^k<<10)|0;f[0]=f[0]+l|0;f[1]=f[1]+k|0;f[2]=f[2]+m|0;f[3]=f[3]+n|0;f[4]=f[4]+p|0;f[5]=f[5]+r|0;f[6]=
f[6]+q|0;f[7]=f[7]+t|0}
sjcl.mode.ccm={name:"ccm",G:[],listenProgress:function(a){sjcl.mode.ccm.G.push(a)},unListenProgress:function(a){a=sjcl.mode.ccm.G.indexOf(a);-1<a&&sjcl.mode.ccm.G.splice(a,1)},fa:function(a){var b=sjcl.mode.ccm.G.slice(),c;for(c=0;c<b.length;c+=1)b[c](a)},encrypt:function(a,b,c,d,e){var g,f=b.slice(0),h=sjcl.bitArray,l=h.bitLength(c)/8,k=h.bitLength(f)/8;e=e||64;d=d||[];if(7>l)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(g=2;4>g&&k>>>8*g;g++);g<15-l&&(g=15-l);c=h.clamp(c,
8*(15-g));b=sjcl.mode.ccm.V(a,b,c,d,e,g);f=sjcl.mode.ccm.C(a,f,c,b,e,g);return h.concat(f.data,f.tag)},decrypt:function(a,b,c,d,e){e=e||64;d=d||[];var g=sjcl.bitArray,f=g.bitLength(c)/8,h=g.bitLength(b),l=g.clamp(b,h-e),k=g.bitSlice(b,h-e),h=(h-e)/8;if(7>f)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(b=2;4>b&&h>>>8*b;b++);b<15-f&&(b=15-f);c=g.clamp(c,8*(15-b));l=sjcl.mode.ccm.C(a,l,c,k,e,b);a=sjcl.mode.ccm.V(a,l.data,c,d,e,b);if(!g.equal(l.tag,a))throw new sjcl.exception.corrupt("ccm: tag doesn't match");
return l.data},na:function(a,b,c,d,e,g){var f=[],h=sjcl.bitArray,l=h.i;d=[h.partial(8,(b.length?64:0)|d-2<<2|g-1)];d=h.concat(d,c);d[3]|=e;d=a.encrypt(d);if(b.length)for(c=h.bitLength(b)/8,65279>=c?f=[h.partial(16,c)]:0xffffffff>=c&&(f=h.concat([h.partial(16,65534)],[c])),f=h.concat(f,b),b=0;b<f.length;b+=4)d=a.encrypt(l(d,f.slice(b,b+4).concat([0,0,0])));return d},V:function(a,b,c,d,e,g){var f=sjcl.bitArray,h=f.i;e/=8;if(e%2||4>e||16<e)throw new sjcl.exception.invalid("ccm: invalid tag length");
if(0xffffffff<d.length||0xffffffff<b.length)throw new sjcl.exception.bug("ccm: can't deal with 4GiB or more data");c=sjcl.mode.ccm.na(a,d,c,e,f.bitLength(b)/8,g);for(d=0;d<b.length;d+=4)c=a.encrypt(h(c,b.slice(d,d+4).concat([0,0,0])));return f.clamp(c,8*e)},C:function(a,b,c,d,e,g){var f,h=sjcl.bitArray;f=h.i;var l=b.length,k=h.bitLength(b),m=l/50,n=m;c=h.concat([h.partial(8,g-1)],c).concat([0,0,0]).slice(0,4);d=h.bitSlice(f(d,a.encrypt(c)),0,e);if(!l)return{tag:d,data:[]};for(f=0;f<l;f+=4)f>m&&(sjcl.mode.ccm.fa(f/
l),m+=n),c[3]++,e=a.encrypt(c),b[f]^=e[0],b[f+1]^=e[1],b[f+2]^=e[2],b[f+3]^=e[3];return{tag:d,data:h.clamp(b,k)}}};
sjcl.mode.ocb2={name:"ocb2",encrypt:function(a,b,c,d,e,g){if(128!==sjcl.bitArray.bitLength(c))throw new sjcl.exception.invalid("ocb iv must be 128 bits");var f,h=sjcl.mode.ocb2.S,l=sjcl.bitArray,k=l.i,m=[0,0,0,0];c=h(a.encrypt(c));var n,p=[];d=d||[];e=e||64;for(f=0;f+4<b.length;f+=4)n=b.slice(f,f+4),m=k(m,n),p=p.concat(k(c,a.encrypt(k(c,n)))),c=h(c);n=b.slice(f);b=l.bitLength(n);f=a.encrypt(k(c,[0,0,0,b]));n=l.clamp(k(n.concat([0,0,0]),f),b);m=k(m,k(n.concat([0,0,0]),f));m=a.encrypt(k(m,k(c,h(c))));
d.length&&(m=k(m,g?d:sjcl.mode.ocb2.pmac(a,d)));return p.concat(l.concat(n,l.clamp(m,e)))},decrypt:function(a,b,c,d,e,g){if(128!==sjcl.bitArray.bitLength(c))throw new sjcl.exception.invalid("ocb iv must be 128 bits");e=e||64;var f=sjcl.mode.ocb2.S,h=sjcl.bitArray,l=h.i,k=[0,0,0,0],m=f(a.encrypt(c)),n,p,r=sjcl.bitArray.bitLength(b)-e,q=[];d=d||[];for(c=0;c+4<r/32;c+=4)n=l(m,a.decrypt(l(m,b.slice(c,c+4)))),k=l(k,n),q=q.concat(n),m=f(m);p=r-32*c;n=a.encrypt(l(m,[0,0,0,p]));n=l(n,h.clamp(b.slice(c),p).concat([0,
0,0]));k=l(k,n);k=a.encrypt(l(k,l(m,f(m))));d.length&&(k=l(k,g?d:sjcl.mode.ocb2.pmac(a,d)));if(!h.equal(h.clamp(k,e),h.bitSlice(b,r)))throw new sjcl.exception.corrupt("ocb: tag doesn't match");return q.concat(h.clamp(n,p))},pmac:function(a,b){var c,d=sjcl.mode.ocb2.S,e=sjcl.bitArray,g=e.i,f=[0,0,0,0],h=a.encrypt([0,0,0,0]),h=g(h,d(d(h)));for(c=0;c+4<b.length;c+=4)h=d(h),f=g(f,a.encrypt(g(h,b.slice(c,c+4))));c=b.slice(c);128>e.bitLength(c)&&(h=g(h,d(h)),c=e.concat(c,[-2147483648,0,0,0]));f=g(f,c);
return a.encrypt(g(d(g(h,d(h))),f))},S:function(a){return[a[0]<<1^a[1]>>>31,a[1]<<1^a[2]>>>31,a[2]<<1^a[3]>>>31,a[3]<<1^135*(a[0]>>>31)]}};
sjcl.mode.gcm={name:"gcm",encrypt:function(a,b,c,d,e){var g=b.slice(0);b=sjcl.bitArray;d=d||[];a=sjcl.mode.gcm.C(!0,a,g,d,c,e||128);return b.concat(a.data,a.tag)},decrypt:function(a,b,c,d,e){var g=b.slice(0),f=sjcl.bitArray,h=f.bitLength(g);e=e||128;d=d||[];e<=h?(b=f.bitSlice(g,h-e),g=f.bitSlice(g,0,h-e)):(b=g,g=[]);a=sjcl.mode.gcm.C(!1,a,g,d,c,e);if(!f.equal(a.tag,b))throw new sjcl.exception.corrupt("gcm: tag doesn't match");return a.data},ka:function(a,b){var c,d,e,g,f,h=sjcl.bitArray.i;e=[0,0,
0,0];g=b.slice(0);for(c=0;128>c;c++){(d=0!==(a[Math.floor(c/32)]&1<<31-c%32))&&(e=h(e,g));f=0!==(g[3]&1);for(d=3;0<d;d--)g[d]=g[d]>>>1|(g[d-1]&1)<<31;g[0]>>>=1;f&&(g[0]^=-0x1f000000)}return e},j:function(a,b,c){var d,e=c.length;b=b.slice(0);for(d=0;d<e;d+=4)b[0]^=0xffffffff&c[d],b[1]^=0xffffffff&c[d+1],b[2]^=0xffffffff&c[d+2],b[3]^=0xffffffff&c[d+3],b=sjcl.mode.gcm.ka(b,a);return b},C:function(a,b,c,d,e,g){var f,h,l,k,m,n,p,r,q=sjcl.bitArray;n=c.length;p=q.bitLength(c);r=q.bitLength(d);h=q.bitLength(e);
f=b.encrypt([0,0,0,0]);96===h?(e=e.slice(0),e=q.concat(e,[1])):(e=sjcl.mode.gcm.j(f,[0,0,0,0],e),e=sjcl.mode.gcm.j(f,e,[0,0,Math.floor(h/0x100000000),h&0xffffffff]));h=sjcl.mode.gcm.j(f,[0,0,0,0],d);m=e.slice(0);d=h.slice(0);a||(d=sjcl.mode.gcm.j(f,h,c));for(k=0;k<n;k+=4)m[3]++,l=b.encrypt(m),c[k]^=l[0],c[k+1]^=l[1],c[k+2]^=l[2],c[k+3]^=l[3];c=q.clamp(c,p);a&&(d=sjcl.mode.gcm.j(f,h,c));a=[Math.floor(r/0x100000000),r&0xffffffff,Math.floor(p/0x100000000),p&0xffffffff];d=sjcl.mode.gcm.j(f,d,a);l=b.encrypt(e);
d[0]^=l[0];d[1]^=l[1];d[2]^=l[2];d[3]^=l[3];return{tag:q.bitSlice(d,0,g),data:c}}};sjcl.misc.hmac=function(a,b){this.W=b=b||sjcl.hash.sha256;var c=[[],[]],d,e=b.prototype.blockSize/32;this.w=[new b,new b];a.length>e&&(a=b.hash(a));for(d=0;d<e;d++)c[0][d]=a[d]^909522486,c[1][d]=a[d]^1549556828;this.w[0].update(c[0]);this.w[1].update(c[1]);this.R=new b(this.w[0])};
sjcl.misc.hmac.prototype.encrypt=sjcl.misc.hmac.prototype.mac=function(a){if(this.aa)throw new sjcl.exception.invalid("encrypt on already updated hmac called!");this.update(a);return this.digest(a)};sjcl.misc.hmac.prototype.reset=function(){this.R=new this.W(this.w[0]);this.aa=!1};sjcl.misc.hmac.prototype.update=function(a){this.aa=!0;this.R.update(a)};sjcl.misc.hmac.prototype.digest=function(){var a=this.R.finalize(),a=(new this.W(this.w[1])).update(a).finalize();this.reset();return a};
sjcl.misc.pbkdf2=function(a,b,c,d,e){c=c||1E3;if(0>d||0>c)throw sjcl.exception.invalid("invalid params to pbkdf2");"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));"string"===typeof b&&(b=sjcl.codec.utf8String.toBits(b));e=e||sjcl.misc.hmac;a=new e(a);var g,f,h,l,k=[],m=sjcl.bitArray;for(l=1;32*k.length<(d||1);l++){e=g=a.encrypt(m.concat(b,[l]));for(f=1;f<c;f++)for(g=a.encrypt(g),h=0;h<g.length;h++)e[h]^=g[h];k=k.concat(e)}d&&(k=m.clamp(k,d));return k};
sjcl.prng=function(a){this.c=[new sjcl.hash.sha256];this.m=[0];this.P=0;this.H={};this.N=0;this.U={};this.Z=this.f=this.o=this.ha=0;this.b=[0,0,0,0,0,0,0,0];this.h=[0,0,0,0];this.L=void 0;this.M=a;this.D=!1;this.K={progress:{},seeded:{}};this.u=this.ga=0;this.I=1;this.J=2;this.ca=0x10000;this.T=[0,48,64,96,128,192,0x100,384,512,768,1024];this.da=3E4;this.ba=80};
sjcl.prng.prototype={randomWords:function(a,b){var c=[],d;d=this.isReady(b);var e;if(d===this.u)throw new sjcl.exception.notReady("generator isn't seeded");if(d&this.J){d=!(d&this.I);e=[];var g=0,f;this.Z=e[0]=(new Date).valueOf()+this.da;for(f=0;16>f;f++)e.push(0x100000000*Math.random()|0);for(f=0;f<this.c.length&&(e=e.concat(this.c[f].finalize()),g+=this.m[f],this.m[f]=0,d||!(this.P&1<<f));f++);this.P>=1<<this.c.length&&(this.c.push(new sjcl.hash.sha256),this.m.push(0));this.f-=g;g>this.o&&(this.o=
g);this.P++;this.b=sjcl.hash.sha256.hash(this.b.concat(e));this.L=new sjcl.cipher.aes(this.b);for(d=0;4>d&&(this.h[d]=this.h[d]+1|0,!this.h[d]);d++);}for(d=0;d<a;d+=4)0===(d+1)%this.ca&&y(this),e=z(this),c.push(e[0],e[1],e[2],e[3]);y(this);return c.slice(0,a)},setDefaultParanoia:function(a,b){if(0===a&&"Setting paranoia=0 will ruin your security; use it only for testing"!==b)throw"Setting paranoia=0 will ruin your security; use it only for testing";this.M=a},addEntropy:function(a,b,c){c=c||"user";
var d,e,g=(new Date).valueOf(),f=this.H[c],h=this.isReady(),l=0;d=this.U[c];void 0===d&&(d=this.U[c]=this.ha++);void 0===f&&(f=this.H[c]=0);this.H[c]=(this.H[c]+1)%this.c.length;switch(typeof a){case "number":void 0===b&&(b=1);this.c[f].update([d,this.N++,1,b,g,1,a|0]);break;case "object":c=Object.prototype.toString.call(a);if("[object Uint32Array]"===c){e=[];for(c=0;c<a.length;c++)e.push(a[c]);a=e}else for("[object Array]"!==c&&(l=1),c=0;c<a.length&&!l;c++)"number"!==typeof a[c]&&(l=1);if(!l){if(void 0===
b)for(c=b=0;c<a.length;c++)for(e=a[c];0<e;)b++,e=e>>>1;this.c[f].update([d,this.N++,2,b,g,a.length].concat(a))}break;case "string":void 0===b&&(b=a.length);this.c[f].update([d,this.N++,3,b,g,a.length]);this.c[f].update(a);break;default:l=1}if(l)throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[f]+=b;this.f+=b;h===this.u&&(this.isReady()!==this.u&&A("seeded",Math.max(this.o,this.f)),A("progress",this.getProgress()))},isReady:function(a){a=this.T[void 0!==
a?a:this.M];return this.o&&this.o>=a?this.m[0]>this.ba&&(new Date).valueOf()>this.Z?this.J|this.I:this.I:this.f>=a?this.J|this.u:this.u},getProgress:function(a){a=this.T[a?a:this.M];return this.o>=a?1:this.f>a?1:this.f/a},startCollectors:function(){if(!this.D){this.a={loadTimeCollector:B(this,this.ma),mouseCollector:B(this,this.oa),keyboardCollector:B(this,this.la),accelerometerCollector:B(this,this.ea),touchCollector:B(this,this.qa)};if(window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,
!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new sjcl.exception.bug("can't attach event");
this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",
this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(a,b){this.K[a][this.ga++]=b},removeEventListener:function(a,b){var c,d,e=this.K[a],g=[];for(d in e)e.hasOwnProperty(d)&&e[d]===b&&g.push(d);for(c=0;c<g.length;c++)d=g[c],delete e[d]},la:function(){C(1)},oa:function(a){var b,c;try{b=a.x||a.clientX||a.offsetX||0,c=a.y||a.clientY||a.offsetY||0}catch(d){c=b=0}0!=b&&0!=c&&sjcl.random.addEntropy([b,c],2,"mouse");C(0)},qa:function(a){a=
a.touches[0]||a.changedTouches[0];sjcl.random.addEntropy([a.pageX||a.clientX,a.pageY||a.clientY],1,"touch");C(0)},ma:function(){C(2)},ea:function(a){a=a.accelerationIncludingGravity.x||a.accelerationIncludingGravity.y||a.accelerationIncludingGravity.z;if(window.orientation){var b=window.orientation;"number"===typeof b&&sjcl.random.addEntropy(b,1,"accelerometer")}a&&sjcl.random.addEntropy(a,2,"accelerometer");C(0)}};
function A(a,b){var c,d=sjcl.random.K[a],e=[];for(c in d)d.hasOwnProperty(c)&&e.push(d[c]);for(c=0;c<e.length;c++)e[c](b)}function C(a){"undefined"!==typeof window&&window.performance&&"function"===typeof window.performance.now?sjcl.random.addEntropy(window.performance.now(),a,"loadtime"):sjcl.random.addEntropy((new Date).valueOf(),a,"loadtime")}function y(a){a.b=z(a).concat(z(a));a.L=new sjcl.cipher.aes(a.b)}
function z(a){for(var b=0;4>b&&(a.h[b]=a.h[b]+1|0,!a.h[b]);b++);return a.L.encrypt(a.h)}function B(a,b){return function(){b.apply(a,arguments)}}sjcl.random=new sjcl.prng(6);
a:try{var D,E,F,G;if(G="undefined"!==typeof module&&module.exports){var H;try{H=require("crypto")}catch(a){H=null}G=E=H}if(G&&E.randomBytes)D=E.randomBytes(128),D=new Uint32Array((new Uint8Array(D)).buffer),sjcl.random.addEntropy(D,1024,"crypto['randomBytes']");else if("undefined"!==typeof window&&"undefined"!==typeof Uint32Array){F=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(F);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(F);
else break a;sjcl.random.addEntropy(F,1024,"crypto['getRandomValues']")}}catch(a){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(a))}
sjcl.json={defaults:{v:1,iter:1E3,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(a,b,c,d){c=c||{};d=d||{};var e=sjcl.json,g=e.g({iv:sjcl.random.randomWords(4,0)},e.defaults),f;e.g(g,c);c=g.adata;"string"===typeof g.salt&&(g.salt=sjcl.codec.base64.toBits(g.salt));"string"===typeof g.iv&&(g.iv=sjcl.codec.base64.toBits(g.iv));if(!sjcl.mode[g.mode]||!sjcl.cipher[g.cipher]||"string"===typeof a&&100>=g.iter||64!==g.ts&&96!==g.ts&&128!==g.ts||128!==g.ks&&192!==g.ks&&0x100!==g.ks||2>g.iv.length||
4<g.iv.length)throw new sjcl.exception.invalid("json encrypt: invalid parameters");"string"===typeof a?(f=sjcl.misc.cachedPbkdf2(a,g),a=f.key.slice(0,g.ks/32),g.salt=f.salt):sjcl.ecc&&a instanceof sjcl.ecc.elGamal.publicKey&&(f=a.kem(),g.kemtag=f.tag,a=f.key.slice(0,g.ks/32));"string"===typeof b&&(b=sjcl.codec.utf8String.toBits(b));"string"===typeof c&&(g.adata=c=sjcl.codec.utf8String.toBits(c));f=new sjcl.cipher[g.cipher](a);e.g(d,g);d.key=a;g.ct="ccm"===g.mode&&sjcl.arrayBuffer&&sjcl.arrayBuffer.ccm&&
b instanceof ArrayBuffer?sjcl.arrayBuffer.ccm.encrypt(f,b,g.iv,c,g.ts):sjcl.mode[g.mode].encrypt(f,b,g.iv,c,g.ts);return g},encrypt:function(a,b,c,d){var e=sjcl.json,g=e.ja.apply(e,arguments);return e.encode(g)},ia:function(a,b,c,d){c=c||{};d=d||{};var e=sjcl.json;b=e.g(e.g(e.g({},e.defaults),b),c,!0);var g,f;g=b.adata;"string"===typeof b.salt&&(b.salt=sjcl.codec.base64.toBits(b.salt));"string"===typeof b.iv&&(b.iv=sjcl.codec.base64.toBits(b.iv));if(!sjcl.mode[b.mode]||!sjcl.cipher[b.cipher]||"string"===
typeof a&&100>=b.iter||64!==b.ts&&96!==b.ts&&128!==b.ts||128!==b.ks&&192!==b.ks&&0x100!==b.ks||!b.iv||2>b.iv.length||4<b.iv.length)throw new sjcl.exception.invalid("json decrypt: invalid parameters");"string"===typeof a?(f=sjcl.misc.cachedPbkdf2(a,b),a=f.key.slice(0,b.ks/32),b.salt=f.salt):sjcl.ecc&&a instanceof sjcl.ecc.elGamal.secretKey&&(a=a.unkem(sjcl.codec.base64.toBits(b.kemtag)).slice(0,b.ks/32));"string"===typeof g&&(g=sjcl.codec.utf8String.toBits(g));f=new sjcl.cipher[b.cipher](a);g="ccm"===
b.mode&&sjcl.arrayBuffer&&sjcl.arrayBuffer.ccm&&b.ct instanceof ArrayBuffer?sjcl.arrayBuffer.ccm.decrypt(f,b.ct,b.iv,b.tag,g,b.ts):sjcl.mode[b.mode].decrypt(f,b.ct,b.iv,g,b.ts);e.g(d,b);d.key=a;return 1===c.raw?g:sjcl.codec.utf8String.fromBits(g)},decrypt:function(a,b,c,d){var e=sjcl.json;return e.ia(a,e.decode(b),c,d)},encode:function(a){var b,c="{",d="";for(b in a)if(a.hasOwnProperty(b)){if(!b.match(/^[a-z0-9]+$/i))throw new sjcl.exception.invalid("json encode: invalid property name");c+=d+'"'+
b+'":';d=",";switch(typeof a[b]){case "number":case "boolean":c+=a[b];break;case "string":c+='"'+escape(a[b])+'"';break;case "object":c+='"'+sjcl.codec.base64.fromBits(a[b],0)+'"';break;default:throw new sjcl.exception.bug("json encode: unsupported type");}}return c+"}"},decode:function(a){a=a.replace(/\s/g,"");if(!a.match(/^\{.*\}$/))throw new sjcl.exception.invalid("json decode: this isn't json!");a=a.replace(/^\{|\}$/g,"").split(/,/);var b={},c,d;for(c=0;c<a.length;c++){if(!(d=a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i)))throw new sjcl.exception.invalid("json decode: this isn't json!");
null!=d[3]?b[d[2]]=parseInt(d[3],10):null!=d[4]?b[d[2]]=d[2].match(/^(ct|adata|salt|iv)$/)?sjcl.codec.base64.toBits(d[4]):unescape(d[4]):null!=d[5]&&(b[d[2]]="true"===d[5])}return b},g:function(a,b,c){void 0===a&&(a={});if(void 0===b)return a;for(var d in b)if(b.hasOwnProperty(d)){if(c&&void 0!==a[d]&&a[d]!==b[d])throw new sjcl.exception.invalid("required parameter overridden");a[d]=b[d]}return a},sa:function(a,b){var c={},d;for(d in a)a.hasOwnProperty(d)&&a[d]!==b[d]&&(c[d]=a[d]);return c},ra:function(a,
b){var c={},d;for(d=0;d<b.length;d++)void 0!==a[b[d]]&&(c[b[d]]=a[b[d]]);return c}};sjcl.encrypt=sjcl.json.encrypt;sjcl.decrypt=sjcl.json.decrypt;sjcl.misc.pa={};sjcl.misc.cachedPbkdf2=function(a,b){var c=sjcl.misc.pa,d;b=b||{};d=b.iter||1E3;c=c[a]=c[a]||{};d=c[d]=c[d]||{firstSalt:b.salt&&b.salt.length?b.salt.slice(0):sjcl.random.randomWords(2,0)};c=void 0===b.salt?d.firstSalt:b.salt;d[c]=d[c]||sjcl.misc.pbkdf2(a,c,b.iter);return{key:d[c].slice(0),salt:c.slice(0)}};
var ENCRYPTION_KEY = "SCJL";
//alert(sjcl.decrypt(ENCRYPTION_KEY, sjcl.encrypt(ENCRYPTION_KEY, "Y0ur-P@ssw0rd")));
var globalConfig = {
'stocks': [
pwdbox( new RegExp("^http://epub.ituring.com.cn/Account/Login.*$"),
'id', 'UserName', 'xxxxxxxxx', 'Password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox( new RegExp("^https?://localhost:900[0-9]/(hac|solrfacetsearch)?.*$"),
'name', 'j_username', 'xxxxxxxxx', 'j_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://localhost:900[0-9]/hmc/hybris.*$"),
'id', 'Main_user', 'xxxxxxxxx', 'Main_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?prod-.*/(hmc/hybris)/?.*$"),
'id', 'Main_user', 'xxxxxxxxx', 'Main_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?prod-emea-.*/(hmc/hybris)/?.*$"),
'id', 'Main_user', 'xxxxxxxxx', 'Main_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?prod-emea-.*/(hac)/?.*$"),
'name', 'j_username', 'xxxxxxxxx', 'j_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?preprod-.*/(hmc/hybris)/?.*$"),
'id', 'Main_user', 'xxxxxxxxx', 'Main_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?preprod-.*/(hac)/?.*$"),
'name', 'j_username', 'xxxxxxxxx', 'j_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?con-.*/(hmc/hybris)/?.*$"),
'id', 'Main_user', 'xxxxxxxxx', 'Main_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?con-.*/(hac)/?.*$"),
'name', 'j_username', 'xxxxxxxxx', 'j_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?qas-.*/(hmc/hybris)/?.*$"),
'id', 'Main_user', 'xxxxxxxxx', 'Main_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?qas-.*/(hac)/?.*$"),
'name', 'j_username', 'xxxxxxxxx', 'j_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?dev-.*/(hmc/hybris)/?.*$"),
'id', 'Main_user', 'xxxxxxxxx', 'Main_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
pwdbox(new RegExp("^https?://(admin-)?dev-.*/(hac)/?.*$"),
'name', 'j_username', 'xxxxxxxxx', 'j_password',
'{"iv":"xxxxxxxxx","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"xxxxxxxxx","ct":"xxxxxxxxx"}'
),
]
};
function pwdbox(targetUrlRegex, attributeName, usernameKey, usernameVal, passwordKey, passwordVal, encryptKey) {
if (!encryptKey) {
encryptKey = ENCRYPTION_KEY;
}
return {
"targetUrlRegex": targetUrlRegex,
"attributeName": attributeName,
"usernameKey": usernameKey,
"usernameVal": usernameVal,
"passwordKey": passwordKey,
"passwordVal": sjcl.decrypt(encryptKey, passwordVal),
"encryptKey": encryptKey
};
}
function autoit() {
try {
var stocks = globalConfig.stocks;
if (!stocks.length) {
return;
}
for (var idx in stocks) {
if (!stocks[idx].targetUrlRegex.test(window.location)) {
continue;
}
var inputs = document.body.getElementsByTagName('input');
for (var i in inputs) {
var input = inputs[i];
if (input[stocks[idx].attributeName] == stocks[idx].usernameKey) {
input.value = stocks[idx].usernameVal;
} else if (input[stocks[idx].attributeName] == stocks[idx].passwordKey) {
input.value = stocks[idx].passwordVal;
}
}
}
} catch (e) {
alert(e.message);
}
}
//alert(ENCRYPTION_KEY);
setTimeout(autoit, 100);
后记
至此,我们的密码自动填充功能已经完成。你还能想起学到了些什么吗?请回顾后回答下面的问题:
Greasemonkey的用途
用户脚本的需要设置什么,目的何在
自动化密码填充的基本策略
如何实现密码的加密与解密