1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include "securityenvironment_mscryptimpl.hxx"
23 #include "xmlsecuritycontext_mscryptimpl.hxx"
24 #include "xmlstreamio.hxx"
26 #include "xmlsecurity/xmlsec-wrapper.h"
27 #include "xmlsec/mscrypto/akmngr.h"
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
;
34 using ::com::sun::star::xml::crypto::XSecurityEnvironment
;
35 using ::com::sun::star::xml::crypto::XXMLSecurityContext
;
37 XMLSecurityContext_MSCryptImpl :: XMLSecurityContext_MSCryptImpl()
38 ://m_pKeysMngr( NULL ) ,
39 m_xSecurityEnvironment( NULL
)
42 if( xmlSecInit() < 0 ) {
43 throw RuntimeException() ;
46 //Init xmlsec crypto engine library
47 if( xmlSecCryptoInit() < 0 ) {
49 throw RuntimeException() ;
52 //Enable external stream handlers
53 if( xmlEnableStreamInputCallbacks() < 0 ) {
54 xmlSecCryptoShutdown() ;
56 throw RuntimeException() ;
60 XMLSecurityContext_MSCryptImpl :: ~XMLSecurityContext_MSCryptImpl() {
61 xmlDisableStreamInputCallbacks() ;
62 xmlSecCryptoShutdown() ;
66 sal_Int32 SAL_CALL
XMLSecurityContext_MSCryptImpl::addSecurityEnvironment(
67 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::crypto::XSecurityEnvironment
>& aSecurityEnvironment
)
68 throw (::com::sun::star::security::SecurityInfrastructureException
, ::com::sun::star::uno::RuntimeException
)
70 if( !aSecurityEnvironment
.is() )
72 throw RuntimeException() ;
75 m_xSecurityEnvironment
= aSecurityEnvironment
;
81 sal_Int32 SAL_CALL
XMLSecurityContext_MSCryptImpl::getSecurityEnvironmentNumber( )
82 throw (::com::sun::star::uno::RuntimeException
)
87 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::crypto::XSecurityEnvironment
> SAL_CALL
88 XMLSecurityContext_MSCryptImpl::getSecurityEnvironmentByIndex( sal_Int32 index
)
89 throw (::com::sun::star::uno::RuntimeException
)
93 return m_xSecurityEnvironment
;
96 throw RuntimeException() ;
99 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::crypto::XSecurityEnvironment
> SAL_CALL
100 XMLSecurityContext_MSCryptImpl::getSecurityEnvironment( )
101 throw (::com::sun::star::uno::RuntimeException
)
103 return m_xSecurityEnvironment
;
106 sal_Int32 SAL_CALL
XMLSecurityContext_MSCryptImpl::getDefaultSecurityEnvironmentIndex( )
107 throw (::com::sun::star::uno::RuntimeException
)
112 void SAL_CALL
XMLSecurityContext_MSCryptImpl::setDefaultSecurityEnvironmentIndex( sal_Int32
/*nDefaultEnvIndex*/ )
113 throw (::com::sun::star::uno::RuntimeException
)
119 OUString SAL_CALL
XMLSecurityContext_MSCryptImpl :: getImplementationName() throw( RuntimeException
) {
120 return impl_getImplementationName() ;
124 sal_Bool SAL_CALL
XMLSecurityContext_MSCryptImpl :: supportsService( const OUString
& serviceName
) throw( RuntimeException
) {
125 Sequence
< OUString
> seqServiceNames
= getSupportedServiceNames() ;
126 const OUString
* pArray
= seqServiceNames
.getConstArray() ;
127 for( sal_Int32 i
= 0 ; i
< seqServiceNames
.getLength() ; i
++ ) {
128 if( *( pArray
+ i
) == serviceName
)
135 Sequence
< OUString
> SAL_CALL
XMLSecurityContext_MSCryptImpl :: getSupportedServiceNames() throw( RuntimeException
) {
136 return impl_getSupportedServiceNames() ;
139 //Helper for XServiceInfo
140 Sequence
< OUString
> XMLSecurityContext_MSCryptImpl :: impl_getSupportedServiceNames() {
141 ::osl::Guard
< ::osl::Mutex
> aGuard( ::osl::Mutex::getGlobalMutex() ) ;
142 Sequence
< OUString
> seqServiceNames( 1 ) ;
143 seqServiceNames
[0] = "com.sun.star.xml.crypto.XMLSecurityContext";
144 return seqServiceNames
;
147 OUString
XMLSecurityContext_MSCryptImpl :: impl_getImplementationName() throw( RuntimeException
) {
148 return OUString("com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_MSCryptImpl") ;
151 //Helper for registry
152 Reference
< XInterface
> SAL_CALL
XMLSecurityContext_MSCryptImpl :: impl_createInstance( const Reference
< XMultiServiceFactory
>& ) throw( RuntimeException
) {
153 return Reference
< XInterface
>( *new XMLSecurityContext_MSCryptImpl
) ;
156 Reference
< XSingleServiceFactory
> XMLSecurityContext_MSCryptImpl :: impl_createFactory( const Reference
< XMultiServiceFactory
>& aServiceManager
) {
157 //Reference< XSingleServiceFactory > xFactory ;
158 //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
160 return ::cppu::createSingleFactory( aServiceManager
, impl_getImplementationName() , impl_createInstance
, impl_getSupportedServiceNames() ) ;
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */