2005-08-18 13:38:39 +04:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 et cindent: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Negotiateauth
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Daniel Kouril.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Daniel Kouril <kouril@ics.muni.cz> (original author)
|
|
|
|
* Wyllys Ingersoll <wyllys.ingersoll@sun.com>
|
|
|
|
* Christopher Nebergall <cneberg@sandia.gov>
|
|
|
|
* Darin Fisher <darin@meer.net>
|
2005-08-18 13:38:45 +04:00
|
|
|
* Mark Mentovai <mark@moxienet.com>
|
2005-08-18 13:38:39 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
//
|
|
|
|
// GSSAPI Authentication Support Module
|
|
|
|
//
|
|
|
|
// Described by IETF Internet draft: draft-brezak-kerberos-http-00.txt
|
|
|
|
// (formerly draft-brezak-spnego-http-04.txt)
|
|
|
|
//
|
|
|
|
// Also described here:
|
|
|
|
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsecure/html/http-sso-1.asp
|
|
|
|
//
|
2005-08-18 13:38:44 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "prlink.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2005-08-18 19:22:33 +04:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
2005-08-18 13:38:39 +04:00
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
#include "nsAuthGSSAPI.h"
|
2005-08-18 13:38:39 +04:00
|
|
|
|
2005-08-18 13:38:42 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include <Kerberos/Kerberos.h>
|
|
|
|
#endif
|
|
|
|
|
2005-08-18 13:38:45 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
typedef KLStatus (*KLCacheHasValidTickets_type)(
|
|
|
|
KLPrincipal,
|
|
|
|
KLKerberosVersion,
|
|
|
|
KLBoolean *,
|
|
|
|
KLPrincipal *,
|
|
|
|
char **);
|
|
|
|
#endif
|
|
|
|
|
2005-08-18 13:38:39 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2005-08-18 13:38:44 +04:00
|
|
|
// We define GSS_C_NT_HOSTBASED_SERVICE explicitly since it may be referenced
|
|
|
|
// by by a different name depending on the implementation of gss but always
|
|
|
|
// has the same value
|
|
|
|
|
|
|
|
static gss_OID_desc gss_c_nt_hostbased_service =
|
|
|
|
{ 10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04" };
|
|
|
|
|
|
|
|
static const char kNegotiateAuthGssLib[] =
|
|
|
|
"network.negotiate-auth.gsslib";
|
|
|
|
static const char kNegotiateAuthNativeImp[] =
|
|
|
|
"network.negotiate-auth.using-native-gsslib";
|
|
|
|
|
|
|
|
static const char *gssFuncStr[] = {
|
|
|
|
"gss_display_status",
|
|
|
|
"gss_init_sec_context",
|
|
|
|
"gss_indicate_mechs",
|
|
|
|
"gss_release_oid_set",
|
|
|
|
"gss_delete_sec_context",
|
|
|
|
"gss_import_name",
|
|
|
|
"gss_release_buffer",
|
2005-08-18 19:22:33 +04:00
|
|
|
"gss_release_name",
|
|
|
|
"gss_wrap",
|
|
|
|
"gss_unwrap"
|
2005-08-18 13:38:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define gssFuncItems NS_ARRAY_LENGTH(gssFuncStr)
|
|
|
|
|
|
|
|
static PRFuncPtr gssFunPtr[gssFuncItems];
|
|
|
|
static PRBool gssNativeImp = PR_TRUE;
|
|
|
|
static PRBool gssFunInit = PR_FALSE;
|
|
|
|
|
|
|
|
#define gss_display_status_ptr ((gss_display_status_type)*gssFunPtr[0])
|
|
|
|
#define gss_init_sec_context_ptr ((gss_init_sec_context_type)*gssFunPtr[1])
|
|
|
|
#define gss_indicate_mechs_ptr ((gss_indicate_mechs_type)*gssFunPtr[2])
|
|
|
|
#define gss_release_oid_set_ptr ((gss_release_oid_set_type)*gssFunPtr[3])
|
|
|
|
#define gss_delete_sec_context_ptr ((gss_delete_sec_context_type)*gssFunPtr[4])
|
|
|
|
#define gss_import_name_ptr ((gss_import_name_type)*gssFunPtr[5])
|
|
|
|
#define gss_release_buffer_ptr ((gss_release_buffer_type)*gssFunPtr[6])
|
|
|
|
#define gss_release_name_ptr ((gss_release_name_type)*gssFunPtr[7])
|
2005-08-18 19:22:33 +04:00
|
|
|
#define gss_wrap_ptr ((gss_wrap_type)*gssFunPtr[8])
|
|
|
|
#define gss_unwrap_ptr ((gss_unwrap_type)*gssFunPtr[9])
|
2005-08-18 13:38:44 +04:00
|
|
|
|
2005-08-18 13:38:45 +04:00
|
|
|
#ifdef XP_MACOSX
|
2005-08-18 13:38:46 +04:00
|
|
|
static PRFuncPtr KLCacheHasValidTicketsPtr;
|
2005-08-18 13:38:45 +04:00
|
|
|
#define KLCacheHasValidTickets_ptr \
|
|
|
|
((KLCacheHasValidTickets_type)*KLCacheHasValidTicketsPtr)
|
|
|
|
#endif
|
|
|
|
|
2005-08-18 13:38:44 +04:00
|
|
|
static nsresult
|
|
|
|
gssInit()
|
|
|
|
{
|
|
|
|
nsXPIDLCString libPath;
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (prefs) {
|
|
|
|
prefs->GetCharPref(kNegotiateAuthGssLib, getter_Copies(libPath));
|
|
|
|
prefs->GetBoolPref(kNegotiateAuthNativeImp, &gssNativeImp);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRLibrary *lib = NULL;
|
|
|
|
|
|
|
|
if (!libPath.IsEmpty()) {
|
|
|
|
LOG(("Attempting to load user specified library [%s]\n", libPath.get()));
|
|
|
|
gssNativeImp = PR_FALSE;
|
|
|
|
lib = PR_LoadLibrary(libPath.get());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const char *const libNames[] = {
|
2005-08-18 19:22:33 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
"gssapi32"
|
|
|
|
#else
|
2005-08-18 13:38:44 +04:00
|
|
|
"gss",
|
|
|
|
"gssapi_krb5",
|
|
|
|
"gssapi"
|
2005-08-18 19:22:33 +04:00
|
|
|
#endif
|
2005-08-18 13:38:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < NS_ARRAY_LENGTH(libNames) && !lib; ++i) {
|
|
|
|
char *libName = PR_GetLibraryName(NULL, libNames[i]);
|
|
|
|
if (libName) {
|
|
|
|
lib = PR_LoadLibrary(libName);
|
|
|
|
PR_FreeLibraryName(libName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lib) {
|
|
|
|
LOG(("Fail to load gssapi library\n"));
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("Attempting to load gss functions\n"));
|
|
|
|
|
|
|
|
for (size_t i = 0; i < gssFuncItems; ++i) {
|
|
|
|
gssFunPtr[i] = PR_FindFunctionSymbol(lib, gssFuncStr[i]);
|
|
|
|
if (!gssFunPtr[i]) {
|
|
|
|
LOG(("Fail to load %s function from gssapi library\n", gssFuncStr[i]));
|
|
|
|
PR_UnloadLibrary(lib);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2005-08-18 13:38:45 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (gssNativeImp &&
|
2005-08-18 13:38:47 +04:00
|
|
|
!(KLCacheHasValidTicketsPtr =
|
2005-08-18 13:38:45 +04:00
|
|
|
PR_FindFunctionSymbol(lib, "KLCacheHasValidTickets"))) {
|
|
|
|
LOG(("Fail to load KLCacheHasValidTickets function from gssapi library\n"));
|
|
|
|
PR_UnloadLibrary(lib);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
2005-08-18 13:38:44 +04:00
|
|
|
|
|
|
|
gssFunInit = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 13:38:39 +04:00
|
|
|
#if defined( PR_LOGGING )
|
|
|
|
|
|
|
|
// Generate proper GSSAPI error messages from the major and
|
|
|
|
// minor status codes.
|
|
|
|
void
|
|
|
|
LogGssError(OM_uint32 maj_stat, OM_uint32 min_stat, const char *prefix)
|
|
|
|
{
|
|
|
|
OM_uint32 new_stat;
|
|
|
|
OM_uint32 msg_ctx = 0;
|
|
|
|
gss_buffer_desc status1_string;
|
|
|
|
gss_buffer_desc status2_string;
|
|
|
|
OM_uint32 ret;
|
2005-08-18 19:22:33 +04:00
|
|
|
nsCAutoString errorStr;
|
|
|
|
errorStr.Assign(prefix);
|
2005-08-18 13:38:39 +04:00
|
|
|
|
2005-08-18 13:38:44 +04:00
|
|
|
if (!gssFunInit)
|
|
|
|
return;
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
errorStr += ": ";
|
2005-08-18 13:38:39 +04:00
|
|
|
do {
|
2005-08-18 13:38:44 +04:00
|
|
|
ret = gss_display_status_ptr(&new_stat,
|
|
|
|
maj_stat,
|
|
|
|
GSS_C_GSS_CODE,
|
|
|
|
GSS_C_NULL_OID,
|
|
|
|
&msg_ctx,
|
|
|
|
&status1_string);
|
2005-08-18 19:22:33 +04:00
|
|
|
errorStr.Append((const char *) status1_string.value, status1_string.length);
|
|
|
|
gss_release_buffer_ptr(&new_stat, &status1_string);
|
|
|
|
|
|
|
|
errorStr += '\n';
|
2005-08-18 13:38:44 +04:00
|
|
|
ret = gss_display_status_ptr(&new_stat,
|
|
|
|
min_stat,
|
|
|
|
GSS_C_MECH_CODE,
|
|
|
|
GSS_C_NULL_OID,
|
|
|
|
&msg_ctx,
|
|
|
|
&status2_string);
|
2005-08-18 19:22:33 +04:00
|
|
|
errorStr.Append((const char *) status2_string.value, status2_string.length);
|
|
|
|
errorStr += '\n';
|
2005-08-18 13:38:39 +04:00
|
|
|
} while (!GSS_ERROR(ret) && msg_ctx != 0);
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
LOG(("%s\n", errorStr.get()));
|
2005-08-18 13:38:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* PR_LOGGING */
|
|
|
|
|
|
|
|
#define LogGssError(x,y,z)
|
|
|
|
|
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
nsAuthGSSAPI::nsAuthGSSAPI(pType package)
|
2005-08-18 13:38:39 +04:00
|
|
|
: mServiceFlags(REQ_DEFAULT)
|
|
|
|
{
|
2005-08-18 19:22:33 +04:00
|
|
|
OM_uint32 minstat;
|
|
|
|
OM_uint32 majstat;
|
2005-08-18 13:38:39 +04:00
|
|
|
gss_OID_set mech_set;
|
|
|
|
gss_OID item;
|
2005-08-18 19:22:33 +04:00
|
|
|
|
2005-08-18 13:38:39 +04:00
|
|
|
unsigned int i;
|
|
|
|
static gss_OID_desc gss_krb5_mech_oid_desc =
|
2005-08-18 13:38:44 +04:00
|
|
|
{ 9, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" };
|
2005-08-18 13:38:39 +04:00
|
|
|
static gss_OID_desc gss_spnego_mech_oid_desc =
|
2005-08-18 13:38:44 +04:00
|
|
|
{ 6, (void *) "\x2b\x06\x01\x05\x05\x02" };
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
LOG(("entering nsAuthGSSAPI::nsAuthGSSAPI()\n"));
|
|
|
|
|
|
|
|
mComplete = PR_FALSE;
|
2005-08-18 13:38:44 +04:00
|
|
|
|
|
|
|
if (!gssFunInit && NS_FAILED(gssInit()))
|
|
|
|
return;
|
2005-08-18 13:38:39 +04:00
|
|
|
|
|
|
|
mCtx = GSS_C_NO_CONTEXT;
|
|
|
|
mMechOID = &gss_krb5_mech_oid_desc;
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
// if the type is kerberos we accept it as default
|
|
|
|
// and exit
|
|
|
|
|
|
|
|
if (package == PACKAGE_TYPE_KERBEROS)
|
|
|
|
return;
|
|
|
|
|
2005-08-18 13:38:39 +04:00
|
|
|
// Now, look at the list of supported mechanisms,
|
|
|
|
// if SPNEGO is found, then use it.
|
|
|
|
// Otherwise, set the desired mechanism to
|
|
|
|
// GSS_C_NO_OID and let the system try to use
|
|
|
|
// the default mechanism.
|
|
|
|
//
|
|
|
|
// Using Kerberos directly (instead of negotiating
|
|
|
|
// with SPNEGO) may work in some cases depending
|
|
|
|
// on how smart the server side is.
|
2005-08-18 19:22:33 +04:00
|
|
|
|
2005-08-18 13:38:44 +04:00
|
|
|
majstat = gss_indicate_mechs_ptr(&minstat, &mech_set);
|
2005-08-18 13:38:39 +04:00
|
|
|
if (GSS_ERROR(majstat))
|
|
|
|
return;
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
if (mech_set) {
|
|
|
|
for (i=0; i<mech_set->count; i++) {
|
|
|
|
item = &mech_set->elements[i];
|
|
|
|
if (item->length == gss_spnego_mech_oid_desc.length &&
|
|
|
|
!memcmp(item->elements, gss_spnego_mech_oid_desc.elements,
|
|
|
|
item->length)) {
|
|
|
|
// ok, we found it
|
|
|
|
mMechOID = &gss_spnego_mech_oid_desc;
|
|
|
|
break;
|
|
|
|
}
|
2005-08-18 13:38:39 +04:00
|
|
|
}
|
2005-08-18 19:22:33 +04:00
|
|
|
gss_release_oid_set_ptr(&minstat, &mech_set);
|
2005-08-18 13:38:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-08-18 19:22:33 +04:00
|
|
|
nsAuthGSSAPI::Reset()
|
2005-08-18 13:38:39 +04:00
|
|
|
{
|
2005-08-18 13:38:44 +04:00
|
|
|
if (gssFunInit && mCtx != GSS_C_NO_CONTEXT) {
|
2005-08-18 13:38:39 +04:00
|
|
|
OM_uint32 minor_status;
|
2005-08-18 13:38:44 +04:00
|
|
|
gss_delete_sec_context_ptr(&minor_status, &mCtx, GSS_C_NO_BUFFER);
|
2005-08-18 13:38:39 +04:00
|
|
|
}
|
|
|
|
mCtx = GSS_C_NO_CONTEXT;
|
2005-08-18 19:22:33 +04:00
|
|
|
mComplete = PR_FALSE;
|
2005-08-18 13:38:39 +04:00
|
|
|
}
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsAuthGSSAPI, nsIAuthModule)
|
2005-08-18 13:38:39 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-08-18 19:22:33 +04:00
|
|
|
nsAuthGSSAPI::Init(const char *serviceName,
|
|
|
|
PRUint32 serviceFlags,
|
|
|
|
const PRUnichar *domain,
|
|
|
|
const PRUnichar *username,
|
|
|
|
const PRUnichar *password)
|
2005-08-18 13:38:39 +04:00
|
|
|
{
|
|
|
|
// we don't expect to be passed any user credentials
|
|
|
|
NS_ASSERTION(!domain && !username && !password, "unexpected credentials");
|
|
|
|
|
|
|
|
// it's critial that the caller supply a service name to be used
|
|
|
|
NS_ENSURE_TRUE(serviceName && *serviceName, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
LOG(("entering nsAuthGSSAPI::Init()\n"));
|
2005-08-18 13:38:44 +04:00
|
|
|
|
|
|
|
if (!gssFunInit)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2005-08-18 13:38:39 +04:00
|
|
|
mServiceName = serviceName;
|
|
|
|
mServiceFlags = serviceFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-08-18 19:22:33 +04:00
|
|
|
nsAuthGSSAPI::GetNextToken(const void *inToken,
|
|
|
|
PRUint32 inTokenLen,
|
|
|
|
void **outToken,
|
|
|
|
PRUint32 *outTokenLen)
|
2005-08-18 13:38:39 +04:00
|
|
|
{
|
|
|
|
OM_uint32 major_status, minor_status;
|
|
|
|
OM_uint32 req_flags = 0;
|
|
|
|
gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER;
|
|
|
|
gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER;
|
|
|
|
gss_buffer_t in_token_ptr = GSS_C_NO_BUFFER;
|
|
|
|
gss_name_t server;
|
2005-08-18 19:22:33 +04:00
|
|
|
nsCAutoString userbuf;
|
|
|
|
nsresult rv;
|
2005-08-18 13:38:39 +04:00
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
LOG(("entering nsAuthGSSAPI::GetNextToken()\n"));
|
2005-08-18 13:38:39 +04:00
|
|
|
|
2005-08-18 13:38:44 +04:00
|
|
|
if (!gssFunInit)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
// If they've called us again after we're complete, reset to start afresh.
|
|
|
|
if (mComplete)
|
|
|
|
Reset();
|
|
|
|
|
2005-08-18 13:38:39 +04:00
|
|
|
if (mServiceFlags & REQ_DELEGATE)
|
|
|
|
req_flags |= GSS_C_DELEG_FLAG;
|
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
if (mServiceFlags & REQ_MUTUAL_AUTH)
|
|
|
|
req_flags |= GSS_C_MUTUAL_FLAG;
|
|
|
|
|
2005-08-18 13:38:39 +04:00
|
|
|
input_token.value = (void *)mServiceName.get();
|
|
|
|
input_token.length = mServiceName.Length() + 1;
|
|
|
|
|
2005-08-18 13:38:44 +04:00
|
|
|
major_status = gss_import_name_ptr(&minor_status,
|
2005-08-18 13:38:39 +04:00
|
|
|
&input_token,
|
2005-08-18 13:38:44 +04:00
|
|
|
&gss_c_nt_hostbased_service,
|
2005-08-18 13:38:39 +04:00
|
|
|
&server);
|
|
|
|
input_token.value = NULL;
|
|
|
|
input_token.length = 0;
|
|
|
|
if (GSS_ERROR(major_status)) {
|
|
|
|
LogGssError(major_status, minor_status, "gss_import_name() failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inToken) {
|
|
|
|
input_token.length = inTokenLen;
|
|
|
|
input_token.value = (void *) inToken;
|
|
|
|
in_token_ptr = &input_token;
|
|
|
|
}
|
|
|
|
else if (mCtx != GSS_C_NO_CONTEXT) {
|
2005-08-18 13:38:43 +04:00
|
|
|
// If there is no input token, then we are starting a new
|
|
|
|
// authentication sequence. If we have already initialized our
|
|
|
|
// security context, then we're in trouble because it means that the
|
|
|
|
// first sequence failed. We need to bail or else we might end up in
|
|
|
|
// an infinite loop.
|
|
|
|
LOG(("Cannot restart authentication sequence!"));
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2005-08-18 13:38:39 +04:00
|
|
|
}
|
|
|
|
|
2005-08-18 13:38:42 +04:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// Suppress Kerberos prompts to get credentials. See bug 240643.
|
2005-08-18 13:38:44 +04:00
|
|
|
// We can only use Mac OS X specific kerb functions if we are using
|
|
|
|
// the native lib
|
2005-10-25 00:02:00 +04:00
|
|
|
KLBoolean found;
|
|
|
|
PRBool doingMailTask = mServiceName.Find("imap@") || mServiceName.Find("pop@") || mServiceName.Find("smtp@");
|
|
|
|
|
|
|
|
if (!doingMailTask && (gssNativeImp &&
|
|
|
|
(KLCacheHasValidTickets_ptr(NULL, kerberosVersion_V5, &found, NULL, NULL) != klNoErr || !found)))
|
2005-08-18 13:38:42 +04:00
|
|
|
{
|
|
|
|
major_status = GSS_S_FAILURE;
|
|
|
|
minor_status = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif /* XP_MACOSX */
|
2005-08-18 13:38:44 +04:00
|
|
|
major_status = gss_init_sec_context_ptr(&minor_status,
|
|
|
|
GSS_C_NO_CREDENTIAL,
|
|
|
|
&mCtx,
|
|
|
|
server,
|
|
|
|
mMechOID,
|
|
|
|
req_flags,
|
|
|
|
GSS_C_INDEFINITE,
|
|
|
|
GSS_C_NO_CHANNEL_BINDINGS,
|
|
|
|
in_token_ptr,
|
|
|
|
nsnull,
|
|
|
|
&output_token,
|
|
|
|
nsnull,
|
|
|
|
nsnull);
|
2005-08-18 13:38:39 +04:00
|
|
|
|
|
|
|
if (GSS_ERROR(major_status)) {
|
|
|
|
LogGssError(major_status, minor_status, "gss_init_sec_context() failed");
|
|
|
|
Reset();
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (major_status == GSS_S_COMPLETE) {
|
2005-08-18 19:22:33 +04:00
|
|
|
// Mark ourselves as being complete, so that if we're called again
|
|
|
|
// we know to start afresh.
|
|
|
|
mComplete = PR_TRUE;
|
2005-08-18 13:38:39 +04:00
|
|
|
}
|
|
|
|
else if (major_status == GSS_S_CONTINUE_NEEDED) {
|
|
|
|
//
|
|
|
|
// The important thing is that we do NOT reset the
|
|
|
|
// context here because it will be needed on the
|
|
|
|
// next call.
|
|
|
|
//
|
|
|
|
}
|
2005-08-18 19:22:33 +04:00
|
|
|
|
|
|
|
*outTokenLen = output_token.length;
|
|
|
|
if (output_token.length != 0)
|
|
|
|
*outToken = nsMemory::Clone(output_token.value, output_token.length);
|
|
|
|
else
|
|
|
|
*outToken = NULL;
|
|
|
|
|
|
|
|
gss_release_buffer_ptr(&minor_status, &output_token);
|
2005-08-18 13:38:39 +04:00
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
if (major_status == GSS_S_COMPLETE)
|
|
|
|
rv = NS_SUCCESS_AUTH_FINISHED;
|
|
|
|
else
|
|
|
|
rv = NS_OK;
|
|
|
|
|
|
|
|
end:
|
|
|
|
gss_release_name_ptr(&minor_status, &server);
|
|
|
|
|
|
|
|
LOG((" leaving nsAuthGSSAPI::GetNextToken [rv=%x]", rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAuthGSSAPI::Unwrap(const void *inToken,
|
|
|
|
PRUint32 inTokenLen,
|
|
|
|
void **outToken,
|
|
|
|
PRUint32 *outTokenLen)
|
|
|
|
{
|
|
|
|
OM_uint32 major_status, minor_status;
|
|
|
|
|
|
|
|
gss_buffer_desc input_token;
|
|
|
|
gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER;
|
|
|
|
|
|
|
|
input_token.value = (void *) inToken;
|
|
|
|
input_token.length = inTokenLen;
|
|
|
|
|
|
|
|
major_status = gss_unwrap_ptr(&minor_status,
|
|
|
|
mCtx,
|
|
|
|
&input_token,
|
|
|
|
&output_token,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (GSS_ERROR(major_status)) {
|
|
|
|
LogGssError(major_status, minor_status, "gss_unwrap() failed");
|
|
|
|
Reset();
|
|
|
|
gss_release_buffer_ptr(&minor_status, &output_token);
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-08-18 13:38:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*outTokenLen = output_token.length;
|
2005-08-18 19:22:33 +04:00
|
|
|
|
|
|
|
if (output_token.length)
|
|
|
|
*outToken = nsMemory::Clone(output_token.value, output_token.length);
|
|
|
|
else
|
|
|
|
*outToken = NULL;
|
2005-08-18 13:38:39 +04:00
|
|
|
|
2005-08-18 13:38:44 +04:00
|
|
|
gss_release_buffer_ptr(&minor_status, &output_token);
|
2005-08-18 13:38:39 +04:00
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAuthGSSAPI::Wrap(const void *inToken,
|
|
|
|
PRUint32 inTokenLen,
|
|
|
|
PRBool confidential,
|
|
|
|
void **outToken,
|
|
|
|
PRUint32 *outTokenLen)
|
|
|
|
{
|
|
|
|
OM_uint32 major_status, minor_status;
|
2005-08-18 13:38:39 +04:00
|
|
|
|
2005-08-18 19:22:33 +04:00
|
|
|
gss_buffer_desc input_token;
|
|
|
|
gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER;
|
|
|
|
|
|
|
|
input_token.value = (void *) inToken;
|
|
|
|
input_token.length = inTokenLen;
|
|
|
|
|
|
|
|
major_status = gss_wrap_ptr(&minor_status,
|
|
|
|
mCtx,
|
|
|
|
confidential,
|
|
|
|
GSS_C_QOP_DEFAULT,
|
|
|
|
&input_token,
|
|
|
|
NULL,
|
|
|
|
&output_token);
|
|
|
|
|
|
|
|
if (GSS_ERROR(major_status)) {
|
|
|
|
LogGssError(major_status, minor_status, "gss_wrap() failed");
|
|
|
|
Reset();
|
|
|
|
gss_release_buffer_ptr(&minor_status, &output_token);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*outTokenLen = output_token.length;
|
|
|
|
|
|
|
|
/* it is not possible for output_token.length to be zero */
|
|
|
|
*outToken = nsMemory::Clone(output_token.value, output_token.length);
|
|
|
|
gss_release_buffer_ptr(&minor_status, &output_token);
|
|
|
|
|
|
|
|
return NS_OK;
|
2005-08-18 13:38:39 +04:00
|
|
|
}
|
2005-08-18 19:22:33 +04:00
|
|
|
|