Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <certificatecontainer.hxx>
21 : :
22 : : #include <sal/config.h>
23 : :
24 : : using namespace ::com::sun::star::uno;
25 : :
26 : :
27 : : sal_Bool
28 : 0 : CertificateContainer::searchMap( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name, Map &_certMap )
29 : : {
30 [ # # ]: 0 : Map::iterator p = _certMap.find(url);
31 : :
32 : 0 : ::sal_Bool ret = sal_False;
33 : :
34 [ # # ]: 0 : while( p != _certMap.end() )
35 : : {
36 : 0 : ret = (sal_Bool) (*p).second.equals(certificate_name);
37 [ # # ]: 0 : if( ret )
38 : 0 : break;
39 : 0 : ++p;
40 : : }
41 : :
42 : 0 : return ret;
43 : : }
44 : : // -------------------------------------------------------------------
45 : :
46 : : sal_Bool
47 : 0 : CertificateContainer::isTemporaryCertificate ( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name )
48 : : throw(::com::sun::star::uno::RuntimeException)
49 : : {
50 : 0 : return searchMap( url, certificate_name, certMap);
51 : : }
52 : :
53 : : // -------------------------------------------------------------------
54 : :
55 : : sal_Bool
56 : 0 : CertificateContainer::isCertificateTrust ( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name )
57 : : throw(::com::sun::star::uno::RuntimeException)
58 : : {
59 : 0 : return searchMap( url, certificate_name, certTrustMap);
60 : : }
61 : :
62 : : // -------------------------------------------------------------------
63 : : sal_Bool
64 : 0 : CertificateContainer::addCertificate( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name, ::sal_Bool trust )
65 : : throw(::com::sun::star::uno::RuntimeException)
66 : : {
67 [ # # ]: 0 : certMap.insert( Map::value_type( url, certificate_name ) );
68 : :
69 : : //remember that the cert is trusted
70 [ # # ]: 0 : if (trust)
71 [ # # ]: 0 : certTrustMap.insert( Map::value_type( url, certificate_name ) );
72 : :
73 : 0 : return true;
74 : : }
75 : :
76 : : //-------------------------------------------------------------------------
77 : : ::security::CertificateContainerStatus
78 : 0 : CertificateContainer::hasCertificate( const ::rtl::OUString & url, const ::rtl::OUString & certificate_name ) throw(::com::sun::star::uno::RuntimeException)
79 : : {
80 [ # # ]: 0 : if ( isTemporaryCertificate( url, certificate_name ) )
81 : : {
82 [ # # ]: 0 : if ( isCertificateTrust( url, certificate_name ) )
83 : 0 : return security::CertificateContainerStatus( security::CertificateContainerStatus_TRUSTED );
84 : : else
85 : 0 : return security::CertificateContainerStatus_UNTRUSTED;
86 : : } else
87 : : {
88 : 0 : return security::CertificateContainerStatus_NOCERT;
89 : : }
90 : : }
91 : : //-------------------------------------------------------------------------
92 : :
93 : : ::rtl::OUString SAL_CALL
94 : 0 : CertificateContainer::getImplementationName( )
95 : : throw(::com::sun::star::uno::RuntimeException)
96 : : {
97 : 0 : return impl_getStaticImplementationName();
98 : : }
99 : :
100 : : //-------------------------------------------------------------------------
101 : :
102 : : sal_Bool SAL_CALL
103 : 0 : CertificateContainer::supportsService( const ::rtl::OUString& ServiceName )
104 : : throw(::com::sun::star::uno::RuntimeException)
105 : : {
106 [ # # ]: 0 : if ( ServiceName.compareToAscii("com.sun.star.security.CertificateContainer") == 0 )
107 : 0 : return sal_True;
108 : : else
109 : 0 : return sal_False;
110 : : }
111 : :
112 : : //-------------------------------------------------------------------------
113 : :
114 : : Sequence< ::rtl::OUString > SAL_CALL
115 : 0 : CertificateContainer::getSupportedServiceNames( )
116 : : throw(::com::sun::star::uno::RuntimeException)
117 : : {
118 : 0 : return impl_getStaticSupportedServiceNames();
119 : : }
120 : :
121 : : //-------------------------------------------------------------------------
122 : :
123 : : Sequence< ::rtl::OUString > SAL_CALL
124 : 0 : CertificateContainer::impl_getStaticSupportedServiceNames( )
125 : : throw(::com::sun::star::uno::RuntimeException)
126 : : {
127 : 0 : Sequence< ::rtl::OUString > aRet(1);
128 [ # # ]: 0 : *aRet.getArray() = ::rtl::OUString("com.sun.star.security.CertificateContainer");
129 : 0 : return aRet;
130 : : }
131 : :
132 : : //-------------------------------------------------------------------------
133 : :
134 : : ::rtl::OUString SAL_CALL
135 : 0 : CertificateContainer::impl_getStaticImplementationName()
136 : : throw(::com::sun::star::uno::RuntimeException)
137 : : {
138 : 0 : return ::rtl::OUString("com.sun.star.security.CertificateContainer");
139 : : }
140 : :
141 : : //-------------------------------------------------------------------------
142 : :
143 : 0 : Reference< XInterface > SAL_CALL CertificateContainer::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager )
144 : : throw( RuntimeException )
145 : : {
146 [ # # ]: 0 : return Reference< XInterface >( *new CertificateContainer( xServiceManager ) );
147 : : }
148 : :
149 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|