Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
onlyoffice_core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
onlyoffice_core
Commits
7b7e9f3e
Commit
7b7e9f3e
authored
Nov 20, 2017
by
Oleg Korshul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d39fa156
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
178 additions
and
1 deletion
+178
-1
DesktopEditor/xmlsec/src/include/OOXMLVerifier.h
DesktopEditor/xmlsec/src/include/OOXMLVerifier.h
+5
-0
DesktopEditor/xmlsec/src/src/OOXMLSigner.cpp
DesktopEditor/xmlsec/src/src/OOXMLSigner.cpp
+6
-1
DesktopEditor/xmlsec/src/src/OOXMLVerifier.cpp
DesktopEditor/xmlsec/src/src/OOXMLVerifier.cpp
+167
-0
No files found.
DesktopEditor/xmlsec/src/include/OOXMLVerifier.h
View file @
7b7e9f3e
...
...
@@ -18,10 +18,13 @@ public:
public:
int
GetValid
();
std
::
string
GetGuid
();
std
::
string
GetDate
();
ICertificate
*
GetCertificate
();
std
::
string
GetImageValidBase64
();
std
::
string
GetImageInvalidBase64
();
std
::
wstring
GetFile
();
public:
void
Check
();
...
...
@@ -41,6 +44,8 @@ public:
int
GetSignatureCount
();
COOXMLSignature
*
GetSignature
(
const
int
&
index
);
void
RemoveSignature
(
const
std
::
string
&
sGuid
);
private:
COOXMLVerifier_private
*
m_internal
;
};
...
...
DesktopEditor/xmlsec/src/src/OOXMLSigner.cpp
View file @
7b7e9f3e
...
...
@@ -432,7 +432,12 @@ Type=\"http://schemas.openxmlformats.org/package/2006/relationships/digital-sign
builder
.
WriteString
(
L"<SignatureProperties><SignatureProperty Id=
\"
idOfficeV1Details
\"
Target=
\"
#idPackageSignature
\"
>"
);
builder
.
WriteString
(
L"<SignatureInfoV1 xmlns=
\"
http://schemas.microsoft.com/office/2006/digsig
\"
>"
);
builder
.
WriteString
(
L"<SetupID>"
);
builder
.
WriteString
(
m_guid
);
std
::
wstring
sGUID
=
m_guid
;
if
(
0
==
sGUID
.
find
(
L"/_xmlsignatures"
))
sGUID
=
L""
;
builder
.
WriteString
(
sGUID
);
builder
.
WriteString
(
L"</SetupID>"
);
builder
.
WriteString
(
L"<SignatureText></SignatureText>"
);
builder
.
WriteString
(
L"<SignatureImage>"
);
...
...
DesktopEditor/xmlsec/src/src/OOXMLVerifier.cpp
View file @
7b7e9f3e
...
...
@@ -14,6 +14,9 @@ public:
std
::
wstring
m_sFolder
;
std
::
wstring
m_sFile
;
std
::
string
m_sDate
;
XmlUtils
::
CXmlNode
m_node
;
// signature file
class
CXmlStackNamespaces
...
...
@@ -144,6 +147,10 @@ public:
{
return
m_guid
;
}
std
::
string
GetDate
()
{
return
m_sDate
;
}
ICertificate
*
GetCertificate
()
{
return
m_cert
;
...
...
@@ -157,6 +164,11 @@ public:
return
m_sImageInvalidBase64
;
}
std
::
wstring
GetFile
()
{
return
m_sFile
;
}
public:
void
Check
()
{
...
...
@@ -178,6 +190,19 @@ public:
std
::
wstring
sSetupID
=
FindFirstChild
(
firstChild
,
L"SetupID"
).
GetText
();
m_guid
=
U_TO_UTF8
(
sSetupID
);
if
(
m_guid
.
empty
())
{
std
::
wstring
sFile
=
m_sFile
;
NSStringUtils
::
string_replace
(
sFile
,
L"
\\
"
,
L"/"
);
std
::
wstring
::
size_type
posSign
=
sFile
.
find
(
L"/_xmlsignatures"
);
if
(
std
::
wstring
::
npos
!=
posSign
)
{
sFile
=
sFile
.
substr
(
posSign
);
}
m_guid
=
U_TO_UTF8
(
sFile
);
}
// 2) Images
XmlUtils
::
CXmlNode
nodeImageValid
=
GetObjectById
(
"idValidSigLnImg"
);
if
(
nodeImageValid
.
IsValid
())
...
...
@@ -194,6 +219,13 @@ public:
return
;
}
XmlUtils
::
CXmlNode
nodeSignProperties
=
GetObjectSignedProperties
();
XmlUtils
::
CXmlNode
nodeSignedSignatureProperties
=
nodeSignProperties
.
ReadNodeNoNS
(
L"SignedSignatureProperties"
);
XmlUtils
::
CXmlNode
nodeST
=
nodeSignedSignatureProperties
.
ReadNodeNoNS
(
L"SigningTime"
);
std
::
wstring
sDateW
=
nodeST
.
GetText
();
if
(
!
sDateW
.
empty
())
m_sDate
=
U_TO_UTF8
(
sDateW
);
XmlUtils
::
CXmlNodes
nodesManifestRefs
=
nodeManifect
.
ReadNode
(
L"Manifest"
).
GetNodes
(
L"Reference"
);
int
nRefsCount
=
nodesManifestRefs
.
GetCount
();
for
(
int
i
=
0
;
i
<
nRefsCount
;
i
++
)
...
...
@@ -272,6 +304,25 @@ public:
return
ret
;
}
XmlUtils
::
CXmlNode
GetObjectSignedProperties
()
{
XmlUtils
::
CXmlNodes
oNodes
=
m_node
.
GetNodes
(
L"Object"
);
int
nCount
=
oNodes
.
GetCount
();
for
(
int
i
=
0
;
i
<
nCount
;
i
++
)
{
XmlUtils
::
CXmlNode
tmp
;
oNodes
.
GetAt
(
i
,
tmp
);
XmlUtils
::
CXmlNode
nodeQ
=
tmp
.
ReadNodeNoNS
(
L"QualifyingProperties"
);
if
(
nodeQ
.
IsValid
())
{
return
nodeQ
.
ReadNodeNoNS
(
L"SignedProperties"
);
}
}
XmlUtils
::
CXmlNode
ret
;
return
ret
;
}
XmlUtils
::
CXmlNode
FindFirstChild
(
XmlUtils
::
CXmlNode
&
node
,
const
std
::
wstring
&
sName
)
{
if
(
node
.
GetName
()
==
sName
)
...
...
@@ -456,6 +507,10 @@ std::string COOXMLSignature::GetGuid()
{
return
m_internal
->
GetGuid
();
}
std
::
string
COOXMLSignature
::
GetDate
()
{
return
m_internal
->
GetDate
();
}
ICertificate
*
COOXMLSignature
::
GetCertificate
()
{
...
...
@@ -482,6 +537,7 @@ class COOXMLVerifier_private
public:
std
::
wstring
m_sFolder
;
std
::
vector
<
COOXMLSignature
*>
m_arSignatures
;
std
::
vector
<
std
::
wstring
>
m_arSignaturesFiles
;
public:
COOXMLVerifier_private
(
const
std
::
wstring
&
sFolder
)
...
...
@@ -515,11 +571,13 @@ public:
continue
;
COOXMLSignature
*
pSignature
=
new
COOXMLSignature
();
pSignature
->
m_internal
->
m_sFile
=
sFile
;
pSignature
->
m_internal
->
m_node
=
nodeSig
;
pSignature
->
m_internal
->
m_sFolder
=
m_sFolder
;
pSignature
->
Check
();
m_arSignatures
.
push_back
(
pSignature
);
m_arSignaturesFiles
.
push_back
(
sFile
);
}
}
~
COOXMLVerifier_private
()
...
...
@@ -531,6 +589,107 @@ public:
}
m_arSignatures
.
clear
();
}
void
RemoveSignature
(
const
std
::
string
&
sGuid
)
{
int
nCountSignatures
=
m_arSignatures
.
size
();
if
(
0
==
nCountSignatures
)
return
;
bool
bIsRemoveAll
=
sGuid
.
empty
();
std
::
wstring
sFile
;
if
(
!
bIsRemoveAll
)
{
for
(
int
i
=
0
;
i
<
nCountSignatures
;
++
i
)
{
COOXMLSignature
*
pSignature
=
m_arSignatures
.
at
(
i
);
if
(
pSignature
->
GetGuid
()
==
sGuid
)
{
sFile
=
m_arSignaturesFiles
.
at
(
i
);
m_arSignatures
.
erase
(
m_arSignatures
.
begin
()
+
i
);
delete
pSignature
;
}
}
bIsRemoveAll
=
m_arSignatures
.
empty
();
}
if
(
!
sFile
.
empty
())
NSFile
::
CFileBinary
::
Remove
(
sFile
);
if
(
!
bIsRemoveAll
&&
sFile
.
empty
())
return
;
XmlUtils
::
CXmlNode
oContentTypes
;
if
(
!
oContentTypes
.
FromXmlFile
(
m_sFolder
+
L"/[Content_Types].xml"
))
return
;
std
::
wstring
sXml
=
L"<Types xmlns=
\"
http://schemas.openxmlformats.org/package/2006/content-types
\"
>"
;
XmlUtils
::
CXmlNodes
oNodes
;
if
(
oContentTypes
.
GetNodes
(
L"*"
,
oNodes
))
{
int
nCount
=
oNodes
.
GetCount
();
for
(
int
i
=
0
;
i
<
nCount
;
++
i
)
{
XmlUtils
::
CXmlNode
oNode
;
oNodes
.
GetAt
(
i
,
oNode
);
if
(
bIsRemoveAll
)
{
if
(
L"Default"
==
oNode
.
GetName
()
&&
L"sigs"
==
oNode
.
GetAttribute
(
L"Extension"
))
continue
;
if
(
L"Override"
==
oNode
.
GetName
()
&&
L"application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
==
oNode
.
GetAttribute
(
L"ContentType"
))
continue
;
sXml
+=
oNode
.
GetXml
();
}
else
{
std
::
wstring
sFileFound
=
sFile
.
substr
(
m_sFolder
.
length
());
if
(
L"Override"
==
oNode
.
GetName
()
&&
L"application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
==
oNode
.
GetAttribute
(
L"ContentType"
)
&&
sFileFound
==
oNode
.
GetAttribute
(
L"PartName"
))
continue
;
sXml
+=
oNode
.
GetXml
();
}
}
}
sXml
+=
L"</Types>"
;
NSFile
::
CFileBinary
::
SaveToFile
(
m_sFolder
+
L"/[Content_Types].xml"
,
sXml
);
if
(
bIsRemoveAll
)
{
NSDirectory
::
DeleteDirectory
(
m_sFolder
+
L"/_xmlsignatures"
);
XmlUtils
::
CXmlNode
oRels
;
if
(
!
oRels
.
FromXmlFile
(
m_sFolder
+
L"/_rels/.rels"
))
return
;
sXml
=
L"<Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
>"
;
XmlUtils
::
CXmlNodes
oNodes
;
if
(
oRels
.
GetNodes
(
L"*"
,
oNodes
))
{
int
nCount
=
oNodes
.
GetCount
();
for
(
int
i
=
0
;
i
<
nCount
;
++
i
)
{
XmlUtils
::
CXmlNode
oNode
;
oNodes
.
GetAt
(
i
,
oNode
);
if
(
L"Relationship"
==
oNode
.
GetName
()
&&
L"http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin"
==
oNode
.
GetAttribute
(
L"Type"
))
continue
;
sXml
+=
oNode
.
GetXml
();
}
}
sXml
+=
L"</Relationships>"
;
NSFile
::
CFileBinary
::
SaveToFile
(
m_sFolder
+
L"/_rels/.rels"
,
sXml
);
}
}
};
COOXMLVerifier
::
COOXMLVerifier
(
const
std
::
wstring
&
sFolder
)
...
...
@@ -554,3 +713,11 @@ COOXMLSignature* COOXMLVerifier::GetSignature(const int& index)
return
NULL
;
return
m_internal
->
m_arSignatures
[
index
];
}
void
COOXMLVerifier
::
RemoveSignature
(
const
std
::
string
&
sGuid
)
{
std
::
wstring
sFolder
=
m_internal
->
m_sFolder
;
m_internal
->
RemoveSignature
(
sGuid
);
RELEASEOBJECT
(
m_internal
);
m_internal
=
new
COOXMLVerifier_private
(
sFolder
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment