LibreOffice Module xmlsecurity (master) 1
signaturecreatorimpl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
23#include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
25#include <osl/diagnose.h>
26#include <rtl/ref.hxx>
27
28namespace com::sun::star::xml::wrapper { class XXMLElementWrapper; }
29
30using namespace com::sun::star::uno;
31
33 : m_nIdOfBlocker(-1)
34{
35}
36
38{
39}
40
42/****** SignatureCreatorImpl/notifyResultListener *****************************
43 *
44 * NAME
45 * notifyResultListener -- notifies the listener about the signature
46 * creation result.
47 ******************************************************************************/
48{
49 css::uno::Reference< css::xml::crypto::sax::XSignatureCreationResultListener >
50 xSignatureCreationResultListener ( m_xResultListener , css::uno::UNO_QUERY ) ;
51
52 xSignatureCreationResultListener->signatureCreated( m_nSecurityId, m_nStatus );
53}
54
56/****** SignatureCreatorImpl/startEngine *************************************
57 *
58 * NAME
59 * startEngine -- generates the signature.
60 *
61 * FUNCTION
62 * generates the signature element, then if succeeds, updates the link
63 * of old template element to the new signature element in
64 * SAXEventKeeper.
65 *
66 * INPUTS
67 * xSignatureTemplate - the signature template (along with all referenced
68 * elements) to be signed.
69 ******************************************************************************/
70{
71 css::uno::Reference< css::xml::crypto::XXMLSignatureTemplate > xResultTemplate;
72 try
73 {
74 xResultTemplate = m_xXMLSignature->generate(css::uno::Reference<css::xml::crypto::XXMLSignatureTemplate>(xSignatureTemplate), m_xSecurityEnvironment);
75 m_nStatus = xResultTemplate->getStatus();
76 }
77 catch( css::uno::Exception& )
78 {
79 m_nStatus = css::xml::crypto::SecurityOperationStatus_RUNTIMEERROR_FAILED;
80 }
81
82 if (m_nStatus == css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED)
83 {
84 css::uno::Reference < css::xml::wrapper::XXMLElementWrapper > xResultSignature = xResultTemplate->getTemplate();
85 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultSignature);
86 }
87}
88
90/****** SignatureCreatorImpl/clearUp *****************************************
91 *
92 * NAME
93 * clearUp -- clear up all resources used by the signature generation.
94 *
95 * SYNOPSIS
96 * clearUp( );
97 *
98 * FUNCTION
99 * cleaning resources up includes:
100 * 1. SignatureEngine's clearing up;
101 * 2. releases the Blocker for the signature template element.
102 ******************************************************************************/
103{
105
106 if (m_nIdOfBlocker != -1)
107 {
108 m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
109 }
110}
111
112/* XBlockerMonitor */
113void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id )
114{
115 m_nIdOfBlocker = id;
116 tryToPerform();
117}
118
119/* XSignatureCreationResultBroadcaster */
121 const css::uno::Reference< css::xml::crypto::sax::XSignatureCreationResultListener >& listener )
122{
123 m_xResultListener = listener;
124 tryToPerform();
125}
126
128 const css::uno::Reference< css::xml::crypto::sax::XSignatureCreationResultListener >&)
129{
130}
131
132/* XInitialization */
133void SAL_CALL SignatureCreatorImpl::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
134{
135 OSL_ASSERT(aArguments.getLength() == 5);
136
137 OUString ouTempString;
138
139 aArguments[0] >>= ouTempString;
140 m_nSecurityId = ouTempString.toInt32();
141 aArguments[1] >>= m_xSAXEventKeeper;
142 aArguments[2] >>= ouTempString;
143 m_nIdOfTemplateEC = ouTempString.toInt32();
145 aArguments[4] >>= m_xXMLSignature;
146}
147
148
150{
151 return "com.sun.star.xml.security.framework.SignatureCreatorImpl";
152}
153
154css::uno::Sequence< OUString > SignatureCreatorImpl_getSupportedServiceNames( )
155{
156 return { "com.sun.star.xml.crypto.sax.SignatureCreator" };
157}
158
159/* XServiceInfo */
161{
163}
164
165sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const OUString& rServiceName )
166{
167 return cppu::supportsService(this, rServiceName);
168}
169
170css::uno::Sequence< OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames( )
171{
173}
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
oslInterlockedCount m_nStatus
virtual void clearUp() const override
virtual OUString SAL_CALL getImplementationName() override
void SAL_CALL addSignatureCreationResultListener(const css::uno::Reference< css::xml::crypto::sax::XSignatureCreationResultListener > &listener) override
virtual void startEngine(const rtl::Reference< XMLSignatureTemplateImpl > &xSignatureTemplate) override
virtual ~SignatureCreatorImpl() override
void SAL_CALL removeSignatureCreationResultListener(const css::uno::Reference< css::xml::crypto::sax::XSignatureCreationResultListener > &listener) override
css::uno::Reference< css::xml::crypto::XSecurityEnvironment > m_xSecurityEnvironment
virtual void SAL_CALL setBlockerId(sal_Int32 id) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void notifyResultListener() const override
virtual void clearUp() const override
Sequence< PropertyValue > aArguments
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString SignatureCreatorImpl_getImplementationName()
css::uno::Sequence< OUString > SignatureCreatorImpl_getSupportedServiceNames()
unsigned char sal_Bool