| 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 |
|
| 21 |
#include <framework/signaturecreatorimpl.hxx> |
| 22 |
#include <framework/xmlsignaturetemplateimpl.hxx> |
| 23 |
#include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp> |
| 24 |
#include <cppuhelper/supportsservice.hxx> |
| 25 |
#include <osl/diagnose.h> |
| 26 |
#include <rtl/ref.hxx> |
| 27 |
|
| 28 |
namespace com::sun::star::xml::wrapper { class XXMLElementWrapper; } |
| 29 |
|
| 30 |
using namespace com::sun::star::uno; |
| 31 |
|
| 32 |
SignatureCreatorImpl::SignatureCreatorImpl() |
| 33 |
: m_nIdOfBlocker(-1) |
| 34 |
{ |
| 35 |
} |
| 36 |
|
| 37 |
SignatureCreatorImpl::~SignatureCreatorImpl( ) |
| 38 |
{ |
| 39 |
} |
| 40 |
|
| 41 |
void SignatureCreatorImpl::notifyResultListener() const |
| 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 |
|
| 55 |
void SignatureCreatorImpl::startEngine(const rtl::Reference<XMLSignatureTemplateImpl>& xSignatureTemplate) |
| 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 |
|
| 89 |
void SignatureCreatorImpl::clearUp() const |
| 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 |
{ |
| 104 |
SignatureEngine::clearUp(); |
| 105 |
|
| 106 |
if (m_nIdOfBlocker != -1) |
| 107 |
{ |
| 108 |
m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
/* XBlockerMonitor */ |
| 113 |
void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id ) |
| 114 |
{ |
| 115 |
m_nIdOfBlocker = id; |
| 116 |
tryToPerform(); |
| 117 |
} |
| 118 |
|
| 119 |
/* XSignatureCreationResultBroadcaster */ |
| 120 |
void SAL_CALL SignatureCreatorImpl::addSignatureCreationResultListener( |
| 121 |
const css::uno::Reference< css::xml::crypto::sax::XSignatureCreationResultListener >& listener ) |
| 122 |
{ |
| 123 |
m_xResultListener = listener; |
| 124 |
tryToPerform(); |
| 125 |
} |
| 126 |
|
| 127 |
void SAL_CALL SignatureCreatorImpl::removeSignatureCreationResultListener( |
| 128 |
const css::uno::Reference< css::xml::crypto::sax::XSignatureCreationResultListener >&) |
| 129 |
{ |
| 130 |
} |
| 131 |
|
| 132 |
/* XInitialization */ |
| 133 |
void 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(); |
| 144 |
aArguments[3] >>= m_xSecurityEnvironment; |
| 145 |
aArguments[4] >>= m_xXMLSignature; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
OUString SignatureCreatorImpl_getImplementationName () |
| 150 |
{ |
| 151 |
return u"com.sun.star.xml.security.framework.SignatureCreatorImpl"_ustr; |
| 152 |
} |
| 153 |
|
| 154 |
css::uno::Sequence< OUString > SignatureCreatorImpl_getSupportedServiceNames( ) |
| 155 |
{ |
| 156 |
return { u"com.sun.star.xml.crypto.sax.SignatureCreator"_ustr }; |
| 157 |
} |
| 158 |
|
| 159 |
/* XServiceInfo */ |
| 160 |
OUString SAL_CALL SignatureCreatorImpl::getImplementationName( ) |
| 161 |
{ |
| 162 |
return SignatureCreatorImpl_getImplementationName(); |
| 163 |
} |
| 164 |
|
| 165 |
sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const OUString& rServiceName ) |
| 166 |
{ |
| 167 |
return cppu::supportsService(this, rServiceName); |
| 168 |
} |
| 169 |
|
| 170 |
css::uno::Sequence< OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames( ) |
| 171 |
{ |
| 172 |
return SignatureCreatorImpl_getSupportedServiceNames(); |
| 173 |
} |
| 174 |
|
| 175 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |