office-gobmx/xmlsecurity/inc/biginteger.hxx
Michael Stahl e63611fabd xmlsecurity: some Distinguished Names are less equal than others
It turns out that the 2 backends NSS and MS CryptoAPI generate different
string representations of the same Distinguished Name in at least one
corner case, when a value contains a quote " U+0022.

The CryptoAPI function to generate the strings is:
CertNameToStr(..., CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG, ...)

This is documented on MSDN:
https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certnametostra#CERT_X500_NAME_STR

NSS appears to implement RFC 1485, at least that's what the internal
function is named after, or perhaps one of its several successor RFCs
(not clear currently if there's a relevant difference).

This is now causing trouble if a certificate with such a DN is used in a
signature, created on WNT but then verified on another platform, because
commit 5af5ea893b
introduced consistency checks that compare the DNs that occur as strings
in META-INF/documentsignatures.xml:

xmlsecurity/source/helper/xmlsignaturehelper.cxx:672: X509Data cannot be parsed

The reason is that in XSecController::setX509Data() the value read from
the X509IssuerSerial element (a string generated by CryptoAPI) doesn't
match the value generated by NSS from the certificate parsed from the
X509Certificate element, so these are erroneously interpreted as 2
distinct certificates.

Try to make the EqualDistinguishedNames() more flexible so that it can
try also a converted variant of the DN.

(libxmlsec's NSS backend also complains that it cannot parse the DN:
 x509vfy.c:607: xmlSecNssX509NameRead() '' '' 12 'invalid data for 'char': actual=34 and expected comma ',''
 but it manages to validate the signature despite this.)

Change-Id: I4f72900738d1f5313146bbda7320a8f44319ebc8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124287
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2021-10-27 20:35:31 +02:00

51 lines
1.8 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* 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 .
*/
#pragma once
#include <sal/config.h>
#include <string_view>
#include <rtl/ustring.hxx>
#include <com/sun/star/uno/Sequence.h>
#include "xsecxmlsecdllapi.h"
namespace xmlsecurity
{
XSECXMLSEC_DLLPUBLIC OUString bigIntegerToNumericString(const css::uno::Sequence<sal_Int8>& serial);
XSECXMLSEC_DLLPUBLIC css::uno::Sequence<sal_Int8>
numericStringToBigInteger(std::u16string_view serialNumber);
// DNs read as strings from XML files may need to be mangled for compatibility
// as NSS and MS CryptoAPI have different string serialisations; if the DN is
// from an XCertificate it's "native" already and doesn't need to be mangled.
enum EqualMode
{
NOCOMPAT,
COMPAT_2ND,
COMPAT_BOTH
};
XSECXMLSEC_DLLPUBLIC bool EqualDistinguishedNames(std::u16string_view rName1,
std::u16string_view rName2, EqualMode eMode);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */