25#include <xmlsec/mscng/x509.h>
27#include <com/sun/star/xml/crypto/SecurityOperationStatus.hpp>
28#include <com/sun/star/xml/crypto/XXMLSignature.hpp>
42using ::com::sun::star::xml::wrapper::XXMLElementWrapper ;
43using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
44using ::com::sun::star::xml::crypto::XXMLSignature ;
45using ::com::sun::star::xml::crypto::XXMLSignatureTemplate ;
46using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
47using ::com::sun::star::xml::crypto::XUriBinding ;
51class XMLSignature_MSCryptImpl :
public ::cppu::WeakImplHelper<
52 css::xml::crypto::XXMLSignature ,
53 css::lang::XServiceInfo >
56 explicit XMLSignature_MSCryptImpl();
59 virtual css::uno::Reference< css::xml::crypto::XXMLSignatureTemplate > SAL_CALL generate(
60 const css::uno::Reference< css::xml::crypto::XXMLSignatureTemplate >& aTemplate ,
61 const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& aEnvironment
64 virtual css::uno::Reference< css::xml::crypto::XXMLSignatureTemplate > SAL_CALL validate(
65 const css::uno::Reference< css::xml::crypto::XXMLSignatureTemplate >& aTemplate ,
66 const css::uno::Reference< css::xml::crypto::XXMLSecurityContext >& aContext
73 const OUString& ServiceName
81XMLSignature_MSCryptImpl::XMLSignature_MSCryptImpl() {
85Reference< XXMLSignatureTemplate >
86SAL_CALL XMLSignature_MSCryptImpl::generate(
87 const Reference< XXMLSignatureTemplate >& aTemplate ,
88 const Reference< XSecurityEnvironment >& aEnvironment
91 xmlSecKeysMngrPtr pMngr = nullptr ;
92 xmlSecDSigCtxPtr pDsigCtx = nullptr ;
93 xmlNodePtr pNode = nullptr ;
98 if( !aEnvironment.is() )
103 if( pSecEnv ==
nullptr )
107 Reference< XXMLElementWrapper > xElement = aTemplate->getTemplate() ;
108 if( !xElement.is() ) {
113 if( pElement ==
nullptr ) {
120 Reference< XUriBinding > xUriBinding = aTemplate->getBinding() ;
121 if( xUriBinding.is() ) {
135 pDsigCtx = xmlSecDSigCtxCreate( pMngr ) ;
136 if( pDsigCtx ==
nullptr )
145 if( xmlSecDSigCtxSign( pDsigCtx , pNode ) == 0 )
147 if (pDsigCtx->status == xmlSecDSigStatusSucceeded)
148 aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED);
150 aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_UNKNOWN);
154 aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_UNKNOWN);
158 xmlSecDSigCtxDestroy( pDsigCtx ) ;
162 if( xUriBinding.is() )
170Reference< XXMLSignatureTemplate >
171SAL_CALL XMLSignature_MSCryptImpl::validate(
172 const Reference< XXMLSignatureTemplate >& aTemplate ,
173 const Reference< XXMLSecurityContext >& aSecurityCtx
175 xmlSecKeysMngrPtr pMngr = nullptr ;
176 xmlSecDSigCtxPtr pDsigCtx = nullptr ;
177 xmlNodePtr pNode = nullptr ;
179 if( !aTemplate.is() )
182 if( !aSecurityCtx.is() )
186 Reference< XSecurityEnvironment > xSecEnv
187 = aSecurityCtx->getSecurityEnvironmentByIndex(
188 aSecurityCtx->getDefaultSecurityEnvironmentIndex());
190 if( pSecEnv ==
nullptr )
194 Reference< XXMLElementWrapper > xElement = aTemplate->getTemplate() ;
199 if( pElement ==
nullptr )
205 Reference< XUriBinding > xUriBinding = aTemplate->getBinding() ;
206 if( xUriBinding.is() ) {
220 pDsigCtx = xmlSecDSigCtxCreate( pMngr ) ;
221 if( pDsigCtx ==
nullptr )
229 pDsigCtx->keyInfoReadCtx.flags |= XMLSEC_KEYINFO_FLAGS_X509DATA_DONT_VERIFY_CERTS;
232 if (xmlSecPtrListAdd(&(pDsigCtx->keyInfoReadCtx.enabledKeyData), BAD_CAST xmlSecMSCngKeyDataX509GetKlass()) < 0)
242 int rs = xmlSecDSigCtxVerify(pDsigCtx , pNode);
245 xmlSecSize nReferenceCount = xmlSecPtrListGetSize(&pDsigCtx->manifestReferences);
247 xmlSecSize nReferenceGood = 0;
248 for (xmlSecSize nReference = 0; nReference < nReferenceCount; ++nReference)
250 xmlSecDSigReferenceCtxPtr pReference =
static_cast<xmlSecDSigReferenceCtxPtr
>(xmlSecPtrListGetItem(&pDsigCtx->manifestReferences, nReference));
253 if (pReference->status == xmlSecDSigStatusSucceeded)
257 SAL_INFO(
"xmlsecurity.xmlsec",
"xmlSecDSigCtxVerify status " << pDsigCtx->status <<
", references good " << nReferenceGood <<
" of " << nReferenceCount);
259 if (rs == 0 && nReferenceCount == nReferenceGood)
261 if (pDsigCtx->status == xmlSecDSigStatusSucceeded)
262 aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED);
264 aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_UNKNOWN);
268 aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_UNKNOWN);
271 xmlSecDSigCtxDestroy( pDsigCtx ) ;
275 if( xUriBinding.is() )
284OUString SAL_CALL XMLSignature_MSCryptImpl::getImplementationName() {
285 return "com.sun.star.xml.crypto.XMLSignature";
289sal_Bool SAL_CALL XMLSignature_MSCryptImpl::supportsService(
const OUString& serviceName) {
294Sequence< OUString > SAL_CALL XMLSignature_MSCryptImpl::getSupportedServiceNames() {
295 return {
"com.sun.star.xml.crypto.XMLSignature" };
298extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
300 uno::Sequence<uno::Any>
const& )
302 return cppu::acquire(
new XMLSignature_MSCryptImpl);
static void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr)
xmlSecKeysMngrPtr createKeysManager()
xmlNodePtr getNativeElement() const
void clearErrorRecorder()
#define SAL_INFO(area, stream)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_xml_crypto_XMLSignature_get_implementation(uno::XComponentContext *, uno::Sequence< uno::Any > const &)
int xmlRegisterStreamInputCallbacks(css::uno::Reference< css::xml::crypto::XUriBinding > const &aUriBinding)
int xmlUnregisterStreamInputCallbacks()