26#include <com/sun/star/security/XCertificate.hpp>
28#include <com/sun/star/security/CertificateCharacters.hpp>
29#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
30#include <com/sun/star/security/CertificateValidity.hpp>
38#include <tools/datetime.hxx>
39#include <bitmaps.hlst>
49 const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment,
50 const css::uno::Reference< css::security::XCertificate >& _rXCert,
bool bCheckForPrivateKey,
52 : GenericDialogController(_pParent,
"xmlsec/ui/viewcertdialog.ui",
"ViewCertDialog")
53 , mbCheckForPrivateKey(bCheckForPrivateKey)
54 , mpParentChooser(pParentChooser)
55 , mxTabCtrl(m_xBuilder->weld_notebook(
"tabcontrol"))
74 mxPathId->ActivatePage();
79 : mxBuilder(
Application::CreateBuilder(pParent, rUIXMLDescription))
87 , m_xCertImg(mxBuilder->weld_image(
"certimage"))
88 , m_xHintNotTrustedFT(mxBuilder->weld_label(
"hintnotrust"))
89 , m_xIssuedToLabelFT(mxBuilder->weld_label(
"issued_to"))
90 , m_xIssuedToFT(mxBuilder->weld_label(
"issued_to_value"))
91 , m_xIssuedByLabelFT(mxBuilder->weld_label(
"issued_by"))
92 , m_xIssuedByFT(mxBuilder->weld_label(
"issued_by_value"))
93 , m_xValidFromDateFT(mxBuilder->weld_label(
"valid_from_value"))
94 , m_xValidToDateFT(mxBuilder->weld_label(
"valid_to_value"))
95 , m_xKeyImg(mxBuilder->weld_image(
"keyimage"))
96 , m_xHintCorrespPrivKeyFT(mxBuilder->weld_label(
"privatekey"))
100 Sequence<Reference<css::security::XCertificate> >());
102 bool bCertValid = certStatus == css::security::CertificateValidity::VALID;
106 m_xCertImg->set_from_icon_name(BMP_STATE_NOT_VALIDATED);
111 css::uno::Reference< css::security::XCertificate > xCert =
mpDlg->
mxCert;
113 OUString sSubjectName(xmlsec::GetContentPart(xCert->getSubjectName(), xCert->getCertificateKind()));
114 if (!sSubjectName.isEmpty())
118 OUString sIssuerName(xmlsec::GetContentPart(xCert->getIssuerName(), xCert->getCertificateKind()));
119 if (!sIssuerName.isEmpty())
136 bool bHasPrivateKey =
false;
141 bHasPrivateKey = (nCertificateCharacters & security::CertificateCharacters::HAS_PRIVATE_KEY);
151 const OUString& rDetails,
bool bFixedWidthFont)
153 m_aUserData.emplace_back(std::make_unique<Details_UserDatat>(rDetails, bFixedWidthFont));
161 , m_xElementsLB(mxBuilder->weld_tree_view(
"tablecontainer"))
162 , m_xValueDetails(mxBuilder->weld_text_view(
"valuedetails"))
164 const int nWidth =
m_xElementsLB->get_approximate_digit_width() * 60;
171 Reference< security::XCertificate > xCert =
mpDlg->
mxCert;
172 sal_uInt16 nLineBreak = 16;
173 const char*
const pHexSep =
" ";
177 aLBEntry =
"V" + OUString::number( xCert->getVersion() + 1 );
180 aLBEntry = xmlsec::GetHexString(
aSeq, pHexSep );
181 aDetails = xmlsec::GetHexString(
aSeq, pHexSep, nLineBreak );
184 std::pair< OUString, OUString> pairIssuer =
185 xmlsec::GetDNForCertDetailsView(xCert->getIssuerName());
186 aLBEntry = pairIssuer.first;
187 aDetails = pairIssuer.second;
200 std::pair< OUString, OUString > pairSubject =
201 xmlsec::GetDNForCertDetailsView(xCert->getSubjectName());
202 aLBEntry = pairSubject.first;
203 aDetails = pairSubject.second;
206 aLBEntry = aDetails = xCert->getSubjectPublicKeyAlgorithm();
208 aSeq = xCert->getSubjectPublicKeyValue();
209 aLBEntry = xmlsec::GetHexString(
aSeq, pHexSep );
210 aDetails = xmlsec::GetHexString(
aSeq, pHexSep, nLineBreak );
213 aLBEntry = aDetails = xCert->getSignatureAlgorithm();
223 aSeq = xCert->getSHA1Thumbprint();
224 aLBEntry = xmlsec::GetHexString(
aSeq, pHexSep );
225 aDetails = xmlsec::GetHexString(
aSeq, pHexSep, nLineBreak );
228 aSeq = xCert->getMD5Thumbprint();
229 aLBEntry = xmlsec::GetHexString(
aSeq, pHexSep );
230 aDetails = xmlsec::GetHexString(
aSeq, pHexSep, nLineBreak );
238 int nEntry = m_xElementsLB->get_selected_index();
239 OUString aElementText;
240 bool bFixedWidthFont;
243 const Details_UserDatat*
p = weld::fromId<Details_UserDatat*>(m_xElementsLB->get_id(nEntry));
244 aElementText =
p->maTxt;
245 bFixedWidthFont =
p->mbFixedWidthFont;
248 bFixedWidthFont =
false;
250 m_xValueDetails->set_monospace(bFixedWidthFont);
251 m_xValueDetails->set_text(aElementText);
257 , mbFirstActivateDone(false)
258 , mxCertPathLB(mxBuilder->weld_tree_view(
"signatures"))
259 , mxScratchIter(mxCertPathLB->make_iterator())
260 , mxViewCertPB(mxBuilder->weld_button(
"viewcert"))
261 , mxCertStatusML(mxBuilder->weld_text_view(
"status"))
262 , mxCertOK(mxBuilder->weld_label(
"certok"))
263 , mxCertNotValidated(mxBuilder->weld_label(
"certnotok"))
265 const int nWidth =
mxCertPathLB->get_approximate_digit_width() * 60;
286 Sequence< Reference< security::XCertificate > > aCertPath =
288 const Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray();
290 sal_Int32
i, nCnt = aCertPath.getLength();
291 std::unique_ptr<weld::TreeIter> xParent;
292 for (
i = nCnt-1;
i >= 0;
i--)
294 const Reference< security::XCertificate > rCert = pCertPath[
i ];
295 OUString
sName = xmlsec::GetContentPart( rCert->getSubjectName(), rCert->getCertificateKind() );
298 Sequence<Reference<css::security::XCertificate> >());
299 bool bCertValid = certStatus == css::security::CertificateValidity::VALID;
328 std::unique_ptr<weld::TreeIter> xIter = mxCertPathLB->make_iterator();
329 if (mxCertPathLB->get_selected(xIter.get()))
331 if (mxCertificateViewer)
332 mxCertificateViewer->response(
RET_OK);
335 mxCertificateViewer = std::make_shared<CertificateViewer>(mpDlg->getDialog(), mpDlg->mxSecurityEnvironment,
336 pData->mxCert,
false,
nullptr);
345 std::unique_ptr<weld::TreeIter> xIter = mxCertPathLB->make_iterator();
346 bool bEntry = mxCertPathLB->get_selected(xIter.get());
351 sStatus =
pData->mbValid ? mxCertOK->get_label() : mxCertNotValidated->get_label();
354 mxCertStatusML->set_text(sStatus);
356 bool bSensitive =
false;
360 if (mxCertPathLB->iter_children(*xIter))
363 mxViewCertPB->set_sensitive(bSensitive);
367 const css::uno::Reference< css::security::XCertificate >& rxCert,
370 auto const sImage = bValid ? std::u16string_view(
u"" BMP_CERT_OK) : std::u16string_view(
u"" BMP_CERT_NOT_OK);
371 maUserData.emplace_back(std::make_unique<CertPath_UserData>(rxCert, bValid));
IMPL_LINK_NOARG(CertificateViewerDetailsTP, ElementSelectHdl, weld::TreeView &, void)
IMPL_LINK(CertificateViewer, ActivatePageHdl, const OUString &, rPage, void)
const LocaleDataWrapper & GetUILocaleDataWrapper() const
static const AllSettings & GetSettings()
static OUString UsageInClearText(int bits)
std::vector< std::unique_ptr< CertPath_UserData > > maUserData
CertificateViewer * mpParent
CertificateViewerCertPathTP(weld::Container *pParent, CertificateViewer *pDlg)
std::unique_ptr< weld::TextView > mxCertStatusML
std::shared_ptr< CertificateViewer > mxCertificateViewer
std::unique_ptr< weld::TreeIter > mxScratchIter
std::unique_ptr< weld::TreeView > mxCertPathLB
void InsertCert(const weld::TreeIter *pParent, const OUString &_rName, const css::uno::Reference< css::security::XCertificate > &rxCert, bool bValid)
~CertificateViewerCertPathTP()
std::unique_ptr< weld::Button > mxViewCertPB
std::vector< std::unique_ptr< Details_UserDatat > > m_aUserData
std::unique_ptr< weld::TreeView > m_xElementsLB
void InsertElement(const OUString &rField, const OUString &rValue, const OUString &rDetails, bool bFixedWidthFont=false)
std::unique_ptr< weld::TextView > m_xValueDetails
CertificateViewerDetailsTP(weld::Container *pParent, CertificateViewer *pDlg)
std::unique_ptr< weld::Image > m_xCertImg
std::unique_ptr< weld::Label > m_xIssuedByFT
std::unique_ptr< weld::Label > m_xHintCorrespPrivKeyFT
std::unique_ptr< weld::Label > m_xValidToDateFT
std::unique_ptr< weld::Label > m_xIssuedByLabelFT
std::unique_ptr< weld::Label > m_xHintNotTrustedFT
CertificateViewerGeneralTP(weld::Container *pParent, CertificateViewer *pDlg)
std::unique_ptr< weld::Label > m_xIssuedToLabelFT
std::unique_ptr< weld::Image > m_xKeyImg
std::unique_ptr< weld::Label > m_xValidFromDateFT
std::unique_ptr< weld::Label > m_xIssuedToFT
CertificateViewerTP(weld::Container *pParent, const OUString &rUIXMLDescription, const OUString &rID, CertificateViewer *pDlg)
CertificateViewer * mpDlg
friend class CertificateViewerDetailsTP
std::unique_ptr< CertificateViewerDetailsTP > mxDetailsPage
std::unique_ptr< weld::Notebook > mxTabCtrl
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)
friend class CertificateViewerGeneralTP
std::unique_ptr< CertificateViewerCertPathTP > mxPathId
std::unique_ptr< CertificateViewerGeneralTP > mxGeneralPage
css::uno::Reference< css::security::XCertificate > mxCert
friend class CertificateViewerCertPathTP
CertificateChooser * GetParentChooser()
css::uno::Reference< css::xml::crypto::XSecurityEnvironment > mxSecurityEnvironment
bool const mbCheckForPrivateKey
sal_Int32 GetDate() const
OUString getDate(const Date &rDate) const
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
RegionData_Impl * mpParent
#define LINK(Instance, Class, Member)
Sequence< sal_Int8 > aSeq
std::unique_ptr< sal_Int32[]> pData
void typeConvert(const Date &_rDate, css::util::Date &_rOut)
OUString toId(const void *pValue)
OUString XsResId(TranslateId aId)