LibreOffice Module xmlsecurity (master) 1
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
XMLSignatureHelper Class Reference

#include <xmlsignaturehelper.hxx>

Collaboration diagram for XMLSignatureHelper:
[legend]

Public Member Functions

 XMLSignatureHelper (const css::uno::Reference< css::uno::XComponentContext > &mrCtx)
 
 ~XMLSignatureHelper ()
 
void StartVerifySignatureElement ()
 
void SetStorage (const css::uno::Reference< css::embed::XStorage > &rxStorage, std::u16string_view sODFVersion)
 
void SetStartVerifySignatureHdl (const Link< LinkParamNone *, bool > &rLink)
 
SignatureInformation GetSignatureInformation (sal_Int32 nSecurityId) const
 
SignatureInformations GetSignatureInformations () const
 
std::vector< css::uno::Reference< css::security::XCertificate > > CheckAndUpdateSignatureInformation (css::uno::Reference< css::xml::crypto::XSecurityEnvironment > const &xSecEnv, SignatureInformation const &rInfo)
 ImplVerifySignature calls this to figure out which X509Data is the signing certificate and update the internal state with the result. More...
 
void StartMission (const css::uno::Reference< css::xml::crypto::XXMLSecurityContext > &xSecurityContext)
 
void EndMission ()
 
sal_Int32 GetNewSecurityId ()
 
void SetX509Certificate (sal_Int32 nSecurityId, const OUString &ouX509IssuerName, const OUString &ouX509SerialNumber, const OUString &ouX509Cert, const OUString &ouX509CertDigest, svl::crypto::SignatureMethodAlgorithm eAlgorithmID)
 sets data that describes the certificate. More...
 
void AddEncapsulatedX509Certificate (const OUString &ouEncapsulatedX509Certificate)
 
void SetGpgCertificate (sal_Int32 nSecurityId, const OUString &ouGpgCertDigest, const OUString &ouGpgCert, const OUString &ouGpgOwner)
 
void SetDateTime (sal_Int32 nSecurityId, const DateTime &rDateTime)
 
void SetDescription (sal_Int32 nSecurityId, const OUString &rDescription)
 
void SetSignatureLineId (sal_Int32 nSecurityId, const OUString &rSignatureLineId)
 
void SetSignatureLineValidGraphic (sal_Int32 nSecurityId, const css::uno::Reference< css::graphic::XGraphic > &xValidGraphic)
 
void SetSignatureLineInvalidGraphic (sal_Int32 nSecurityId, const css::uno::Reference< css::graphic::XGraphic > &xInvalidGraphic)
 
void AddForSigning (sal_Int32 securityId, const OUString &uri, bool bBinary, bool bXAdESCompliantIfODF)
 
void CreateAndWriteSignature (const css::uno::Reference< css::xml::sax::XDocumentHandler > &xDocumentHandler, bool bXAdESCompliantIfODF)
 
bool ReadAndVerifySignature (const css::uno::Reference< css::io::XInputStream > &xInputStream)
 
css::uno::Reference< css::xml::sax::XWriter > CreateDocumentHandlerWithHeader (const css::uno::Reference< css::io::XOutputStream > &xOutputStream)
 
bool ReadAndVerifySignatureStorage (const css::uno::Reference< css::embed::XStorage > &xStorage, bool bCacheLastSignature=true)
 Read and verify OOXML signatures. More...
 
bool ReadAndVerifySignatureStorageStream (const css::uno::Reference< css::io::XInputStream > &xInputStream)
 Read and verify a single OOXML signature. More...
 
void EnsureSignaturesRelation (const css::uno::Reference< css::embed::XStorage > &xStorage, bool bAdd)
 Adds or removes an OOXML digital signature relation to _rels/.rels if there wasn't any before. More...
 
void ExportSignatureRelations (const css::uno::Reference< css::embed::XStorage > &xStorage, int nSignatureCount)
 Given that xStorage is an OOXML _xmlsignatures storage, create origin.sigs and its relations. More...
 
void CreateAndWriteOOXMLSignature (const css::uno::Reference< css::embed::XStorage > &xRootStorage, const css::uno::Reference< css::embed::XStorage > &xSignatureStorage, int nSignatureIndex)
 Given that xSignatureStorage is an OOXML _xmlsignatures storage, create and write a new signature. More...
 
void ExportOOXMLSignature (const css::uno::Reference< css::embed::XStorage > &xRootStorage, const css::uno::Reference< css::embed::XStorage > &xSignatureStorage, const SignatureInformation &rInformation, int nSignatureIndex)
 Similar to CreateAndWriteOOXMLSignature(), but used to write the signature to the persistent storage, not the temporary one. More...
 
void ExportSignatureContentTypes (const css::uno::Reference< css::embed::XStorage > &xStorage, int nSignatureCount)
 Given that xStorage is an OOXML root storage, advertise signatures in its [Content_Types].xml stream. More...
 

Static Public Member Functions

static void CloseDocumentHandler (const css::uno::Reference< css::xml::sax::XDocumentHandler > &xDocumentHandler)
 
static void ExportSignature (const css::uno::Reference< css::xml::sax::XDocumentHandler > &xDocumentHandler, const SignatureInformation &signatureInfo, bool bXAdESCompliantIfODF)
 

Private Member Functions

 XMLSignatureHelper (const XMLSignatureHelper &)=delete
 

Private Attributes

css::uno::Reference< css::uno::XComponentContext > mxCtx
 
rtl::Reference< UriBindingHelpermxUriBinding
 
rtl::Reference< XSecControllermpXSecController
 
bool mbError
 
bool mbODFPre1_2
 
Link< LinkParamNone *, bool > maStartVerifySignatureHdl
 

Detailed Description

Definition at line 63 of file xmlsignaturehelper.hxx.

Constructor & Destructor Documentation

◆ XMLSignatureHelper() [1/2]

XMLSignatureHelper::XMLSignatureHelper ( const XMLSignatureHelper )
privatedelete

◆ XMLSignatureHelper() [2/2]

XMLSignatureHelper::XMLSignatureHelper ( const css::uno::Reference< css::uno::XComponentContext > &  mrCtx)

◆ ~XMLSignatureHelper()

XMLSignatureHelper::~XMLSignatureHelper ( )

Definition at line 67 of file xmlsignaturehelper.cxx.

Member Function Documentation

◆ AddEncapsulatedX509Certificate()

void XMLSignatureHelper::AddEncapsulatedX509Certificate ( const OUString &  ouEncapsulatedX509Certificate)

Definition at line 123 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ AddForSigning()

void XMLSignatureHelper::AddForSigning ( sal_Int32  securityId,
const OUString &  uri,
bool  bBinary,
bool  bXAdESCompliantIfODF 
)

Definition at line 168 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ CheckAndUpdateSignatureInformation()

std::vector< uno::Reference< security::XCertificate > > XMLSignatureHelper::CheckAndUpdateSignatureInformation ( css::uno::Reference< css::xml::crypto::XSecurityEnvironment > const &  xSecEnv,
SignatureInformation const &  rInfo 
)

ImplVerifySignature calls this to figure out which X509Data is the signing certificate and update the internal state with the result.

Returns
A sequence with the signing certificate at the back on success. An empty sequence on failure.

Definition at line 680 of file xmlsignaturehelper.cxx.

References CheckX509Data(), mpXSecController, SignatureInformation::nSecurityId, and SignatureInformation::X509Datas.

Referenced by DocumentSignatureManager::read().

◆ CloseDocumentHandler()

void XMLSignatureHelper::CloseDocumentHandler ( const css::uno::Reference< css::xml::sax::XDocumentHandler > &  xDocumentHandler)
static

◆ CreateAndWriteOOXMLSignature()

void XMLSignatureHelper::CreateAndWriteOOXMLSignature ( const css::uno::Reference< css::embed::XStorage > &  xRootStorage,
const css::uno::Reference< css::embed::XStorage > &  xSignatureStorage,
int  nSignatureIndex 
)

Given that xSignatureStorage is an OOXML _xmlsignatures storage, create and write a new signature.

Definition at line 541 of file xmlsignaturehelper.cxx.

References mbError, mpXSecController, and mxCtx.

Referenced by DocumentSignatureManager::add().

◆ CreateAndWriteSignature()

void XMLSignatureHelper::CreateAndWriteSignature ( const css::uno::Reference< css::xml::sax::XDocumentHandler > &  xDocumentHandler,
bool  bXAdESCompliantIfODF 
)

Definition at line 242 of file xmlsignaturehelper.cxx.

References mbError, and mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ CreateDocumentHandlerWithHeader()

uno::Reference< xml::sax::XWriter > XMLSignatureHelper::CreateDocumentHandlerWithHeader ( const css::uno::Reference< css::io::XOutputStream > &  xOutputStream)

◆ EndMission()

void XMLSignatureHelper::EndMission ( )

◆ EnsureSignaturesRelation()

void XMLSignatureHelper::EnsureSignaturesRelation ( const css::uno::Reference< css::embed::XStorage > &  xStorage,
bool  bAdd 
)

Adds or removes an OOXML digital signature relation to _rels/.rels if there wasn't any before.

Definition at line 417 of file xmlsignaturehelper.cxx.

References comphelper::containerToSequence(), mxCtx, nCount, OOXML_SIGNATURE_ORIGIN, comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(), u, and comphelper::OFOPXMLHelper::WriteRelationsInfoSequence().

Referenced by DocumentSignatureManager::add(), and DocumentSignatureManager::write().

◆ ExportOOXMLSignature()

void XMLSignatureHelper::ExportOOXMLSignature ( const css::uno::Reference< css::embed::XStorage > &  xRootStorage,
const css::uno::Reference< css::embed::XStorage > &  xSignatureStorage,
const SignatureInformation rInformation,
int  nSignatureIndex 
)

Similar to CreateAndWriteOOXMLSignature(), but used to write the signature to the persistent storage, not the temporary one.

Definition at line 223 of file xmlsignaturehelper.cxx.

References SignatureInformation::aSignatureBytes, mpXSecController, and mxCtx.

Referenced by DocumentSignatureManager::add(), DocumentSignatureManager::remove(), and DocumentSignatureManager::write().

◆ ExportSignature()

void XMLSignatureHelper::ExportSignature ( const css::uno::Reference< css::xml::sax::XDocumentHandler > &  xDocumentHandler,
const SignatureInformation signatureInfo,
bool  bXAdESCompliantIfODF 
)
static

◆ ExportSignatureContentTypes()

void XMLSignatureHelper::ExportSignatureContentTypes ( const css::uno::Reference< css::embed::XStorage > &  xStorage,
int  nSignatureCount 
)

Given that xStorage is an OOXML root storage, advertise signatures in its [Content_Types].xml stream.

Definition at line 499 of file xmlsignaturehelper.cxx.

References comphelper::containerToSequence(), i, mxCtx, comphelper::OFOPXMLHelper::ReadContentTypeSequence(), SAL_WARN, comphelper::OFOPXMLHelper::WriteContentSequence(), and xStream.

Referenced by DocumentSignatureManager::write().

◆ ExportSignatureRelations()

void XMLSignatureHelper::ExportSignatureRelations ( const css::uno::Reference< css::embed::XStorage > &  xStorage,
int  nSignatureCount 
)

Given that xStorage is an OOXML _xmlsignatures storage, create origin.sigs and its relations.

Definition at line 473 of file xmlsignaturehelper.cxx.

References comphelper::containerToSequence(), i, mxCtx, OOXML_SIGNATURE_SIGNATURE, and comphelper::OFOPXMLHelper::WriteRelationsInfoSequence().

Referenced by DocumentSignatureManager::add(), DocumentSignatureManager::remove(), and DocumentSignatureManager::write().

◆ GetNewSecurityId()

sal_Int32 XMLSignatureHelper::GetNewSecurityId ( )

Definition at line 101 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ GetSignatureInformation()

SignatureInformation XMLSignatureHelper::GetSignatureInformation ( sal_Int32  nSecurityId) const

Definition at line 290 of file xmlsignaturehelper.cxx.

References mpXSecController.

◆ GetSignatureInformations()

SignatureInformations XMLSignatureHelper::GetSignatureInformations ( ) const

Definition at line 295 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::read().

◆ ReadAndVerifySignature()

bool XMLSignatureHelper::ReadAndVerifySignature ( const css::uno::Reference< css::io::XInputStream > &  xInputStream)

◆ ReadAndVerifySignatureStorage()

bool XMLSignatureHelper::ReadAndVerifySignatureStorage ( const css::uno::Reference< css::embed::XStorage > &  xStorage,
bool  bCacheLastSignature = true 
)

◆ ReadAndVerifySignatureStorageStream()

bool XMLSignatureHelper::ReadAndVerifySignatureStorageStream ( const css::uno::Reference< css::io::XInputStream > &  xInputStream)

Read and verify a single OOXML signature.

Definition at line 383 of file xmlsignaturehelper.cxx.

References DBG_UNHANDLED_EXCEPTION, mbError, mpXSecController, and mxCtx.

Referenced by ReadAndVerifySignatureStorage().

◆ SetDateTime()

void XMLSignatureHelper::SetDateTime ( sal_Int32  nSecurityId,
const DateTime rDateTime 
)

Definition at line 140 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ SetDescription()

void XMLSignatureHelper::SetDescription ( sal_Int32  nSecurityId,
const OUString &  rDescription 
)

Definition at line 146 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ SetGpgCertificate()

void XMLSignatureHelper::SetGpgCertificate ( sal_Int32  nSecurityId,
const OUString &  ouGpgCertDigest,
const OUString &  ouGpgCert,
const OUString &  ouGpgOwner 
)

Definition at line 128 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ SetSignatureLineId()

void XMLSignatureHelper::SetSignatureLineId ( sal_Int32  nSecurityId,
const OUString &  rSignatureLineId 
)

Definition at line 151 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ SetSignatureLineInvalidGraphic()

void XMLSignatureHelper::SetSignatureLineInvalidGraphic ( sal_Int32  nSecurityId,
const css::uno::Reference< css::graphic::XGraphic > &  xInvalidGraphic 
)

Definition at line 162 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ SetSignatureLineValidGraphic()

void XMLSignatureHelper::SetSignatureLineValidGraphic ( sal_Int32  nSecurityId,
const css::uno::Reference< css::graphic::XGraphic > &  xValidGraphic 
)

Definition at line 156 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ SetStartVerifySignatureHdl()

void XMLSignatureHelper::SetStartVerifySignatureHdl ( const Link< LinkParamNone *, bool > &  rLink)

Definition at line 82 of file xmlsignaturehelper.cxx.

References maStartVerifySignatureHdl.

Referenced by DigitalSignaturesDialog::Init().

◆ SetStorage()

void XMLSignatureHelper::SetStorage ( const css::uno::Reference< css::embed::XStorage > &  rxStorage,
std::u16string_view  sODFVersion 
)

◆ SetX509Certificate()

void XMLSignatureHelper::SetX509Certificate ( sal_Int32  nSecurityId,
const OUString &  ouX509IssuerName,
const OUString &  ouX509SerialNumber,
const OUString &  ouX509Cert,
const OUString &  ouX509CertDigest,
svl::crypto::SignatureMethodAlgorithm  eAlgorithmID 
)

sets data that describes the certificate.

It is absolutely necessary that the parameter ouX509IssuerName is set. It contains the base64 encoded certificate, which is DER encoded. The XMLSec needs it to find the private key. Although issuer name and certificate should be sufficient to identify the certificate the implementation in XMLSec is broken, both for Windows and mozilla. The reason is that they use functions to find the certificate which take as parameter the DER encoded ASN.1 issuer name. The issuer name is a DName, where most attributes are of type DirectoryName, which is a choice of 5 string types. This information is not contained in the issuer string and while it is converted to the ASN.1 name the conversion function must assume a particular type, which is often wrong. For example, the Windows function CertStrToName will use a T.61 string if the string does not contain special characters. So if the certificate uses simple characters but encodes the issuer attributes in Utf8, then CertStrToName will use T.61. The resulting DER encoded ASN.1 name now contains different bytes which indicate the string type. The functions for finding the certificate apparently use memcmp - hence they fail to find the certificate.

Definition at line 106 of file xmlsignaturehelper.cxx.

References mpXSecController.

Referenced by DocumentSignatureManager::add().

◆ StartMission()

void XMLSignatureHelper::StartMission ( const css::uno::Reference< css::xml::crypto::XXMLSecurityContext > &  xSecurityContext)

◆ StartVerifySignatureElement()

void XMLSignatureHelper::StartVerifySignatureElement ( )

Member Data Documentation

◆ maStartVerifySignatureHdl

Link<LinkParamNone*,bool> XMLSignatureHelper::maStartVerifySignatureHdl
private

◆ mbError

bool XMLSignatureHelper::mbError
private

◆ mbODFPre1_2

bool XMLSignatureHelper::mbODFPre1_2
private

Definition at line 71 of file xmlsignaturehelper.hxx.

Referenced by CreateDocumentHandlerWithHeader(), and SetStorage().

◆ mpXSecController

rtl::Reference<XSecController> XMLSignatureHelper::mpXSecController
private

◆ mxCtx

css::uno::Reference< css::uno::XComponentContext > XMLSignatureHelper::mxCtx
private

◆ mxUriBinding

rtl::Reference<UriBindingHelper> XMLSignatureHelper::mxUriBinding
private

Definition at line 67 of file xmlsignaturehelper.hxx.

Referenced by SetStorage(), and StartMission().


The documentation for this class was generated from the following files: