FreeTDS API

Classes | Macros | Typedefs | Enumerations | Functions | Variables
Authentication
LibTDS API

Functions for handling authentication. More...

Collaboration diagram for Authentication:

## Classes
struct | asn1_der_iterator
struct | mpz_t
struct | names_blob_prefix_t
struct | rsa_public_key
struct | tds_answer
struct | tds_ntlm_auth

## Macros
#define | dump(b) dumpl(b, sizeof(b))
#define | dumpl(b, l) tdsdump_dump_buf(TDS_DBG_INFO1, #b, b, l)
#define | hash_func sha1
#define | HAVE_GMP 1
#define | HAVE_NETTLE 1
#define | mpz_clear(n) gcry_mpi_release((n)->num)
#define | mpz_init(n) do { (n)->num = NULL; } while(0)
#define | mpz_powm(w, n, e, m) gcry_mpi_powm((w)->num, (n)->num, (e)->num, (m)->num);

## Typedefs
typedef void | nettle_random_func(void *ctx, size_t len, uint8_t *out)
typedef struct tds_answer | TDSANSWER
typedef struct tds_ntlm_auth | TDSNTLMAUTH

## Enumerations
enum | { OPT_VERSION = 0x01, OPT_TIMER = 0x02, OPT_NOFOOTER = 0x04, OPT_NOHEADER = 0x08, OPT_QUIET = 0x10, OPT_VERBOSE = 0x20, OPT_INSTANCES = 0x40, POS_ISO1, POS_UTF8, POS_UCS2LE, POS_UCS2BE, MUL_STARTED = 1, ASN1_SEQUENCE = ASN1_TAG_SEQUENCE, CS_USERNAME = 9100, CS_USERNAME = 9100, CS_PASSWORD = 9101, CS_PASSWORD = 9101, CS_APPNAME = 9102, CS_APPNAME = 9102, CS_HOSTNAME = 9103, CS_HOSTNAME = 9103, CS_LOGIN_STATUS = 9104, CS_LOGIN_STATUS = 9104, CS_TDS_VERSION = 9105, CS_TDS_VERSION = 9105, CS_CHARSETCNV = 9106, CS_CHARSETCNV = 9106, CS_PACKETSIZE = 9107, CS_PACKETSIZE = 9107, CS_USERDATA = 9108, CS_USERDATA = 9108, CS_NETIO = 9110, CS_NETIO = 9110, CS_TEXTLIMIT = 9112, CS_TEXTLIMIT = 9112, CS_HIDDEN_KEYS = 9113, CS_HIDDEN_KEYS = 9113, CS_VERSION = 9114, CS_VERSION = 9114, CS_IFILE = 9115, CS_IFILE = 9115, CS_LOGIN_TIMEOUT = 9116, CS_LOGIN_TIMEOUT = 9116, CS_TIMEOUT = 9117, CS_TIMEOUT = 9117, CS_MAX_CONNECT = 9118, CS_MAX_CONNECT = 9118, CS_EXPOSE_FMTS = 9120, CS_EXPOSE_FMTS = 9120, CS_EXTRA_INF = 9121, CS_EXTRA_INF = 9121, CS_ANSI_BINDS = 9123, CS_ANSI_BINDS = 9123, CS_BULK_LOGIN = 9124, CS_BULK_LOGIN = 9124, CS_LOC_PROP = 9125, CS_LOC_PROP = 9125, CS_PARENT_HANDLE = 9130, CS_PARENT_HANDLE = 9130, CS_EED_CMD = 9131, CS_EED_CMD = 9131, CS_DIAG_TIMEOUT = 9132, CS_DIAG_TIMEOUT = 9132, CS_DISABLE_POLL = 9133, CS_DISABLE_POLL = 9133, CS_SEC_ENCRYPTION = 9135, CS_SEC_ENCRYPTION = 9135, CS_SEC_CHALLENGE = 9136, CS_SEC_CHALLENGE = 9136, CS_SEC_NEGOTIATE = 9137, CS_SEC_NEGOTIATE = 9137, CS_CON_STATUS = 9143, CS_CON_STATUS = 9143, CS_VER_STRING = 9144, CS_VER_STRING = 9144, CS_SERVERNAME = 9146, CS_SERVERNAME = 9146, CS_SEC_APPDEFINED = 9149, CS_SEC_APPDEFINED = 9149, CS_STICKY_BINDS = 9151, CS_STICKY_BINDS = 9151, CS_SEC_NETWORKAUTH = 9175, CS_SEC_NETWORKAUTH = 9175, CS_SEC_DELEGATION = 9176, CS_SEC_DELEGATION = 9176, CS_SEC_MUTUALAUTH = 9177, CS_SEC_MUTUALAUTH = 9177, CS_SEC_SERVERPRINCIPAL = 9188, CS_SEC_SERVERPRINCIPAL = 9188, CS_SERVERADDR = 9206, CS_SERVERADDR = 9206, CS_PORT = 9300, CS_PORT = 9300, CS_CLIENTCHARSET = 9301, CS_CLIENTCHARSET = 9301, CS_DATABASE, dblib_msdblib = 0, TDS_CHARSET_ISO_8859_1 = 0, TDS_CHARSET_UTF_8 = 1, TDS_CHARSET_UCS_2LE = 2, TDS_CHARSET_UCS_2BE = 3, TDS_CHARSET_ARMSCII_8 = 4, TDS_CHARSET_BIG_5 = 5, TDS_CHARSET_BIG5_HKSCS = 6, TDS_CHARSET_C99 = 7, TDS_CHARSET_CHINESE = 8, TDS_CHARSET_CN = 9, TDS_CHARSET_CN_GB = 10, TDS_CHARSET_CN_GB_ISOIR165 = 11, TDS_CHARSET_CP1133 = 12, TDS_CHARSET_CP1250 = 13, TDS_CHARSET_CP1251 = 14, TDS_CHARSET_CP1252 = 15, TDS_CHARSET_CP1253 = 16, TDS_CHARSET_CP1254 = 17, TDS_CHARSET_CP1255 = 18, TDS_CHARSET_CP1256 = 19, TDS_CHARSET_CP1257 = 20, TDS_CHARSET_CP1258 = 21, TDS_CHARSET_CP1361 = 22, TDS_CHARSET_CP437 = 23, TDS_CHARSET_CP850 = 24, TDS_CHARSET_CP862 = 25, TDS_CHARSET_CP866 = 26, TDS_CHARSET_CP874 = 27, TDS_CHARSET_CP932 = 28, TDS_CHARSET_CP936 = 29, TDS_CHARSET_CP949 = 30, TDS_CHARSET_CP950 = 31, TDS_CHARSET_EUC_JP = 32, TDS_CHARSET_EUC_KR = 33, TDS_CHARSET_EUC_TW = 34, TDS_CHARSET_GB18030 = 35, TDS_CHARSET_GEORGIAN_ACADEMY = 36, TDS_CHARSET_GEORGIAN_PS = 37, TDS_CHARSET_HZ = 38, TDS_CHARSET_ISO_2022_CN = 39, TDS_CHARSET_ISO_2022_CN_EXT = 40, TDS_CHARSET_ISO_2022_JP = 41, TDS_CHARSET_ISO_2022_JP_1 = 42, TDS_CHARSET_ISO_2022_JP_2 = 43, TDS_CHARSET_ISO_2022_KR = 44, TDS_CHARSET_ISO_8859_10 = 45, TDS_CHARSET_ISO_8859_13 = 46, TDS_CHARSET_ISO_8859_14 = 47, TDS_CHARSET_ISO_8859_15 = 48, TDS_CHARSET_ISO_8859_16 = 49, TDS_CHARSET_ISO_8859_2 = 50, TDS_CHARSET_ISO_8859_3 = 51, TDS_CHARSET_ISO_8859_4 = 52, TDS_CHARSET_ISO_8859_5 = 53, TDS_CHARSET_ISO_8859_6 = 54, TDS_CHARSET_ISO_8859_7 = 55, TDS_CHARSET_ISO_8859_8 = 56, TDS_CHARSET_ISO_8859_9 = 57, TDS_CHARSET_ISO_IR_14 = 58, TDS_CHARSET_ISO_IR_149 = 59, TDS_CHARSET_ISO_IR_159 = 60, TDS_CHARSET_ISO_IR_166 = 61, TDS_CHARSET_ISO_IR_87 = 62, TDS_CHARSET_JAVA = 63, TDS_CHARSET_JISX0201_1976 = 64, TDS_CHARSET_KOI8_R = 65, TDS_CHARSET_KOI8_RU = 66, TDS_CHARSET_KOI8_T = 67, TDS_CHARSET_KOI8_U = 68, TDS_CHARSET_MAC = 69, TDS_CHARSET_MACARABIC = 70, TDS_CHARSET_MACCENTRALEUROPE = 71, TDS_CHARSET_MACCROATIAN = 72, TDS_CHARSET_MACCYRILLIC = 73, TDS_CHARSET_MACGREEK = 74, TDS_CHARSET_MACHEBREW = 75, TDS_CHARSET_MACICELAND = 76, TDS_CHARSET_MACROMANIA = 77, TDS_CHARSET_MACTHAI = 78, TDS_CHARSET_MACTURKISH = 79, TDS_CHARSET_MACUKRAINE = 80, TDS_CHARSET_MULELAO_1 = 81, TDS_CHARSET_NEXTSTEP = 82, TDS_CHARSET_ROMAN8 = 83, TDS_CHARSET_SJIS = 84, TDS_CHARSET_TCVN = 85, TDS_CHARSET_UCS_4BE = 86, TDS_CHARSET_UCS_4LE = 87, TDS_CHARSET_US_ASCII = 88, TDS_CHARSET_UTF_16BE = 89, TDS_CHARSET_UTF_16LE = 90, TDS_CHARSET_UTF_32BE = 91, TDS_CHARSET_UTF_32LE = 92, TDS_CHARSET_UTF_7 = 93, TDS_CHARSET_VISCII = 94, TDS_NUM_CHARSETS = 95, ODBC_PARAM_SIZE, TDS_OPT_ARITHOVERFLOW = 0x01, TDS_OPT_NUMERICTRUNC = 0x02, TDS_CUR_ISTAT_UNUSED = 0x00, TDS_CUR_ISTAT_DECLARED = 0x01, TDS_CUR_ISTAT_OPEN = 0x02, TDS_CUR_ISTAT_CLOSED = 0x04, TDS_CUR_ISTAT_RDONLY = 0x08, TDS_CUR_ISTAT_UPDATABLE = 0x10, TDS_CUR_ISTAT_ROWCNT = 0x20, TDS_CUR_ISTAT_DEALLOC = 0x40, SYBCHAR = 47, SYBCHAR = 47, SYBVARCHAR = 39, SYBVARCHAR = 39, SYBINTN = 38, SYBINTN = 38, SYBINT1 = 48, SYBINT1 = 48, SYBINT2 = 52, SYBINT2 = 52, SYBINT4 = 56, SYBINT4 = 56, SYBINT8 = 127, SYBINT8 = 127, SYBFLT8 = 62, SYBFLT8 = 62, SYBDATETIME = 61, SYBDATETIME = 61, SYBBIT = 50, SYBBIT = 50, SYBBITN = 104, SYBBITN = 104, SYBTEXT = 35, SYBTEXT = 35, SYBNTEXT = 99, SYBNTEXT = 99, SYBIMAGE = 34, SYBIMAGE = 34, SYBMONEY4 = 122, SYBMONEY4 = 122, SYBMONEY = 60, SYBMONEY = 60, SYBDATETIME4 = 58, SYBDATETIME4 = 58, SYBREAL = 59, SYBREAL = 59, SYBBINARY = 45, SYBBINARY = 45, SYBVOID = 31, SYBVOID = 31, SYBVARBINARY = 37, SYBVARBINARY = 37, SYBNUMERIC = 108, SYBNUMERIC = 108, SYBDECIMAL = 106, SYBDECIMAL = 106, SYBFLTN = 109, SYBFLTN = 109, SYBMONEYN = 110, SYBMONEYN = 110, SYBDATETIMN = 111, SYBDATETIMN = 111, SYBNVARCHAR = 103, SYBNVARCHAR = 103, SYBDATE = 49, SYBDATE = 49, SYBTIME = 51, SYBTIME = 51, SYBBIGDATETIME = 187, SYBBIGDATETIME = 187, SYBBIGTIME = 188, SYBBIGTIME = 188, SYBMSDATE = 40, SYBMSDATE = 40, SYBMSTIME = 41, SYBMSTIME = 41, SYBMSDATETIME2 = 42, SYBMSDATETIME2 = 42, SYBMSDATETIMEOFFSET = 43, SYBMSDATETIMEOFFSET = 43 }
enum | { hash_len = 20, CS_ADD = 1, CS_SUB, CS_MULT, CS_DIV, TDS_SMP_SYN = 1, TDS_SMP_ACK = 2, TDS_SMP_FIN = 4, TDS_SMP_DATA = 8, TDS_TYPEFLAG_INVALID = 0, TDS_TYPEFLAG_NULLABLE = 1, TDS_TYPEFLAG_FIXED = 2, TDS_TYPEFLAG_VARIABLE = 4, TDS_TYPEFLAG_COLLATE = 8, TDS_TYPEFLAG_ASCII = 16, TDS_TYPEFLAG_UNICODE = 32, TDS_TYPEFLAG_BINARY = 64, TDS_TYPEFLAG_DATETIME = 128, TDS_TYPEFLAG_NUMERIC = 256, TDS_TYPEFLAG_VARIANT = 512, MAXCOLNAMELEN = 512 }
enum | { key_size_max = 1024, CS_TDS_AUTO = 0, CS_TDS_AUTO = 0, CS_TDS_40 = 7360, CS_TDS_42, CS_TDS_46, CS_TDS_495, CS_TDS_50, CS_TDS_70, CS_TDS_71, CS_TDS_71, CS_TDS_72, CS_TDS_72, CS_TDS_73, CS_TDS_73, CS_TDS_74, CS_TDS_74, TDS_CUR_TYPE_KEYSET = 0x0001, TDS_CUR_TYPE_DYNAMIC = 0x0002, TDS_CUR_TYPE_FORWARD = 0x0004, TDS_CUR_TYPE_STATIC = 0x0008, TDS_CUR_TYPE_FASTFORWARDONLY = 0x0010, TDS_CUR_TYPE_PARAMETERIZED = 0x1000, TDS_CUR_TYPE_AUTO_FETCH = 0x2000 }
enum | asn1_iterator_result { ASN1_ITERATOR_ERROR, ASN1_ITERATOR_PRIMITIVE, ASN1_ITERATOR_CONSTRUCTED, ASN1_ITERATOR_END }

## Functions
static enum asn1_iterator_result | asn1_der_iterator_first (struct asn1_der_iterator *der, int size, const void *der_buf)
static enum asn1_iterator_result | asn1_der_iterator_next (struct asn1_der_iterator *der)
static void | convert_to_upper (char *buf, size_t len)
static size_t | convert_to_usc2le_string (TDSSOCKET *tds, const char *s, size_t len, char *out)
static void | fill_names_blob_prefix (names_blob_prefix_t *prefix)
static unsigned char * | make_lm_v2_response (const unsigned char ntlm_v2_hash[16], const unsigned char *client_data, int client_data_len, const unsigned char challenge[8])
static TDSRET | make_ntlm_hash (TDSSOCKET *tds, const char *passwd, unsigned char ntlm_hash[16])
static TDSRET | make_ntlm_v2_hash (TDSSOCKET *tds, const char *passwd, unsigned char ntlm_v2_hash[16])
static void | memxor (uint8_t *dest, const uint8_t *src, size_t len)
static void | mgf_mask (uint8_t *dest, size_t dest_len, const uint8_t *mask, size_t mask_len)
static void | nettle_mpz_get_str_256 (unsigned length, uint8_t *s, const mpz_t x)
static void | nettle_mpz_set_str_256_u (mpz_t x, unsigned length, const uint8_t *s)
static int | oaep_encrypt (size_t key_size, void *random_ctx, nettle_random_func *random, size_t length, const uint8_t *message, mpz_t m)
static void | rnd_func (void *ctx, size_t len, uint8_t *out)
static int | rsa_encrypt_oaep (const struct rsa_public_key *key, void *random_ctx, nettle_random_func *random, size_t length, const uint8_t *message, mpz_t gibberish)
static const BIGNUM * | rsa_get_n (const RSA *rsa)
static void | rsa_public_key_clear (struct rsa_public_key *key)
static int | rsa_public_key_from_der_iterator (struct rsa_public_key *key, unsigned key_bits, struct asn1_der_iterator *der)
static void | rsa_public_key_init (struct rsa_public_key *key)
static void | sha1 (uint8_t *hash, const void *data, size_t len)
TDSAUTHENTICATION * | tds5_negotiate_get_auth (TDSSOCKET *tds)
static void * | tds5_rsa_encrypt (const void *key, size_t key_len, const void *nonce, size_t nonce_len, const char *pwd, size_t *em_size)
static TDSRET | tds7_send_auth (TDSSOCKET *tds, const unsigned char *challenge, uint32_t flags, const unsigned char *names_blob, int names_blob_len)
static TDSRET | tds_answer_challenge (TDSSOCKET *tds, TDSLOGIN *login, const unsigned char *challenge, uint32_t *flags, const unsigned char *names_blob, int names_blob_len, TDSANSWER *answer, unsigned char **ntlm_v2_response)
| Crypt a given password using schema required for NTLMv1 or NTLM2 authentication. More...
static TDSRET | tds_answer_challenge_ntlmv2 (TDSSOCKET *tds, TDSLOGIN *login, const unsigned char *challenge, uint32_t *flags, const unsigned char *names_blob, int names_blob_len, TDSANSWER *answer, unsigned char **ntlm_v2_response)
static void | tds_convert_key (const unsigned char *key_56, DES_KEY *ks)
static void | tds_encrypt_answer (const unsigned char *hash, const unsigned char *challenge, unsigned char *answer)
static TDSRET | tds_ntlm_free (TDSCONNECTION *conn, TDSAUTHENTICATION *tds_auth)
TDSAUTHENTICATION * | tds_ntlm_get_auth (TDSSOCKET *tds)
| Build a NTLMSPP packet to send to server. More...
static TDSRET | tds_ntlm_handle_next (TDSSOCKET *tds, struct tds_authentication *auth, size_t len)
static void | unix_to_nt_time (uint64_t *nt, struct timeval *tv)
| put a 8 byte filetime from a time_t This takes GMT as input

## Variables
static const char | label [] = ""
static const unsigned char | ntlm_id [] = "NTLMSSP"

## Detailed Description

Functions for handling authentication.

## Function Documentation

## ◆ tds_answer_challenge()

static TDSRET tds_answer_challenge | ( | TDSSOCKET * | tds,
|  | TDSLOGIN * | login,
|  | const unsigned char * | challenge,
|  | uint32_t * | flags,
|  | const unsigned char * | names_blob,
|  | int | names_blob_len,
|  | TDSANSWER * | answer,
|  | unsigned char ** | ntlm_v2_response
| ) |  |
| static

Crypt a given password using schema required for NTLMv1 or NTLM2 authentication.

Parameters

  passwd | clear text domain password
  challenge | challenge data given by server
  flags | NTLM flags from server side
  answer | buffer where to store crypted password

Here is the call graph for this function:

## ◆ tds_ntlm_get_auth()

TDSAUTHENTICATION* tds_ntlm_get_auth | ( | TDSSOCKET * | tds | ) |

Build a NTLMSPP packet to send to server.

Parameters

  tds | A pointer to the TDSSOCKET structure managing a client/server operation.

Returns
  authentication info

Here is the call graph for this function: