13#include <com/sun/star/security/CertificateContainer.hpp>
14#include <com/sun/star/security/XCertificate.hpp>
15#include <com/sun/star/security/XCertificateContainer.hpp>
16#include <com/sun/star/xml/crypto/SEInitializer.hpp>
17#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
25#define STD_TO_OUSTR( str ) OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
33 bool bValidate =
false;
34 if ( !aCertificates.empty() &&
m_xEnv.is() )
36 uno::Reference< xml::crypto::XSEInitializer > xSEInitializer;
39 xSEInitializer = xml::crypto::SEInitializer::create(
m_xContext );
41 catch ( uno::Exception
const & )
45 if ( xSEInitializer.is() )
47 uno::Reference< xml::crypto::XXMLSecurityContext > xSecurityContext(
48 xSEInitializer->createSecurityContext( OUString() ) );
50 uno::Reference< xml::crypto::XSecurityEnvironment > xSecurityEnv(
51 xSecurityContext->getSecurityEnvironment() );
53 std::vector< std::string >::iterator pIt = aCertificates.begin();
54 std::string sCert = *pIt;
57 sCleanCert = sCleanCert.replaceAll(
"-----BEGIN CERTIFICATE-----",
"" );
58 sCleanCert = sCleanCert.replaceAll(
"-----END CERTIFICATE-----",
"" );
59 uno::Reference< security::XCertificate > xCert(
60 xSecurityEnv->createCertificateFromAscii(
63 uno::Reference< security::XCertificateContainer > xCertificateContainer;
66 xCertificateContainer = security::CertificateContainer::create(
m_xContext );
68 catch ( uno::Exception
const & )
72 if ( xCertificateContainer.is( ) )
74 security::CertificateContainerStatus status(
75 xCertificateContainer->hasCertificate(
78 if ( status != security::CertificateContainerStatus_NOCERT )
79 return status == security::CertificateContainerStatus_TRUSTED;
83 std::vector< uno::Reference< security::XCertificate > > vecCerts;
85 for ( ++pIt; pIt != aCertificates.end(); ++pIt )
88 uno::Reference< security::XCertificate> xImCert(
89 xSecurityEnv->createCertificateFromAscii(
92 vecCerts.push_back( xImCert );
95 sal_Int64 certValidity = xSecurityEnv->verifyCertificate( xCert,
96 ::comphelper::containerToSequence( vecCerts ) );
98 uno::Reference< task::XInteractionHandler > xIH(
99 m_xEnv->getInteractionHandler() );
105 xIH->handle( xRequest );
107 = xRequest->getSelection();
109 if ( xSelection.is() )
111 uno::Reference< task::XInteractionApprove > xApprove(
112 xSelection.get(), uno::UNO_QUERY );
113 bValidate = xApprove.is();
116 xCertificateContainer->addCertificate(
#define STD_TO_OUSTR(str)
bool validateCertificate(std::vector< std::string > certificates) override
const css::uno::Reference< css::uno::XComponentContext > & m_xContext
const css::uno::Reference< css::ucb::XCommandEnvironment > & m_xEnv