source: filezilla/trunk/fuentes/src/interface/verifyhostkeydialog.cpp @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

File size: 1.7 KB
Line 
1#include <filezilla.h>
2#include "verifyhostkeydialog.h"
3#include <wx/tokenzr.h>
4#include "dialogex.h"
5#include "ipcmutex.h"
6
7std::list<CVerifyHostkeyDialog::t_keyData> CVerifyHostkeyDialog::m_sessionTrustedKeys;
8
9void CVerifyHostkeyDialog::ShowVerificationDialog(wxWindow* parent, CHostKeyNotification& notification)
10{
11        wxDialogEx dlg;
12        bool loaded;
13        if (notification.GetRequestID() == reqId_hostkey)
14                loaded = dlg.Load(parent, _T("ID_HOSTKEY"));
15        else
16                loaded = dlg.Load(parent, _T("ID_HOSTKEYCHANGED"));
17        if (!loaded) {
18                notification.m_trust = false;
19                notification.m_alwaysTrust = false;
20                wxBell();
21                return;
22        }
23
24        dlg.WrapText(&dlg, XRCID("ID_DESC"), 400);
25
26        const wxString host = wxString::Format(_T("%s:%d"), notification.GetHost(), notification.GetPort());
27        dlg.SetChildLabel(XRCID("ID_HOST"), host);
28        dlg.SetChildLabel(XRCID("ID_FINGERPRINT"), notification.GetFingerprint());
29
30        dlg.GetSizer()->Fit(&dlg);
31        dlg.GetSizer()->SetSizeHints(&dlg);
32
33        int res = dlg.ShowModal();
34
35        if (res == wxID_OK) {
36                notification.m_trust = true;
37                notification.m_alwaysTrust = XRCCTRL(dlg, "ID_ALWAYS", wxCheckBox)->GetValue();
38
39                struct t_keyData data;
40                data.host = host;
41                data.fingerprint = notification.GetFingerprint();
42                m_sessionTrustedKeys.push_back(data);
43                return;
44        }
45
46        notification.m_trust = false;
47        notification.m_alwaysTrust = false;
48}
49
50bool CVerifyHostkeyDialog::IsTrusted(CHostKeyNotification const& notification)
51{
52        const wxString host = wxString::Format(_T("%s:%d"), notification.GetHost(), notification.GetPort());
53
54        for(auto const& trusted : m_sessionTrustedKeys ) {
55                if (trusted.host == host && trusted.fingerprint == notification.GetFingerprint())
56                        return true;
57        }
58
59        return false;
60}
Note: See TracBrowser for help on using the repository browser.