1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_xmlsecurity.hxx" 29 #include <certificatecontainer.hxx> 30 31 #include <sal/config.h> 32 33 using namespace ::com::sun::star::uno; 34 35 36 sal_Bool 37 CertificateContainer::searchMap( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name, Map &_certMap ) 38 { 39 Map::iterator p = _certMap.find(url); 40 41 ::sal_Bool ret = sal_False; 42 43 while( p != _certMap.end() ) 44 { 45 ret = (sal_Bool) (*p).second.equals(certificate_name); 46 if( ret ) 47 break; 48 p++; 49 } 50 51 return ret; 52 } 53 // ------------------------------------------------------------------- 54 55 sal_Bool 56 CertificateContainer::isTemporaryCertificate ( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name ) 57 throw(::com::sun::star::uno::RuntimeException) 58 { 59 return searchMap( url, certificate_name, certMap); 60 } 61 62 // ------------------------------------------------------------------- 63 64 sal_Bool 65 CertificateContainer::isCertificateTrust ( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name ) 66 throw(::com::sun::star::uno::RuntimeException) 67 { 68 return searchMap( url, certificate_name, certTrustMap); 69 } 70 71 // ------------------------------------------------------------------- 72 sal_Bool 73 CertificateContainer::addCertificate( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name, ::sal_Bool trust ) 74 throw(::com::sun::star::uno::RuntimeException) 75 { 76 certMap.insert( Map::value_type( url, certificate_name ) ); 77 78 //remember that the cert is trusted 79 if (trust) 80 certTrustMap.insert( Map::value_type( url, certificate_name ) ); 81 82 return true; 83 } 84 85 //------------------------------------------------------------------------- 86 ::security::CertificateContainerStatus 87 CertificateContainer::hasCertificate( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name ) throw(::com::sun::star::uno::RuntimeException) 88 { 89 if ( isTemporaryCertificate( url, certificate_name ) ) 90 { 91 if ( isCertificateTrust( url, certificate_name ) ) 92 return security::CertificateContainerStatus( security::CertificateContainerStatus_TRUSTED ); 93 else 94 return security::CertificateContainerStatus_UNTRUSTED; 95 } else 96 { 97 return security::CertificateContainerStatus_NOCERT; 98 } 99 } 100 //------------------------------------------------------------------------- 101 102 ::rtl::OUString SAL_CALL 103 CertificateContainer::getImplementationName( ) 104 throw(::com::sun::star::uno::RuntimeException) 105 { 106 return impl_getStaticImplementationName(); 107 } 108 109 //------------------------------------------------------------------------- 110 111 sal_Bool SAL_CALL 112 CertificateContainer::supportsService( const ::rtl::OUString& ServiceName ) 113 throw(::com::sun::star::uno::RuntimeException) 114 { 115 if ( ServiceName.compareToAscii("com.sun.star.security.CertificateContainer") == 0 ) 116 return sal_True; 117 else 118 return sal_False; 119 } 120 121 //------------------------------------------------------------------------- 122 123 Sequence< ::rtl::OUString > SAL_CALL 124 CertificateContainer::getSupportedServiceNames( ) 125 throw(::com::sun::star::uno::RuntimeException) 126 { 127 return impl_getStaticSupportedServiceNames(); 128 } 129 130 //------------------------------------------------------------------------- 131 132 Sequence< ::rtl::OUString > SAL_CALL 133 CertificateContainer::impl_getStaticSupportedServiceNames( ) 134 throw(::com::sun::star::uno::RuntimeException) 135 { 136 Sequence< ::rtl::OUString > aRet(1); 137 *aRet.getArray() = ::rtl::OUString::createFromAscii("com.sun.star.security.CertificateContainer"); 138 return aRet; 139 } 140 141 //------------------------------------------------------------------------- 142 143 ::rtl::OUString SAL_CALL 144 CertificateContainer::impl_getStaticImplementationName() 145 throw(::com::sun::star::uno::RuntimeException) 146 { 147 return ::rtl::OUString::createFromAscii("com.sun.star.security.CertificateContainer"); 148 } 149 150 //------------------------------------------------------------------------- 151 152 Reference< XInterface > SAL_CALL CertificateContainer::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager ) 153 throw( RuntimeException ) 154 { 155 return Reference< XInterface >( *new CertificateContainer( xServiceManager ) ); 156 } 157 158 //------------------------------------------------------------------------- 159 160 Reference< XSingleServiceFactory > SAL_CALL 161 CertificateContainer::impl_createFactory( const Reference< XMultiServiceFactory >& ServiceManager ) 162 throw(RuntimeException) 163 { 164 Reference< XSingleServiceFactory > xReturn( ::cppu::createOneInstanceFactory( ServiceManager, 165 CertificateContainer::impl_getStaticImplementationName(), 166 CertificateContainer::impl_createInstance, 167 CertificateContainer::impl_getStaticSupportedServiceNames())); 168 169 return xReturn; 170 } 171 172