1*ec61c6edSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ec61c6edSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ec61c6edSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ec61c6edSAndrew Rist * distributed with this work for additional information 6*ec61c6edSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ec61c6edSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ec61c6edSAndrew Rist * "License"); you may not use this file except in compliance 9*ec61c6edSAndrew Rist * with the License. You may obtain a copy of the License at 10*ec61c6edSAndrew Rist * 11*ec61c6edSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ec61c6edSAndrew Rist * 13*ec61c6edSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ec61c6edSAndrew Rist * software distributed under the License is distributed on an 15*ec61c6edSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ec61c6edSAndrew Rist * KIND, either express or implied. See the License for the 17*ec61c6edSAndrew Rist * specific language governing permissions and limitations 18*ec61c6edSAndrew Rist * under the License. 19*ec61c6edSAndrew Rist * 20*ec61c6edSAndrew Rist *************************************************************/ 21*ec61c6edSAndrew Rist 22*ec61c6edSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _XSECURITYENVIRONMENT_NSSIMPL_HXX_ 25cdf0e10cSrcweir #define _XSECURITYENVIRONMENT_NSSIMPL_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <sal/config.h> 28cdf0e10cSrcweir #include <rtl/ustring.hxx> 29cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 30cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx> 31cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_ 34cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_ 39cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 40cdf0e10cSrcweir #endif 41cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 42cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> 43cdf0e10cSrcweir #include <com/sun/star/security/XCertificate.hpp> 44cdf0e10cSrcweir #include <com/sun/star/security/CertificateCharacters.hpp> 45cdf0e10cSrcweir #include <com/sun/star/security/CertificateValidity.hpp> 46cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp> 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include "osl/mutex.hxx" 49cdf0e10cSrcweir 50cdf0e10cSrcweir #include "pk11func.h" 51cdf0e10cSrcweir #include "keyhi.h" 52cdf0e10cSrcweir #include "certdb.h" 53cdf0e10cSrcweir #include "list" 54cdf0e10cSrcweir 55cdf0e10cSrcweir #include <sal/types.h> 56cdf0e10cSrcweir //For reasons that escape me, this is what xmlsec does when size_t is not 4 57cdf0e10cSrcweir #if SAL_TYPES_SIZEOFPOINTER != 4 58cdf0e10cSrcweir # define XMLSEC_NO_SIZE_T 59cdf0e10cSrcweir #endif 60cdf0e10cSrcweir #include "xmlsec/xmlsec.h" 61cdf0e10cSrcweir 62cdf0e10cSrcweir class SecurityEnvironment_NssImpl : public ::cppu::WeakImplHelper4< 63cdf0e10cSrcweir ::com::sun::star::xml::crypto::XSecurityEnvironment , 64cdf0e10cSrcweir ::com::sun::star::lang::XInitialization , 65cdf0e10cSrcweir ::com::sun::star::lang::XServiceInfo , 66cdf0e10cSrcweir ::com::sun::star::lang::XUnoTunnel > 67cdf0e10cSrcweir { 68cdf0e10cSrcweir private : 69cdf0e10cSrcweir 70cdf0e10cSrcweir std::list< PK11SlotInfo* > m_Slots; 71cdf0e10cSrcweir typedef std::list< PK11SlotInfo* >::const_iterator CIT_SLOTS; 72cdf0e10cSrcweir 73cdf0e10cSrcweir osl::Mutex m_mutex; 74cdf0e10cSrcweir 75cdf0e10cSrcweir CERTCertDBHandle* m_pHandler ; 76cdf0e10cSrcweir std::list< PK11SymKey* > m_tSymKeyList ; 77cdf0e10cSrcweir std::list< SECKEYPublicKey* > m_tPubKeyList ; 78cdf0e10cSrcweir std::list< SECKEYPrivateKey* > m_tPriKeyList ; 79cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ; 80cdf0e10cSrcweir 81cdf0e10cSrcweir public : 82cdf0e10cSrcweir SecurityEnvironment_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ; 83cdf0e10cSrcweir virtual ~SecurityEnvironment_NssImpl() ; 84cdf0e10cSrcweir 85cdf0e10cSrcweir //Methods from XSecurityEnvironment 86cdf0e10cSrcweir 87cdf0e10cSrcweir //Methods from XInitialization 88cdf0e10cSrcweir virtual void SAL_CALL initialize( 89cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments 90cdf0e10cSrcweir ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 91cdf0e10cSrcweir 92cdf0e10cSrcweir //Methods from XServiceInfo 93cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ; 94cdf0e10cSrcweir 95cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( 96cdf0e10cSrcweir const ::rtl::OUString& ServiceName 97cdf0e10cSrcweir ) throw( ::com::sun::star::uno::RuntimeException ) ; 98cdf0e10cSrcweir 99cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) ; 100cdf0e10cSrcweir 101cdf0e10cSrcweir //Helper for XServiceInfo 102cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ; 103cdf0e10cSrcweir 104cdf0e10cSrcweir static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ; 105cdf0e10cSrcweir 106cdf0e10cSrcweir //Helper for registry 107cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL impl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) throw( ::com::sun::star::uno::RuntimeException ) ; 108cdf0e10cSrcweir 109cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > impl_createFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) ; 110cdf0e10cSrcweir 111cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL verifyCertificate( 112cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 113cdf0e10cSrcweir ::com::sun::star::security::XCertificate >& xCert, 114cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< 115cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > & 116cdf0e10cSrcweir intermediateCerts) 117cdf0e10cSrcweir throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ; 118cdf0e10cSrcweir 119cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCertificateCharacters( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& xCert ) throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ; 120cdf0e10cSrcweir 121cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getSecurityEnvironmentInformation( ) throw (::com::sun::star::uno::RuntimeException); 122cdf0e10cSrcweir 123cdf0e10cSrcweir //Methods from XUnoTunnel 124cdf0e10cSrcweir virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) 125cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 126cdf0e10cSrcweir 127cdf0e10cSrcweir static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ; 128cdf0e10cSrcweir static SecurityEnvironment_NssImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ; 129cdf0e10cSrcweir 130cdf0e10cSrcweir //Native mehtods 131cdf0e10cSrcweir virtual CERTCertDBHandle* getCertDb() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 132cdf0e10cSrcweir 133cdf0e10cSrcweir virtual void setCertDb( CERTCertDBHandle* aCertDb ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 134cdf0e10cSrcweir 135cdf0e10cSrcweir virtual void adoptSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 136cdf0e10cSrcweir 137cdf0e10cSrcweir virtual void rejectSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 138cdf0e10cSrcweir 139cdf0e10cSrcweir virtual PK11SymKey* getSymKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 140cdf0e10cSrcweir 141cdf0e10cSrcweir virtual void adoptPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 142cdf0e10cSrcweir 143cdf0e10cSrcweir virtual void rejectPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 144cdf0e10cSrcweir 145cdf0e10cSrcweir virtual SECKEYPublicKey* getPubKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 146cdf0e10cSrcweir 147cdf0e10cSrcweir virtual void adoptPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 148cdf0e10cSrcweir 149cdf0e10cSrcweir virtual void rejectPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 150cdf0e10cSrcweir 151cdf0e10cSrcweir virtual SECKEYPrivateKey* getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 152cdf0e10cSrcweir 153cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > SAL_CALL getPersonalCertificates() throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ; 154cdf0e10cSrcweir 155cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL getCertificate( const ::rtl::OUString& issuerName, const ::com::sun::star::uno::Sequence< sal_Int8 >& serialNumber ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ; 156cdf0e10cSrcweir 157cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL getCertificate( const ::rtl::OUString& issuerName, const ::rtl::OUString& serialNumber ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ; 158cdf0e10cSrcweir 159cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > SAL_CALL buildCertificatePath( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& beginCert ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ; 160cdf0e10cSrcweir 161cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL createCertificateFromRaw( const ::com::sun::star::uno::Sequence< sal_Int8 >& rawCertificate ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ; 162cdf0e10cSrcweir 163cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL createCertificateFromAscii( const ::rtl::OUString& asciiCertificate ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ; 164cdf0e10cSrcweir 165cdf0e10cSrcweir 166cdf0e10cSrcweir //Native mehtods 167cdf0e10cSrcweir virtual xmlSecKeysMngrPtr createKeysManager() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 168cdf0e10cSrcweir virtual void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 169cdf0e10cSrcweir 170cdf0e10cSrcweir private: 171cdf0e10cSrcweir void updateSlots(); 172cdf0e10cSrcweir 173cdf0e10cSrcweir virtual void addCryptoSlot( PK11SlotInfo* aSlot ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ; 174cdf0e10cSrcweir 175cdf0e10cSrcweir 176cdf0e10cSrcweir } ; 177cdf0e10cSrcweir 178cdf0e10cSrcweir #endif // _XSECURITYENVIRONMENT_NSSIMPL_HXX_ 179cdf0e10cSrcweir 180