Line data Source code
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 "decryptorimpl.hxx"
22 : #include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
23 : #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
24 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 : #include <comphelper/processfactory.hxx>
26 : #include <cppuhelper/supportsservice.hxx>
27 : #include <osl/diagnose.h>
28 :
29 : using namespace com::sun::star::uno;
30 : namespace cssu = com::sun::star::uno;
31 : namespace cssl = com::sun::star::lang;
32 : namespace cssxc = com::sun::star::xml::crypto;
33 : namespace cssxw = com::sun::star::xml::wrapper;
34 :
35 : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl"
36 :
37 1 : DecryptorImpl::DecryptorImpl(const Reference< XComponentContext > & xContext) : DecryptorImpl_Base(xContext)
38 : {
39 1 : }
40 :
41 2 : DecryptorImpl::~DecryptorImpl()
42 : {
43 2 : }
44 :
45 0 : bool DecryptorImpl::checkReady() const
46 : /****** DecryptorImpl/checkReady *********************************************
47 : *
48 : * NAME
49 : * checkReady -- checks the conditions for the decryption.
50 : *
51 : * SYNOPSIS
52 : * bReady = checkReady( );
53 : *
54 : * FUNCTION
55 : * checks whether all following conditions are satisfied:
56 : * 1. the result listener is ready;
57 : * 2. the EncryptionEngine is ready.
58 : *
59 : * INPUTS
60 : * empty
61 : *
62 : * RESULT
63 : * bReady - true if all conditions are satisfied, false otherwise
64 : *
65 : * AUTHOR
66 : * Michael Mi
67 : * Email: michael.mi@sun.com
68 : ******************************************************************************/
69 : {
70 0 : return (m_xResultListener.is() && EncryptionEngine::checkReady());
71 : }
72 :
73 0 : void DecryptorImpl::notifyResultListener() const
74 : throw (cssu::Exception, cssu::RuntimeException)
75 : /****** DecryptorImpl/notifyResultListener ***********************************
76 : *
77 : * NAME
78 : * notifyResultListener -- notifies the listener about the decryption
79 : * result.
80 : *
81 : * SYNOPSIS
82 : * notifyResultListener( );
83 : *
84 : * FUNCTION
85 : * see NAME.
86 : *
87 : * INPUTS
88 : * empty
89 : *
90 : * RESULT
91 : * empty
92 : *
93 : * AUTHOR
94 : * Michael Mi
95 : * Email: michael.mi@sun.com
96 : ******************************************************************************/
97 : {
98 : cssu::Reference< cssxc::sax::XDecryptionResultListener >
99 0 : xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
100 :
101 0 : xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus);
102 0 : }
103 :
104 0 : void DecryptorImpl::startEngine( const cssu::Reference<
105 : cssxc::XXMLEncryptionTemplate >&
106 : xEncryptionTemplate)
107 : throw (cssu::Exception, cssu::RuntimeException)
108 : /****** DecryptorImpl/startEngine ********************************************
109 : *
110 : * NAME
111 : * startEngine -- decrypts the encryption.
112 : *
113 : * SYNOPSIS
114 : * startEngine( xEncryptionTemplate );
115 : *
116 : * FUNCTION
117 : * decrypts the encryption element, then if succeeds, updates the link
118 : * of old template element to the new encryption element in
119 : * SAXEventKeeper.
120 : *
121 : * INPUTS
122 : * xEncryptionTemplate - the encryption template to be decrypted.
123 : *
124 : * RESULT
125 : * empty
126 : *
127 : * AUTHOR
128 : * Michael Mi
129 : * Email: michael.mi@sun.com
130 : ******************************************************************************/
131 : {
132 0 : cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate;
133 : try
134 : {
135 0 : xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext);
136 0 : m_nStatus = xResultTemplate->getStatus();
137 : }
138 0 : catch( cssu::Exception& )
139 : {
140 0 : m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
141 : }
142 :
143 0 : if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
144 : {
145 : cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement
146 0 : = xResultTemplate->getTemplate();
147 0 : m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement);
148 0 : }
149 0 : }
150 :
151 : /* XDecryptionResultBroadcaster */
152 0 : void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
153 : throw (cssu::Exception, cssu::RuntimeException, std::exception)
154 : {
155 0 : m_xResultListener = listener;
156 0 : tryToPerform();
157 0 : }
158 :
159 0 : void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >&)
160 : throw (cssu::RuntimeException, std::exception)
161 : {
162 0 : }
163 :
164 : /* XInitialization */
165 0 : void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
166 : throw (cssu::Exception, cssu::RuntimeException, std::exception)
167 : {
168 : OSL_ASSERT(aArguments.getLength() == 5);
169 :
170 0 : OUString ouTempString;
171 :
172 0 : aArguments[0] >>= ouTempString;
173 0 : m_nSecurityId = ouTempString.toInt32();
174 0 : aArguments[1] >>= m_xSAXEventKeeper;
175 0 : aArguments[2] >>= ouTempString;
176 0 : m_nIdOfTemplateEC = ouTempString.toInt32();
177 0 : aArguments[3] >>= m_xXMLSecurityContext;
178 0 : aArguments[4] >>= m_xXMLEncryption;
179 0 : }
180 :
181 8 : OUString DecryptorImpl_getImplementationName ()
182 : throw (cssu::RuntimeException)
183 : {
184 8 : return OUString ( IMPLEMENTATION_NAME );
185 : }
186 :
187 2 : cssu::Sequence< OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames( )
188 : throw (cssu::RuntimeException)
189 : {
190 2 : cssu::Sequence < OUString > aRet(1);
191 2 : OUString* pArray = aRet.getArray();
192 2 : pArray[0] = "com.sun.star.xml.crypto.sax.Decryptor";
193 2 : return aRet;
194 : }
195 :
196 1 : cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& xMSF)
197 : throw( cssu::Exception )
198 : {
199 1 : return static_cast<cppu::OWeakObject*>(new DecryptorImpl( comphelper::getComponentContext( xMSF ) ));
200 : }
201 :
202 : /* XServiceInfo */
203 1 : OUString SAL_CALL DecryptorImpl::getImplementationName( )
204 : throw (cssu::RuntimeException, std::exception)
205 : {
206 1 : return DecryptorImpl_getImplementationName();
207 : }
208 :
209 0 : sal_Bool SAL_CALL DecryptorImpl::supportsService( const OUString& rServiceName )
210 : throw (cssu::RuntimeException, std::exception)
211 : {
212 0 : return cppu::supportsService(this, rServiceName);
213 : }
214 :
215 1 : cssu::Sequence< OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames( )
216 : throw (cssu::RuntimeException, std::exception)
217 : {
218 1 : return DecryptorImpl_getSupportedServiceNames();
219 : }
220 :
221 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|