mirror of
https://github.com/bitwarden/web
synced 2025-12-06 00:03:28 +00:00
1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
!function(e,t,r,n,o,a,s){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,a=t.createElement(r),s=t.getElementsByTagName(r)[0],a.async=1,a.src="https://www.google-analytics.com/analytics.js",s.parentNode.insertBefore(a,s)}(window,document,"script",0,"ga"),ga("create","UA-81915606-3","auto");var AdminLTEOptions={controlSidebarOptions:{selector:"#adminlte-fakeselector"}};!function(e){var t=-1!==navigator.userAgent.indexOf("Firefox")||-1!==navigator.userAgent.indexOf("Gecko/"),r=!(void 0===e.u2f||!e.u2f.register);if(t&&r)e.u2f.isSupported=!0;else{var n=e.u2f||{};n.isSupported=!!(void 0!==n&&n.register||"undefined"!=typeof chrome&&chrome.runtime);var o;n.EXTENSION_ID="kmendfapggjehodndflmmgagdbamhnfd",n.MessageTypes={U2F_REGISTER_REQUEST:"u2f_register_request",U2F_REGISTER_RESPONSE:"u2f_register_response",U2F_SIGN_REQUEST:"u2f_sign_request",U2F_SIGN_RESPONSE:"u2f_sign_response",U2F_GET_API_VERSION_REQUEST:"u2f_get_api_version_request",U2F_GET_API_VERSION_RESPONSE:"u2f_get_api_version_response"},n.ErrorCodes={OK:0,OTHER_ERROR:1,BAD_REQUEST:2,CONFIGURATION_UNSUPPORTED:3,DEVICE_INELIGIBLE:4,TIMEOUT:5},n.U2fRequest,n.U2fResponse,n.Error,n.Transport,n.Transports,n.SignRequest,n.SignResponse,n.RegisterRequest,n.RegisterResponse,n.RegisteredKey,n.GetJsApiVersionResponse,n.getMessagePort=function(e){if("undefined"!=typeof chrome&&chrome.runtime){var t={type:n.MessageTypes.U2F_SIGN_REQUEST,signRequests:[]};chrome.runtime.sendMessage(n.EXTENSION_ID,t,function(){chrome.runtime.lastError?n.getIframePort_(e):n.getChromeRuntimePort_(e)})}else n.isAndroidChrome_()?n.getAuthenticatorPort_(e):n.isIosChrome_()?n.getIosPort_(e):n.getIframePort_(e)},n.isAndroidChrome_=function(){var e=navigator.userAgent;return-1!=e.indexOf("Chrome")&&-1!=e.indexOf("Android")},n.isIosChrome_=function(){return["iPhone","iPad","iPod"].indexOf(navigator.platform)>-1},n.getChromeRuntimePort_=function(e){var t=chrome.runtime.connect(n.EXTENSION_ID,{includeTlsChannelId:!0});setTimeout(function(){e(new n.WrappedChromeRuntimePort_(t))},0)},n.getAuthenticatorPort_=function(e){setTimeout(function(){e(new n.WrappedAuthenticatorPort_)},0)},n.getIosPort_=function(e){setTimeout(function(){e(new n.WrappedIosPort_)},0)},n.WrappedChromeRuntimePort_=function(e){this.port_=e},n.formatSignRequest_=function(e,t,r,a,s){if(void 0===o||o<1.1){for(var i=[],u=0;u<r.length;u++)i[u]={version:r[u].version,challenge:t,keyHandle:r[u].keyHandle,appId:e};return{type:n.MessageTypes.U2F_SIGN_REQUEST,signRequests:i,timeoutSeconds:a,requestId:s}}return{type:n.MessageTypes.U2F_SIGN_REQUEST,appId:e,challenge:t,registeredKeys:r,timeoutSeconds:a,requestId:s}},n.formatRegisterRequest_=function(e,t,r,a,s){if(void 0===o||o<1.1){for(u=0;u<r.length;u++)r[u].appId=e;for(var i=[],u=0;u<t.length;u++)i[u]={version:t[u].version,challenge:r[0],keyHandle:t[u].keyHandle,appId:e};return{type:n.MessageTypes.U2F_REGISTER_REQUEST,signRequests:i,registerRequests:r,timeoutSeconds:a,requestId:s}}return{type:n.MessageTypes.U2F_REGISTER_REQUEST,appId:e,registerRequests:r,registeredKeys:t,timeoutSeconds:a,requestId:s}},n.WrappedChromeRuntimePort_.prototype.postMessage=function(e){this.port_.postMessage(e)},n.WrappedChromeRuntimePort_.prototype.addEventListener=function(e,t){var r=e.toLowerCase();"message"==r||"onmessage"==r?this.port_.onMessage.addListener(function(e){t({data:e})}):console.error("WrappedChromeRuntimePort only supports onMessage")},n.WrappedAuthenticatorPort_=function(){this.requestId_=-1,this.requestObject_=null},n.WrappedAuthenticatorPort_.prototype.postMessage=function(e){var t=n.WrappedAuthenticatorPort_.INTENT_URL_BASE_+";S.request="+encodeURIComponent(JSON.stringify(e))+";end";document.location=t},n.WrappedAuthenticatorPort_.prototype.getPortType=function(){return"WrappedAuthenticatorPort_"},n.WrappedAuthenticatorPort_.prototype.addEventListener=function(e,t){if("message"==e.toLowerCase()){var r=this;window.addEventListener("message",r.onRequestUpdate_.bind(r,t),!1)}else console.error("WrappedAuthenticatorPort only supports message")},n.WrappedAuthenticatorPort_.prototype.onRequestUpdate_=function(e,t){var r=JSON.parse(t.data),n=(r.intentURL,r.errorCode,null);r.hasOwnProperty("data")&&(n=JSON.parse(r.data)),e({data:n})},n.WrappedAuthenticatorPort_.INTENT_URL_BASE_="intent:#Intent;action=com.google.android.apps.authenticator.AUTHENTICATE",n.WrappedIosPort_=function(){},n.WrappedIosPort_.prototype.postMessage=function(e){var t=JSON.stringify(e),r="u2f://auth?"+encodeURI(t);location.replace(r)},n.WrappedIosPort_.prototype.getPortType=function(){return"WrappedIosPort_"},n.WrappedIosPort_.prototype.addEventListener=function(e,t){"message"!==e.toLowerCase()&&console.error("WrappedIosPort only supports message")},n.getIframePort_=function(e){var t="chrome-extension://"+n.EXTENSION_ID,r=document.createElement("iframe");r.src=t+"/u2f-comms.html",r.setAttribute("style","display:none"),document.body.appendChild(r);var o=new MessageChannel,a=function(t){"ready"==t.data?(o.port1.removeEventListener("message",a),e(o.port1)):console.error('First event on iframe port was not "ready"')};o.port1.addEventListener("message",a),o.port1.start(),r.addEventListener("load",function(){r.contentWindow.postMessage("init",t,[o.port2])})},n.EXTENSION_TIMEOUT_SEC=30,n.port_=null,n.waitingForPort_=[],n.reqCounter_=0,n.callbackMap_={},n.getPortSingleton_=function(e){n.port_?e(n.port_):(0==n.waitingForPort_.length&&n.getMessagePort(function(e){for(n.port_=e,n.port_.addEventListener("message",n.responseHandler_);n.waitingForPort_.length;)n.waitingForPort_.shift()(n.port_)}),n.waitingForPort_.push(e))},n.responseHandler_=function(e){var t=e.data,r=t.requestId;if(r&&n.callbackMap_[r]){var o=n.callbackMap_[r];delete n.callbackMap_[r],o(t.responseData)}else console.error("Unknown or missing requestId in response.")},n.sign=function(e,t,r,a,s){void 0===o?n.getApiVersion(function(i){o=void 0===i.js_api_version?0:i.js_api_version,console.log("Extension JS API Version: ",o),n.sendSignRequest(e,t,r,a,s)}):n.sendSignRequest(e,t,r,a,s)},n.sendSignRequest=function(e,t,r,o,a){n.getPortSingleton_(function(s){var i=++n.reqCounter_;n.callbackMap_[i]=o;var u=void 0!==a?a:n.EXTENSION_TIMEOUT_SEC,p=n.formatSignRequest_(e,t,r,u,i);s.postMessage(p)})},n.register=function(e,t,r,a,s){void 0===o?n.getApiVersion(function(i){o=void 0===i.js_api_version?0:i.js_api_version,console.log("Extension JS API Version: ",o),n.sendRegisterRequest(e,t,r,a,s)}):n.sendRegisterRequest(e,t,r,a,s)},n.sendRegisterRequest=function(e,t,r,o,a){n.getPortSingleton_(function(s){var i=++n.reqCounter_;n.callbackMap_[i]=o;var u=void 0!==a?a:n.EXTENSION_TIMEOUT_SEC,p=n.formatRegisterRequest_(e,r,t,u,i);s.postMessage(p)})},n.getApiVersion=function(e,t){n.getPortSingleton_(function(r){if(r.getPortType){var o;switch(r.getPortType()){case"WrappedIosPort_":case"WrappedAuthenticatorPort_":o=1.1;break;default:o=0}e({js_api_version:o})}else{var a=++n.reqCounter_;n.callbackMap_[a]=e;var s={type:n.MessageTypes.U2F_GET_API_VERSION_REQUEST,timeoutSeconds:void 0!==t?t:n.EXTENSION_TIMEOUT_SEC,requestId:a};r.postMessage(s)}})},e.u2f=n}}(this),function(e){"use strict";function t(e){return btoa(e).replace(/\=+$/,"").replace(/\+/g,"-").replace(/\//g,"_")}function r(e){return e+="===",e=e.slice(0,-e.length%4),atob(e.replace(/-/g,"+").replace(/_/g,"/"))}function n(e){for(var t=new Uint8Array(e.length),r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}function o(e){return e instanceof ArrayBuffer&&(e=new Uint8Array(e)),String.fromCharCode.apply(String,e)}function a(e){var t={name:(e.name||e||"").toUpperCase().replace("V","v")};switch(t.name){case"SHA-1":case"SHA-256":case"SHA-384":case"SHA-512":break;case"AES-CBC":case"AES-GCM":case"AES-KW":e.length&&(t.length=e.length);break;case"HMAC":e.hash&&(t.hash=a(e.hash)),e.length&&(t.length=e.length);break;case"RSAES-PKCS1-v1_5":e.publicExponent&&(t.publicExponent=new Uint8Array(e.publicExponent)),e.modulusLength&&(t.modulusLength=e.modulusLength);break;case"RSASSA-PKCS1-v1_5":case"RSA-OAEP":e.hash&&(t.hash=a(e.hash)),e.publicExponent&&(t.publicExponent=new Uint8Array(e.publicExponent)),e.modulusLength&&(t.modulusLength=e.modulusLength);break;default:throw new SyntaxError("Bad algorithm name")}return t}function s(e){return{HMAC:{"SHA-1":"HS1","SHA-256":"HS256","SHA-384":"HS384","SHA-512":"HS512"},"RSASSA-PKCS1-v1_5":{"SHA-1":"RS1","SHA-256":"RS256","SHA-384":"RS384","SHA-512":"RS512"},"RSAES-PKCS1-v1_5":{"":"RSA1_5"},"RSA-OAEP":{"SHA-1":"RSA-OAEP","SHA-256":"RSA-OAEP-256"},"AES-KW":{128:"A128KW",192:"A192KW",256:"A256KW"},"AES-GCM":{128:"A128GCM",192:"A192GCM",256:"A256GCM"},"AES-CBC":{128:"A128CBC",192:"A192CBC",256:"A256CBC"}}[e.name][(e.hash||{}).name||e.length||""]}function i(e){(e instanceof ArrayBuffer||e instanceof Uint8Array)&&(e=JSON.parse(decodeURIComponent(escape(o(e)))));var t={kty:e.kty,alg:e.alg,ext:e.ext||e.extractable};switch(t.kty){case"oct":t.k=e.k;case"RSA":["n","e","d","p","q","dp","dq","qi","oth"].forEach(function(r){r in e&&(t[r]=e[r])});break;default:throw new TypeError("Unsupported key type")}return t}function u(e){var t=i(e);return E&&(t.extractable=t.ext,delete t.ext),n(unescape(encodeURIComponent(JSON.stringify(t)))).buffer}function p(e){var r=l(e),n=!1;r.length>2&&(n=!0,r.shift());var a={ext:!0};switch(r[0][0]){case"1.2.840.113549.1.1.1":var s=["n","e","d","p","q","dp","dq","qi"],i=l(r[1]);n&&i.shift();for(var u=0;u<i.length;u++)i[u][0]||(i[u]=i[u].subarray(1)),a[s[u]]=t(o(i[u]));a.kty="RSA";break;default:throw new TypeError("Unsupported key type")}return a}function c(e){var t,o=[["",null]],a=!1;switch(e.kty){case"RSA":for(var s=["n","e","d","p","q","dp","dq","qi"],i=[],u=0;u<s.length&&s[u]in e;u++){var p=i[u]=n(r(e[s[u]]));128&p[0]&&(i[u]=new Uint8Array(p.length+1),i[u].set(p,1))}i.length>2&&(a=!0,i.unshift(new Uint8Array([0]))),o[0][0]="1.2.840.113549.1.1.1",t=i;break;default:throw new TypeError("Unsupported key type")}return o.push(new Uint8Array(f(t)).buffer),a?o.unshift(new Uint8Array([0])):o[1]={tag:3,value:o[1]},new Uint8Array(f(o)).buffer}function l(e,t){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),t||(t={pos:0,end:e.length}),t.end-t.pos<2||t.end>e.length)throw new RangeError("Malformed DER");var r=e[t.pos++],n=e[t.pos++];if(n>=128){if(n&=127,t.end-t.pos<n)throw new RangeError("Malformed DER");for(var a=0;n--;)a<<=8,a|=e[t.pos++];n=a}if(t.end-t.pos<n)throw new RangeError("Malformed DER");var s;switch(r){case 2:s=e.subarray(t.pos,t.pos+=n);break;case 3:if(e[t.pos++])throw new Error("Unsupported bit string");n--;case 4:s=new Uint8Array(e.subarray(t.pos,t.pos+=n)).buffer;break;case 5:s=null;break;case 6:var i=btoa(o(e.subarray(t.pos,t.pos+=n)));if(!(i in v))throw new Error("Unsupported OBJECT ID "+i);s=v[i];break;case 48:s=[];for(var u=t.pos+n;t.pos<u;)s.push(l(e,t));break;default:throw new Error("Unsupported DER tag 0x"+r.toString(16))}return s}function f(e,t){t||(t=[]);var r=0,o=0,a=t.length+2;if(t.push(0,0),e instanceof Uint8Array){r=2,o=e.length;for(i=0;i<o;i++)t.push(e[i])}else if(e instanceof ArrayBuffer){r=4,o=e.byteLength,e=new Uint8Array(e);for(i=0;i<o;i++)t.push(e[i])}else if(null===e)r=5,o=0;else if("string"==typeof e&&e in w){var s=n(atob(w[e]));r=6,o=s.length;for(i=0;i<o;i++)t.push(s[i])}else if(e instanceof Array){for(i=0;i<e.length;i++)f(e[i],t);r=48,o=t.length-a}else{if(!("object"==typeof e&&3===e.tag&&e.value instanceof ArrayBuffer))throw new Error("Unsupported DER value "+e);r=3,o=(e=new Uint8Array(e.value)).byteLength,t.push(0);for(var i=0;i<o;i++)t.push(e[i]);o++}if(o>=128){var u=o,o=4;for(t.splice(a,0,u>>24&255,u>>16&255,u>>8&255,255&u);o>1&&!(u>>24);)u<<=8,o--;o<4&&t.splice(a,4-o),o|=128}return t.splice(a-2,2,r,o),t}function g(e,t,r,n){Object.defineProperties(this,{_key:{value:e},type:{value:e.type,enumerable:!0},extractable:{value:void 0===r?e.extractable:r,enumerable:!0},algorithm:{value:void 0===t?e.algorithm:t,enumerable:!0},usages:{value:void 0===n?e.usages:n,enumerable:!0}})}function d(e){return"verify"===e||"encrypt"===e||"wrapKey"===e}function y(e){return"sign"===e||"decrypt"===e||"unwrapKey"===e}var h=e.crypto||e.msCrypto;if(h){var _=h.subtle||h.webkitSubtle;if(_){var m=e.Crypto||h.constructor||Object,S=e.SubtleCrypto||_.constructor||Object,E=(e.CryptoKey||e.Key||Object,!!e.msCrypto),A=!h.subtle&&!!h.webkitSubtle;if(E||A){e.cryptoShimmed=!0;var v={KoZIhvcNAQEB:"1.2.840.113549.1.1.1"},w={"1.2.840.113549.1.1.1":"KoZIhvcNAQEB"};if(["generateKey","importKey","unwrapKey"].forEach(function(e){var t=_[e];_[e]=function(o,c,l){var f,m,S,v=[].slice.call(arguments);switch(e){case"generateKey":f=a(o),m=c,S=l;break;case"importKey":f=a(l),m=v[3],S=v[4],"jwk"===o&&((c=i(c)).alg||(c.alg=s(f)),c.key_ops||(c.key_ops="oct"!==c.kty?"d"in c?S.filter(y):S.filter(d):S.slice()),v[1]=u(c));break;case"unwrapKey":f=v[4],m=v[5],S=v[6],v[2]=l._key}if("generateKey"===e&&"HMAC"===f.name&&f.hash)return f.length=f.length||{"SHA-1":512,"SHA-256":512,"SHA-384":1024,"SHA-512":1024}[f.hash.name],_.importKey("raw",h.getRandomValues(new Uint8Array(f.length+7>>3)),f,m,S);if(A&&"generateKey"===e&&"RSASSA-PKCS1-v1_5"===f.name&&(!f.modulusLength||f.modulusLength>=2048))return o=a(o),o.name="RSAES-PKCS1-v1_5",delete o.hash,_.generateKey(o,!0,["encrypt","decrypt"]).then(function(e){return Promise.all([_.exportKey("jwk",e.publicKey),_.exportKey("jwk",e.privateKey)])}).then(function(e){return e[0].alg=e[1].alg=s(f),e[0].key_ops=S.filter(d),e[1].key_ops=S.filter(y),Promise.all([_.importKey("jwk",e[0],f,!0,e[0].key_ops),_.importKey("jwk",e[1],f,m,e[1].key_ops)])}).then(function(e){return{publicKey:e[0],privateKey:e[1]}});if((A||E&&"SHA-1"===(f.hash||{}).name)&&"importKey"===e&&"jwk"===o&&"HMAC"===f.name&&"oct"===c.kty)return _.importKey("raw",n(r(c.k)),l,v[3],v[4]);if(A&&"importKey"===e&&("spki"===o||"pkcs8"===o))return _.importKey("jwk",p(c),l,v[3],v[4]);if(E&&"unwrapKey"===e)return _.decrypt(v[3],l,c).then(function(e){return _.importKey(o,e,v[4],v[5],v[6])});var w;try{w=t.apply(_,v)}catch(e){return Promise.reject(e)}return E&&(w=new Promise(function(e,t){w.onabort=w.onerror=function(e){t(e)},w.oncomplete=function(t){e(t.target.result)}})),w=w.then(function(e){return"HMAC"===f.name&&(f.length||(f.length=8*e.algorithm.length)),0==f.name.search("RSA")&&(f.modulusLength||(f.modulusLength=(e.publicKey||e).algorithm.modulusLength),f.publicExponent||(f.publicExponent=(e.publicKey||e).algorithm.publicExponent)),e=e.publicKey&&e.privateKey?{publicKey:new g(e.publicKey,f,m,S.filter(d)),privateKey:new g(e.privateKey,f,m,S.filter(y))}:new g(e,f,m,S)})}}),["exportKey","wrapKey"].forEach(function(e){var r=_[e];_[e]=function(a,u,p){var l=[].slice.call(arguments);switch(e){case"exportKey":l[1]=u._key;break;case"wrapKey":l[1]=u._key,l[2]=p._key}if((A||E&&"SHA-1"===(u.algorithm.hash||{}).name)&&"exportKey"===e&&"jwk"===a&&"HMAC"===u.algorithm.name&&(l[0]="raw"),!A||"exportKey"!==e||"spki"!==a&&"pkcs8"!==a||(l[0]="jwk"),E&&"wrapKey"===e)return _.exportKey(a,u).then(function(e){return"jwk"===a&&(e=n(unescape(encodeURIComponent(JSON.stringify(i(e)))))),_.encrypt(l[3],p,e)});var f;try{f=r.apply(_,l)}catch(e){return Promise.reject(e)}return E&&(f=new Promise(function(e,t){f.onabort=f.onerror=function(e){t(e)},f.oncomplete=function(t){e(t.target.result)}})),"exportKey"===e&&"jwk"===a&&(f=f.then(function(e){return(A||E&&"SHA-1"===(u.algorithm.hash||{}).name)&&"HMAC"===u.algorithm.name?{kty:"oct",alg:s(u.algorithm),key_ops:u.usages.slice(),ext:!0,k:t(o(e))}:((e=i(e)).alg||(e.alg=s(u.algorithm)),e.key_ops||(e.key_ops="public"===u.type?u.usages.filter(d):"private"===u.type?u.usages.filter(y):u.usages.slice()),e)})),!A||"exportKey"!==e||"spki"!==a&&"pkcs8"!==a||(f=f.then(function(e){return e=c(i(e))})),f}}),["encrypt","decrypt","sign","verify"].forEach(function(e){var t=_[e];_[e]=function(r,n,o,s){if(E&&(!o.byteLength||s&&!s.byteLength))throw new Error("Empy input is not allowed");var i=[].slice.call(arguments),u=a(r);if(E&&"decrypt"===e&&"AES-GCM"===u.name){var p=r.tagLength>>3;i[2]=(o.buffer||o).slice(0,o.byteLength-p),r.tag=(o.buffer||o).slice(o.byteLength-p)}i[1]=n._key;var c;try{c=t.apply(_,i)}catch(e){return Promise.reject(e)}return E&&(c=new Promise(function(t,r){c.onabort=c.onerror=function(e){r(e)},c.oncomplete=function(r){var r=r.target.result;if("encrypt"===e&&r instanceof AesGcmEncryptResult){var n=r.ciphertext,o=r.tag;(r=new Uint8Array(n.byteLength+o.byteLength)).set(new Uint8Array(n),0),r.set(new Uint8Array(o),n.byteLength),r=r.buffer}t(r)}})),c}}),E){var R=_.digest;_.digest=function(e,t){if(!t.byteLength)throw new Error("Empy input is not allowed");var r;try{r=R.call(_,e,t)}catch(e){return Promise.reject(e)}return r=new Promise(function(e,t){r.onabort=r.onerror=function(e){t(e)},r.oncomplete=function(t){e(t.target.result)}})},e.crypto=Object.create(h,{getRandomValues:{value:function(e){return h.getRandomValues(e)}},subtle:{value:_}}),e.CryptoKey=g}A&&(h.subtle=_,e.Crypto=m,e.SubtleCrypto=S,e.CryptoKey=g)}}}}("undefined"==typeof window?"undefined"==typeof self?this:self:window); |