2008-08-10 13:10:31 +00:00
|
|
|
#ifndef NO_GSSAPI
|
|
|
|
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
#include <limits.h>
|
2008-11-25 18:54:05 +00:00
|
|
|
#include "putty.h"
|
|
|
|
|
2014-11-01 14:44:16 +00:00
|
|
|
#define SECURITY_WIN32
|
2008-08-10 13:10:31 +00:00
|
|
|
#include <security.h>
|
2008-11-25 18:54:05 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
#include "pgssapi.h"
|
2008-08-10 13:10:31 +00:00
|
|
|
#include "sshgss.h"
|
2010-05-19 18:22:17 +00:00
|
|
|
#include "sshgssc.h"
|
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
#include "misc.h"
|
|
|
|
|
2019-09-08 19:29:00 +00:00
|
|
|
#define UNIX_EPOCH 11644473600ULL /* Seconds from Windows epoch */
|
|
|
|
#define CNS_PERSEC 10000000ULL /* # 100ns per second */
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note, as a special case, 0 relative to the Windows epoch (unspecified) maps
|
|
|
|
* to 0 relative to the POSIX epoch (unspecified)!
|
|
|
|
*/
|
|
|
|
#define TIME_WIN_TO_POSIX(ft, t) do { \
|
|
|
|
ULARGE_INTEGER uli; \
|
|
|
|
uli.LowPart = (ft).dwLowDateTime; \
|
|
|
|
uli.HighPart = (ft).dwHighDateTime; \
|
|
|
|
if (uli.QuadPart != 0) \
|
|
|
|
uli.QuadPart = uli.QuadPart / CNS_PERSEC - UNIX_EPOCH; \
|
|
|
|
(t) = (time_t) uli.QuadPart; \
|
|
|
|
} while(0)
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
/* Windows code to set up the GSSAPI library list. */
|
|
|
|
|
2017-08-04 18:46:21 +00:00
|
|
|
#ifdef _WIN64
|
|
|
|
#define MIT_KERB_SUFFIX "64"
|
|
|
|
#else
|
|
|
|
#define MIT_KERB_SUFFIX "32"
|
|
|
|
#endif
|
|
|
|
|
2010-09-25 07:16:56 +00:00
|
|
|
const int ngsslibs = 3;
|
|
|
|
const char *const gsslibnames[3] = {
|
2017-08-04 18:46:21 +00:00
|
|
|
"MIT Kerberos GSSAPI"MIT_KERB_SUFFIX".DLL",
|
2010-09-25 07:16:56 +00:00
|
|
|
"Microsoft SSPI SECUR32.DLL",
|
|
|
|
"User-specified GSSAPI DLL",
|
2010-05-19 18:22:17 +00:00
|
|
|
};
|
2011-06-25 17:37:31 +00:00
|
|
|
const struct keyvalwhere gsslibkeywords[] = {
|
|
|
|
{ "gssapi32", 0, -1, -1 },
|
|
|
|
{ "sspi", 1, -1, -1 },
|
|
|
|
{ "custom", 2, -1, -1 },
|
2010-05-19 18:22:17 +00:00
|
|
|
};
|
|
|
|
|
2009-11-08 18:47:41 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
|
2019-09-08 19:29:00 +00:00
|
|
|
AcquireCredentialsHandleA,
|
|
|
|
(SEC_CHAR *, SEC_CHAR *, ULONG, PVOID,
|
|
|
|
PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp));
|
2009-11-08 18:47:41 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
|
2019-09-08 19:29:00 +00:00
|
|
|
InitializeSecurityContextA,
|
|
|
|
(PCredHandle, PCtxtHandle, SEC_CHAR *, ULONG, ULONG,
|
|
|
|
ULONG, PSecBufferDesc, ULONG, PCtxtHandle,
|
|
|
|
PSecBufferDesc, PULONG, PTimeStamp));
|
2009-11-08 18:47:41 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
|
2019-09-08 19:29:00 +00:00
|
|
|
FreeContextBuffer,
|
|
|
|
(PVOID));
|
2009-11-08 18:47:41 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
|
2019-09-08 19:29:00 +00:00
|
|
|
FreeCredentialsHandle,
|
|
|
|
(PCredHandle));
|
2009-11-08 18:47:41 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
|
2019-09-08 19:29:00 +00:00
|
|
|
DeleteSecurityContext,
|
|
|
|
(PCtxtHandle));
|
2009-11-08 18:47:41 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
|
2019-09-08 19:29:00 +00:00
|
|
|
QueryContextAttributesA,
|
|
|
|
(PCtxtHandle, ULONG, PVOID));
|
2009-11-08 18:47:41 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
|
2019-09-08 19:29:00 +00:00
|
|
|
MakeSignature,
|
|
|
|
(PCtxtHandle, ULONG, PSecBufferDesc, ULONG));
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(static, SECURITY_STATUS,
|
|
|
|
VerifySignature,
|
|
|
|
(PCtxtHandle, PSecBufferDesc, ULONG, PULONG));
|
2017-04-03 19:30:18 +00:00
|
|
|
DECL_WINDOWS_FUNCTION(static, DLL_DIRECTORY_COOKIE,
|
|
|
|
AddDllDirectory,
|
|
|
|
(PCWSTR));
|
2008-08-10 13:10:31 +00:00
|
|
|
|
|
|
|
typedef struct winSsh_gss_ctx {
|
|
|
|
unsigned long maj_stat;
|
|
|
|
unsigned long min_stat;
|
|
|
|
CredHandle cred_handle;
|
|
|
|
CtxtHandle context;
|
|
|
|
PCtxtHandle context_handle;
|
|
|
|
TimeStamp expiry;
|
|
|
|
} winSsh_gss_ctx;
|
|
|
|
|
|
|
|
|
|
|
|
const Ssh_gss_buf gss_mech_krb5={9,"\x2A\x86\x48\x86\xF7\x12\x01\x02\x02"};
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
const char *gsslogmsg = NULL;
|
|
|
|
|
|
|
|
static void ssh_sspi_bind_fns(struct ssh_gss_library *lib);
|
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
struct ssh_gss_liblist *ssh_gss_setup(Conf *conf)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
2010-05-19 18:22:17 +00:00
|
|
|
HMODULE module;
|
2010-09-25 07:16:56 +00:00
|
|
|
HKEY regkey;
|
|
|
|
struct ssh_gss_liblist *list = snew(struct ssh_gss_liblist);
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
char *path;
|
2017-04-03 19:30:18 +00:00
|
|
|
static HMODULE kernel32_module;
|
|
|
|
if (!kernel32_module) {
|
|
|
|
kernel32_module = load_system32_dll("kernel32.dll");
|
|
|
|
}
|
Add automatic type-checking to GET_WINDOWS_FUNCTION.
This gives me an extra safety-check against having mistyped one of the
function prototypes that we load at run time from DLLs: we verify that
the typedef we defined based on the prototype in our source code
matches the type of the real function as declared in the Windows
headers.
This was an idea I had while adding a pile of further functions using
this mechanism. It didn't catch any errors (either in the new
functions or in the existing collection), but that's no reason not to
keep it anyway now that I've thought of it!
In VS2015, this automated type-check works for most functions, but a
couple manage to break it. SetCurrentProcessExplicitAppUserModelID in
winjump.c can't be type-checked, because including <shobjidl.h> where
that function is declared would also bring in a load of other stuff
that conflicts with the painful manual COM declarations in winjump.c.
(That stuff could probably be removed now we're on an up-to-date
Visual Studio, on the other hand, but that's a separate chore.) And
gai_strerror, used in winnet.c, does _have_ an implementation in a
DLL, but the header files like to provide an inline version with a
different calling convention, which defeats this error-checking trick.
And in the older VS2003 that we still precautionarily build with,
several more type-checks have to be #ifdeffed out because the
functions they check against just aren't there at all.
2017-04-11 17:56:55 +00:00
|
|
|
#if defined _MSC_VER && _MSC_VER < 1900
|
|
|
|
/* Omit the type-check because older MSVCs don't have this function */
|
|
|
|
GET_WINDOWS_FUNCTION_NO_TYPECHECK(kernel32_module, AddDllDirectory);
|
|
|
|
#else
|
2017-04-03 19:30:18 +00:00
|
|
|
GET_WINDOWS_FUNCTION(kernel32_module, AddDllDirectory);
|
Add automatic type-checking to GET_WINDOWS_FUNCTION.
This gives me an extra safety-check against having mistyped one of the
function prototypes that we load at run time from DLLs: we verify that
the typedef we defined based on the prototype in our source code
matches the type of the real function as declared in the Windows
headers.
This was an idea I had while adding a pile of further functions using
this mechanism. It didn't catch any errors (either in the new
functions or in the existing collection), but that's no reason not to
keep it anyway now that I've thought of it!
In VS2015, this automated type-check works for most functions, but a
couple manage to break it. SetCurrentProcessExplicitAppUserModelID in
winjump.c can't be type-checked, because including <shobjidl.h> where
that function is declared would also bring in a load of other stuff
that conflicts with the painful manual COM declarations in winjump.c.
(That stuff could probably be removed now we're on an up-to-date
Visual Studio, on the other hand, but that's a separate chore.) And
gai_strerror, used in winnet.c, does _have_ an implementation in a
DLL, but the header files like to provide an inline version with a
different calling convention, which defeats this error-checking trick.
And in the older VS2003 that we still precautionarily build with,
several more type-checks have to be #ifdeffed out because the
functions they check against just aren't there at all.
2017-04-11 17:56:55 +00:00
|
|
|
#endif
|
2010-05-19 18:22:17 +00:00
|
|
|
|
2010-09-25 07:16:56 +00:00
|
|
|
list->libraries = snewn(3, struct ssh_gss_library);
|
|
|
|
list->nlibraries = 0;
|
2010-05-19 18:22:17 +00:00
|
|
|
|
|
|
|
/* MIT Kerberos GSSAPI implementation */
|
2010-09-25 07:16:56 +00:00
|
|
|
module = NULL;
|
|
|
|
if (RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\MIT\\Kerberos", ®key)
|
2019-09-08 19:29:00 +00:00
|
|
|
== ERROR_SUCCESS) {
|
|
|
|
DWORD type, size;
|
|
|
|
LONG ret;
|
|
|
|
char *buffer;
|
2010-09-25 07:16:56 +00:00
|
|
|
|
2019-09-08 19:29:00 +00:00
|
|
|
/* Find out the string length */
|
2010-09-25 07:16:56 +00:00
|
|
|
ret = RegQueryValueEx(regkey, "InstallDir", NULL, &type, NULL, &size);
|
|
|
|
|
2019-09-08 19:29:00 +00:00
|
|
|
if (ret == ERROR_SUCCESS && type == REG_SZ) {
|
|
|
|
buffer = snewn(size + 20, char);
|
|
|
|
ret = RegQueryValueEx(regkey, "InstallDir", NULL,
|
|
|
|
&type, (LPBYTE)buffer, &size);
|
|
|
|
if (ret == ERROR_SUCCESS && type == REG_SZ) {
|
2017-04-03 19:30:18 +00:00
|
|
|
strcat (buffer, "\\bin");
|
|
|
|
if(p_AddDllDirectory) {
|
|
|
|
/* Add MIT Kerberos' path to the DLL search path,
|
|
|
|
* it loads its own DLLs further down the road */
|
|
|
|
wchar_t *dllPath =
|
|
|
|
dup_mb_to_wc(DEFAULT_CODEPAGE, 0, buffer);
|
|
|
|
p_AddDllDirectory(dllPath);
|
|
|
|
sfree(dllPath);
|
|
|
|
}
|
2017-08-04 18:46:21 +00:00
|
|
|
strcat (buffer, "\\gssapi"MIT_KERB_SUFFIX".dll");
|
2017-04-03 19:30:18 +00:00
|
|
|
module = LoadLibraryEx (buffer, NULL,
|
|
|
|
LOAD_LIBRARY_SEARCH_SYSTEM32 |
|
|
|
|
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
|
|
|
|
LOAD_LIBRARY_SEARCH_USER_DIRS);
|
2019-09-08 19:29:00 +00:00
|
|
|
}
|
|
|
|
sfree(buffer);
|
|
|
|
}
|
|
|
|
RegCloseKey(regkey);
|
2010-09-25 07:16:56 +00:00
|
|
|
}
|
2010-05-19 18:22:17 +00:00
|
|
|
if (module) {
|
2019-09-08 19:29:00 +00:00
|
|
|
struct ssh_gss_library *lib =
|
|
|
|
&list->libraries[list->nlibraries++];
|
2010-05-19 18:22:17 +00:00
|
|
|
|
2019-09-08 19:29:00 +00:00
|
|
|
lib->id = 0;
|
|
|
|
lib->gsslogmsg = "Using GSSAPI from GSSAPI"MIT_KERB_SUFFIX".DLL";
|
|
|
|
lib->handle = (void *)module;
|
2010-05-19 18:22:17 +00:00
|
|
|
|
|
|
|
#define BIND_GSS_FN(name) \
|
|
|
|
lib->u.gssapi.name = (t_gss_##name) GetProcAddress(module, "gss_" #name)
|
|
|
|
|
|
|
|
BIND_GSS_FN(delete_sec_context);
|
|
|
|
BIND_GSS_FN(display_status);
|
|
|
|
BIND_GSS_FN(get_mic);
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
BIND_GSS_FN(verify_mic);
|
2010-05-19 18:22:17 +00:00
|
|
|
BIND_GSS_FN(import_name);
|
|
|
|
BIND_GSS_FN(init_sec_context);
|
|
|
|
BIND_GSS_FN(release_buffer);
|
|
|
|
BIND_GSS_FN(release_cred);
|
|
|
|
BIND_GSS_FN(release_name);
|
2019-03-19 09:18:37 +00:00
|
|
|
BIND_GSS_FN(acquire_cred);
|
|
|
|
BIND_GSS_FN(inquire_cred_by_mech);
|
2010-05-19 18:22:17 +00:00
|
|
|
|
|
|
|
#undef BIND_GSS_FN
|
|
|
|
|
|
|
|
ssh_gssapi_bind_fns(lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Microsoft SSPI Implementation */
|
2010-09-13 08:29:45 +00:00
|
|
|
module = load_system32_dll("secur32.dll");
|
2010-05-19 18:22:17 +00:00
|
|
|
if (module) {
|
2019-09-08 19:29:00 +00:00
|
|
|
struct ssh_gss_library *lib =
|
|
|
|
&list->libraries[list->nlibraries++];
|
|
|
|
|
|
|
|
lib->id = 1;
|
|
|
|
lib->gsslogmsg = "Using SSPI from SECUR32.DLL";
|
|
|
|
lib->handle = (void *)module;
|
|
|
|
|
|
|
|
GET_WINDOWS_FUNCTION(module, AcquireCredentialsHandleA);
|
|
|
|
GET_WINDOWS_FUNCTION(module, InitializeSecurityContextA);
|
|
|
|
GET_WINDOWS_FUNCTION(module, FreeContextBuffer);
|
|
|
|
GET_WINDOWS_FUNCTION(module, FreeCredentialsHandle);
|
|
|
|
GET_WINDOWS_FUNCTION(module, DeleteSecurityContext);
|
|
|
|
GET_WINDOWS_FUNCTION(module, QueryContextAttributesA);
|
|
|
|
GET_WINDOWS_FUNCTION(module, MakeSignature);
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
GET_WINDOWS_FUNCTION(module, VerifySignature);
|
2010-05-19 18:22:17 +00:00
|
|
|
|
2019-09-08 19:29:00 +00:00
|
|
|
ssh_sspi_bind_fns(lib);
|
2008-08-10 13:10:31 +00:00
|
|
|
}
|
2010-09-25 07:16:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Custom GSSAPI DLL.
|
|
|
|
*/
|
|
|
|
module = NULL;
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
path = conf_get_filename(conf, CONF_ssh_gss_custom)->path;
|
|
|
|
if (*path) {
|
2017-04-03 19:30:18 +00:00
|
|
|
if(p_AddDllDirectory) {
|
|
|
|
/* Add the custom directory as well in case it chainloads
|
|
|
|
* some other DLLs (e.g a non-installed MIT Kerberos
|
|
|
|
* instance) */
|
|
|
|
int pathlen = strlen(path);
|
|
|
|
|
|
|
|
while (pathlen > 0 && path[pathlen-1] != ':' &&
|
|
|
|
path[pathlen-1] != '\\')
|
|
|
|
pathlen--;
|
|
|
|
|
|
|
|
if (pathlen > 0 && path[pathlen-1] != '\\')
|
|
|
|
pathlen--;
|
|
|
|
|
|
|
|
if (pathlen > 0) {
|
|
|
|
char *dirpath = dupprintf("%.*s", pathlen, path);
|
|
|
|
wchar_t *dllPath = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, dirpath);
|
|
|
|
p_AddDllDirectory(dllPath);
|
|
|
|
sfree(dllPath);
|
|
|
|
sfree(dirpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module = LoadLibraryEx(path, NULL,
|
|
|
|
LOAD_LIBRARY_SEARCH_SYSTEM32 |
|
|
|
|
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
|
|
|
|
LOAD_LIBRARY_SEARCH_USER_DIRS);
|
2010-09-25 07:16:56 +00:00
|
|
|
}
|
|
|
|
if (module) {
|
2019-09-08 19:29:00 +00:00
|
|
|
struct ssh_gss_library *lib =
|
|
|
|
&list->libraries[list->nlibraries++];
|
2010-09-25 07:16:56 +00:00
|
|
|
|
2019-09-08 19:29:00 +00:00
|
|
|
lib->id = 2;
|
|
|
|
lib->gsslogmsg = dupprintf("Using GSSAPI from user-specified"
|
|
|
|
" library '%s'", path);
|
|
|
|
lib->handle = (void *)module;
|
2010-09-25 07:16:56 +00:00
|
|
|
|
|
|
|
#define BIND_GSS_FN(name) \
|
|
|
|
lib->u.gssapi.name = (t_gss_##name) GetProcAddress(module, "gss_" #name)
|
|
|
|
|
|
|
|
BIND_GSS_FN(delete_sec_context);
|
|
|
|
BIND_GSS_FN(display_status);
|
|
|
|
BIND_GSS_FN(get_mic);
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
BIND_GSS_FN(verify_mic);
|
2010-09-25 07:16:56 +00:00
|
|
|
BIND_GSS_FN(import_name);
|
|
|
|
BIND_GSS_FN(init_sec_context);
|
|
|
|
BIND_GSS_FN(release_buffer);
|
|
|
|
BIND_GSS_FN(release_cred);
|
|
|
|
BIND_GSS_FN(release_name);
|
2019-03-19 09:18:37 +00:00
|
|
|
BIND_GSS_FN(acquire_cred);
|
|
|
|
BIND_GSS_FN(inquire_cred_by_mech);
|
2010-09-25 07:16:56 +00:00
|
|
|
|
|
|
|
#undef BIND_GSS_FN
|
|
|
|
|
|
|
|
ssh_gssapi_bind_fns(lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ssh_gss_cleanup(struct ssh_gss_liblist *list)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LoadLibrary and FreeLibrary are defined to employ reference
|
|
|
|
* counting in the case where the same library is repeatedly
|
|
|
|
* loaded, so even in a multiple-sessions-per-process context
|
|
|
|
* (not that we currently expect ever to have such a thing on
|
|
|
|
* Windows) it's safe to naively FreeLibrary everything here
|
|
|
|
* without worrying about destroying it under the feet of
|
|
|
|
* another SSH instance still using it.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < list->nlibraries; i++) {
|
2019-09-08 19:29:00 +00:00
|
|
|
FreeLibrary((HMODULE)list->libraries[i].handle);
|
|
|
|
if (list->libraries[i].id == 2) {
|
|
|
|
/* The 'custom' id involves a dynamically allocated message.
|
|
|
|
* Note that we must cast away the 'const' to free it. */
|
|
|
|
sfree((char *)list->libraries[i].gsslogmsg);
|
|
|
|
}
|
2010-09-25 07:16:56 +00:00
|
|
|
}
|
|
|
|
sfree(list->libraries);
|
|
|
|
sfree(list);
|
2008-08-10 13:10:31 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_indicate_mech(struct ssh_gss_library *lib,
|
2019-09-08 19:29:00 +00:00
|
|
|
Ssh_gss_buf *mech)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
*mech = gss_mech_krb5;
|
|
|
|
return SSH_GSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_import_name(struct ssh_gss_library *lib,
|
2019-09-08 19:29:00 +00:00
|
|
|
char *host, Ssh_gss_name *srv_name)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
char *pStr;
|
|
|
|
|
|
|
|
/* Check hostname */
|
|
|
|
if (host == NULL) return SSH_GSS_FAILURE;
|
2019-09-08 19:29:00 +00:00
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
/* copy it into form host/FQDN */
|
Make dupcat() into a variadic macro.
Up until now, it's been a variadic _function_, whose argument list
consists of 'const char *' ASCIZ strings to concatenate, terminated by
one containing a null pointer. Now, that function is dupcat_fn(), and
it's wrapped by a C99 variadic _macro_ called dupcat(), which
automatically suffixes the null-pointer terminating argument.
This has three benefits. Firstly, it's just less effort at every call
site. Secondly, it protects against the risk of accidentally leaving
off the NULL, causing arbitrary words of stack memory to be
dereferenced as char pointers. And thirdly, it protects against the
more subtle risk of writing a bare 'NULL' as the terminating argument,
instead of casting it explicitly to a pointer. That last one is
necessary because C permits the macro NULL to expand to an integer
constant such as 0, so NULL by itself may not have pointer type, and
worse, it may not be marshalled in a variadic argument list in the
same way as a pointer. (For example, on a 64-bit machine it might only
occupy 32 bits. And yet, on another 64-bit platform, it might work
just fine, so that you don't notice the mistake!)
I was inspired to do this by happening to notice one of those bare
NULL terminators, and thinking I'd better check if there were any
more. Turned out there were quite a few. Now there are none.
2019-10-14 18:42:37 +00:00
|
|
|
pStr = dupcat("host/", host);
|
2008-08-10 13:10:31 +00:00
|
|
|
|
|
|
|
*srv_name = (Ssh_gss_name) pStr;
|
|
|
|
|
|
|
|
return SSH_GSS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_acquire_cred(struct ssh_gss_library *lib,
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
Ssh_gss_ctx *ctx,
|
|
|
|
time_t *expiry)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
winSsh_gss_ctx *winctx = snew(winSsh_gss_ctx);
|
2008-10-17 20:55:08 +00:00
|
|
|
memset(winctx, 0, sizeof(winSsh_gss_ctx));
|
2008-08-10 13:10:31 +00:00
|
|
|
|
|
|
|
/* prepare our "wrapper" structure */
|
|
|
|
winctx->maj_stat = winctx->min_stat = SEC_E_OK;
|
|
|
|
winctx->context_handle = NULL;
|
|
|
|
|
|
|
|
/* Specifying no principal name here means use the credentials of
|
|
|
|
the current logged-in user */
|
|
|
|
|
|
|
|
winctx->maj_stat = p_AcquireCredentialsHandleA(NULL,
|
2019-09-08 19:29:00 +00:00
|
|
|
"Kerberos",
|
|
|
|
SECPKG_CRED_OUTBOUND,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&winctx->cred_handle,
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (winctx->maj_stat != SEC_E_OK) {
|
|
|
|
p_FreeCredentialsHandle(&winctx->cred_handle);
|
|
|
|
sfree(winctx);
|
|
|
|
return SSH_GSS_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Windows does not return a valid expiration from AcquireCredentials */
|
|
|
|
if (expiry)
|
|
|
|
*expiry = GSS_NO_EXPIRATION;
|
2008-08-10 13:10:31 +00:00
|
|
|
|
|
|
|
*ctx = (Ssh_gss_ctx) winctx;
|
|
|
|
return SSH_GSS_OK;
|
|
|
|
}
|
|
|
|
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
static void localexp_to_exp_lifetime(TimeStamp *localexp,
|
|
|
|
time_t *expiry, unsigned long *lifetime)
|
|
|
|
{
|
|
|
|
FILETIME nowUTC;
|
|
|
|
FILETIME expUTC;
|
|
|
|
time_t now;
|
|
|
|
time_t exp;
|
|
|
|
time_t delta;
|
|
|
|
|
|
|
|
if (!lifetime && !expiry)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GetSystemTimeAsFileTime(&nowUTC);
|
|
|
|
TIME_WIN_TO_POSIX(nowUTC, now);
|
|
|
|
|
|
|
|
if (lifetime)
|
|
|
|
*lifetime = 0;
|
|
|
|
if (expiry)
|
|
|
|
*expiry = GSS_NO_EXPIRATION;
|
|
|
|
|
2018-06-03 13:53:29 +00:00
|
|
|
/*
|
|
|
|
* Type oddity: localexp is a pointer to 'TimeStamp', whereas
|
|
|
|
* LocalFileTimeToFileTime expects a pointer to FILETIME. However,
|
|
|
|
* despite having different formal type names from the compiler's
|
|
|
|
* point of view, these two structures are specified to be
|
|
|
|
* isomorphic in the MS documentation, so it's legitimate to copy
|
|
|
|
* between them:
|
|
|
|
*
|
|
|
|
* https://msdn.microsoft.com/en-us/library/windows/desktop/aa380511(v=vs.85).aspx
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
FILETIME localexp_ft;
|
|
|
|
enum { vorpal_sword = 1 / (sizeof(*localexp) == sizeof(localexp_ft)) };
|
|
|
|
memcpy(&localexp_ft, localexp, sizeof(localexp_ft));
|
|
|
|
if (!LocalFileTimeToFileTime(&localexp_ft, &expUTC))
|
|
|
|
return;
|
|
|
|
}
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
|
|
|
|
TIME_WIN_TO_POSIX(expUTC, exp);
|
|
|
|
delta = exp - now;
|
|
|
|
if (exp == 0 || delta <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (expiry)
|
|
|
|
*expiry = exp;
|
|
|
|
if (lifetime) {
|
|
|
|
if (delta <= ULONG_MAX)
|
|
|
|
*lifetime = (unsigned long)delta;
|
|
|
|
else
|
|
|
|
*lifetime = ULONG_MAX;
|
|
|
|
}
|
|
|
|
}
|
2008-08-10 13:10:31 +00:00
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_init_sec_context(struct ssh_gss_library *lib,
|
2019-09-08 19:29:00 +00:00
|
|
|
Ssh_gss_ctx *ctx,
|
|
|
|
Ssh_gss_name srv_name,
|
|
|
|
int to_deleg,
|
|
|
|
Ssh_gss_buf *recv_tok,
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
Ssh_gss_buf *send_tok,
|
|
|
|
time_t *expiry,
|
|
|
|
unsigned long *lifetime)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
winSsh_gss_ctx *winctx = (winSsh_gss_ctx *) *ctx;
|
2008-11-24 23:44:55 +00:00
|
|
|
SecBuffer wsend_tok = {send_tok->length,SECBUFFER_TOKEN,send_tok->value};
|
|
|
|
SecBuffer wrecv_tok = {recv_tok->length,SECBUFFER_TOKEN,recv_tok->value};
|
2008-08-10 13:10:31 +00:00
|
|
|
SecBufferDesc output_desc={SECBUFFER_VERSION,1,&wsend_tok};
|
|
|
|
SecBufferDesc input_desc ={SECBUFFER_VERSION,1,&wrecv_tok};
|
|
|
|
unsigned long flags=ISC_REQ_MUTUAL_AUTH|ISC_REQ_REPLAY_DETECT|
|
2019-09-08 19:29:00 +00:00
|
|
|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_ALLOCATE_MEMORY;
|
2008-08-10 13:10:31 +00:00
|
|
|
unsigned long ret_flags=0;
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
TimeStamp localexp;
|
2019-09-08 19:29:00 +00:00
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
/* check if we have to delegate ... */
|
|
|
|
if (to_deleg) flags |= ISC_REQ_DELEGATE;
|
|
|
|
winctx->maj_stat = p_InitializeSecurityContextA(&winctx->cred_handle,
|
2019-09-08 19:29:00 +00:00
|
|
|
winctx->context_handle,
|
|
|
|
(char*) srv_name,
|
|
|
|
flags,
|
|
|
|
0, /* reserved */
|
|
|
|
SECURITY_NATIVE_DREP,
|
|
|
|
&input_desc,
|
|
|
|
0, /* reserved */
|
|
|
|
&winctx->context,
|
|
|
|
&output_desc,
|
|
|
|
&ret_flags,
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
&localexp);
|
|
|
|
|
|
|
|
localexp_to_exp_lifetime(&localexp, expiry, lifetime);
|
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
/* prepare for the next round */
|
|
|
|
winctx->context_handle = &winctx->context;
|
2008-11-24 23:44:55 +00:00
|
|
|
send_tok->value = wsend_tok.pvBuffer;
|
|
|
|
send_tok->length = wsend_tok.cbBuffer;
|
2019-09-08 19:29:00 +00:00
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
/* check & return our status */
|
|
|
|
if (winctx->maj_stat==SEC_E_OK) return SSH_GSS_S_COMPLETE;
|
|
|
|
if (winctx->maj_stat==SEC_I_CONTINUE_NEEDED) return SSH_GSS_S_CONTINUE_NEEDED;
|
2019-09-08 19:29:00 +00:00
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
return SSH_GSS_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_free_tok(struct ssh_gss_library *lib,
|
2019-09-08 19:29:00 +00:00
|
|
|
Ssh_gss_buf *send_tok)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
/* check input */
|
|
|
|
if (send_tok == NULL) return SSH_GSS_FAILURE;
|
|
|
|
|
|
|
|
/* free Windows buffer */
|
2008-11-24 23:44:55 +00:00
|
|
|
p_FreeContextBuffer(send_tok->value);
|
|
|
|
SSH_GSS_CLEAR_BUF(send_tok);
|
2019-09-08 19:29:00 +00:00
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
return SSH_GSS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_release_cred(struct ssh_gss_library *lib,
|
2019-09-08 19:29:00 +00:00
|
|
|
Ssh_gss_ctx *ctx)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
winSsh_gss_ctx *winctx= (winSsh_gss_ctx *) *ctx;
|
|
|
|
|
|
|
|
/* check input */
|
|
|
|
if (winctx == NULL) return SSH_GSS_FAILURE;
|
|
|
|
|
|
|
|
/* free Windows data */
|
|
|
|
p_FreeCredentialsHandle(&winctx->cred_handle);
|
|
|
|
p_DeleteSecurityContext(&winctx->context);
|
|
|
|
|
|
|
|
/* delete our "wrapper" structure */
|
|
|
|
sfree(winctx);
|
|
|
|
*ctx = (Ssh_gss_ctx) NULL;
|
|
|
|
|
|
|
|
return SSH_GSS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_release_name(struct ssh_gss_library *lib,
|
2019-09-08 19:29:00 +00:00
|
|
|
Ssh_gss_name *srv_name)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
char *pStr= (char *) *srv_name;
|
|
|
|
|
|
|
|
if (pStr == NULL) return SSH_GSS_FAILURE;
|
|
|
|
sfree(pStr);
|
|
|
|
*srv_name = (Ssh_gss_name) NULL;
|
|
|
|
|
|
|
|
return SSH_GSS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_display_status(struct ssh_gss_library *lib,
|
2019-09-08 19:29:00 +00:00
|
|
|
Ssh_gss_ctx ctx, Ssh_gss_buf *buf)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
winSsh_gss_ctx *winctx = (winSsh_gss_ctx *) ctx;
|
2015-05-15 10:15:42 +00:00
|
|
|
const char *msg;
|
2008-08-10 13:10:31 +00:00
|
|
|
|
|
|
|
if (winctx == NULL) return SSH_GSS_FAILURE;
|
|
|
|
|
|
|
|
/* decode the error code */
|
|
|
|
switch (winctx->maj_stat) {
|
|
|
|
case SEC_E_OK: msg="SSPI status OK"; break;
|
|
|
|
case SEC_E_INVALID_HANDLE: msg="The handle passed to the function"
|
2019-09-08 19:29:00 +00:00
|
|
|
" is invalid.";
|
|
|
|
break;
|
2008-08-10 13:10:31 +00:00
|
|
|
case SEC_E_TARGET_UNKNOWN: msg="The target was not recognized."; break;
|
|
|
|
case SEC_E_LOGON_DENIED: msg="The logon failed."; break;
|
|
|
|
case SEC_E_INTERNAL_ERROR: msg="The Local Security Authority cannot"
|
2019-09-08 19:29:00 +00:00
|
|
|
" be contacted.";
|
|
|
|
break;
|
2008-08-10 13:10:31 +00:00
|
|
|
case SEC_E_NO_CREDENTIALS: msg="No credentials are available in the"
|
2019-09-08 19:29:00 +00:00
|
|
|
" security package.";
|
|
|
|
break;
|
2008-08-10 13:10:31 +00:00
|
|
|
case SEC_E_NO_AUTHENTICATING_AUTHORITY:
|
2019-09-08 19:29:00 +00:00
|
|
|
msg="No authority could be contacted for authentication."
|
|
|
|
"The domain name of the authenticating party could be wrong,"
|
|
|
|
" the domain could be unreachable, or there might have been"
|
|
|
|
" a trust relationship failure.";
|
|
|
|
break;
|
2008-08-10 13:10:31 +00:00
|
|
|
case SEC_E_INSUFFICIENT_MEMORY:
|
2019-09-08 19:29:00 +00:00
|
|
|
msg="One or more of the SecBufferDesc structures passed as"
|
|
|
|
" an OUT parameter has a buffer that is too small.";
|
|
|
|
break;
|
2008-08-10 13:10:31 +00:00
|
|
|
case SEC_E_INVALID_TOKEN:
|
2019-09-08 19:29:00 +00:00
|
|
|
msg="The error is due to a malformed input token, such as a"
|
|
|
|
" token corrupted in transit, a token"
|
|
|
|
" of incorrect size, or a token passed into the wrong"
|
|
|
|
" security package. Passing a token to"
|
|
|
|
" the wrong package can happen if client and server did not"
|
|
|
|
" negotiate the proper security package.";
|
|
|
|
break;
|
2008-08-10 13:10:31 +00:00
|
|
|
default:
|
2019-09-08 19:29:00 +00:00
|
|
|
msg = "Internal SSPI error";
|
|
|
|
break;
|
2008-08-10 13:10:31 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 23:44:55 +00:00
|
|
|
buf->value = dupstr(msg);
|
2008-11-26 14:11:49 +00:00
|
|
|
buf->length = strlen(buf->value);
|
2019-09-08 19:29:00 +00:00
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
return SSH_GSS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_get_mic(struct ssh_gss_library *lib,
|
2019-09-08 19:29:00 +00:00
|
|
|
Ssh_gss_ctx ctx, Ssh_gss_buf *buf,
|
|
|
|
Ssh_gss_buf *hash)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
winSsh_gss_ctx *winctx= (winSsh_gss_ctx *) ctx;
|
|
|
|
SecPkgContext_Sizes ContextSizes;
|
|
|
|
SecBufferDesc InputBufferDescriptor;
|
|
|
|
SecBuffer InputSecurityToken[2];
|
|
|
|
|
|
|
|
if (winctx == NULL) return SSH_GSS_FAILURE;
|
2019-09-08 19:29:00 +00:00
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
winctx->maj_stat = 0;
|
|
|
|
|
|
|
|
memset(&ContextSizes, 0, sizeof(ContextSizes));
|
|
|
|
|
|
|
|
winctx->maj_stat = p_QueryContextAttributesA(&winctx->context,
|
2019-09-08 19:29:00 +00:00
|
|
|
SECPKG_ATTR_SIZES,
|
|
|
|
&ContextSizes);
|
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
if (winctx->maj_stat != SEC_E_OK ||
|
2019-09-08 19:29:00 +00:00
|
|
|
ContextSizes.cbMaxSignature == 0)
|
|
|
|
return winctx->maj_stat;
|
2008-08-10 13:10:31 +00:00
|
|
|
|
|
|
|
InputBufferDescriptor.cBuffers = 2;
|
|
|
|
InputBufferDescriptor.pBuffers = InputSecurityToken;
|
|
|
|
InputBufferDescriptor.ulVersion = SECBUFFER_VERSION;
|
|
|
|
InputSecurityToken[0].BufferType = SECBUFFER_DATA;
|
2008-11-24 23:44:55 +00:00
|
|
|
InputSecurityToken[0].cbBuffer = buf->length;
|
|
|
|
InputSecurityToken[0].pvBuffer = buf->value;
|
2008-08-10 13:10:31 +00:00
|
|
|
InputSecurityToken[1].BufferType = SECBUFFER_TOKEN;
|
|
|
|
InputSecurityToken[1].cbBuffer = ContextSizes.cbMaxSignature;
|
|
|
|
InputSecurityToken[1].pvBuffer = snewn(ContextSizes.cbMaxSignature, char);
|
|
|
|
|
|
|
|
winctx->maj_stat = p_MakeSignature(&winctx->context,
|
2019-09-08 19:29:00 +00:00
|
|
|
0,
|
|
|
|
&InputBufferDescriptor,
|
|
|
|
0);
|
2008-08-10 13:10:31 +00:00
|
|
|
|
|
|
|
if (winctx->maj_stat == SEC_E_OK) {
|
2019-09-08 19:29:00 +00:00
|
|
|
hash->length = InputSecurityToken[1].cbBuffer;
|
|
|
|
hash->value = InputSecurityToken[1].pvBuffer;
|
2008-08-10 13:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return winctx->maj_stat;
|
|
|
|
}
|
|
|
|
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_verify_mic(struct ssh_gss_library *lib,
|
|
|
|
Ssh_gss_ctx ctx,
|
|
|
|
Ssh_gss_buf *buf,
|
|
|
|
Ssh_gss_buf *mic)
|
|
|
|
{
|
|
|
|
winSsh_gss_ctx *winctx= (winSsh_gss_ctx *) ctx;
|
|
|
|
SecBufferDesc InputBufferDescriptor;
|
|
|
|
SecBuffer InputSecurityToken[2];
|
|
|
|
ULONG qop;
|
|
|
|
|
|
|
|
if (winctx == NULL) return SSH_GSS_FAILURE;
|
|
|
|
|
|
|
|
winctx->maj_stat = 0;
|
|
|
|
|
|
|
|
InputBufferDescriptor.cBuffers = 2;
|
|
|
|
InputBufferDescriptor.pBuffers = InputSecurityToken;
|
|
|
|
InputBufferDescriptor.ulVersion = SECBUFFER_VERSION;
|
|
|
|
InputSecurityToken[0].BufferType = SECBUFFER_DATA;
|
|
|
|
InputSecurityToken[0].cbBuffer = buf->length;
|
|
|
|
InputSecurityToken[0].pvBuffer = buf->value;
|
|
|
|
InputSecurityToken[1].BufferType = SECBUFFER_TOKEN;
|
|
|
|
InputSecurityToken[1].cbBuffer = mic->length;
|
|
|
|
InputSecurityToken[1].pvBuffer = mic->value;
|
|
|
|
|
|
|
|
winctx->maj_stat = p_VerifySignature(&winctx->context,
|
|
|
|
&InputBufferDescriptor,
|
|
|
|
0, &qop);
|
|
|
|
return winctx->maj_stat;
|
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static Ssh_gss_stat ssh_sspi_free_mic(struct ssh_gss_library *lib,
|
2019-09-08 19:29:00 +00:00
|
|
|
Ssh_gss_buf *hash)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
2008-11-24 23:44:55 +00:00
|
|
|
sfree(hash->value);
|
2008-08-10 13:10:31 +00:00
|
|
|
return SSH_GSS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
static void ssh_sspi_bind_fns(struct ssh_gss_library *lib)
|
|
|
|
{
|
|
|
|
lib->indicate_mech = ssh_sspi_indicate_mech;
|
|
|
|
lib->import_name = ssh_sspi_import_name;
|
|
|
|
lib->release_name = ssh_sspi_release_name;
|
|
|
|
lib->init_sec_context = ssh_sspi_init_sec_context;
|
|
|
|
lib->free_tok = ssh_sspi_free_tok;
|
|
|
|
lib->acquire_cred = ssh_sspi_acquire_cred;
|
|
|
|
lib->release_cred = ssh_sspi_release_cred;
|
|
|
|
lib->get_mic = ssh_sspi_get_mic;
|
Support GSS key exchange, for Kerberos 5 only.
This is a heavily edited (by me) version of a patch originally due to
Nico Williams and Viktor Dukhovni. Their comments:
* Don't delegate credentials when rekeying unless there's a new TGT
or the old service ticket is nearly expired.
* Check for the above conditions more frequently (every two minutes
by default) and rekey when we would delegate credentials.
* Do not rekey with very short service ticket lifetimes; some GSSAPI
libraries may lose the race to use an almost expired ticket. Adjust
the timing of rekey checks to try to avoid this possibility.
My further comments:
The most interesting thing about this patch to me is that the use of
GSS key exchange causes a switch over to a completely different model
of what host keys are for. This comes from RFC 4462 section 2.1: the
basic idea is that when your session is mostly bidirectionally
authenticated by the GSSAPI exchanges happening in initial kex and
every rekey, host keys become more or less vestigial, and their
remaining purpose is to allow a rekey to happen if the requirements of
the SSH protocol demand it at an awkward moment when the GSS
credentials are not currently available (e.g. timed out and haven't
been renewed yet). As such, there's no need for host keys to be
_permanent_ or to be a reliable identifier of a particular host, and
RFC 4462 allows for the possibility that they might be purely
transient and only for this kind of emergency fallback purpose.
Therefore, once PuTTY has done a GSS key exchange, it disconnects
itself completely from the permanent host key cache functions in
storage.h, and instead switches to a _transient_ host key cache stored
in memory with the lifetime of just that SSH session. That cache is
populated with keys received from the server as a side effect of GSS
kex (via the optional SSH2_MSG_KEXGSS_HOSTKEY message), and used if
later in the session we have to fall back to a non-GSS key exchange.
However, in practice servers we've tested against do not send a host
key in that way, so we also have a fallback method of populating the
transient cache by triggering an immediate non-GSS rekey straight
after userauth (reusing the code path we also use to turn on OpenSSH
delayed encryption without the race condition).
2018-04-26 06:18:59 +00:00
|
|
|
lib->verify_mic = ssh_sspi_verify_mic;
|
2010-05-19 18:22:17 +00:00
|
|
|
lib->free_mic = ssh_sspi_free_mic;
|
|
|
|
lib->display_status = ssh_sspi_display_status;
|
|
|
|
}
|
|
|
|
|
2008-08-10 13:10:31 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* Dummy function so this source file defines something if NO_GSSAPI
|
|
|
|
is defined. */
|
|
|
|
|
2010-05-19 18:22:17 +00:00
|
|
|
void ssh_gss_init(void)
|
2008-08-10 13:10:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|