2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-16 17:32:30 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* 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/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2006-09-16 13:35:59 +00:00
|
|
|
|
2004-07-12 12:15:31 +00:00
|
|
|
#include "resourcemanager.hxx"
|
|
|
|
|
|
|
|
#include <vcl/svapp.hxx>
|
2004-07-27 06:57:37 +00:00
|
|
|
#include <vcl/fixed.hxx>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/solar.hrc>
|
|
|
|
#include <unotools/syslocale.hxx>
|
2009-09-17 13:53:54 +00:00
|
|
|
#include <rtl/ustring.h>
|
|
|
|
#include <rtl/ustrbuf.h>
|
|
|
|
#include <vector>
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
using namespace std;
|
2004-07-12 12:15:31 +00:00
|
|
|
|
|
|
|
namespace XmlSec
|
|
|
|
{
|
2017-06-11 20:56:30 +01:00
|
|
|
const std::locale& GetResLocale()
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2017-07-31 17:16:27 +01:00
|
|
|
static const std::locale loc = Translate::Create("xsc");
|
2017-06-11 20:56:30 +01:00
|
|
|
return loc;
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
const LocaleDataWrapper& GetLocaleData()
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2017-06-18 22:13:22 +02:00
|
|
|
static SvtSysLocale ourSysLocale;
|
|
|
|
|
|
|
|
return ourSysLocale.GetLocaleData();
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 09:49:00 +02:00
|
|
|
DateTime GetDateTime( const css::util::DateTime& _rDT )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2015-01-11 13:35:38 +02:00
|
|
|
return DateTime(_rDT);
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 09:49:00 +02:00
|
|
|
OUString GetDateTimeString( const css::util::DateTime& _rDT )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2010-11-08 00:44:02 +01:00
|
|
|
// String with date and time information (#i20172#)
|
2004-11-26 13:52:58 +00:00
|
|
|
DateTime aDT( GetDateTime( _rDT ) );
|
2006-04-07 13:24:56 +00:00
|
|
|
const LocaleDataWrapper& rLoDa = GetLocaleData();
|
2013-08-17 01:11:11 +02:00
|
|
|
|
|
|
|
return rLoDa.getDate( aDT ) + " " + rLoDa.getTime( aDT );
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 09:49:00 +02:00
|
|
|
OUString GetDateString( const css::util::DateTime& _rDT )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2006-04-07 13:24:56 +00:00
|
|
|
return GetLocaleData().getDate( GetDateTime( _rDT ) );
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 14:21:06 +02:00
|
|
|
OUString GetCertificateKind( const css::security::CertificateKind &rKind )
|
|
|
|
{
|
|
|
|
switch (rKind)
|
|
|
|
{
|
|
|
|
case css::security::CertificateKind_X509:
|
|
|
|
return OUString("X.509");
|
|
|
|
case css::security::CertificateKind_OPENPGP:
|
|
|
|
return OUString("OpenPGP");
|
|
|
|
default:
|
|
|
|
return OUString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
/*
|
|
|
|
Creates two strings based on the distinguished name which are displayed in the
|
|
|
|
certificate details view. The first string contains only the values of the attribute
|
2015-09-29 18:13:49 +02:00
|
|
|
and values pairs, which are separated by commas. All escape characters ('"') are
|
2009-09-17 13:53:54 +00:00
|
|
|
removed.
|
|
|
|
The second string is for the details view at the bottom. It shows the attribute/value
|
|
|
|
pairs on different lines. All escape characters ('"') are removed.
|
|
|
|
*/
|
|
|
|
pair< OUString, OUString> GetDNForCertDetailsView( const OUString & rRawString)
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2009-09-17 13:53:54 +00:00
|
|
|
vector< pair< OUString, OUString > > vecAttrValueOfDN = parseDN(rRawString);
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer s1, s2;
|
2009-09-17 13:53:54 +00:00
|
|
|
typedef vector< pair < OUString, OUString > >::const_iterator CIT;
|
2011-01-06 14:13:42 +00:00
|
|
|
for (CIT i = vecAttrValueOfDN.begin(); i < vecAttrValueOfDN.end(); ++i)
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2009-09-17 13:53:54 +00:00
|
|
|
if (i != vecAttrValueOfDN.begin())
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2013-12-20 14:23:33 +02:00
|
|
|
s1.append(',');
|
|
|
|
s2.append('\n');
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
2013-08-17 15:27:06 +00:00
|
|
|
s1.append(i->second);
|
2015-11-06 09:23:33 +02:00
|
|
|
s2.append(i->first + " = " + i->second);
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
2009-09-17 13:53:54 +00:00
|
|
|
return make_pair(s1.makeStringAndClear(), s2.makeStringAndClear());
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
/*
|
|
|
|
Whenever the attribute value contains special characters, such as '"' or ',' (without '')
|
|
|
|
then the value will be enclosed in double quotes by the respective Windows or NSS function
|
|
|
|
which we use to retrieve, for example, the subject name. If double quotes appear in the value then
|
|
|
|
they are escaped with a double quote. This function removes the escape characters.
|
|
|
|
*/
|
2016-02-16 14:14:43 +02:00
|
|
|
#ifdef _WIN32
|
2009-09-17 13:53:54 +00:00
|
|
|
vector< pair< OUString, OUString> > parseDN(const OUString& rRawString)
|
2010-06-18 15:33:33 +02:00
|
|
|
{
|
2009-09-17 13:53:54 +00:00
|
|
|
vector< pair<OUString, OUString> > retVal;
|
|
|
|
bool bInEscape = false;
|
|
|
|
bool bInValue = false;
|
|
|
|
bool bInType = true;
|
|
|
|
sal_Int32 nTypeNameStart = 0;
|
|
|
|
OUString sType;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer sbufValue;
|
2009-09-17 13:53:54 +00:00
|
|
|
sal_Int32 length = rRawString.getLength();
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
for (sal_Int32 i = 0; i < length; i++)
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2009-09-17 13:53:54 +00:00
|
|
|
sal_Unicode c = rRawString[i];
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
if (c == '=')
|
|
|
|
{
|
|
|
|
if (! bInValue)
|
|
|
|
{
|
|
|
|
sType = rRawString.copy(nTypeNameStart, i - nTypeNameStart);
|
|
|
|
sType = sType.trim();
|
|
|
|
bInType = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sbufValue.append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '"')
|
|
|
|
{
|
|
|
|
if (!bInEscape)
|
|
|
|
{
|
|
|
|
//If this is the quote is the first of the couple which enclose the
|
|
|
|
//whole value, because the value contains special characters
|
|
|
|
//then we just drop it. That is, this character must be followed by
|
|
|
|
//a character which is not '"'.
|
|
|
|
if ( i + 1 < length && rRawString[i+1] == '"')
|
|
|
|
bInEscape = true;
|
|
|
|
else
|
|
|
|
bInValue = !bInValue; //value is enclosed in " "
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//This quote is escaped by a preceding quote and therefore is
|
|
|
|
//part of the value
|
|
|
|
sbufValue.append(c);
|
|
|
|
bInEscape = false;
|
|
|
|
}
|
|
|
|
}
|
2010-06-18 15:33:33 +02:00
|
|
|
else if (c == ',' || c == '+')
|
2009-09-17 13:53:54 +00:00
|
|
|
{
|
|
|
|
//The comma separate the attribute value pairs.
|
|
|
|
//If the comma is not part of a value (the value would then be enclosed in '"'),
|
|
|
|
//then we have reached the end of the value
|
|
|
|
if (!bInValue)
|
|
|
|
{
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT(!sType.isEmpty());
|
2009-09-17 13:53:54 +00:00
|
|
|
retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
|
2014-11-12 14:24:10 +05:30
|
|
|
sType.clear();
|
2009-09-17 13:53:54 +00:00
|
|
|
//The next char is the start of the new type
|
|
|
|
nTypeNameStart = i + 1;
|
|
|
|
bInType = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//The whole string is enclosed because it contains special characters.
|
|
|
|
//The enclosing '"' are not part of certificate but will be added by
|
|
|
|
//the function (Windows or NSS) which retrieves DN
|
|
|
|
sbufValue.append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!bInType)
|
|
|
|
sbufValue.append(c);
|
|
|
|
}
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
2009-09-17 13:53:54 +00:00
|
|
|
if (sbufValue.getLength())
|
|
|
|
{
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT(!sType.isEmpty());
|
2009-09-17 13:53:54 +00:00
|
|
|
retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
|
|
|
|
}
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
vector< pair< OUString, OUString> > parseDN(const OUString& rRawString)
|
|
|
|
{
|
|
|
|
vector< pair<OUString, OUString> > retVal;
|
|
|
|
//bInEscape == true means that the preceding character is an escape character
|
|
|
|
bool bInEscape = false;
|
|
|
|
bool bInValue = false;
|
|
|
|
bool bInType = true;
|
|
|
|
sal_Int32 nTypeNameStart = 0;
|
|
|
|
OUString sType;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer sbufValue;
|
2009-09-17 13:53:54 +00:00
|
|
|
sal_Int32 length = rRawString.getLength();
|
|
|
|
|
|
|
|
for (sal_Int32 i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
sal_Unicode c = rRawString[i];
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
if (c == '=')
|
|
|
|
{
|
|
|
|
if (! bInValue)
|
|
|
|
{
|
|
|
|
sType = rRawString.copy(nTypeNameStart, i - nTypeNameStart);
|
|
|
|
sType = sType.trim();
|
|
|
|
bInType = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sbufValue.append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '\\')
|
|
|
|
{
|
|
|
|
if (!bInEscape)
|
|
|
|
{
|
|
|
|
bInEscape = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // bInEscape is true
|
|
|
|
sbufValue.append(c);
|
|
|
|
bInEscape = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '"')
|
|
|
|
{
|
|
|
|
//an unescaped '"' is either at the beginning or end of the value
|
|
|
|
if (!bInEscape)
|
|
|
|
{
|
|
|
|
if ( !bInValue)
|
|
|
|
bInValue = true;
|
|
|
|
else if (bInValue)
|
|
|
|
bInValue = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//This quote is escaped by a preceding quote and therefore is
|
|
|
|
//part of the value
|
|
|
|
sbufValue.append(c);
|
|
|
|
bInEscape = false;
|
|
|
|
}
|
|
|
|
}
|
2010-06-18 15:33:33 +02:00
|
|
|
else if (c == ',' || c == '+')
|
2009-09-17 13:53:54 +00:00
|
|
|
{
|
|
|
|
//The comma separate the attribute value pairs.
|
|
|
|
//If the comma is not part of a value (the value would then be enclosed in '"'),
|
|
|
|
//then we have reached the end of the value
|
|
|
|
if (!bInValue)
|
|
|
|
{
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT(!sType.isEmpty());
|
2009-09-17 13:53:54 +00:00
|
|
|
retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
|
2014-11-12 14:24:10 +05:30
|
|
|
sType.clear();
|
2009-09-17 13:53:54 +00:00
|
|
|
//The next char is the start of the new type
|
|
|
|
nTypeNameStart = i + 1;
|
|
|
|
bInType = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//The whole string is enclosed because it contains special characters.
|
|
|
|
//The enclosing '"' are not part of certificate but will be added by
|
|
|
|
//the function (Windows or NSS) which retrieves DN
|
|
|
|
sbufValue.append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!bInType)
|
|
|
|
{
|
|
|
|
sbufValue.append(c);
|
|
|
|
bInEscape = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-18 20:02:13 +02:00
|
|
|
if (!sbufValue.isEmpty())
|
2009-09-17 13:53:54 +00:00
|
|
|
{
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT(!sType.isEmpty());
|
2009-09-17 13:53:54 +00:00
|
|
|
retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
|
|
|
|
}
|
|
|
|
return retVal;
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
2004-07-15 05:20:09 +00:00
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
#endif
|
|
|
|
|
2012-09-24 16:39:58 +04:00
|
|
|
OUString GetContentPart( const OUString& _rRawString )
|
2005-03-10 17:05:44 +00:00
|
|
|
{
|
2015-11-10 10:29:43 +01:00
|
|
|
char const * aIDs[] = { "CN", "OU", "O", "E", nullptr };
|
2017-02-02 17:33:30 +01:00
|
|
|
bool shouldBeParsed = false;
|
2005-03-10 17:05:44 +00:00
|
|
|
int i = 0;
|
2017-02-02 17:33:30 +01:00
|
|
|
while ( aIDs[i] )
|
|
|
|
{
|
|
|
|
if (_rRawString.startsWith(OUString::createFromAscii(aIDs[i++])))
|
|
|
|
{
|
|
|
|
shouldBeParsed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!shouldBeParsed)
|
|
|
|
return _rRawString;
|
|
|
|
|
|
|
|
OUString retVal;
|
|
|
|
i = 0;
|
2009-09-17 13:53:54 +00:00
|
|
|
vector< pair< OUString, OUString > > vecAttrValueOfDN = parseDN(_rRawString);
|
2005-03-10 17:05:44 +00:00
|
|
|
while ( aIDs[i] )
|
|
|
|
{
|
2009-09-17 13:53:54 +00:00
|
|
|
OUString sPartId = OUString::createFromAscii( aIDs[i++] );
|
|
|
|
typedef vector< pair < OUString, OUString > >::const_iterator CIT;
|
2011-01-06 14:13:42 +00:00
|
|
|
for (CIT idn = vecAttrValueOfDN.begin(); idn != vecAttrValueOfDN.end(); ++idn)
|
2005-03-10 17:05:44 +00:00
|
|
|
{
|
2017-07-07 12:14:59 +02:00
|
|
|
if (idn->first == sPartId)
|
2009-09-17 13:53:54 +00:00
|
|
|
{
|
|
|
|
retVal = idn->second;
|
|
|
|
break;
|
|
|
|
}
|
2005-03-10 17:05:44 +00:00
|
|
|
}
|
2012-01-28 09:56:30 -02:00
|
|
|
if (!retVal.isEmpty())
|
2009-09-17 13:53:54 +00:00
|
|
|
break;
|
2005-03-10 17:05:44 +00:00
|
|
|
}
|
2009-09-17 13:53:54 +00:00
|
|
|
return retVal;
|
2005-03-10 17:05:44 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 09:49:00 +02:00
|
|
|
OUString GetHexString( const css::uno::Sequence< sal_Int8 >& _rSeq, const char* _pSep, sal_uInt16 _nLineBreak )
|
2004-07-15 05:20:09 +00:00
|
|
|
{
|
|
|
|
const sal_Int8* pSerNumSeq = _rSeq.getConstArray();
|
|
|
|
int nCnt = _rSeq.getLength();
|
2012-09-24 16:39:58 +04:00
|
|
|
OUStringBuffer aStr;
|
2004-11-26 13:52:58 +00:00
|
|
|
const char pHexDigs[ 17 ] = "0123456789ABCDEF";
|
2004-07-15 05:20:09 +00:00
|
|
|
char pBuffer[ 3 ] = " ";
|
2011-01-14 14:16:44 +01:00
|
|
|
sal_uInt8 nNum;
|
|
|
|
sal_uInt16 nBreakStart = _nLineBreak? _nLineBreak : 1;
|
|
|
|
sal_uInt16 nBreak = nBreakStart;
|
2004-07-15 05:20:09 +00:00
|
|
|
for( int i = 0 ; i < nCnt ; ++i )
|
|
|
|
{
|
2011-01-14 14:16:44 +01:00
|
|
|
nNum = sal_uInt8( pSerNumSeq[ i ] );
|
2004-11-26 13:52:58 +00:00
|
|
|
|
2011-03-05 16:45:26 +00:00
|
|
|
// exchange the buffer[0] and buffer[1], which make it consistent with Mozilla and Windows
|
2004-11-26 13:52:58 +00:00
|
|
|
pBuffer[ 1 ] = pHexDigs[ nNum & 0x0F ];
|
2004-07-15 05:20:09 +00:00
|
|
|
nNum >>= 4;
|
2004-11-26 13:52:58 +00:00
|
|
|
pBuffer[ 0 ] = pHexDigs[ nNum ];
|
2012-09-24 16:39:58 +04:00
|
|
|
aStr.appendAscii( pBuffer );
|
2004-07-15 05:20:09 +00:00
|
|
|
|
|
|
|
--nBreak;
|
|
|
|
if( nBreak )
|
2012-09-24 16:39:58 +04:00
|
|
|
aStr.appendAscii( _pSep );
|
2004-07-15 05:20:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
nBreak = nBreakStart;
|
2012-09-24 16:39:58 +04:00
|
|
|
aStr.append( '\n' );
|
2004-07-15 05:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 16:39:58 +04:00
|
|
|
return aStr.makeStringAndClear();
|
2004-07-15 05:20:09 +00:00
|
|
|
}
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:57:08 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|