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 : #include <cppuhelper/supportsservice.hxx>
22 :
23 : #include <sal/config.h>
24 :
25 : using namespace ::com::sun::star;
26 : using namespace ::com::sun::star::lang;
27 : using namespace ::com::sun::star::uno;
28 :
29 : bool
30 0 : CertificateContainer::searchMap( const OUString & url, const OUString & certificate_name, Map &_certMap )
31 : {
32 0 : Map::iterator p = _certMap.find(url);
33 :
34 0 : bool ret = false;
35 :
36 0 : while( p != _certMap.end() )
37 : {
38 0 : ret = (*p).second.equals(certificate_name);
39 0 : if( ret )
40 0 : break;
41 0 : ++p;
42 : }
43 :
44 0 : return ret;
45 : }
46 :
47 : bool
48 0 : CertificateContainer::isTemporaryCertificate ( const OUString & url, const OUString & certificate_name )
49 : throw(::com::sun::star::uno::RuntimeException)
50 : {
51 0 : return searchMap( url, certificate_name, certMap);
52 : }
53 :
54 : bool
55 0 : CertificateContainer::isCertificateTrust ( const OUString & url, const OUString & certificate_name )
56 : throw(::com::sun::star::uno::RuntimeException)
57 : {
58 0 : return searchMap( url, certificate_name, certTrustMap);
59 : }
60 :
61 : sal_Bool
62 0 : CertificateContainer::addCertificate( const OUString & url, const OUString & certificate_name, sal_Bool trust )
63 : throw(::com::sun::star::uno::RuntimeException, std::exception)
64 : {
65 0 : certMap.insert( Map::value_type( url, certificate_name ) );
66 :
67 : //remember that the cert is trusted
68 0 : if (trust)
69 0 : certTrustMap.insert( Map::value_type( url, certificate_name ) );
70 :
71 0 : return true;
72 : }
73 :
74 : ::security::CertificateContainerStatus
75 0 : CertificateContainer::hasCertificate( const OUString & url, const OUString & certificate_name ) throw(::com::sun::star::uno::RuntimeException, std::exception)
76 : {
77 0 : if ( isTemporaryCertificate( url, certificate_name ) )
78 : {
79 0 : if ( isCertificateTrust( url, certificate_name ) )
80 0 : return security::CertificateContainerStatus( security::CertificateContainerStatus_TRUSTED );
81 : else
82 0 : return security::CertificateContainerStatus_UNTRUSTED;
83 : } else
84 : {
85 0 : return security::CertificateContainerStatus_NOCERT;
86 : }
87 : }
88 :
89 : OUString SAL_CALL
90 1 : CertificateContainer::getImplementationName( )
91 : throw(::com::sun::star::uno::RuntimeException, std::exception)
92 : {
93 1 : return impl_getStaticImplementationName();
94 : }
95 :
96 : sal_Bool SAL_CALL
97 0 : CertificateContainer::supportsService( const OUString& ServiceName )
98 : throw(::com::sun::star::uno::RuntimeException, std::exception)
99 : {
100 0 : return cppu::supportsService( this, ServiceName );
101 : }
102 :
103 : Sequence< OUString > SAL_CALL
104 1 : CertificateContainer::getSupportedServiceNames( )
105 : throw(::com::sun::star::uno::RuntimeException, std::exception)
106 : {
107 1 : return impl_getStaticSupportedServiceNames();
108 : }
109 :
110 : Sequence< OUString > SAL_CALL
111 2 : CertificateContainer::impl_getStaticSupportedServiceNames( )
112 : throw(::com::sun::star::uno::RuntimeException)
113 : {
114 2 : Sequence< OUString > aRet(1);
115 2 : aRet[0] = "com.sun.star.security.CertificateContainer";
116 2 : return aRet;
117 : }
118 :
119 : OUString SAL_CALL
120 2 : CertificateContainer::impl_getStaticImplementationName()
121 : throw(::com::sun::star::uno::RuntimeException)
122 : {
123 2 : return OUString("com.sun.star.security.CertificateContainer");
124 : }
125 :
126 1 : Reference< XInterface > SAL_CALL CertificateContainer::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager )
127 : throw( RuntimeException )
128 : {
129 1 : return Reference< XInterface >( *new CertificateContainer( xServiceManager ) );
130 : }
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|