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 #ifndef INCLUDED_XMLSECURITY_INC_CERTIFICATEVIEWER_HXX
21 #define INCLUDED_XMLSECURITY_INC_CERTIFICATEVIEWER_HXX
22 
23 #include <vcl/weld.hxx>
24 
25 namespace com {
26 namespace sun {
27 namespace star {
28 namespace security {
29     class XCertificate; }
30 namespace xml { namespace crypto {
31     class XSecurityEnvironment; }}
32 }}}
33 
34 class CertificateViewerGeneralTP;
35 class CertificateViewerDetailsTP;
36 class CertificateViewerCertPathTP;
37 class CertificateChooser;
38 
39 class CertificateViewer : public weld::GenericDialogController
40 {
41 private:
42     friend class CertificateViewerGeneralTP;
43     friend class CertificateViewerDetailsTP;
44     friend class CertificateViewerCertPathTP;
45 
46     bool const          mbCheckForPrivateKey;
47 
48     css::uno::Reference< css::xml::crypto::XSecurityEnvironment > mxSecurityEnvironment;
49     css::uno::Reference< css::security::XCertificate > mxCert;
50 
51     CertificateChooser* mpParentChooser;
52 
53     std::unique_ptr<weld::Notebook> mxTabCtrl;
54 
55     std::unique_ptr<CertificateViewerGeneralTP> mxGeneralPage;
56     std::unique_ptr<CertificateViewerDetailsTP> mxDetailsPage;
57     std::unique_ptr<CertificateViewerCertPathTP> mxPathId;
58 
59     DECL_LINK(ActivatePageHdl, const OString&, void);
60 
61 public:
62     CertificateViewer(weld::Window* pParent, const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& rxSecurityEnvironment, const css::uno::Reference< css::security::XCertificate >& rXCert, bool bCheckForPrivateKey, CertificateChooser* pParentChooser);
GetParentChooser()63     CertificateChooser* GetParentChooser() { return mpParentChooser; }
64 };
65 
66 class CertificateViewerTP
67 {
68 protected:
69     std::unique_ptr<weld::Builder> mxBuilder;
70     std::unique_ptr<weld::Container> mxContainer;
71     CertificateViewer* mpDlg;
72 
73 public:
74     CertificateViewerTP(weld::Container* pParent, const OUString& rUIXMLDescription,
75                         const OString& rID, CertificateViewer* pDlg);
76 };
77 
78 class CertificateViewerGeneralTP : public CertificateViewerTP
79 {
80 private:
81     std::unique_ptr<weld::Image> m_xCertImg;
82     std::unique_ptr<weld::Label> m_xHintNotTrustedFT;
83     std::unique_ptr<weld::Label> m_xIssuedToLabelFT;
84     std::unique_ptr<weld::Label> m_xIssuedToFT;
85     std::unique_ptr<weld::Label> m_xIssuedByLabelFT;
86     std::unique_ptr<weld::Label> m_xIssuedByFT;
87     std::unique_ptr<weld::Label> m_xValidFromDateFT;
88     std::unique_ptr<weld::Label> m_xValidToDateFT;
89     std::unique_ptr<weld::Image> m_xKeyImg;
90     std::unique_ptr<weld::Label> m_xHintCorrespPrivKeyFT;
91 
92 public:
93     CertificateViewerGeneralTP(weld::Container* pParent, CertificateViewer* pDlg);
94 };
95 
96 struct Details_UserDatat
97 {
98     OUString const  maTxt;
99     bool const      mbFixedWidthFont;
100 
Details_UserDatatDetails_UserDatat101     Details_UserDatat(const OUString& rTxt, bool bFixedWidthFont)
102         : maTxt(rTxt)
103         , mbFixedWidthFont(bFixedWidthFont)
104     {
105     }
106 };
107 
108 class CertificateViewerDetailsTP : public CertificateViewerTP
109 {
110 private:
111     std::vector<std::unique_ptr<Details_UserDatat>> m_aUserData;
112 
113     std::unique_ptr<weld::TreeView> m_xElementsLB;
114     std::unique_ptr<weld::TextView> m_xValueDetails;
115 
116     DECL_LINK(ElementSelectHdl, weld::TreeView&, void);
117     void                InsertElement(const OUString& rField, const OUString& rValue,
118                                       const OUString& rDetails, bool bFixedWidthFont = false);
119 public:
120     CertificateViewerDetailsTP(weld::Container* pParent, CertificateViewer* pDlg);
121 };
122 
123 struct CertPath_UserData
124 {
125     css::uno::Reference< css::security::XCertificate > mxCert;
126     bool const mbValid;
127 
CertPath_UserDataCertPath_UserData128     CertPath_UserData(css::uno::Reference<css::security::XCertificate> const & xCert, bool bValid)
129         : mxCert(xCert)
130         , mbValid(bValid)
131     {
132     }
133 };
134 
135 class CertificateViewerCertPathTP : public CertificateViewerTP
136 {
137 private:
138     CertificateViewer*  mpParent;
139     bool                mbFirstActivateDone;
140 
141     std::vector<std::unique_ptr<CertPath_UserData>> maUserData;
142 
143     std::unique_ptr<weld::TreeView> mxCertPathLB;
144     std::unique_ptr<weld::Button> mxViewCertPB;
145     std::unique_ptr<weld::TextView> mxCertStatusML;
146     std::unique_ptr<weld::Label> mxCertOK;
147     std::unique_ptr<weld::Label> mxCertNotValidated;
148 
149     DECL_LINK(ViewCertHdl, weld::Button&, void);
150     DECL_LINK(CertSelectHdl, weld::TreeView&, void);
151     void                InsertCert(const weld::TreeIter* pParent, const OUString& _rName,
152                                    const css::uno::Reference< css::security::XCertificate >& rxCert,
153                                    bool bValid);
154 
155 public:
156     CertificateViewerCertPathTP(weld::Container* pParent, CertificateViewer* pDlg);
157     void ActivatePage();
158 };
159 
160 
161 #endif // INCLUDED_XMLSECURITY_INC_CERTIFICATEVIEWER_HXX
162 
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
164