lemonldap-ng/lemonldap-ng-portal/site/htdocs/static/common/js/u2f-api.min.js

1 line
6.9 KiB
JavaScript
Raw Normal View History

2017-02-02 22:48:32 +01:00
"use strict";var u2f=u2f||{};var js_api_version;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(b){if(typeof chrome!="undefined"&&chrome.runtime){var a={type:u2f.MessageTypes.U2F_SIGN_REQUEST,signRequests:[]};chrome.runtime.sendMessage(u2f.EXTENSION_ID,a,function(){if(!chrome.runtime.lastError){u2f.getChromeRuntimePort_(b)}else{u2f.getIframePort_(b)}})}else{if(u2f.isAndroidChrome_()){u2f.getAuthenticatorPort_(b)}else{if(u2f.isIosChrome_()){u2f.getIosPort_(b)}else{u2f.getIframePort_(b)}}}};u2f.isAndroidChrome_=function(){var a=navigator.userAgent;return a.indexOf("Chrome")!=-1&&a.indexOf("Android")!=-1};u2f.isIosChrome_=function(){return $.inArray(navigator.platform,["iPhone","iPad","iPod"])>-1};u2f.getChromeRuntimePort_=function(b){var a=chrome.runtime.connect(u2f.EXTENSION_ID,{includeTlsChannelId:true});setTimeout(function(){b(new u2f.WrappedChromeRuntimePort_(a))},0)};u2f.getAuthenticatorPort_=function(a){setTimeout(function(){a(new u2f.WrappedAuthenticatorPort_())},0)};u2f.getIosPort_=function(a){setTimeout(function(){a(new u2f.WrappedIosPort_())},0)};u2f.WrappedChromeRuntimePort_=function(a){this.port_=a};u2f.formatSignRequest_=function(g,d,b,a,f){if(js_api_version===undefined||js_api_version<1.1){var e=[];for(var c=0;c<b.length;c++){e[c]={version:b[c].version,challenge:d,keyHandle:b[c].keyHandle,appId:g}}return{type:u2f.MessageTypes.U2F_SIGN_REQUEST,signRequests:e,timeoutSeconds:a,requestId:f}}return{type:u2f.MessageTypes.U2F_SIGN_REQUEST,appId:g,challenge:d,registeredKeys:b,timeoutSeconds:a,requestId:f}};u2f.formatRegisterRequest_=function(g,c,a,b,f){if(js_api_version===undefined||js_api_version<1.1){for(var d=0;d<a.length;d++){a[d].appId=g}var e=[];for(var d=0;d<c.length;d++){e[d]={version:c[d].version,challenge:a[0],keyHandle:c[d].keyHandle,appId:g}}return{type:u2f.MessageTypes.U2F_REGISTER_REQUEST,signRequests:e,registerRequests:a,timeoutSeconds:b,requestId:f}}return{type:u2f.MessageTypes.U2F_REGISTER_REQUEST,appId:g,registerRequests:a,registeredKeys:c,timeoutSeconds:b,requestId:f}};u2f.WrappedChromeRuntimePort_.prototype.postMessage=function(a){this.port_.postMessage(a)};u2f.WrappedChromeRuntimePort_.prototype.addEventListener=function(a,c){var b=a.toLowerCase();if(b=="message"||b=="onmessage"){this.port_.onMessage.addListener(function(d){c({data:d})})}else{console.error("WrappedChromeRuntimePort only supports onMessage")}};u2f.WrappedAuthenticatorPort_=function(){this.requestId_=-1;this.requestObject_=null};u2f.WrappedAuthenticatorPort_.prototype.postMessage=function(a){var b=u2f.WrappedAuthenticatorPort_.INTENT_URL_BASE_+";S.request="+encodeURIComponent(JSON.stringify(a))+";end";document.location=b};u2f.WrappedAuthenticatorPort_.prototype.getPortType=function(){return"WrappedAuthenticatorPort_"};u2f.WrappedAuthenticatorPort_.prototype.addEventListener=function(b,d){var c=b.toLowerCase();if(c=="message"){var a=this;window.addEventListener("message",a.onRequestUpdate_.bind(a,d),false)}else{console.error("WrappedAuthenticatorPort only supports message")}};u2f.WrappedAuthenticatorPort_.prototype.onRequestUpdate_=function(f,c){var b=JSON.parse(c.data);var e=b.intentURL;var d=b.errorCode;var a=null;if(b.hasOwnProperty("data")){a=(JSON.parse(b.data))}f({data:a})};u2f.WrappedAuthenticatorPort_.INTENT_URL_BASE_="intent:#Intent;action=com.google.android.apps.authenticator.AUTHENTICATE";u2f.WrappedIosPort_=function(){};u2f.WrappedIosPort_.prototype.postMessage=function(b){var c=JSON.stringify(b);var