Commit d48880be authored by Samir Sadyhov's avatar Samir Sadyhov 🤔

NCALayer - добавлена авторизации в синержи по эцп

parent dfef9af0
...@@ -8,6 +8,12 @@ NCALayer.sign('AUTH', null, result => { ...@@ -8,6 +8,12 @@ NCALayer.sign('AUTH', null, result => {
NCALayer.sign('SIGN','documentID', result => { NCALayer.sign('SIGN','documentID', result => {
console.log(result) console.log(result)
}); });
авторизация в синержи по эцп
NCALayer.authEDS(result => {
console.log(result)
});
*/ */
this.NCALayer = { this.NCALayer = {
...@@ -43,6 +49,7 @@ this.NCALayer = { ...@@ -43,6 +49,7 @@ this.NCALayer = {
this.webSocket.onmessage = function(event) { this.webSocket.onmessage = function(event) {
const result = parseNcaLayerMsg(event); const result = parseNcaLayerMsg(event);
console.log('webSocket.onmessage', result);
if(result.hasOwnProperty('code')) { if(result.hasOwnProperty('code')) {
if(result.code == 200) { if(result.code == 200) {
if (result.responseObject.hasOwnProperty('keyId')) { if (result.responseObject.hasOwnProperty('keyId')) {
...@@ -63,8 +70,17 @@ this.NCALayer = { ...@@ -63,8 +70,17 @@ this.NCALayer = {
if(me.successHandler) me.successHandler(me.info); if(me.successHandler) me.successHandler(me.info);
} }
} else { } else {
me.info = {...me.info, ...result.responseObject}; me.info.xml = result.responseObject;
if(result.responseObject.hasOwnProperty('signedData')) me.verificationKey(); if(result.responseObject.hasOwnProperty('signedData')) {
me.verificationKey();
} else {
if (me.keysConstType == 'authEDS') {
me.authSynergyEDS();
} else if (me.keysConstType == 'registerEDS') {
me.registerSynergyEDS();
}
}
} }
} else { } else {
console.log('[NCALayer onmessage error]', result); console.log('[NCALayer onmessage error]', result);
...@@ -102,6 +118,20 @@ this.NCALayer = { ...@@ -102,6 +118,20 @@ this.NCALayer = {
}, 100); }, 100);
}, },
signXML: function(uuid){
const param = {
module: 'kz.gov.pki.knca.commonUtils',
method: 'signXml',
args: [this.storageName, "AUTH", `<xml>${uuid}</xml>`, "", ""]
};
if(!this.webSocket) this.webSocket = this.getNCALayerSocket();
setTimeout(() => {
this.webSocket.send(JSON.stringify(param));
}, 100);
},
signDocument: async function(socket){ signDocument: async function(socket){
const { rawdata } = await AS.FORMS.ApiUtils.simpleAsyncGet(`rest/api/docflow/doc/document_info?documentID=${this.documentID}&locale=${AS.OPTIONS.locale}`); const { rawdata } = await AS.FORMS.ApiUtils.simpleAsyncGet(`rest/api/docflow/doc/document_info?documentID=${this.documentID}&locale=${AS.OPTIONS.locale}`);
...@@ -118,6 +148,30 @@ this.NCALayer = { ...@@ -118,6 +148,30 @@ this.NCALayer = {
}, 100); }, 100);
}, },
registerSynergyEDS: async function(){
if(this.successHandler) this.successHandler(this.info);
},
authSynergyEDS: async function(){
try {
const url = `../Synergy/rest/api/authEDS`;
const response = await fetch(url, {
method: 'POST',
headers: {"Content-Type": "application/json; charset=UTF-8"},
body: JSON.stringify({"cert": this.info.xml})
});
const result = await response.json();
if(!response.ok) throw new Error(result.errorMessage);
if(this.successHandler) this.successHandler(result);
} catch (err) {
console.log(`ERROR [authSynergyEDS]: ${err.message}`);
if(this.successHandler) this.successHandler({errorCode: 13, errorMessage: err.message});
}
},
verificationKey: async function() { verificationKey: async function() {
try { try {
const {dataForSign, certificate, signedData, CN} = this.info; const {dataForSign, certificate, signedData, CN} = this.info;
...@@ -163,6 +217,41 @@ this.NCALayer = { ...@@ -163,6 +217,41 @@ this.NCALayer = {
clearInterval(timerID); clearInterval(timerID);
} }
}, 500); }, 500);
},
getAuthUUID: async function(){
return new Promise(async resolve => {
try {
const response = await fetch(`../Synergy/rest/api/uuidForSignature`, {method: 'GET'});
if(!response.ok) throw new Error(await response.text());
resolve(response.json());
} catch (err) {
console.log(`ERROR [ getAsfDataUUID ]: ${err.message}`);
resolve(null);
}
});
},
authEDS: function(handler) {
if(!this.webSocket) this.initNCALayerSocket();
this.keysConstType = 'authEDS';
this.info = {};
if(handler && typeof handler == 'function') {
this.successHandler = handler;
} else {
this.successHandler = null;
}
this.getAuthUUID().then(res => {
const timerID = setInterval(() => {
if(this.connect) {
this.signXML(res.uuid);
clearInterval(timerID);
}
}, 500);
});
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment