1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: certificatecontainer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_xmlsecurity.hxx"
32 #include <certificatecontainer.hxx>
34 #include <sal/config.h>
36 using namespace ::com::sun::star::uno
;
40 CertificateContainer::searchMap( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
, Map
&_certMap
)
42 Map::iterator p
= _certMap
.find(url
);
44 ::sal_Bool ret
= sal_False
;
46 while( p
!= _certMap
.end() )
48 ret
= (sal_Bool
) (*p
).second
.equals(certificate_name
);
56 // -------------------------------------------------------------------
59 CertificateContainer::isTemporaryCertificate ( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
)
60 throw(::com::sun::star::uno::RuntimeException
)
62 return searchMap( url
, certificate_name
, certMap
);
65 // -------------------------------------------------------------------
68 CertificateContainer::isCertificateTrust ( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
)
69 throw(::com::sun::star::uno::RuntimeException
)
71 return searchMap( url
, certificate_name
, certTrustMap
);
74 // -------------------------------------------------------------------
76 CertificateContainer::addCertificate( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
, ::sal_Bool trust
)
77 throw(::com::sun::star::uno::RuntimeException
)
79 certMap
.insert( Map::value_type( url
, certificate_name
) );
81 //remember that the cert is trusted
83 certTrustMap
.insert( Map::value_type( url
, certificate_name
) );
88 //-------------------------------------------------------------------------
89 ::security::CertificateContainerStatus
90 CertificateContainer::hasCertificate( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
) throw(::com::sun::star::uno::RuntimeException
)
92 if ( isTemporaryCertificate( url
, certificate_name
) )
94 if ( isCertificateTrust( url
, certificate_name
) )
95 return security::CertificateContainerStatus( security::CertificateContainerStatus_TRUSTED
);
97 return security::CertificateContainerStatus_UNTRUSTED
;
100 return security::CertificateContainerStatus_NOCERT
;
103 //-------------------------------------------------------------------------
105 ::rtl::OUString SAL_CALL
106 CertificateContainer::getImplementationName( )
107 throw(::com::sun::star::uno::RuntimeException
)
109 return impl_getStaticImplementationName();
112 //-------------------------------------------------------------------------
115 CertificateContainer::supportsService( const ::rtl::OUString
& ServiceName
)
116 throw(::com::sun::star::uno::RuntimeException
)
118 if ( ServiceName
.compareToAscii("com.sun.star.security.CertificateContainer") == 0 )
124 //-------------------------------------------------------------------------
126 Sequence
< ::rtl::OUString
> SAL_CALL
127 CertificateContainer::getSupportedServiceNames( )
128 throw(::com::sun::star::uno::RuntimeException
)
130 return impl_getStaticSupportedServiceNames();
133 //-------------------------------------------------------------------------
135 Sequence
< ::rtl::OUString
> SAL_CALL
136 CertificateContainer::impl_getStaticSupportedServiceNames( )
137 throw(::com::sun::star::uno::RuntimeException
)
139 Sequence
< ::rtl::OUString
> aRet(1);
140 *aRet
.getArray() = ::rtl::OUString::createFromAscii("com.sun.star.security.CertificateContainer");
144 //-------------------------------------------------------------------------
146 ::rtl::OUString SAL_CALL
147 CertificateContainer::impl_getStaticImplementationName()
148 throw(::com::sun::star::uno::RuntimeException
)
150 return ::rtl::OUString::createFromAscii("com.sun.star.security.CertificateContainer");
153 //-------------------------------------------------------------------------
155 Reference
< XInterface
> SAL_CALL
CertificateContainer::impl_createInstance( const Reference
< XMultiServiceFactory
>& xServiceManager
)
156 throw( RuntimeException
)
158 return Reference
< XInterface
>( *new CertificateContainer( xServiceManager
) );
161 //-------------------------------------------------------------------------
163 Reference
< XSingleServiceFactory
> SAL_CALL
164 CertificateContainer::impl_createFactory( const Reference
< XMultiServiceFactory
>& ServiceManager
)
165 throw(RuntimeException
)
167 Reference
< XSingleServiceFactory
> xReturn( ::cppu::createOneInstanceFactory( ServiceManager
,
168 CertificateContainer::impl_getStaticImplementationName(),
169 CertificateContainer::impl_createInstance
,
170 CertificateContainer::impl_getStaticSupportedServiceNames()));