2011-09-08 13:50:30 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
2013-04-19 21:10:42 +01:00
|
|
|
* This file is part of the LibreOffice project.
|
2011-09-08 13:50:30 +01:00
|
|
|
*
|
2013-04-19 21:10:42 +01:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2011-09-08 13:50:30 +01:00
|
|
|
*/
|
2011-12-06 21:15:10 +00:00
|
|
|
|
2011-09-08 13:50:30 +01:00
|
|
|
#include <comphelper/xmltools.hxx>
|
|
|
|
#include <rtl/random.h>
|
2017-12-11 14:38:54 +01:00
|
|
|
#include <rtl/uuid.h>
|
2011-09-08 13:50:30 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace com::sun::star;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
//Will be inside an xml comment, so can't use '-' in case '--' appears in
|
|
|
|
//output, etc. Despite what *is* legal in an xml comment, just using the
|
|
|
|
//base-64 subset to avoid pain with simplistic third-party parsers
|
|
|
|
static const sal_uInt8 aChaffEncoder[] =
|
|
|
|
{
|
|
|
|
'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
|
|
|
|
'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
|
|
|
|
'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
|
|
|
|
'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
|
|
|
|
'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
|
|
|
|
'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
|
|
|
|
'M', 'c', 's', '8', 'N', 'd', 't', '9',
|
|
|
|
'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
|
|
|
|
|
|
|
|
'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
|
|
|
|
'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
|
|
|
|
'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
|
|
|
|
'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
|
|
|
|
'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
|
|
|
|
'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
|
|
|
|
'M', 'c', 's', '8', 'N', 'd', 't', '9',
|
|
|
|
'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
|
|
|
|
|
|
|
|
'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
|
|
|
|
'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
|
|
|
|
'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
|
|
|
|
'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
|
|
|
|
'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
|
|
|
|
'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
|
|
|
|
'M', 'c', 's', '8', 'N', 'd', 't', '9',
|
|
|
|
'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
|
|
|
|
|
|
|
|
'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
|
|
|
|
'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
|
|
|
|
'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
|
|
|
|
'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
|
|
|
|
'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
|
|
|
|
'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
|
|
|
|
'M', 'c', 's', '8', 'N', 'd', 't', '9',
|
|
|
|
'O', 'e', 'u', '+', 'P', 'f', 'v', '/'
|
|
|
|
};
|
|
|
|
|
|
|
|
void encodeChaff(std::vector<sal_uInt8> &rChaff)
|
|
|
|
{
|
2015-02-05 20:54:12 +00:00
|
|
|
static_assert(sizeof(aChaffEncoder) == 256, "this has to cover all chars");
|
2011-09-08 13:50:30 +01:00
|
|
|
|
2018-02-26 21:45:06 +01:00
|
|
|
for (auto & elem : rChaff)
|
2011-09-08 13:50:30 +01:00
|
|
|
{
|
2018-02-26 21:45:06 +01:00
|
|
|
elem = aChaffEncoder[elem];
|
2011-09-08 13:50:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-14 16:25:06 +02:00
|
|
|
namespace comphelper::xml
|
2020-01-23 15:16:37 +02:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OString makeXMLChaff()
|
2011-09-08 13:50:30 +01:00
|
|
|
{
|
|
|
|
rtlRandomPool pool = rtl_random_createPool();
|
|
|
|
|
|
|
|
sal_Int8 n;
|
|
|
|
rtl_random_getBytes(pool, &n, 1);
|
|
|
|
|
|
|
|
sal_Int32 nLength = 1024+n;
|
2015-07-23 12:14:39 +01:00
|
|
|
// coverity[tainted_data] - 1024 deliberate random minus max -127/plus max 128
|
2011-09-08 13:50:30 +01:00
|
|
|
std::vector<sal_uInt8> aChaff(nLength);
|
2019-05-22 13:49:30 +02:00
|
|
|
rtl_random_getBytes(pool, aChaff.data(), nLength);
|
2011-09-08 13:50:30 +01:00
|
|
|
|
|
|
|
rtl_random_destroyPool(pool);
|
|
|
|
|
|
|
|
encodeChaff(aChaff);
|
|
|
|
|
2019-12-18 12:02:07 +02:00
|
|
|
return OString(reinterpret_cast<const char*>(aChaff.data()), nLength);
|
2011-09-08 13:50:30 +01:00
|
|
|
}
|
2017-12-11 14:38:54 +01:00
|
|
|
|
|
|
|
OString generateGUIDString()
|
|
|
|
{
|
|
|
|
sal_uInt8 aSeq[16];
|
|
|
|
rtl_createUuid(aSeq, nullptr, true);
|
|
|
|
|
|
|
|
char str[39];
|
|
|
|
sprintf(str, "{%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
|
|
|
|
aSeq[0], aSeq[1], aSeq[2], aSeq[3], aSeq[4], aSeq[5], aSeq[6], aSeq[7], aSeq[8],
|
|
|
|
aSeq[9], aSeq[10], aSeq[11], aSeq[12], aSeq[13], aSeq[14], aSeq[15]);
|
|
|
|
|
2019-07-30 17:57:47 +02:00
|
|
|
return str;
|
2017-12-11 14:38:54 +01:00
|
|
|
}
|
2020-01-23 15:16:37 +02:00
|
|
|
}
|
2011-09-08 13:50:30 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|