Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
38495479
Kaydet (Commit)
38495479
authored
Şub 26, 2018
tarafından
Eike Rathke
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Move convenience abstractions to DocPasswordHelper, tdf#104250 follow-up
Change-Id: If0775ccf14b631918e51342a767412948e812c87
üst
f1a11b9c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
98 deletions
+112
-98
test_hash.cxx
comphelper/qa/unit/test_hash.cxx
+2
-1
docpasswordhelper.cxx
comphelper/source/misc/docpasswordhelper.cxx
+48
-0
hash.cxx
comphelper/source/misc/hash.cxx
+0
-46
docpasswordhelper.hxx
include/comphelper/docpasswordhelper.hxx
+59
-0
hash.hxx
include/comphelper/hash.hxx
+1
-50
tabprotection.cxx
sc/source/core/data/tabprotection.cxx
+2
-1
No files found.
comphelper/qa/unit/test_hash.cxx
Dosyayı görüntüle @
38495479
...
...
@@ -8,6 +8,7 @@
*/
#include <comphelper/hash.hxx>
#include <comphelper/docpasswordhelper.hxx>
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
...
...
@@ -111,7 +112,7 @@ void TestHash::testSHA512_saltspin()
const
OUString
aPass
(
"pwd"
);
const
OUString
aAlgo
(
"SHA-512"
);
const
OUString
aSalt
(
"876MLoKTq42+/DLp415iZQ=="
);
const
OUString
aHash
=
comphelper
::
Hash
::
calculateHash
Base64
(
aPass
,
aSalt
,
100000
,
aAlgo
);
const
OUString
aHash
=
comphelper
::
DocPasswordHelper
::
GetOoxHashAs
Base64
(
aPass
,
aSalt
,
100000
,
aAlgo
);
const
OUString
aStr
(
"5l3mgNHXpWiFaBPv5Yso1Xd/UifWvQWmlDnl/hsCYbFT2sJCzorjRmBCQ/3qeDu6Q/4+GIE8a1DsdaTwYh1q2g=="
);
CPPUNIT_ASSERT_EQUAL
(
aStr
,
aHash
);
}
...
...
comphelper/source/misc/docpasswordhelper.cxx
Dosyayı görüntüle @
38495479
...
...
@@ -23,6 +23,9 @@
#include <comphelper/docpasswordhelper.hxx>
#include <comphelper/storagehelper.hxx>
#include <comphelper/hash.hxx>
#include <comphelper/base64.hxx>
#include <comphelper/sequence.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/task/XInteractionHandler.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
...
...
@@ -256,6 +259,51 @@ Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence(
}
css
::
uno
::
Sequence
<
sal_Int8
>
DocPasswordHelper
::
GetOoxHashAsSequence
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
)
{
comphelper
::
HashType
eType
;
if
(
rAlgorithmName
==
"SHA-512"
)
eType
=
comphelper
::
HashType
::
SHA512
;
else
if
(
rAlgorithmName
==
"SHA-256"
)
eType
=
comphelper
::
HashType
::
SHA256
;
else
if
(
rAlgorithmName
==
"SHA-1"
)
eType
=
comphelper
::
HashType
::
SHA1
;
else
if
(
rAlgorithmName
==
"MD5"
)
eType
=
comphelper
::
HashType
::
MD5
;
else
return
css
::
uno
::
Sequence
<
sal_Int8
>
();
std
::
vector
<
unsigned
char
>
aSaltVec
;
if
(
!
rSaltValue
.
isEmpty
())
{
css
::
uno
::
Sequence
<
sal_Int8
>
aSaltSeq
;
comphelper
::
Base64
::
decode
(
aSaltSeq
,
rSaltValue
);
aSaltVec
=
comphelper
::
sequenceToContainer
<
std
::
vector
<
unsigned
char
>>
(
aSaltSeq
);
}
std
::
vector
<
unsigned
char
>
hash
(
comphelper
::
Hash
::
calculateHash
(
rPassword
,
aSaltVec
,
nSpinCount
,
eType
));
return
comphelper
::
containerToSequence
<
sal_Int8
>
(
hash
);
}
OUString
DocPasswordHelper
::
GetOoxHashAsBase64
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
)
{
css
::
uno
::
Sequence
<
sal_Int8
>
aSeq
(
GetOoxHashAsSequence
(
rPassword
,
rSaltValue
,
nSpinCount
,
rAlgorithmName
));
OUStringBuffer
aBuf
;
comphelper
::
Base64
::
encode
(
aBuf
,
aSeq
);
return
aBuf
.
makeStringAndClear
();
}
/*static*/
uno
::
Sequence
<
sal_Int8
>
DocPasswordHelper
::
GenerateRandomByteSequence
(
sal_Int32
nLength
)
{
uno
::
Sequence
<
sal_Int8
>
aResult
(
nLength
);
...
...
comphelper/source/misc/hash.cxx
Dosyayı görüntüle @
38495479
...
...
@@ -8,8 +8,6 @@
*/
#include <comphelper/hash.hxx>
#include <comphelper/base64.hxx>
#include <comphelper/sequence.hxx>
#include <rtl/ustring.hxx>
#include <rtl/alloc.h>
#include <osl/endian.h>
...
...
@@ -231,50 +229,6 @@ std::vector<unsigned char> Hash::calculateHash(
return
calculateHash
(
pPassBytes
,
nPassBytesLen
,
rSaltValue
.
data
(),
rSaltValue
.
size
(),
nSpinCount
,
eType
);
}
css
::
uno
::
Sequence
<
sal_Int8
>
Hash
::
calculateHashSequence
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
)
{
HashType
eType
;
if
(
rAlgorithmName
==
"SHA-512"
)
eType
=
HashType
::
SHA512
;
else
if
(
rAlgorithmName
==
"SHA-256"
)
eType
=
HashType
::
SHA256
;
else
if
(
rAlgorithmName
==
"SHA-1"
)
eType
=
HashType
::
SHA1
;
else
if
(
rAlgorithmName
==
"MD5"
)
eType
=
HashType
::
MD5
;
else
return
css
::
uno
::
Sequence
<
sal_Int8
>
();
std
::
vector
<
unsigned
char
>
aSaltVec
;
if
(
!
rSaltValue
.
isEmpty
())
{
css
::
uno
::
Sequence
<
sal_Int8
>
aSaltSeq
;
comphelper
::
Base64
::
decode
(
aSaltSeq
,
rSaltValue
);
aSaltVec
=
comphelper
::
sequenceToContainer
<
std
::
vector
<
unsigned
char
>>
(
aSaltSeq
);
}
std
::
vector
<
unsigned
char
>
hash
(
calculateHash
(
rPassword
,
aSaltVec
,
nSpinCount
,
eType
));
return
comphelper
::
containerToSequence
<
sal_Int8
>
(
hash
);
}
OUString
Hash
::
calculateHashBase64
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
)
{
css
::
uno
::
Sequence
<
sal_Int8
>
aSeq
(
calculateHashSequence
(
rPassword
,
rSaltValue
,
nSpinCount
,
rAlgorithmName
));
OUStringBuffer
aBuf
;
comphelper
::
Base64
::
encode
(
aBuf
,
aSeq
);
return
aBuf
.
makeStringAndClear
();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
include/comphelper/docpasswordhelper.hxx
Dosyayı görüntüle @
38495479
...
...
@@ -180,6 +180,65 @@ public:
const
OUString
&
aString
);
/** Convenience function to calculate a salted hash with iterations as
specified in https://msdn.microsoft.com/en-us/library/dd920692 for the
OOXML sheetProtection and fileSharing elements.
@param rPassword
UTF-16LE encoded string without leading BOM character
@param rSaltValue
Base64 encoded salt that will be decoded and prepended to password
data.
@param nSpinCount
If >0 the number of repeated iterations.
@param rAlgorithmName
One of "SHA-512", "SHA-256", ... as listed in
https://msdn.microsoft.com/en-us/library/dd920692
that have a valid match in HashType. If not, an empty string is
returned. Not all algorithm names are supported.
@return the raw hash value as sal_Int8 sequence.
*/
static
css
::
uno
::
Sequence
<
sal_Int8
>
GetOoxHashAsSequence
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
);
/** Convenience function to calculate a salted hash with iterations as
specified in https://msdn.microsoft.com/en-us/library/dd920692 for the
OOXML sheetProtection and fileSharing elements.
@param rPassword
UTF-16LE encoded string without leading BOM character
@param rSaltValue
Base64 encoded salt that will be decoded and prepended to password
data.
@param nSpinCount
If >0 the number of repeated iterations.
@param rAlgorithmName
One of "SHA-512", "SHA-256", ... as listed in
https://msdn.microsoft.com/en-us/library/dd920692
that have a valid match in HashType. If not, an empty string is
returned. Not all algorithm names are supported.
@return the base64 encoded string of the hash value, that can be
compared against a stored base64 encoded hash value.
*/
static
rtl
::
OUString
GetOoxHashAsBase64
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
);
/** This helper function generates a random sequence of bytes of
requested length.
*/
...
...
include/comphelper/hash.hxx
Dosyayı görüntüle @
38495479
...
...
@@ -12,8 +12,6 @@
#include <comphelper/comphelperdllapi.h>
#include <com/sun/star/uno/Sequence.hxx>
#include <memory>
#include <vector>
...
...
@@ -73,7 +71,7 @@ public:
/** Convenience function to calculate a salted hash with iterations.
@param rPassword
UTF-16LE encoded string
without leading BOM character
UTF-16LE encoded string
, hashed byte-wise as unsigned char.
@param rSaltValue
Salt that will be prepended to password data.
...
...
@@ -84,53 +82,6 @@ public:
sal_uInt32
nSpinCount
,
HashType
eType
);
/** Convenience function to calculate a salted hash with iterations.
@param rPassword
UTF-16LE encoded string without leading BOM character
@param rSaltValue
Base64 encoded salt that will be decoded and prepended to password
data.
@param rAlgorithmName
One of "SHA-512", "SHA-256", ... as listed in
https://msdn.microsoft.com/en-us/library/dd920692
that have a valid match in HashType. If not, an empty string is
returned. Not all algorithm names are supported.
@return the raw hash value as sal_Int8 sequence.
*/
static
css
::
uno
::
Sequence
<
sal_Int8
>
calculateHashSequence
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
);
/** Convenience function to calculate a salted hash with iterations.
@param rPassword
UTF-16LE encoded string without leading BOM character
@param rSaltValue
Base64 encoded salt that will be decoded and prepended to password
data.
@param rAlgorithmName
One of "SHA-512", "SHA-256", ... as listed in
https://msdn.microsoft.com/en-us/library/dd920692
that have a valid match in HashType. If not, an empty string is
returned. Not all algorithm names are supported.
@return the base64 encoded string of the hash value, that can be
compared against a stored base64 encoded hash value.
*/
static
rtl
::
OUString
calculateHashBase64
(
const
rtl
::
OUString
&
rPassword
,
const
rtl
::
OUString
&
rSaltValue
,
sal_uInt32
nSpinCount
,
const
rtl
::
OUString
&
rAlgorithmName
);
size_t
getLength
()
const
;
};
...
...
sc/source/core/data/tabprotection.cxx
Dosyayı görüntüle @
38495479
...
...
@@ -94,7 +94,8 @@ bool ScOoxPasswordHash::verifyPassword( const OUString& aPassText ) const
if
(
!
hasPassword
())
return
false
;
const
OUString
aHash
(
comphelper
::
Hash
::
calculateHashBase64
(
aPassText
,
maSaltValue
,
mnSpinCount
,
maAlgorithmName
));
const
OUString
aHash
(
comphelper
::
DocPasswordHelper
::
GetOoxHashAsBase64
(
aPassText
,
maSaltValue
,
mnSpinCount
,
maAlgorithmName
));
if
(
aHash
.
isEmpty
())
// unsupported algorithm
return
false
;
...
...
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