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 : #include <sal/config.h>
21 : #include <rtl/uuid.h>
22 : #include "securityenvironment_nssimpl.hxx"
23 :
24 : #include "xmlsecuritycontext_nssimpl.hxx"
25 : #include "xmlstreamio.hxx"
26 :
27 : #include "xmlsecurity/xmlsec-wrapper.h"
28 :
29 : using namespace ::com::sun::star::uno ;
30 : using namespace ::com::sun::star::lang ;
31 : using ::com::sun::star::lang::XMultiServiceFactory ;
32 : using ::com::sun::star::lang::XSingleServiceFactory ;
33 :
34 : using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
35 : using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
36 :
37 0 : XMLSecurityContext_NssImpl :: XMLSecurityContext_NssImpl()
38 : ://i39448 : m_pKeysMngr( NULL ) ,
39 0 : m_nDefaultEnvIndex(-1)
40 : //m_xSecurityEnvironment( NULL )
41 : {
42 : //Init xmlsec library
43 0 : if( xmlSecInit() < 0 ) {
44 0 : throw RuntimeException() ;
45 : }
46 :
47 : //Init xmlsec crypto engine library
48 0 : if( xmlSecCryptoInit() < 0 ) {
49 0 : xmlSecShutdown() ;
50 0 : throw RuntimeException() ;
51 : }
52 :
53 : //Enable external stream handlers
54 0 : if( xmlEnableStreamInputCallbacks() < 0 ) {
55 0 : xmlSecCryptoShutdown() ;
56 0 : xmlSecShutdown() ;
57 0 : throw RuntimeException() ;
58 : }
59 0 : }
60 :
61 0 : XMLSecurityContext_NssImpl :: ~XMLSecurityContext_NssImpl() {
62 : //i39448
63 :
64 0 : xmlDisableStreamInputCallbacks() ;
65 0 : xmlSecCryptoShutdown() ;
66 0 : xmlSecShutdown() ;
67 0 : }
68 :
69 : //i39448 : new methods
70 0 : sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::addSecurityEnvironment(
71 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment)
72 : throw (::com::sun::star::security::SecurityInfrastructureException, ::com::sun::star::uno::RuntimeException, std::exception)
73 : {
74 0 : if( !aSecurityEnvironment.is() )
75 : {
76 0 : throw RuntimeException() ;
77 : }
78 :
79 0 : m_vSecurityEnvironments.push_back( aSecurityEnvironment );
80 :
81 0 : return m_vSecurityEnvironments.size() - 1 ;
82 : }
83 :
84 :
85 0 : sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironmentNumber( )
86 : throw (::com::sun::star::uno::RuntimeException, std::exception)
87 : {
88 0 : return m_vSecurityEnvironments.size();
89 : }
90 :
91 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
92 0 : XMLSecurityContext_NssImpl::getSecurityEnvironmentByIndex( sal_Int32 index )
93 : throw (::com::sun::star::uno::RuntimeException, std::exception)
94 : {
95 0 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecurityEnvironment;
96 :
97 0 : if (index >= 0 && index < ( sal_Int32 )m_vSecurityEnvironments.size())
98 : {
99 0 : xSecurityEnvironment = m_vSecurityEnvironments[index];
100 : }
101 : else
102 0 : throw RuntimeException() ;
103 :
104 0 : return xSecurityEnvironment;
105 : }
106 :
107 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL
108 0 : XMLSecurityContext_NssImpl::getSecurityEnvironment( )
109 : throw (::com::sun::star::uno::RuntimeException, std::exception)
110 : {
111 0 : if (m_nDefaultEnvIndex >= 0 && m_nDefaultEnvIndex < ( sal_Int32 )m_vSecurityEnvironments.size())
112 0 : return getSecurityEnvironmentByIndex(m_nDefaultEnvIndex);
113 : else
114 0 : throw RuntimeException() ;
115 : }
116 :
117 0 : sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getDefaultSecurityEnvironmentIndex( )
118 : throw (::com::sun::star::uno::RuntimeException, std::exception)
119 : {
120 0 : return m_nDefaultEnvIndex ;
121 : }
122 :
123 0 : void SAL_CALL XMLSecurityContext_NssImpl::setDefaultSecurityEnvironmentIndex( sal_Int32 nDefaultEnvIndex )
124 : throw (::com::sun::star::uno::RuntimeException, std::exception)
125 : {
126 0 : m_nDefaultEnvIndex = nDefaultEnvIndex;
127 0 : }
128 :
129 : //i39448 : old methods deleted
130 :
131 :
132 : /* XServiceInfo */
133 0 : OUString SAL_CALL XMLSecurityContext_NssImpl :: getImplementationName() throw( RuntimeException, std::exception ) {
134 0 : return impl_getImplementationName() ;
135 : }
136 :
137 : /* XServiceInfo */
138 0 : sal_Bool SAL_CALL XMLSecurityContext_NssImpl :: supportsService( const OUString& serviceName) throw( RuntimeException, std::exception ) {
139 0 : Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
140 0 : const OUString* pArray = seqServiceNames.getConstArray() ;
141 0 : for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
142 0 : if( *( pArray + i ) == serviceName )
143 0 : return sal_True ;
144 : }
145 0 : return sal_False ;
146 : }
147 :
148 : /* XServiceInfo */
149 0 : Sequence< OUString > SAL_CALL XMLSecurityContext_NssImpl :: getSupportedServiceNames() throw( RuntimeException, std::exception ) {
150 0 : return impl_getSupportedServiceNames() ;
151 : }
152 :
153 : //Helper for XServiceInfo
154 0 : Sequence< OUString > XMLSecurityContext_NssImpl :: impl_getSupportedServiceNames() {
155 0 : ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
156 0 : Sequence< OUString > seqServiceNames( 1 ) ;
157 0 : seqServiceNames[0] = "com.sun.star.xml.crypto.XMLSecurityContext";
158 0 : return seqServiceNames ;
159 : }
160 :
161 0 : OUString XMLSecurityContext_NssImpl :: impl_getImplementationName() throw( RuntimeException ) {
162 0 : return OUString("com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_NssImpl") ;
163 : }
164 :
165 : //Helper for registry
166 0 : Reference< XInterface > SAL_CALL XMLSecurityContext_NssImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& ) throw( RuntimeException ) {
167 0 : return Reference< XInterface >( *new XMLSecurityContext_NssImpl ) ;
168 : }
169 :
170 0 : Reference< XSingleServiceFactory > XMLSecurityContext_NssImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
171 : //Reference< XSingleServiceFactory > xFactory ;
172 : //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
173 : //return xFactory ;
174 0 : return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
175 : }
176 :
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|