LibreOffice Module xmlsecurity (master) 1
|
#include <xmlsignaturehelper.hxx>
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< UriBindingHelper > | mxUriBinding |
rtl::Reference< XSecController > | mpXSecController |
bool | mbError |
bool | mbODFPre1_2 |
Link< LinkParamNone *, bool > | maStartVerifySignatureHdl |
Definition at line 63 of file xmlsignaturehelper.hxx.
|
privatedelete |
XMLSignatureHelper::XMLSignatureHelper | ( | const css::uno::Reference< css::uno::XComponentContext > & | mrCtx | ) |
XMLSignatureHelper::~XMLSignatureHelper | ( | ) |
Definition at line 67 of file xmlsignaturehelper.cxx.
void XMLSignatureHelper::AddEncapsulatedX509Certificate | ( | const OUString & | ouEncapsulatedX509Certificate | ) |
Definition at line 123 of file xmlsignaturehelper.cxx.
References mpXSecController.
Referenced by DocumentSignatureManager::add().
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().
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.
Definition at line 680 of file xmlsignaturehelper.cxx.
References CheckX509Data(), mpXSecController, SignatureInformation::nSecurityId, and SignatureInformation::X509Datas.
Referenced by DocumentSignatureManager::read().
|
static |
Definition at line 209 of file xmlsignaturehelper.cxx.
Referenced by DocumentSignatureManager::add(), DocumentSignatureManager::remove(), and DocumentSignatureManager::write().
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().
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().
uno::Reference< xml::sax::XWriter > XMLSignatureHelper::CreateDocumentHandlerWithHeader | ( | const css::uno::Reference< css::io::XOutputStream > & | xOutputStream | ) |
Definition at line 174 of file xmlsignaturehelper.cxx.
References mbODFPre1_2, mxCtx, NS_DOCUMENTSIGNATURES, and NS_DOCUMENTSIGNATURES_ODF_1_2.
Referenced by DocumentSignatureManager::add(), DocumentSignatureManager::remove(), and DocumentSignatureManager::write().
void XMLSignatureHelper::EndMission | ( | ) |
Definition at line 96 of file xmlsignaturehelper.cxx.
References mpXSecController.
Referenced by DocumentSignatureManager::add(), and DocumentSignatureManager::read().
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().
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().
|
static |
Definition at line 215 of file xmlsignaturehelper.cxx.
References XSecController::exportSignature().
Referenced by DocumentSignatureManager::add(), DocumentSignatureManager::remove(), and DocumentSignatureManager::write().
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().
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().
sal_Int32 XMLSignatureHelper::GetNewSecurityId | ( | ) |
Definition at line 101 of file xmlsignaturehelper.cxx.
References mpXSecController.
Referenced by DocumentSignatureManager::add().
SignatureInformation XMLSignatureHelper::GetSignatureInformation | ( | sal_Int32 | nSecurityId | ) | const |
Definition at line 290 of file xmlsignaturehelper.cxx.
References mpXSecController.
SignatureInformations XMLSignatureHelper::GetSignatureInformations | ( | ) | const |
Definition at line 295 of file xmlsignaturehelper.cxx.
References mpXSecController.
Referenced by DocumentSignatureManager::read().
bool XMLSignatureHelper::ReadAndVerifySignature | ( | const css::uno::Reference< css::io::XInputStream > & | xInputStream | ) |
Definition at line 252 of file xmlsignaturehelper.cxx.
References DBG_UNHANDLED_EXCEPTION, mbError, mpXSecController, mxCtx, and SAL_WARN_IF.
Referenced by DocumentSignatureManager::read().
bool XMLSignatureHelper::ReadAndVerifySignatureStorage | ( | const css::uno::Reference< css::embed::XStorage > & | xStorage, |
bool | bCacheLastSignature = true |
||
) |
Read and verify OOXML signatures.
Definition at line 321 of file xmlsignaturehelper.cxx.
References aData, i, mpXSecController, mxCtx, ReadAndVerifySignatureStorageStream(), comphelper::OFOPXMLHelper::ReadRelationsInfoSequence(), SAL_MAX_INT32, SAL_WARN, and u.
Referenced by DocumentSignatureManager::read().
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().
void XMLSignatureHelper::SetDateTime | ( | sal_Int32 | nSecurityId, |
const DateTime & | rDateTime | ||
) |
Definition at line 140 of file xmlsignaturehelper.cxx.
References mpXSecController.
Referenced by DocumentSignatureManager::add().
void XMLSignatureHelper::SetDescription | ( | sal_Int32 | nSecurityId, |
const OUString & | rDescription | ||
) |
Definition at line 146 of file xmlsignaturehelper.cxx.
References mpXSecController.
Referenced by DocumentSignatureManager::add().
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().
void XMLSignatureHelper::SetSignatureLineId | ( | sal_Int32 | nSecurityId, |
const OUString & | rSignatureLineId | ||
) |
Definition at line 151 of file xmlsignaturehelper.cxx.
References mpXSecController.
Referenced by DocumentSignatureManager::add().
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().
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().
void XMLSignatureHelper::SetStartVerifySignatureHdl | ( | const Link< LinkParamNone *, bool > & | rLink | ) |
Definition at line 82 of file xmlsignaturehelper.cxx.
References maStartVerifySignatureHdl.
Referenced by DigitalSignaturesDialog::Init().
void XMLSignatureHelper::SetStorage | ( | const css::uno::Reference< css::embed::XStorage > & | rxStorage, |
std::u16string_view | sODFVersion | ||
) |
Definition at line 71 of file xmlsignaturehelper.cxx.
References DocumentSignatureHelper::isODFPre_1_2(), mbODFPre1_2, mxUriBinding, and SAL_WARN_IF.
Referenced by DigitalSignaturesDialog::SetStorage().
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().
void XMLSignatureHelper::StartMission | ( | const css::uno::Reference< css::xml::crypto::XXMLSecurityContext > & | xSecurityContext | ) |
Definition at line 88 of file xmlsignaturehelper.cxx.
References mpXSecController, and mxUriBinding.
Referenced by DocumentSignatureManager::add(), and DocumentSignatureManager::read().
void XMLSignatureHelper::StartVerifySignatureElement | ( | ) |
Definition at line 300 of file xmlsignaturehelper.cxx.
References Link< typename Arg, typename Ret >::Call(), Link< typename Arg, typename Ret >::IsSet(), maStartVerifySignatureHdl, and mpXSecController.
Referenced by OOXMLSecParser::DsSignatureContext::StartElement(), and XSecParser::DsSignatureContext::StartElement().
|
private |
Definition at line 72 of file xmlsignaturehelper.hxx.
Referenced by SetStartVerifySignatureHdl(), and StartVerifySignatureElement().
|
private |
Definition at line 70 of file xmlsignaturehelper.hxx.
Referenced by CreateAndWriteOOXMLSignature(), CreateAndWriteSignature(), ReadAndVerifySignature(), and ReadAndVerifySignatureStorageStream().
|
private |
Definition at line 71 of file xmlsignaturehelper.hxx.
Referenced by CreateDocumentHandlerWithHeader(), and SetStorage().
|
private |
Definition at line 69 of file xmlsignaturehelper.hxx.
Referenced by AddEncapsulatedX509Certificate(), AddForSigning(), CheckAndUpdateSignatureInformation(), CreateAndWriteOOXMLSignature(), CreateAndWriteSignature(), EndMission(), ExportOOXMLSignature(), GetNewSecurityId(), GetSignatureInformation(), GetSignatureInformations(), ReadAndVerifySignature(), ReadAndVerifySignatureStorage(), ReadAndVerifySignatureStorageStream(), SetDateTime(), SetDescription(), SetGpgCertificate(), SetSignatureLineId(), SetSignatureLineInvalidGraphic(), SetSignatureLineValidGraphic(), SetX509Certificate(), StartMission(), and StartVerifySignatureElement().
|
private |
Definition at line 66 of file xmlsignaturehelper.hxx.
Referenced by CreateAndWriteOOXMLSignature(), CreateDocumentHandlerWithHeader(), EnsureSignaturesRelation(), ExportOOXMLSignature(), ExportSignatureContentTypes(), ExportSignatureRelations(), ReadAndVerifySignature(), ReadAndVerifySignatureStorage(), and ReadAndVerifySignatureStorageStream().
|
private |
Definition at line 67 of file xmlsignaturehelper.hxx.
Referenced by SetStorage(), and StartMission().