|
| 1 | +export const GSS_C_DELEG_FLAG: number; |
| 2 | +export const GSS_C_MUTUAL_FLAG: number; |
| 3 | +export const GSS_C_REPLAY_FLAG: number; |
| 4 | +export const GSS_C_SEQUENCE_FLAG: number; |
| 5 | +export const GSS_C_CONF_FLAG: number; |
| 6 | +export const GSS_C_INTEG_FLAG: number; |
| 7 | +export const GSS_C_ANON_FLAG: number; |
| 8 | +export const GSS_C_PROT_READY_FLAG: number; |
| 9 | +export const GSS_C_TRANS_FLAG: number; |
| 10 | + |
| 11 | +export const GSS_C_NO_OID: number; |
| 12 | +export const GSS_MECH_OID_KRB5: number; |
| 13 | +export const GSS_MECH_OID_SPNEGO: number; |
| 14 | + |
| 15 | +/** |
| 16 | + * Optional settings for *KerberosClient.wrap* method. |
| 17 | + */ |
| 18 | +export interface WrapOptions { |
| 19 | + /** |
| 20 | + * The user to authorize. |
| 21 | + */ |
| 22 | + user?: string; |
| 23 | + |
| 24 | + /** |
| 25 | + * Indicates if the wrap should request message confidentiality. |
| 26 | + */ |
| 27 | + protect?: boolean; |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Options for `initializeClient()`. |
| 32 | + */ |
| 33 | +export interface InitializeClientOptions { |
| 34 | + /** |
| 35 | + * Optional string containing the client principal in the form 'user@realm' (e.g. 'jdoe@example.com'). |
| 36 | + */ |
| 37 | + principal?: string; |
| 38 | + /** |
| 39 | + * Optional integer used to set GSS flags. (e.g. `GSS_C_DELEG_FLAG|GSS_C_MUTUAL_FLAG|GSS_C_SEQUENCE_FLAG` will allow for forwarding credentials to the remote host). |
| 40 | + */ |
| 41 | + gssFlag?: number; |
| 42 | + /** |
| 43 | + * Optional GSS mech OID. Defaults to None (GSS_C_NO_OID). Other possible values are `GSS_MECH_OID_KRB5`, `GSS_MECH_OID_SPNEGO`. |
| 44 | + */ |
| 45 | + mechOID?: number; |
| 46 | + |
| 47 | + /** |
| 48 | + * The username with which to authenticate. Only used on Windows. |
| 49 | + */ |
| 50 | + user?: string; |
| 51 | + |
| 52 | + /** |
| 53 | + * The password with which to authenticate. Only used on Windows. |
| 54 | + */ |
| 55 | + pass?: string; |
| 56 | +} |
| 57 | + |
| 58 | +export class KerberosClient { |
| 59 | + /** |
| 60 | + * The username used for authentication. |
| 61 | + */ |
| 62 | + username: string; |
| 63 | + /** |
| 64 | + * The last response received during authentication steps. |
| 65 | + */ |
| 66 | + response: string; |
| 67 | + /** |
| 68 | + * Indicates whether confidentiality was applied or not (GSSAPI only). |
| 69 | + */ |
| 70 | + responseConf: string; |
| 71 | + /** |
| 72 | + * Indicates that authentication has successfully completed or not. |
| 73 | + */ |
| 74 | + contextComplete: boolean; |
| 75 | + |
| 76 | + /** |
| 77 | + * Processes a single kerberos client-side step using the supplied server challenge. |
| 78 | + * |
| 79 | + * @param challenge A string containing the base64-encoded server data (which may be empty for the first step) |
| 80 | + */ |
| 81 | + step(challenge: string): Promise<string>; |
| 82 | + |
| 83 | + /** |
| 84 | + * Perform the client side kerberos wrap step. |
| 85 | + * |
| 86 | + * @param challenge The response returned after calling `unwrap` |
| 87 | + * @param options Optional settings |
| 88 | + */ |
| 89 | + wrap(challenge: string, options?: WrapOptions): Promise<string>; |
| 90 | + |
| 91 | + /** |
| 92 | + * Perform the client side kerberos unwrap step |
| 93 | + * |
| 94 | + * @param challenge A string containing the base64-encoded server data |
| 95 | + */ |
| 96 | + unwrap(challenge: string): Promise<string>; |
| 97 | +} |
| 98 | + |
| 99 | +export class KerberosServer { |
| 100 | + /** |
| 101 | + * The username used for authentication |
| 102 | + */ |
| 103 | + username: string; |
| 104 | + /** |
| 105 | + * @description The last response received during authentication steps |
| 106 | + */ |
| 107 | + response: string; |
| 108 | + /** |
| 109 | + * @description The target used for authentication |
| 110 | + */ |
| 111 | + targetName: string; |
| 112 | + /** |
| 113 | + * @description Indicates that authentication has successfully completed or not |
| 114 | + */ |
| 115 | + contextComplete: boolean; |
| 116 | + |
| 117 | + /** |
| 118 | + * Processes a single kerberos server-side step using the supplied client data. |
| 119 | + * |
| 120 | + * @param challenge A string containing the base64-encoded client data |
| 121 | + */ |
| 122 | + step(challenge: string): Promise<string>; |
| 123 | +} |
| 124 | + |
| 125 | +/** |
| 126 | + * This function provides a simple way to verify that a user name and password |
| 127 | + * match those normally used for Kerberos authentication. |
| 128 | + * It does this by checking that the supplied user name and password can be |
| 129 | + * used to get a ticket for the supplied service. |
| 130 | + * If the user name does not contain a realm, then the default realm supplied |
| 131 | + * is used. |
| 132 | + * |
| 133 | + * For this to work properly the Kerberos must be configured properly on this |
| 134 | + * machine. |
| 135 | + * That will likely mean ensuring that the edu.mit.Kerberos preference file |
| 136 | + * has the correct realms and KDCs listed. |
| 137 | + * |
| 138 | + * IMPORTANT: This method is vulnerable to KDC spoofing attacks and it should |
| 139 | + * only be used for testing. Do not use this in any production system - your |
| 140 | + * security could be compromised if you do. |
| 141 | + * |
| 142 | + * @param username The Kerberos user name. If no realm is supplied, then the `defaultRealm` will be used. |
| 143 | + * @param password The password for the user. |
| 144 | + * @param service The Kerberos service to check access for. |
| 145 | + * @param defaultRealm The default realm to use if one is not supplied in the user argument. |
| 146 | + */ |
| 147 | +export function checkPassword( |
| 148 | + name: string, |
| 149 | + password: string, |
| 150 | + service: string, |
| 151 | + defaultRealm?: string |
| 152 | +): Promise<void>; |
| 153 | + |
| 154 | +/** |
| 155 | + * This function returns the service principal for the server given a service type and hostname. |
| 156 | + * |
| 157 | + * Details are looked up via the `/etc/keytab` file. |
| 158 | + * |
| 159 | + * @param service The Kerberos service type for the server. |
| 160 | + * @param hostname The hostname of the server. |
| 161 | + */ |
| 162 | +export function principalDetails(service: string, hostname: string): Promise<string>; |
| 163 | + |
| 164 | +/** |
| 165 | + * Initializes a context for client-side authentication with the given service principal. |
| 166 | + * |
| 167 | + * @param service A string containing the service principal in the form '`type@fqdn`'. |
| 168 | + * @param [options] Optional settings |
| 169 | + */ |
| 170 | +export function initializeClient( |
| 171 | + service: string, |
| 172 | + options?: InitializeClientOptions |
| 173 | +): Promise<KerberosClient>; |
| 174 | + |
| 175 | +/** |
| 176 | + * Initializes a context for server-side authentication with the given service principal. |
| 177 | + * |
| 178 | + * @param service A string containing the service principal in the form 'type@fqdn' (e.g. 'imap@mail.apple.com'). |
| 179 | + */ |
| 180 | +export function initializeServer(service: string): Promise<KerberosServer>; |
| 181 | + |
| 182 | +/** |
| 183 | + * The version of the Kerberos package. |
| 184 | + */ |
| 185 | +export const version: string; |
0 commit comments