1*06b3ce53SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*06b3ce53SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*06b3ce53SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*06b3ce53SAndrew Rist * distributed with this work for additional information 6*06b3ce53SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*06b3ce53SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*06b3ce53SAndrew Rist * "License"); you may not use this file except in compliance 9*06b3ce53SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*06b3ce53SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*06b3ce53SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*06b3ce53SAndrew Rist * software distributed under the License is distributed on an 15*06b3ce53SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*06b3ce53SAndrew Rist * KIND, either express or implied. See the License for the 17*06b3ce53SAndrew Rist * specific language governing permissions and limitations 18*06b3ce53SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*06b3ce53SAndrew Rist *************************************************************/ 21*06b3ce53SAndrew Rist 22*06b3ce53SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx" 25cdf0e10cSrcweir #include <certificatecontainer.hxx> 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <sal/config.h> 28cdf0e10cSrcweir 29cdf0e10cSrcweir using namespace ::com::sun::star::uno; 30cdf0e10cSrcweir 31cdf0e10cSrcweir 32cdf0e10cSrcweir sal_Bool 33cdf0e10cSrcweir CertificateContainer::searchMap( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name, Map &_certMap ) 34cdf0e10cSrcweir { 35cdf0e10cSrcweir Map::iterator p = _certMap.find(url); 36cdf0e10cSrcweir 37cdf0e10cSrcweir ::sal_Bool ret = sal_False; 38cdf0e10cSrcweir 39cdf0e10cSrcweir while( p != _certMap.end() ) 40cdf0e10cSrcweir { 41cdf0e10cSrcweir ret = (sal_Bool) (*p).second.equals(certificate_name); 42cdf0e10cSrcweir if( ret ) 43cdf0e10cSrcweir break; 44cdf0e10cSrcweir p++; 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir return ret; 48cdf0e10cSrcweir } 49cdf0e10cSrcweir // ------------------------------------------------------------------- 50cdf0e10cSrcweir 51cdf0e10cSrcweir sal_Bool 52cdf0e10cSrcweir CertificateContainer::isTemporaryCertificate ( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name ) 53cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir return searchMap( url, certificate_name, certMap); 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir // ------------------------------------------------------------------- 59cdf0e10cSrcweir 60cdf0e10cSrcweir sal_Bool 61cdf0e10cSrcweir CertificateContainer::isCertificateTrust ( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name ) 62cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir return searchMap( url, certificate_name, certTrustMap); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir // ------------------------------------------------------------------- 68cdf0e10cSrcweir sal_Bool 69cdf0e10cSrcweir CertificateContainer::addCertificate( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name, ::sal_Bool trust ) 70cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir certMap.insert( Map::value_type( url, certificate_name ) ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir //remember that the cert is trusted 75cdf0e10cSrcweir if (trust) 76cdf0e10cSrcweir certTrustMap.insert( Map::value_type( url, certificate_name ) ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir return true; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir //------------------------------------------------------------------------- 82cdf0e10cSrcweir ::security::CertificateContainerStatus 83cdf0e10cSrcweir CertificateContainer::hasCertificate( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name ) throw(::com::sun::star::uno::RuntimeException) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir if ( isTemporaryCertificate( url, certificate_name ) ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir if ( isCertificateTrust( url, certificate_name ) ) 88cdf0e10cSrcweir return security::CertificateContainerStatus( security::CertificateContainerStatus_TRUSTED ); 89cdf0e10cSrcweir else 90cdf0e10cSrcweir return security::CertificateContainerStatus_UNTRUSTED; 91cdf0e10cSrcweir } else 92cdf0e10cSrcweir { 93cdf0e10cSrcweir return security::CertificateContainerStatus_NOCERT; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir } 96cdf0e10cSrcweir //------------------------------------------------------------------------- 97cdf0e10cSrcweir 98cdf0e10cSrcweir ::rtl::OUString SAL_CALL 99cdf0e10cSrcweir CertificateContainer::getImplementationName( ) 100cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir return impl_getStaticImplementationName(); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir //------------------------------------------------------------------------- 106cdf0e10cSrcweir 107cdf0e10cSrcweir sal_Bool SAL_CALL 108cdf0e10cSrcweir CertificateContainer::supportsService( const ::rtl::OUString& ServiceName ) 109cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir if ( ServiceName.compareToAscii("com.sun.star.security.CertificateContainer") == 0 ) 112cdf0e10cSrcweir return sal_True; 113cdf0e10cSrcweir else 114cdf0e10cSrcweir return sal_False; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir //------------------------------------------------------------------------- 118cdf0e10cSrcweir 119cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL 120cdf0e10cSrcweir CertificateContainer::getSupportedServiceNames( ) 121cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir return impl_getStaticSupportedServiceNames(); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir //------------------------------------------------------------------------- 127cdf0e10cSrcweir 128cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL 129cdf0e10cSrcweir CertificateContainer::impl_getStaticSupportedServiceNames( ) 130cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir Sequence< ::rtl::OUString > aRet(1); 133cdf0e10cSrcweir *aRet.getArray() = ::rtl::OUString::createFromAscii("com.sun.star.security.CertificateContainer"); 134cdf0e10cSrcweir return aRet; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir //------------------------------------------------------------------------- 138cdf0e10cSrcweir 139cdf0e10cSrcweir ::rtl::OUString SAL_CALL 140cdf0e10cSrcweir CertificateContainer::impl_getStaticImplementationName() 141cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.security.CertificateContainer"); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir //------------------------------------------------------------------------- 147cdf0e10cSrcweir 148cdf0e10cSrcweir Reference< XInterface > SAL_CALL CertificateContainer::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager ) 149cdf0e10cSrcweir throw( RuntimeException ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir return Reference< XInterface >( *new CertificateContainer( xServiceManager ) ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir //------------------------------------------------------------------------- 155cdf0e10cSrcweir 156cdf0e10cSrcweir Reference< XSingleServiceFactory > SAL_CALL 157cdf0e10cSrcweir CertificateContainer::impl_createFactory( const Reference< XMultiServiceFactory >& ServiceManager ) 158cdf0e10cSrcweir throw(RuntimeException) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir Reference< XSingleServiceFactory > xReturn( ::cppu::createOneInstanceFactory( ServiceManager, 161cdf0e10cSrcweir CertificateContainer::impl_getStaticImplementationName(), 162cdf0e10cSrcweir CertificateContainer::impl_createInstance, 163cdf0e10cSrcweir CertificateContainer::impl_getStaticSupportedServiceNames())); 164cdf0e10cSrcweir 165cdf0e10cSrcweir return xReturn; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168