Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/de protect #3038

Merged
merged 27 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cell/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7068,7 +7068,7 @@ var editor;
password: arr[i].temporaryPassword,
salt: arr[i].saltValue,
spinCount: arr[i].spinCount,
alg: AscCommonExcel.fromModelAlgoritmName(arr[i].algorithmName)
alg: AscCommon.fromModelAlgorithmName(arr[i].algorithmName)
});
}
}
Expand Down Expand Up @@ -7297,7 +7297,7 @@ var editor;
checkPassword([AscCommonExcel.getPasswordHash(props.temporaryPassword, true)]);
} else {
var checkHash = {password: props.temporaryPassword, salt: props.saltValue, spinCount: props.spinCount,
alg: AscCommonExcel.fromModelAlgoritmName(props.algorithmName)};
alg: AscCommon.fromModelAlgorithmName(props.algorithmName)};
AscCommon.calculateProtectHash([checkHash], checkPassword);
}
} else {
Expand Down Expand Up @@ -7412,7 +7412,7 @@ var editor;
checkPassword([AscCommonExcel.getPasswordHash(props.temporaryPassword, true)]);
} else {
var checkHash = {password: props.temporaryPassword, salt: props.workbookSaltValue, spinCount: props.workbookSpinCount,
alg: AscCommonExcel.fromModelAlgoritmName(props.workbookAlgorithmName)};
alg: AscCommon.fromModelAlgorithmName(props.algorithmName)};
AscCommon.calculateProtectHash([checkHash], checkPassword);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion cell/model/Workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -10964,7 +10964,7 @@
password: val,
salt: this.aProtectedRanges[i].saltValue,
spinCount: this.aProtectedRanges[i].spinCount,
alg: AscCommonExcel.fromModelAlgoritmName(this.aProtectedRanges[i].algorithmName)
alg: AscCommon.fromModelAlgorithmName(this.aProtectedRanges[i].algorithmName)
});
}
}
Expand Down
108 changes: 27 additions & 81 deletions cell/model/WorkbookProtection.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,86 +52,38 @@
this.pivotTables = true;
this.selectUnlockedCells = false;*/

var c_oSerProtectedAlgorithmNameTypes = {
MD2: 1,
MD4: 2,
MD5: 3,
RIPEMD_128: 4,
RIPEMD_160: 5,
SHA_1: 6,
SHA_256: 7,
SHA_384: 8,
SHA_512: 9,
WHIRLPOOL: 10
};

function fromModelAlgoritmName(alg) {
switch (alg) {
case c_oSerProtectedAlgorithmNameTypes.MD2 :
alg = AscCommon.HashAlgs.MD2;
break;
case c_oSerProtectedAlgorithmNameTypes.MD4 :
alg = AscCommon.HashAlgs.MD4;
break;
case c_oSerProtectedAlgorithmNameTypes.MD5 :
alg = AscCommon.HashAlgs.MD5;
break;
case c_oSerProtectedAlgorithmNameTypes.RIPEMD_160 :
alg = AscCommon.HashAlgs.RMD160;
break;
case c_oSerProtectedAlgorithmNameTypes.SHA_1 :
alg = AscCommon.HashAlgs.SHA1;
break;
case c_oSerProtectedAlgorithmNameTypes.SHA_256 :
alg = AscCommon.HashAlgs.SHA256;
break;
case c_oSerProtectedAlgorithmNameTypes.SHA_384 :
alg = AscCommon.HashAlgs.SHA384;
break;
case c_oSerProtectedAlgorithmNameTypes.SHA_512 :
alg = AscCommon.HashAlgs.SHA512;
break;
case c_oSerProtectedAlgorithmNameTypes.WHIRLPOOL :
alg = AscCommon.HashAlgs.WHIRLPOOL;
break;
default:
alg = AscCommon.HashAlgs.SHA256;
}
return alg;
}

function FromXml_ST_AlgorithmName(str) {
var alg = null;
switch (str) {
case "MD2" :
alg = c_oSerProtectedAlgorithmNameTypes.MD2;
alg = AscCommon.c_oSerAlgorithmNameTypes.MD2;
break;
case "MD4" :
alg = c_oSerProtectedAlgorithmNameTypes.MD4;
alg = AscCommon.c_oSerAlgorithmNameTypes.MD4;
break;
case "MD5" :
alg = c_oSerProtectedAlgorithmNameTypes.MD5;
alg = AscCommon.c_oSerAlgorithmNameTypes.MD5;
break;
case "RIPEMD-128" :
alg = c_oSerProtectedAlgorithmNameTypes.RIPEMD_128;
alg = AscCommon.c_oSerAlgorithmNameTypes.RIPEMD_128;
break;
case "RIPEMD-160" :
alg = c_oSerProtectedAlgorithmNameTypes.RIPEMD_160;
alg = AscCommon.c_oSerAlgorithmNameTypes.RIPEMD_160;
break;
case "SHA-1" :
alg = c_oSerProtectedAlgorithmNameTypes.SHA1;
alg = AscCommon.c_oSerAlgorithmNameTypes.SHA1;
break;
case "SHA-256" :
alg = c_oSerProtectedAlgorithmNameTypes.SHA_256;
alg = AscCommon.c_oSerAlgorithmNameTypes.SHA_256;
break;
case "SHA-384" :
alg = c_oSerProtectedAlgorithmNameTypes.SHA_384;
alg = AscCommon.c_oSerAlgorithmNameTypes.SHA_384;
break;
case "SHA-512" :
alg = c_oSerProtectedAlgorithmNameTypes.SHA_512;
alg = AscCommon.c_oSerAlgorithmNameTypes.SHA_512;
break;
case "WHIRLPOOL" :
alg = c_oSerProtectedAlgorithmNameTypes.WHIRLPOOL;
alg = AscCommon.c_oSerAlgorithmNameTypes.WHIRLPOOL;
break;
}
return alg;
Expand All @@ -140,45 +92,40 @@
function ToXml_ST_AlgorithmName(alg) {
var str = null;
switch (alg) {
case c_oSerProtectedAlgorithmNameTypes.MD2:
case AscCommon.c_oSerAlgorithmNameTypes.MD2:
str = "MD2";
break;
case c_oSerProtectedAlgorithmNameTypes.MD4:
case AscCommon.c_oSerAlgorithmNameTypes.MD4:
str = "MD4";
break;
case c_oSerProtectedAlgorithmNameTypes.MD5:
case AscCommon.c_oSerAlgorithmNameTypes.MD5:
str = "MD5";
break;
case c_oSerProtectedAlgorithmNameTypes.RIPEMD_128:
case AscCommon.c_oSerAlgorithmNameTypes.RIPEMD_128:
str = "RIPEMD-128";
break;
case c_oSerProtectedAlgorithmNameTypes.RIPEMD_160:
case AscCommon.c_oSerAlgorithmNameTypes.RIPEMD_160:
str = "RIPEMD-160";
break;
case c_oSerProtectedAlgorithmNameTypes.SHA1:
case AscCommon.c_oSerAlgorithmNameTypes.SHA1:
str = "SHA-1";
break;
case c_oSerProtectedAlgorithmNameTypes.SHA_256 :
case AscCommon.c_oSerAlgorithmNameTypes.SHA_256 :
str = "SHA-256";
break;
case c_oSerProtectedAlgorithmNameTypes.SHA_384 :
case AscCommon.c_oSerAlgorithmNameTypes.SHA_384 :
str = "SHA-384";
break;
case c_oSerProtectedAlgorithmNameTypes.SHA_512:
case AscCommon.c_oSerAlgorithmNameTypes.SHA_512:
str = "SHA-512";
break;
case c_oSerProtectedAlgorithmNameTypes.WHIRLPOOL:
case AscCommon.c_oSerAlgorithmNameTypes.WHIRLPOOL:
str = "WHIRLPOOL";
break;
}
return str;
}


function generateHashParams() {
return {spinCount: 100000, saltValue: AscCommon.randomBytes(16).base64(), algorithmName: c_oSerProtectedAlgorithmNameTypes.SHA_512};
}

function getPasswordHash(password, getString) {
var nResult = null;
if (password.length) {
Expand Down Expand Up @@ -573,10 +520,10 @@
//просталяю временный пароль, аспинхронная проверка пароля в asc_setProtectedSheet
this.setSheet(!this.sheet);
if (this.sheet && password) {
var hashParams = generateHashParams();
var hashParams = AscCommon.generateHashParams();
this.saltValue = hashParams.saltValue;
this.spinCount = hashParams.spinCount;
this.algorithmName = hashParams.algorithmName;
this.algorithmName = AscCommon.c_oSerAlgorithmNameTypes.SHA_512;
}
this.temporaryPassword = password;
if (callback) {
Expand Down Expand Up @@ -877,10 +824,10 @@
this.setLockStructure(!this.lockStructure);

if (this.lockStructure && password) {
var hashParams = generateHashParams();
var hashParams = AscCommon.generateHashParams();
this.workbookSaltValue = hashParams.saltValue;
this.workbookSpinCount = hashParams.spinCount;
this.workbookAlgorithmName = hashParams.algorithmName;
this.workbookAlgorithmName = AscCommon.c_oSerAlgorithmNameTypes.SHA_512;
}
this.temporaryPassword = password;
if (callback) {
Expand Down Expand Up @@ -1316,10 +1263,10 @@
};
CProtectedRange.prototype.asc_setPassword = function (val) {
if (val) {
var hashParams = generateHashParams();
var hashParams = AscCommon.generateHashParams();
this.saltValue = hashParams.saltValue;
this.spinCount = hashParams.spinCount;
this.algorithmName = hashParams.algorithmName;
this.algorithmName = AscCommon.c_oSerAlgorithmNameTypes.SHA_512;
}
//генерируем хэш
this.temporaryPassword = val;
Expand All @@ -1331,7 +1278,7 @@
return this.isLock;
};
CProtectedRange.prototype.asc_checkPassword = function (val, callback) {
var checkHash = {password: val, salt: this.saltValue, spinCount: this.spinCount, alg: fromModelAlgoritmName(this.algorithmName)};
var checkHash = {password: val, salt: this.saltValue, spinCount: this.spinCount, alg: AscCommon.fromModelAlgorithmName(this.algorithmName)};
AscCommon.calculateProtectHash([checkHash], function (hash) {
callback(hash && hash[0] === this.hashValue);
});
Expand Down Expand Up @@ -1439,7 +1386,6 @@
prot["asc_checkPassword"] = prot.asc_checkPassword;
prot["asc_getId"] = prot.asc_getId;

window["AscCommonExcel"].fromModelAlgoritmName = fromModelAlgoritmName;
window["AscCommonExcel"].getPasswordHash = getPasswordHash;
window["AscCommonExcel"].FromXml_ST_AlgorithmName = FromXml_ST_AlgorithmName;
window["AscCommonExcel"].ToXml_ST_AlgorithmName = ToXml_ST_AlgorithmName;
Expand Down
1 change: 1 addition & 0 deletions common/HistoryCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4359,6 +4359,7 @@
window['AscDFH'].historydescription_Document_CorrectFormTextByFormat = 0x0196;
window['AscDFH'].historydescription_Document_CorrectEnterText = 0x0197;
window['AscDFH'].historydescription_Document_ConvertMathView = 0x0198;
window['AscDFH'].historydescription_Document_DocumentProtection = 0x0198;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
33 changes: 33 additions & 0 deletions common/SerializeCommonWordExcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,35 @@ var c_oSerShdType = {
nodeAttributeEnd: 0xFB
};

var c_oSerAlgorithmNameTypes = {
MD2: 1,
MD4: 2,
MD5: 3,
RIPEMD_128: 4,
RIPEMD_160: 5,
SHA_1: 6,
SHA_256: 7,
SHA_384: 8,
SHA_512: 9,
WHIRLPOOL: 10
};

var c_oSerCryptAlgorithmSid = {
MD2: 1,
MD4: 2,
MD5: 3,
SHA_1: 4,
MAC: 5,
RIPEMD: 6,
RIPEMD_160: 7,
//SHA_384: 8,
HMAC: 9,
SHA_256: 12,
SHA_384: 13,
SHA_512: 14,
};


function BinaryCommonWriter(memory)
{
this.memory = memory;
Expand Down Expand Up @@ -1532,4 +1561,8 @@ function isRealObject(obj)
window['AscCommon'].GetStringUtf8 = GetStringUtf8;
window['AscCommon'].g_nodeAttributeStart = c_nodeAttribute.nodeAttributeStart;
window['AscCommon'].g_nodeAttributeEnd = c_nodeAttribute.nodeAttributeEnd;
window['AscCommon'].c_oSerAlgorithmNameTypes = c_oSerAlgorithmNameTypes;
window['AscCommon'].c_oSerCryptAlgorithmSid = c_oSerCryptAlgorithmSid;


})(window);
2 changes: 2 additions & 0 deletions common/commonDefines.js
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ var lcid_haLatn = 0x7c68; // Hausa, Latin
var changestype_Document_Settings = 77; // Изменение общих настроек документа Document.Settings
var changestype_Timing = 78;
var changestype_ViewPr = 79;
var changestype_DocumentProtection = 80;

var changestype_2_InlineObjectMove = 1; // Передвигаем объект в заданную позцию (проверяем место, в которое пытаемся передвинуть)
var changestype_2_HdrFtr = 2; // Изменения с колонтитулом
Expand Down Expand Up @@ -4341,6 +4342,7 @@ var lcid_haLatn = 0x7c68; // Hausa, Latin
window["AscCommon"].changestype_Document_Settings = changestype_Document_Settings;
window["AscCommon"].changestype_Timing = changestype_Timing;
window["AscCommon"].changestype_ViewPr = changestype_ViewPr;
window["AscCommon"].changestype_DocumentProtection = changestype_DocumentProtection;

window["AscCommon"].changestype_2_InlineObjectMove = changestype_2_InlineObjectMove;
window["AscCommon"].changestype_2_HdrFtr = changestype_2_HdrFtr;
Expand Down
Loading