2 // Copyright (c) 2010-2013 Yves Langisch. All rights reserved.
3 // http://cyberduck.ch/
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // Bug fixes, suggestions and comments should be sent to:
20 using Ch
.Cyberduck
.Ui
.Winforms
.Taskdialog
;
21 using ch
.cyberduck
.core
;
22 using ch
.cyberduck
.core
.exception
;
23 using ch
.cyberduck
.core
.sftp
;
24 using ch
.cyberduck
.ui
;
26 using org
.apache
.log4j
;
28 namespace Ch
.Cyberduck
.Ui
.Controller
30 public class HostKeyController
: PreferencesHostKeyVerifier
32 private static readonly Logger Log
= Logger
.getLogger(typeof (HostKeyController
).FullName
);
37 private readonly WindowController _parent
;
39 private HostKeyController(WindowController c
)
44 protected override bool isUnknownKeyAccepted(string hostname
, int port
, string serverHostKeyAlgorithm
,
47 if (base.isUnknownKeyAccepted(hostname
, port
, serverHostKeyAlgorithm
, serverHostKey
))
51 AsyncController
.AsyncDelegate d
= delegate
54 String
.Format(LocaleFactory
.localizedString("Unknown host key for {0}."), hostname
),
55 String
.Format(LocaleFactory
.localizedString("Unknown host key for {0}."), hostname
),
57 LocaleFactory
.localizedString(
58 "The host is currently unknown to the system. The host key fingerprint is {0}."),
59 KnownHosts
.createHexFingerprint(serverHostKeyAlgorithm
, serverHostKey
)),
60 String
.Format("{0}|{1}", LocaleFactory
.localizedString("Allow"),
61 LocaleFactory
.localizedString("Deny")), false,
62 LocaleFactory
.localizedString("Always"), SysIcons
.Question
,
63 Preferences
.instance().getProperty("website.help") + "/" + Scheme
.sftp
.name(),
64 delegate(int option
, bool verificationChecked
)
69 allow(hostname
, serverHostKeyAlgorithm
, serverHostKey
, verificationChecked
);
72 Log
.warn("Cannot continue without a valid host key");
73 throw new ConnectionCanceledException();
77 _parent
.Invoke(d
, true);
81 protected override bool isChangedKeyAccepted(string hostname
, int port
, string serverHostKeyAlgorithm
,
84 AsyncController
.AsyncDelegate d
= delegate
87 String
.Format(LocaleFactory
.localizedString("Host key mismatch for {0}"), hostname
),
88 String
.Format(LocaleFactory
.localizedString("Host key mismatch for {0}"), hostname
),
89 String
.Format(LocaleFactory
.localizedString("The host key supplied is {0}."),
90 KnownHosts
.createHexFingerprint(serverHostKeyAlgorithm
, serverHostKey
)),
91 String
.Format("{0}|{1}", LocaleFactory
.localizedString("Allow"),
92 LocaleFactory
.localizedString("Deny")), false,
93 LocaleFactory
.localizedString("Always"), SysIcons
.Warning
,
94 Preferences
.instance().getProperty("website.help") + "/" + Scheme
.sftp
.name(),
95 delegate(int option
, bool verificationChecked
)
100 allow(hostname
, serverHostKeyAlgorithm
, serverHostKey
, verificationChecked
);
103 Log
.warn("Cannot continue without a valid host key");
104 throw new ConnectionCanceledException();
108 _parent
.Invoke(d
, true);
112 public static void Register()
114 HostKeyControllerFactory
.addFactory(ch
.cyberduck
.core
.Factory
.NATIVE_PLATFORM
, new Factory());
117 private class Factory
: HostKeyControllerFactory
119 protected override object create()
124 public override HostKeyCallback
create(ch
.cyberduck
.ui
.Controller c
, Protocol protocol
)
126 if (Scheme
.sftp
.equals(protocol
.getScheme()))
128 return new HostKeyController(c
as WindowController
);
130 return new DisabledHostKeyCallback();