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 <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
22 #include "securityenvironment_mscryptimpl.hxx"
23 
24 #include <xmlsec/xmlstreamio.hxx>
25 #include "akmngr.hxx"
26 
27 #include <xmlsec-wrapper.h>
28 
29 using namespace ::com::sun::star;
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 class XMLSecurityContext_MSCryptImpl : public ::cppu::WeakImplHelper<
38     css::xml::crypto::XXMLSecurityContext ,
39     css::lang::XServiceInfo >
40 {
41     private:
42         //xmlSecKeysMngrPtr m_pKeysMngr ;
43         css::uno::Reference< css::xml::crypto::XSecurityEnvironment > m_xSecurityEnvironment ;
44 
45     public:
46         XMLSecurityContext_MSCryptImpl();
47 
48         //Methods from XXMLSecurityContext
49         virtual sal_Int32 SAL_CALL addSecurityEnvironment(
50             const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment
51             ) override;
52 
53         virtual ::sal_Int32 SAL_CALL getSecurityEnvironmentNumber(  ) override;
54 
55         virtual css::uno::Reference<
56             css::xml::crypto::XSecurityEnvironment > SAL_CALL
57             getSecurityEnvironmentByIndex( ::sal_Int32 index ) override;
58 
59         virtual css::uno::Reference<
60             css::xml::crypto::XSecurityEnvironment > SAL_CALL
61             getSecurityEnvironment(  ) override;
62 
63         virtual ::sal_Int32 SAL_CALL getDefaultSecurityEnvironmentIndex(  ) override;
64 
65         virtual void SAL_CALL setDefaultSecurityEnvironmentIndex( sal_Int32 nDefaultEnvIndex ) override;
66 
67 
68         //Methods from XServiceInfo
69         virtual OUString SAL_CALL getImplementationName() override;
70 
71         virtual sal_Bool SAL_CALL supportsService(
72             const OUString& ServiceName
73         ) override;
74 
75         virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
76 };
77 
XMLSecurityContext_MSCryptImpl()78 XMLSecurityContext_MSCryptImpl::XMLSecurityContext_MSCryptImpl()
79 {
80 }
81 
addSecurityEnvironment(const css::uno::Reference<css::xml::crypto::XSecurityEnvironment> & aSecurityEnvironment)82 sal_Int32 SAL_CALL XMLSecurityContext_MSCryptImpl::addSecurityEnvironment(
83     const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment)
84 {
85     if( !aSecurityEnvironment.is() )
86     {
87         throw uno::RuntimeException() ;
88     }
89 
90     m_xSecurityEnvironment = aSecurityEnvironment;
91 
92     return 0;
93 }
94 
95 
getSecurityEnvironmentNumber()96 sal_Int32 SAL_CALL XMLSecurityContext_MSCryptImpl::getSecurityEnvironmentNumber(  )
97 {
98     return 1;
99 }
100 
101 css::uno::Reference< css::xml::crypto::XSecurityEnvironment > SAL_CALL
getSecurityEnvironmentByIndex(sal_Int32 index)102     XMLSecurityContext_MSCryptImpl::getSecurityEnvironmentByIndex( sal_Int32 index )
103 {
104     if (index != 0)
105     {
106         throw uno::RuntimeException() ;
107     }
108     return m_xSecurityEnvironment;
109 }
110 
111 css::uno::Reference< css::xml::crypto::XSecurityEnvironment > SAL_CALL
getSecurityEnvironment()112     XMLSecurityContext_MSCryptImpl::getSecurityEnvironment(  )
113 {
114     return m_xSecurityEnvironment;
115 }
116 
getDefaultSecurityEnvironmentIndex()117 sal_Int32 SAL_CALL XMLSecurityContext_MSCryptImpl::getDefaultSecurityEnvironmentIndex(  )
118 {
119     return 0;
120 }
121 
setDefaultSecurityEnvironmentIndex(sal_Int32)122 void SAL_CALL XMLSecurityContext_MSCryptImpl::setDefaultSecurityEnvironmentIndex( sal_Int32 /*nDefaultEnvIndex*/ )
123 {
124     //dummy
125 }
126 
127 /* XServiceInfo */
getImplementationName()128 OUString SAL_CALL XMLSecurityContext_MSCryptImpl::getImplementationName() {
129     return "com.sun.star.xml.crypto.XMLSecurityContext" ;
130 }
131 
132 /* XServiceInfo */
supportsService(const OUString & serviceName)133 sal_Bool SAL_CALL XMLSecurityContext_MSCryptImpl::supportsService( const OUString& serviceName) {
134     uno::Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
135     const OUString* pArray = seqServiceNames.getConstArray() ;
136     for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
137         if( *( pArray + i ) == serviceName )
138             return true ;
139     }
140     return false ;
141 }
142 
143 /* XServiceInfo */
getSupportedServiceNames()144 uno::Sequence< OUString > SAL_CALL XMLSecurityContext_MSCryptImpl::getSupportedServiceNames() {
145     uno::Sequence<OUString> seqServiceNames { "com.sun.star.xml.crypto.XMLSecurityContext" };
146     return seqServiceNames ;
147 }
148 
149 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_xml_crypto_XMLSecurityContext_get_implementation(uno::XComponentContext *,uno::Sequence<uno::Any> const &)150 com_sun_star_xml_crypto_XMLSecurityContext_get_implementation(
151     uno::XComponentContext* /*pCtx*/, uno::Sequence<uno::Any> const& /*rSeq*/)
152 {
153     return cppu::acquire(new XMLSecurityContext_MSCryptImpl);
154 }
155 
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
157