lemonldap-ng/lemonldap-ng-portal/site/htdocs/static/common/js/u2f-api.min.js
2021-04-02 16:09:50 +02:00

2 lines
6.7 KiB
JavaScript

//Copyright 2014-2015 Google Inc. All rights reserved.
"use strict";var js_api_version,u2f=u2f||{};u2f.EXTENSION_ID="kmendfapggjehodndflmmgagdbamhnfd",u2f.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"},u2f.ErrorCodes={OK:0,OTHER_ERROR:1,BAD_REQUEST:2,CONFIGURATION_UNSUPPORTED:3,DEVICE_INELIGIBLE:4,TIMEOUT:5},u2f.U2fRequest,u2f.U2fResponse,u2f.Error,u2f.Transport,u2f.Transports,u2f.SignRequest,u2f.SignResponse,u2f.RegisterRequest,u2f.RegisterResponse,u2f.RegisteredKey,u2f.GetJsApiVersionResponse,u2f.getMessagePort=function(e){var t;"undefined"!=typeof chrome&&chrome.runtime?(t={type:u2f.MessageTypes.U2F_SIGN_REQUEST,signRequests:[]},chrome.runtime.sendMessage(u2f.EXTENSION_ID,t,function(){chrome.runtime.lastError?u2f.getIframePort_(e):u2f.getChromeRuntimePort_(e)})):u2f.isAndroidChrome_()?u2f.getAuthenticatorPort_(e):u2f.isIosChrome_()?u2f.getIosPort_(e):u2f.getIframePort_(e)},u2f.isAndroidChrome_=function(){var e=navigator.userAgent;return-1!=e.indexOf("Chrome")&&-1!=e.indexOf("Android")},u2f.isIosChrome_=function(){return-1<$.inArray(navigator.platform,["iPhone","iPad","iPod"])},u2f.getChromeRuntimePort_=function(e){var t=chrome.runtime.connect(u2f.EXTENSION_ID,{includeTlsChannelId:!0});setTimeout(function(){e(new u2f.WrappedChromeRuntimePort_(t))},0)},u2f.getAuthenticatorPort_=function(e){setTimeout(function(){e(new u2f.WrappedAuthenticatorPort_)},0)},u2f.getIosPort_=function(e){setTimeout(function(){e(new u2f.WrappedIosPort_)},0)},u2f.WrappedChromeRuntimePort_=function(e){this.port_=e},u2f.formatSignRequest_=function(e,t,o,r,n){if(void 0===js_api_version||js_api_version<1.1){for(var s=[],u=0;u<o.length;u++)s[u]={version:o[u].version,challenge:t,keyHandle:o[u].keyHandle,appId:e};return{type:u2f.MessageTypes.U2F_SIGN_REQUEST,signRequests:s,timeoutSeconds:r,requestId:n}}return{type:u2f.MessageTypes.U2F_SIGN_REQUEST,appId:e,challenge:t,registeredKeys:o,timeoutSeconds:r,requestId:n}},u2f.formatRegisterRequest_=function(e,t,o,r,n){if(void 0===js_api_version||js_api_version<1.1){for(var s=0;s<o.length;s++)o[s].appId=e;for(var u=[],s=0;s<t.length;s++)u[s]={version:t[s].version,challenge:o[0],keyHandle:t[s].keyHandle,appId:e};return{type:u2f.MessageTypes.U2F_REGISTER_REQUEST,signRequests:u,registerRequests:o,timeoutSeconds:r,requestId:n}}return{type:u2f.MessageTypes.U2F_REGISTER_REQUEST,appId:e,registerRequests:o,registeredKeys:t,timeoutSeconds:r,requestId:n}},u2f.WrappedChromeRuntimePort_.prototype.postMessage=function(e){this.port_.postMessage(e)},u2f.WrappedChromeRuntimePort_.prototype.addEventListener=function(e,t){e=e.toLowerCase();"message"==e||"onmessage"==e?this.port_.onMessage.addListener(function(e){t({data:e})}):console.error("WrappedChromeRuntimePort only supports onMessage")},u2f.WrappedAuthenticatorPort_=function(){this.requestId_=-1,this.requestObject_=null},u2f.WrappedAuthenticatorPort_.prototype.postMessage=function(e){e=u2f.WrappedAuthenticatorPort_.INTENT_URL_BASE_+";S.request="+encodeURIComponent(JSON.stringify(e))+";end";document.location=e},u2f.WrappedAuthenticatorPort_.prototype.getPortType=function(){return"WrappedAuthenticatorPort_"},u2f.WrappedAuthenticatorPort_.prototype.addEventListener=function(e,t){"message"==e.toLowerCase()?window.addEventListener("message",this.onRequestUpdate_.bind(this,t),!1):console.error("WrappedAuthenticatorPort only supports message")},u2f.WrappedAuthenticatorPort_.prototype.onRequestUpdate_=function(e,t){var o=JSON.parse(t.data),t=(o.intentURL,o.errorCode,null);e({data:t=o.hasOwnProperty("data")?JSON.parse(o.data):t})},u2f.WrappedAuthenticatorPort_.INTENT_URL_BASE_="intent:#Intent;action=com.google.android.apps.authenticator.AUTHENTICATE",u2f.WrappedIosPort_=function(){},u2f.WrappedIosPort_.prototype.postMessage=function(e){e=JSON.stringify(e),e="u2f://auth?"+encodeURI(e);location.replace(e)},u2f.WrappedIosPort_.prototype.getPortType=function(){return"WrappedIosPort_"},u2f.WrappedIosPort_.prototype.addEventListener=function(e,t){"message"!==e.toLowerCase()&&console.error("WrappedIosPort only supports message")},u2f.getIframePort_=function(t){var e="chrome-extension://"+u2f.EXTENSION_ID,o=document.createElement("iframe");o.src=e+"/u2f-comms.html",o.setAttribute("style","display:none"),document.body.appendChild(o);var r=new MessageChannel,n=function(e){"ready"==e.data?(r.port1.removeEventListener("message",n),t(r.port1)):console.error('First event on iframe port was not "ready"')};r.port1.addEventListener("message",n),r.port1.start(),o.addEventListener("load",function(){o.contentWindow.postMessage("init",e,[r.port2])})},u2f.EXTENSION_TIMEOUT_SEC=30,u2f.port_=null,u2f.waitingForPort_=[],u2f.reqCounter_=0,u2f.callbackMap_={},u2f.getPortSingleton_=function(e){u2f.port_?e(u2f.port_):(0==u2f.waitingForPort_.length&&u2f.getMessagePort(function(e){for(u2f.port_=e,u2f.port_.addEventListener("message",u2f.responseHandler_);u2f.waitingForPort_.length;)u2f.waitingForPort_.shift()(u2f.port_)}),u2f.waitingForPort_.push(e))},u2f.responseHandler_=function(e){var t=e.data,o=t.requestId;o&&u2f.callbackMap_[o]?(e=u2f.callbackMap_[o],delete u2f.callbackMap_[o],e(t.responseData)):console.error("Unknown or missing requestId in response.")},u2f.sign=function(t,o,r,n,s){void 0===js_api_version?u2f.getApiVersion(function(e){js_api_version=void 0===e.js_api_version?0:e.js_api_version,console.log("Extension JS API Version: ",js_api_version),u2f.sendSignRequest(t,o,r,n,s)}):u2f.sendSignRequest(t,o,r,n,s)},u2f.sendSignRequest=function(r,n,s,u,i){u2f.getPortSingleton_(function(e){var t=++u2f.reqCounter_;u2f.callbackMap_[t]=u;var o=void 0!==i?i:u2f.EXTENSION_TIMEOUT_SEC,t=u2f.formatSignRequest_(r,n,s,o,t);e.postMessage(t)})},u2f.register=function(t,o,r,n,s){void 0===js_api_version?u2f.getApiVersion(function(e){js_api_version=void 0===e.js_api_version?0:e.js_api_version,console.log("Extension JS API Version: ",js_api_version),u2f.sendRegisterRequest(t,o,r,n,s)}):u2f.sendRegisterRequest(t,o,r,n,s)},u2f.sendRegisterRequest=function(r,n,s,u,i){u2f.getPortSingleton_(function(e){var t=++u2f.reqCounter_;u2f.callbackMap_[t]=u;var o=void 0!==i?i:u2f.EXTENSION_TIMEOUT_SEC,t=u2f.formatRegisterRequest_(r,s,n,o,t);e.postMessage(t)})},u2f.getApiVersion=function(r,n){u2f.getPortSingleton_(function(e){if(e.getPortType){var t;switch(e.getPortType()){case"WrappedIosPort_":case"WrappedAuthenticatorPort_":t=1.1;break;default:t=0}r({js_api_version:t})}else{var o=++u2f.reqCounter_;u2f.callbackMap_[o]=r;o={type:u2f.MessageTypes.U2F_GET_API_VERSION_REQUEST,timeoutSeconds:void 0!==n?n:u2f.EXTENSION_TIMEOUT_SEC,requestId:o};e.postMessage(o)}})};