Developing

This commit is contained in:
Oleg Korshul
2022-12-13 13:02:56 +03:00
parent 6d29cda8ea
commit 162e96cebd
4 changed files with 16 additions and 164 deletions

View File

@ -2,8 +2,8 @@ import sys;
sys.path.append("../../../../../../../build_tools/scripts");
import base;
base.replaceInFile("./deploy/engine.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){window.Asc.cryptoJS.onLoad();}];");
base.replaceInFile("./deploy/engine.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){window.Asc.cryptoJS.onLoad();}];");
base.replaceInFile("./deploy/engine.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){window.cryptoJS.onLoad();}];");
base.replaceInFile("./deploy/engine.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){window.cryptoJS.onLoad();}];");
base.replaceInFile("./deploy/engine.js", "function getBinaryPromise()", "function getBinaryPromise2()");
base.copy_file("./index.html", "./deploy/index.html");

View File

@ -1,134 +1,18 @@
window.onload = function()
{
var xmlCertificate = new window.XmlSignature();
var XmlError = window.XmlSignatureError;
function loadCert(data, password)
let url = "./engine";
let useWasm = false;
let webAsmObj = window["WebAssembly"];
if (typeof webAsmObj === "object" && typeof webAsmObj["Memory"] === "function")
{
window.certFileData = data;
var err = xmlCertificate.loadCert(window.certFileData, password);
switch (err)
{
case XmlError.OPEN_SSL_WARNING_ERR:
{
alert("error");
break;
}
case XmlError.OPEN_SSL_WARNING_ALL_OK:
{
document.getElementById("key").style.display = "none";
document.getElementById("password").style.display = "none";
break;
}
case XmlError.OPEN_SSL_WARNING_OK:
{
document.getElementById("key").style.display = "";
document.getElementById("password").style.display = "none";
break;
}
case XmlError.OPEN_SSL_WARNING_PASS:
{
document.getElementById("key").style.display = "none";
document.getElementById("password").style.display = "";
break;
}
default:
break;
}
if ((typeof webAsmObj["instantiateStreaming"] === "function") || (typeof webAsmObj["instantiate"] === "function"))
useWasm = true;
}
function loadKey(data, password)
{
window.keyFileData = data;
var err = xmlCertificate.loadKey(window.keyFileData, password);
switch (err)
{
case XmlError.OPEN_SSL_WARNING_ERR:
{
alert("error");
break;
}
case XmlError.OPEN_SSL_WARNING_ALL_OK:
case XmlError.OPEN_SSL_WARNING_OK:
{
document.getElementById("password").style.display = "none";
break;
}
case XmlError.OPEN_SSL_WARNING_PASS:
{
document.getElementById("password").style.display = "";
break;
}
default:
break;
}
}
document.getElementById('button_certificate').onchange = function() {
var reader = new FileReader();
reader.onload = function() {
loadCert(this.result);
};
reader.readAsArrayBuffer(this.files[0]);
};
document.getElementById('button_key').onchange = function() {
var reader = new FileReader();
reader.onload = function() {
loadKey(this.result);
};
reader.readAsArrayBuffer(this.files[0]);
};
document.getElementById('file_select').onchange = function() {
var reader = new FileReader();
reader.onload = function() {
window.fileFileData = this.result;
};
reader.readAsArrayBuffer(this.files[0]);
};
document.getElementById('button_password').onclick = function() {
if (document.getElementById("key").style.display == "none")
loadCert(window.certFileData, document.getElementById("area_password").value);
else
loadKey(window.keyFileData, document.getElementById("area_password").value);
};
document.getElementById('button_sign').onclick = function() {
if (!window.fileFileData)
{
alert("Please select file");
return;
}
function downloadBlob(data, fileName, mimeType) {
var blob, url;
blob = new Blob([data], {
type: mimeType
});
url = window.URL.createObjectURL(blob);
downloadURL(url, fileName);
setTimeout(function() {
return window.URL.revokeObjectURL(url);
}, 1000);
};
function downloadURL(data, fileName) {
var a;
a = document.createElement('a');
a.href = data;
a.download = fileName;
document.body.appendChild(a);
a.style = 'display: none';
a.click();
a.remove();
};
var result = xmlCertificate.sign(window.fileFileData);
downloadBlob(result, 'sign_file.docx', 'application/octet-stream');
};
url += (useWasm ? ".js" : "_ie.js");
let script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
document.head.appendChild(script);
};

View File

@ -86,7 +86,7 @@
};
CryptoJS.prototype.onLoad = function()
{
CryptoJS.prototype.isModuleInit = true;
this.isModuleInit = true;
};
CryptoJS.prototype.generateKeys = function(password, salt)
@ -201,7 +201,7 @@
return privateKeyString;
};
window.CryptoJS = CryptoJS;
window.cryptoJS = new CryptoJS();
//module

View File

@ -5,38 +5,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8">
<script src="./code.js"></script>
<script src="./openssl.js"></script>
<style>
div {
margin: 10px;
}
</style>
</head>
<body style="width:100%;height:100%;margin:50;padding:0;overflow:hidden;">
<div id="certificate">
<label for="button_certificate">Select Certificate</label>
<input type="file" id="button_certificate">
</div>
<div id="key" style="display:none;">
<label for="button_key">Select Private Key</label>
<input type="file" id="button_key" value="load key">
</div>
<div id="password" style="display:none;">
<textarea id="area_password" placeholder="password..."></textarea>
<input type="button" id="button_password" value="setup password">
</div>
<div id="file">
<label for="file_select">Select OOXML File</label>
<input type="file" id="file_select" value="load file">
</div>
<div id="sign">
<input type="button" id="button_sign" value="Sign">
</div>
</body>
<body></body>
</html>