1/* -*- mode: objc -*- 2 * Copyright (c) 2010 Kungliga Tekniska Högskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Portions Copyright (c) 2010 Apple Inc. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * 3. Neither the name of the Institute nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36#ifndef GSSKIT_GSSKIT_H_ 37#define GSSKIT_GSSKIT_H_ 38 39#import <GSS/gssapi.h> 40#import <dispatch/dispatch.h> 41 42enum { 43 GSS_C_ENC_BINARY, 44 GSS_C_ENC_BASE64 45}; 46typedef OM_uint32 GSSEncoding; 47 48@interface GSSError : NSObject 49- (OM_uint32)majorStatus; 50- (OM_uint32)minorStatus; 51- (uint32_t)windowsErrorCode; 52- (NSString *)displayString; 53@end 54 55@interface GSSOID : NSObject 56 57- (NSString *)description; 58- (gssOID)GSSOID; 59 60@end 61 62@interface GSSName : NSObject 63 64+ (GSSName *)nameWithHostBasedService: (NSString *)service withHostName: (NSString *)hostname; 65+ (GSSName *)nameWithUserName: (NSString *username); 66+ (GSSName *)nameWithGSSTypes: (NSData *)data withMech: (gssOID)nameType; 67 68- (NSData *)exportName; 69@end 70 71@interface GSSMechanism : NSObject 72+ (GSSMechanism *)mechanismSPNEGO; 73+ (GSSMechanism *)mechanismKerberos; 74+ (GSSMechanism *)mechanismPKU2U; 75+ (GSSMechanism *)mechanismSCRAM; 76+ (GSSMechanism *)mechanismNTLM; 77+ (GSSMechanism *)mechanismSASLDigestMD5; 78 79+ (GSSMechanism *)mechanismWithOID: (gssOID)oid; 80+ (GSSMechanism *)mechanismWithDERData: (NSData *)data; 81+ (GSSMechanism *)mechanismWithSASLName: (NSString *)name; 82 83- (gssOID)oid; 84- (NSString *)name; 85@end 86 87@interface GSSCredential : NSObject 88+ (void)credentialWithExistingCredential: (GSSName *) mech: (GSSMechanism *)mech usageflags: (OM_uint32)flags queue:(dispatch_queue_t)queue completion: (^)(GSSCredential *, GSSError *); 89+ (void)credentialWithExportedData: (NSData *)exportedData queue:(dispatch_queue_t)queue completion: (^)(GSSCredential *, GSSError *); 90+ (void)credentialWithName: (GSSName *) mech: (GSSMechanism *)mech usageFlags: (OM_uint32)flags authIdentity: (gss_auth_identity_t)authId queue:(dispatch_queue_t)queue completion: (^)(GSSCredential *, GSSError *); 91+ (void)credentialWithNameAndPassword: (GSSName *) mech: (GSSMechanism *)mech usageFlags: (OM_uint32)flags password: (NSString *) queue:(dispatch_queue_t)queue completion: (^)(GSSCredential *, GSSError *); 92 93+ (void)iterateWithFlags: (OM_uint32)flags ofMechanism: (GSSName *) mech 94 callback: (^)(GSSMechanism mech, gss_cred_id_t cred); 95 96- (void)mergeWithCredential: (GSSCredential *)additionalCredential; 97 98- (void)destroy; 99 100- (GSSName *)name; 101- (OM_uint32)lifetime; 102- (OM_uint32)credUsage; 103- (NSArray *)mechanisms; 104- (NSData *)export; 105 106 107- (void)retainCredential; 108- (void)releaseCredential; 109@end 110 111@interface GSSBindings : NSObject 112+ bindingsFromSecCertificate: (SecCertificateRef)certificate; 113- setInitiatorAddress: (NSData *)addr ofType: (OM_uint32)type; 114- setAcceptorAddress: (NSData *)addr ofType: (OM_uint32)type; 115- setApplicationData: (NSData *)data; 116@end 117 118@interface GSSContext : NSObject 119 120- (void)initWithRequestFlags: (OM_uint32)flags queue: (dispatch_queue_t)queue isInitiator: (bool)initiator; 121 122/** 123 * If not set, default mechanism is SPNEGO 124 */ 125- (void)setMechanism: (GSSMechanism *)mechanism; 126- (void)setRequestFlags: (OM_uint32)flags; 127- (void)setTargetName: (GSSName *)targetName; 128- (void)setCredential: (GSSCredential *)credential; 129- (void)setChannelBindings: (GSSChannelBindings *)bindings; 130 131- (void)setEncoding:(GSSEncoding)encoding; 132 133- (void)stepWithData: (NSData *)indata completionHandler: (^)(GSSStatusCode major, NSData *data, OM_uint32 flags)handler; 134 135- (GSSMechanism *)finalMechanism; 136- (OM_uint32)finalFlags; 137 138- (GSSCredential *)delegatedCredentials; 139 140- (GSSError *)lastError; 141 142/* 143 * 144 */ 145 146- (NSData *)wrapData: (NSData *)data withFlags: (OM_uint32)flags; 147- (NSData *)unwrapData: (NSData *)data withFlags: (OM_uint32 *)flags; 148 149- (NSData *)messageIntegrityCodeFromData: (NSData *)data withFlags: (OM_uint32)flags; 150- (BOOL)verifyMessageIntegrityCodeFromData: (NSData *)data withCode: (NSData *)mic returnFlags: (OM_uint32 *)flags error: (NSError *)error; 151 152@end 153 154@interface NetworkAuthenticationSelection : NSObject 155 156- (bool)acquire:(^)(NSError *)completion; 157- (NSDictionary *)authInfo; 158- (GSSCredential *)credential; 159- (GSSMechanism *)mech; 160- (GSSName *)acceptorName; 161 162@end 163 164@interface NetworkAuthenticationHelper : NSObject 165 166 167(NetworkAuthenticationHelper *)initWithHostname: (NSString *)hostname withService: (NSService *)service withParams: (NSDictionary *)info; 168 169(NSArray *)selections; 170 171 172@end 173