Update cadesplugin_api to v.2.3.1

This commit is contained in:
Artem Vasilev 2021-09-14 19:21:59 +03:00
parent a99231bc9a
commit 34b4e23404

View File

@ -9,11 +9,10 @@
var plugin_resolve; var plugin_resolve;
var isOpera = 0; var isOpera = 0;
var isFireFox = 0; var isFireFox = 0;
var isEdge = 0;
var isSafari = 0; var isSafari = 0;
var failed_extensions = 0; var isYandex = 0;
var canPromise = !!window.Promise; var canPromise = !!window.Promise;
var cadesplugin_loaded_event_recieved = false;
var cadesplugin; var cadesplugin;
if(canPromise) if(canPromise)
@ -29,17 +28,19 @@
} }
function check_browser() { function check_browser() {
var ua= navigator.userAgent, tem, M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; var ua= navigator.userAgent, tem, M= ua.match(/(opera|yabrowser|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1])){ if(/trident/i.test(M[1])){
tem = /\brv[ :]+(\d+)/g.exec(ua) || []; tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return { name:'IE', version:(tem[1] || '')}; return { name:'IE', version:(tem[1] || '')};
} }
if(M[1] === 'Chrome'){ if(M[1] === 'Chrome'){
tem= ua.match(/\b(OPR|Edge)\/(\d+)/); tem = ua.match(/\b(OPR|Edg|YaBrowser)\/(\d+)/);
if(tem!= null) return {name:tem[1].replace('OPR', 'Opera'),version:tem[2]}; if (tem != null)
return { name: tem[1].replace('OPR', 'Opera'), version: tem[2] };
} }
M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?']; M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]); if ((tem = ua.match(/version\/(\d+)/i)) != null)
M.splice(1, 1, tem[1]);
return {name:M[0],version:M[1]}; return {name:M[0],version:M[1]};
} }
var browserSpecs = check_browser(); var browserSpecs = check_browser();
@ -86,10 +87,14 @@
function set_constantValues() function set_constantValues()
{ {
cadesplugin.CAPICOM_MEMORY_STORE = 0;
cadesplugin.CAPICOM_LOCAL_MACHINE_STORE = 1; cadesplugin.CAPICOM_LOCAL_MACHINE_STORE = 1;
cadesplugin.CAPICOM_CURRENT_USER_STORE = 2; cadesplugin.CAPICOM_CURRENT_USER_STORE = 2;
cadesplugin.CAPICOM_SMART_CARD_USER_STORE = 4;
cadesplugin.CADESCOM_MEMORY_STORE = 0;
cadesplugin.CADESCOM_LOCAL_MACHINE_STORE = 1; cadesplugin.CADESCOM_LOCAL_MACHINE_STORE = 1;
cadesplugin.CADESCOM_CURRENT_USER_STORE = 2; cadesplugin.CADESCOM_CURRENT_USER_STORE = 2;
cadesplugin.CADESCOM_SMART_CARD_USER_STORE = 4;
cadesplugin.CADESCOM_CONTAINER_STORE = 100; cadesplugin.CADESCOM_CONTAINER_STORE = 100;
cadesplugin.CAPICOM_MY_STORE = "My"; cadesplugin.CAPICOM_MY_STORE = "My";
@ -102,11 +107,22 @@
cadesplugin.CADESCOM_XML_SIGNATURE_TYPE_ENVELOPING = 1; cadesplugin.CADESCOM_XML_SIGNATURE_TYPE_ENVELOPING = 1;
cadesplugin.CADESCOM_XML_SIGNATURE_TYPE_TEMPLATE = 2; cadesplugin.CADESCOM_XML_SIGNATURE_TYPE_TEMPLATE = 2;
cadesplugin.CADESCOM_XADES_DEFAULT = 0x00000010;
cadesplugin.CADESCOM_XADES_BES = 0x00000020;
cadesplugin.CADESCOM_XADES_T = 0x00000050;
cadesplugin.CADESCOM_XADES_X_LONG_TYPE_1 = 0x000005d0;
cadesplugin.CADESCOM_XMLDSIG_TYPE = 0x00000000;
cadesplugin.XmlDsigGost3410UrlObsolete = "http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411"; cadesplugin.XmlDsigGost3410UrlObsolete = "http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411";
cadesplugin.XmlDsigGost3411UrlObsolete = "http://www.w3.org/2001/04/xmldsig-more#gostr3411"; cadesplugin.XmlDsigGost3411UrlObsolete = "http://www.w3.org/2001/04/xmldsig-more#gostr3411";
cadesplugin.XmlDsigGost3410Url = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102001-gostr3411"; cadesplugin.XmlDsigGost3410Url = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102001-gostr3411";
cadesplugin.XmlDsigGost3411Url = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr3411"; cadesplugin.XmlDsigGost3411Url = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr3411";
cadesplugin.XmlDsigGost3411Url2012256 = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256";
cadesplugin.XmlDsigGost3410Url2012256 = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-256";
cadesplugin.XmlDsigGost3411Url2012512 = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-512";
cadesplugin.XmlDsigGost3410Url2012512 = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-512";
cadesplugin.CADESCOM_CADES_DEFAULT = 0; cadesplugin.CADESCOM_CADES_DEFAULT = 0;
cadesplugin.CADESCOM_CADES_BES = 1; cadesplugin.CADESCOM_CADES_BES = 1;
cadesplugin.CADESCOM_CADES_T = 0x5; cadesplugin.CADESCOM_CADES_T = 0x5;
@ -155,6 +171,7 @@
cadesplugin.CADESCOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME = 0; cadesplugin.CADESCOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME = 0;
cadesplugin.CADESCOM_AUTHENTICATED_ATTRIBUTE_DOCUMENT_NAME = 1; cadesplugin.CADESCOM_AUTHENTICATED_ATTRIBUTE_DOCUMENT_NAME = 1;
cadesplugin.CADESCOM_AUTHENTICATED_ATTRIBUTE_DOCUMENT_DESCRIPTION = 2; cadesplugin.CADESCOM_AUTHENTICATED_ATTRIBUTE_DOCUMENT_DESCRIPTION = 2;
cadesplugin.CADESCOM_AUTHENTICATED_ATTRIBUTE_MACHINE_INFO = 0x100;
cadesplugin.CADESCOM_ATTRIBUTE_OTHER = -1; cadesplugin.CADESCOM_ATTRIBUTE_OTHER = -1;
cadesplugin.CADESCOM_STRING_TO_UCS2LE = 0; cadesplugin.CADESCOM_STRING_TO_UCS2LE = 0;
@ -194,6 +211,31 @@
cadesplugin.CADESCOM_AllowUntrustedCertificate = 0x2; cadesplugin.CADESCOM_AllowUntrustedCertificate = 0x2;
cadesplugin.CADESCOM_AllowUntrustedRoot = 0x4; cadesplugin.CADESCOM_AllowUntrustedRoot = 0x4;
cadesplugin.CADESCOM_SkipInstallToStore = 0x10000000; cadesplugin.CADESCOM_SkipInstallToStore = 0x10000000;
cadesplugin.CADESCOM_InstallCertChainToContainer = 0x20000000;
cadesplugin.CADESCOM_UseContainerStore = 0x40000000;
cadesplugin.ENABLE_CARRIER_TYPE_CSP = 0x01;
cadesplugin.ENABLE_CARRIER_TYPE_FKC_NO_SM = 0x02;
cadesplugin.ENABLE_CARRIER_TYPE_FKC_SM = 0x04;
cadesplugin.ENABLE_ANY_CARRIER_TYPE = 0x07;
cadesplugin.DISABLE_EVERY_CARRIER_OPERATION = 0x00;
cadesplugin.ENABLE_CARRIER_OPEN_ENUM = 0x01;
cadesplugin.ENABLE_CARRIER_CREATE = 0x02;
cadesplugin.ENABLE_ANY_OPERATION = 0x03;
cadesplugin.CADESCOM_PRODUCT_CSP = 0;
cadesplugin.CADESCOM_PRODUCT_OCSP = 1;
cadesplugin.CADESCOM_PRODUCT_TSP = 2;
cadesplugin.MEDIA_TYPE_REGISTRY = 0x00000001;
cadesplugin.MEDIA_TYPE_HDIMAGE = 0x00000002;
cadesplugin.MEDIA_TYPE_CLOUD = 0x00000004;
cadesplugin.MEDIA_TYPE_SCARD = 0x00000008;
cadesplugin.XCN_CRYPT_STRING_BASE64HEADER = 0;
cadesplugin.AT_KEYEXCHANGE = 1;
cadesplugin.AT_SIGNATURE = 2;
} }
function async_spawn(generatorFunc) { function async_spawn(generatorFunc) {
@ -234,8 +276,11 @@
if(isIE()) if(isIE())
return false; return false;
// В Edge работаем через NativeMessage // В Edge работаем через NativeMessage
if(browserSpecs.name === 'Edge') { if (browserSpecs.name === 'Edg') {
isEdge = true; return true;
}
if (browserSpecs.name === 'YaBrowser') {
isYandex = true;
return true; return true;
} }
// В Chrome, Firefox, Safari и Opera работаем через асинхронную версию в зависимости от версии // В Chrome, Firefox, Safari и Opera работаем через асинхронную версию в зависимости от версии
@ -436,57 +481,7 @@
ovr.style.visibility="visible"; ovr.style.visibility="visible";
} }
} }
function firefox_or_safari_nmcades_onload() {
//Выводим окно поверх других с предложением установить расширение для Opera.
//Если установленна переменная cadesplugin_skip_extension_install - не предлагаем установить расширение
function install_opera_extension()
{
if (!window.cadesplugin_skip_extension_install)
{
document.addEventListener('DOMContentLoaded', function() {
var ovr = document.createElement('div');
ovr.id = "cadesplugin_ovr";
ovr.style = "visibility: hidden; position: fixed; left: 0px; top: 0px; width:100%; height:100%; background-color: rgba(0,0,0,0.7)";
ovr.innerHTML = "<div id='cadesplugin_ovr_item' style='position:relative; width:400px; margin:100px auto; background-color:#fff; border:2px solid #000; padding:10px; text-align:center; opacity: 1; z-index: 1500'>" +
"<button id='cadesplugin_close_install' style='float: right; font-size: 10px; background: transparent; border: 1; margin: -5px'>X</button>" +
"<p>Для работы КриптоПро ЭЦП Browser plugin на данном сайте необходимо установить расширение из каталога дополнений Opera." +
"<p><button id='cadesplugin_install' style='font:12px Arial'>Установить расширение</button></p>" +
"</div>";
document.getElementsByTagName("Body")[0].appendChild(ovr);
var btn_install = document.getElementById("cadesplugin_install");
btn_install.addEventListener('click', function(event) {
opr.addons.installExtension("epebfcehmdedogndhlcacafjaacknbcm",
function()
{
document.getElementById("cadesplugin_ovr").style.visibility = 'hidden';
location.reload();
},
function(){})
});
document.getElementById("cadesplugin_close_install").addEventListener('click',function()
{
plugin_loaded_error("Плагин недоступен");
document.getElementById("cadesplugin_ovr").style.visibility = 'hidden';
});
ovr.addEventListener('click',function()
{
plugin_loaded_error("Плагин недоступен");
document.getElementById("cadesplugin_ovr").style.visibility = 'hidden';
});
ovr.style.visibility="visible";
document.getElementById("cadesplugin_ovr_item").addEventListener('click',function(e){
e.stopPropagation();
});
});
}else
{
plugin_loaded_error("Плагин недоступен");
}
}
function firefox_or_edge_nmcades_onload() {
cpcsp_chrome_nmcades.check_chrome_plugin(plugin_loaded, plugin_loaded_error); cpcsp_chrome_nmcades.check_chrome_plugin(plugin_loaded, plugin_loaded_error);
} }
@ -495,45 +490,56 @@
window.addEventListener("message", function (event){ window.addEventListener("message", function (event){
if (typeof(event.data) !== "string" || !event.data.match("cadesplugin_loaded")) if (typeof(event.data) !== "string" || !event.data.match("cadesplugin_loaded"))
return; return;
if(isFireFox || isEdge || isSafari) if (cadesplugin_loaded_event_recieved)
return;
if(isFireFox || isSafari)
{ {
// Для Firefox, Сафари, Edge вместе с сообщением cadesplugin_loaded прилетает url для загрузки nmcades_plugin_api.js // Для Firefox, Сафари вместе с сообщением cadesplugin_loaded прилетает url для загрузки nmcades_plugin_api.js
var url = event.data.substring(event.data.indexOf("url:") + 4); var url = event.data.substring(event.data.indexOf("url:") + 4);
if (!url.match("^moz-extension://[a-zA-Z0-9-]+/nmcades_plugin_api.js$")
&& !url.match("^safari-extension://[a-zA-Z0-9-]+/[a-zA-Z0-9]+/nmcades_plugin_api.js$"))
{
cpcsp_console_log(cadesplugin.LOG_LEVEL_ERROR, "Bad url \"" + url + "\" for load CryptoPro Extension for CAdES Browser plug-in");
plugin_loaded_error();
return;
}
var fileref = document.createElement('script'); var fileref = document.createElement('script');
fileref.setAttribute("type", "text/javascript"); fileref.setAttribute("type", "text/javascript");
fileref.setAttribute("src", url); fileref.setAttribute("src", url);
fileref.onerror = plugin_loaded_error; fileref.onerror = plugin_loaded_error;
fileref.onload = firefox_or_edge_nmcades_onload; fileref.onload = firefox_or_safari_nmcades_onload;
document.getElementsByTagName("head")[0].appendChild(fileref); document.getElementsByTagName("head")[0].appendChild(fileref);
// Для Firefox, Safari и Edge у нас только по одному расширению.
failed_extensions++;
}else { }else {
cpcsp_chrome_nmcades.check_chrome_plugin(plugin_loaded, plugin_loaded_error); cpcsp_chrome_nmcades.check_chrome_plugin(plugin_loaded, plugin_loaded_error);
} }
cadesplugin_loaded_event_recieved = true;
}, false); }, false);
} }
//Загружаем расширения для Chrome, Opera, YaBrowser, FireFox, Edge, Safari //Загружаем расширения для Chrome, Opera, YaBrowser, FireFox, Edge, Safari
function load_extension() function load_extension()
{ {
if(isFireFox || isSafari){
if(isFireFox || isEdge || isSafari){
// вызываем callback руками т.к. нам нужно узнать ID расширения. Он уникальный для браузера. // вызываем callback руками т.к. нам нужно узнать ID расширения. Он уникальный для браузера.
nmcades_api_onload(); nmcades_api_onload();
} else { } else {
// в асинхронном варианте для chrome и opera подключаем оба расширения // в асинхронном варианте для Yandex и Opera подключаем расширение из Opera store.
if (isOpera || isYandex) {
var fileref = document.createElement('script');
fileref.setAttribute("type", "text/javascript");
fileref.setAttribute("src", "chrome-extension://epebfcehmdedogndhlcacafjaacknbcm/nmcades_plugin_api.js");
fileref.onerror = plugin_loaded_error;
fileref.onload = nmcades_api_onload;
document.getElementsByTagName("head")[0].appendChild(fileref);
} else {
// для Chrome, Chromium, Chromium Edge расширение из Chrome store
var fileref = document.createElement('script'); var fileref = document.createElement('script');
fileref.setAttribute("type", "text/javascript"); fileref.setAttribute("type", "text/javascript");
fileref.setAttribute("src", "chrome-extension://iifchhfnnmpdbibifmljnfjhpififfog/nmcades_plugin_api.js"); fileref.setAttribute("src", "chrome-extension://iifchhfnnmpdbibifmljnfjhpififfog/nmcades_plugin_api.js");
fileref.onerror = plugin_loaded_error; fileref.onerror = plugin_loaded_error;
fileref.onload = nmcades_api_onload; fileref.onload = nmcades_api_onload;
document.getElementsByTagName("head")[0].appendChild(fileref); document.getElementsByTagName("head")[0].appendChild(fileref);
fileref = document.createElement('script'); }
fileref.setAttribute("type", "text/javascript");
fileref.setAttribute("src", "chrome-extension://epebfcehmdedogndhlcacafjaacknbcm/nmcades_plugin_api.js");
fileref.onerror = plugin_loaded_error;
fileref.onload = nmcades_api_onload;
document.getElementsByTagName("head")[0].appendChild(fileref);
} }
} }
@ -576,18 +582,6 @@
//Отправляем событие что сломались. //Отправляем событие что сломались.
function plugin_loaded_error(msg) function plugin_loaded_error(msg)
{ {
if(isNativeMessageSupported())
{
//в асинхронном варианте подключаем оба расширения, если сломались оба пробуем установить для Opera
failed_extensions++;
if(failed_extensions<2)
return;
if(isOpera && (typeof(msg) === 'undefined'|| typeof(msg) === 'object'))
{
install_opera_extension();
return;
}
}
if(typeof(msg) === 'undefined' || typeof(msg) === 'object') if(typeof(msg) === 'undefined' || typeof(msg) === 'object')
msg = "Плагин недоступен"; msg = "Плагин недоступен";
plugin_resolved = 1; plugin_resolved = 1;
@ -698,7 +692,7 @@
}; };
//Export //Export
cadesplugin.JSModuleVersion = "2.1.2"; cadesplugin.JSModuleVersion = "2.3.1";
cadesplugin.async_spawn = async_spawn; cadesplugin.async_spawn = async_spawn;
cadesplugin.set = set_pluginObject; cadesplugin.set = set_pluginObject;
cadesplugin.set_log_level = set_log_level; cadesplugin.set_log_level = set_log_level;