1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #include "precompiled_xmlsecurity.hxx"
29 #include <certificatecontainer.hxx>
31 #include <sal/config.h>
33 using namespace ::com::sun::star::uno
;
37 CertificateContainer::searchMap( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
, Map
&_certMap
)
39 Map::iterator p
= _certMap
.find(url
);
41 ::sal_Bool ret
= sal_False
;
43 while( p
!= _certMap
.end() )
45 ret
= (sal_Bool
) (*p
).second
.equals(certificate_name
);
53 // -------------------------------------------------------------------
56 CertificateContainer::isTemporaryCertificate ( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
)
57 throw(::com::sun::star::uno::RuntimeException
)
59 return searchMap( url
, certificate_name
, certMap
);
62 // -------------------------------------------------------------------
65 CertificateContainer::isCertificateTrust ( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
)
66 throw(::com::sun::star::uno::RuntimeException
)
68 return searchMap( url
, certificate_name
, certTrustMap
);
71 // -------------------------------------------------------------------
73 CertificateContainer::addCertificate( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
, ::sal_Bool trust
)
74 throw(::com::sun::star::uno::RuntimeException
)
76 certMap
.insert( Map::value_type( url
, certificate_name
) );
78 //remember that the cert is trusted
80 certTrustMap
.insert( Map::value_type( url
, certificate_name
) );
85 //-------------------------------------------------------------------------
86 ::security::CertificateContainerStatus
87 CertificateContainer::hasCertificate( const ::rtl::OUString
& url
, const ::rtl::OUString
& certificate_name
) throw(::com::sun::star::uno::RuntimeException
)
89 if ( isTemporaryCertificate( url
, certificate_name
) )
91 if ( isCertificateTrust( url
, certificate_name
) )
92 return security::CertificateContainerStatus( security::CertificateContainerStatus_TRUSTED
);
94 return security::CertificateContainerStatus_UNTRUSTED
;
97 return security::CertificateContainerStatus_NOCERT
;
100 //-------------------------------------------------------------------------
102 ::rtl::OUString SAL_CALL
103 CertificateContainer::getImplementationName( )
104 throw(::com::sun::star::uno::RuntimeException
)
106 return impl_getStaticImplementationName();
109 //-------------------------------------------------------------------------
112 CertificateContainer::supportsService( const ::rtl::OUString
& ServiceName
)
113 throw(::com::sun::star::uno::RuntimeException
)
115 if ( ServiceName
.compareToAscii("com.sun.star.security.CertificateContainer") == 0 )
121 //-------------------------------------------------------------------------
123 Sequence
< ::rtl::OUString
> SAL_CALL
124 CertificateContainer::getSupportedServiceNames( )
125 throw(::com::sun::star::uno::RuntimeException
)
127 return impl_getStaticSupportedServiceNames();
130 //-------------------------------------------------------------------------
132 Sequence
< ::rtl::OUString
> SAL_CALL
133 CertificateContainer::impl_getStaticSupportedServiceNames( )
134 throw(::com::sun::star::uno::RuntimeException
)
136 Sequence
< ::rtl::OUString
> aRet(1);
137 *aRet
.getArray() = ::rtl::OUString::createFromAscii("com.sun.star.security.CertificateContainer");
141 //-------------------------------------------------------------------------
143 ::rtl::OUString SAL_CALL
144 CertificateContainer::impl_getStaticImplementationName()
145 throw(::com::sun::star::uno::RuntimeException
)
147 return ::rtl::OUString::createFromAscii("com.sun.star.security.CertificateContainer");
150 //-------------------------------------------------------------------------
152 Reference
< XInterface
> SAL_CALL
CertificateContainer::impl_createInstance( const Reference
< XMultiServiceFactory
>& xServiceManager
)
153 throw( RuntimeException
)
155 return Reference
< XInterface
>( *new CertificateContainer( xServiceManager
) );
158 //-------------------------------------------------------------------------
160 Reference
< XSingleServiceFactory
> SAL_CALL
161 CertificateContainer::impl_createFactory( const Reference
< XMultiServiceFactory
>& ServiceManager
)
162 throw(RuntimeException
)
164 Reference
< XSingleServiceFactory
> xReturn( ::cppu::createOneInstanceFactory( ServiceManager
,
165 CertificateContainer::impl_getStaticImplementationName(),
166 CertificateContainer::impl_createInstance
,
167 CertificateContainer::impl_getStaticSupportedServiceNames()));