1*ebfedea0SLionel Sambuc /*	$NetBSD: netlogon.h,v 1.1.1.1 2011/04/13 18:14:47 elric Exp $	*/
2*ebfedea0SLionel Sambuc 
3*ebfedea0SLionel Sambuc /*
4*ebfedea0SLionel Sambuc  * Copyright (c) 2010 Kungliga Tekniska Högskolan
5*ebfedea0SLionel Sambuc  * (Royal Institute of Technology, Stockholm, Sweden).
6*ebfedea0SLionel Sambuc  * All rights reserved.
7*ebfedea0SLionel Sambuc  *
8*ebfedea0SLionel Sambuc  * Portions Copyright (c) 2010 Apple Inc. All rights reserved.
9*ebfedea0SLionel Sambuc  *
10*ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
11*ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
12*ebfedea0SLionel Sambuc  * are met:
13*ebfedea0SLionel Sambuc  *
14*ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
15*ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
16*ebfedea0SLionel Sambuc  *
17*ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
18*ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
19*ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
20*ebfedea0SLionel Sambuc  *
21*ebfedea0SLionel Sambuc  * 3. Neither the name of the Institute nor the names of its contributors
22*ebfedea0SLionel Sambuc  *    may be used to endorse or promote products derived from this software
23*ebfedea0SLionel Sambuc  *    without specific prior written permission.
24*ebfedea0SLionel Sambuc  *
25*ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26*ebfedea0SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27*ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28*ebfedea0SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29*ebfedea0SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30*ebfedea0SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31*ebfedea0SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32*ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33*ebfedea0SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34*ebfedea0SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35*ebfedea0SLionel Sambuc  * SUCH DAMAGE.
36*ebfedea0SLionel Sambuc  */
37*ebfedea0SLionel Sambuc 
38*ebfedea0SLionel Sambuc #ifndef NETLOGON_NETLOGON_H
39*ebfedea0SLionel Sambuc #define NETLOGON_NETLOGON_H
40*ebfedea0SLionel Sambuc 
41*ebfedea0SLionel Sambuc #include <config.h>
42*ebfedea0SLionel Sambuc 
43*ebfedea0SLionel Sambuc #include <stdio.h>
44*ebfedea0SLionel Sambuc #include <stdlib.h>
45*ebfedea0SLionel Sambuc #include <assert.h>
46*ebfedea0SLionel Sambuc #include <string.h>
47*ebfedea0SLionel Sambuc #include <errno.h>
48*ebfedea0SLionel Sambuc 
49*ebfedea0SLionel Sambuc #include <gssapi/gssapi.h>
50*ebfedea0SLionel Sambuc #include <gssapi_mech.h>
51*ebfedea0SLionel Sambuc #include <gssapi_netlogon.h>
52*ebfedea0SLionel Sambuc 
53*ebfedea0SLionel Sambuc #include <krb5/krb5.h>
54*ebfedea0SLionel Sambuc 
55*ebfedea0SLionel Sambuc #include <krb5/roken.h>
56*ebfedea0SLionel Sambuc #include <heim_threads.h>
57*ebfedea0SLionel Sambuc 
58*ebfedea0SLionel Sambuc #define HC_DEPRECATED_CRYPTO
59*ebfedea0SLionel Sambuc #include "crypto-headers.h"
60*ebfedea0SLionel Sambuc 
61*ebfedea0SLionel Sambuc /*
62*ebfedea0SLionel Sambuc  *
63*ebfedea0SLionel Sambuc  */
64*ebfedea0SLionel Sambuc 
65*ebfedea0SLionel Sambuc typedef struct {
66*ebfedea0SLionel Sambuc #define NL_NEGOTIATE_REQUEST_MESSAGE    0x00000000
67*ebfedea0SLionel Sambuc #define NL_NEGOTIATE_RESPONSE_MESSAGE   0x00000001
68*ebfedea0SLionel Sambuc     uint32_t MessageType;
69*ebfedea0SLionel Sambuc #define NL_FLAG_NETBIOS_DOMAIN_NAME     0x00000001
70*ebfedea0SLionel Sambuc #define NL_FLAG_NETBIOS_COMPUTER_NAME   0x00000002
71*ebfedea0SLionel Sambuc #define NL_FLAG_DNS_DOMAIN_NAME         0x00000004
72*ebfedea0SLionel Sambuc #define NL_FLAG_DNS_HOST_NAME           0x00000008 /* not used */
73*ebfedea0SLionel Sambuc #define NL_FLAG_UTF8_COMPUTER_NAME      0x00000010
74*ebfedea0SLionel Sambuc     uint32_t Flags;
75*ebfedea0SLionel Sambuc     char *Buffer[0];
76*ebfedea0SLionel Sambuc } NL_AUTH_MESSAGE;
77*ebfedea0SLionel Sambuc 
78*ebfedea0SLionel Sambuc #define NL_AUTH_MESSAGE_LENGTH          8
79*ebfedea0SLionel Sambuc 
80*ebfedea0SLionel Sambuc /* SignatureAlgorithm */
81*ebfedea0SLionel Sambuc #define NL_SIGN_ALG_HMAC_MD5            0x0077
82*ebfedea0SLionel Sambuc #define NL_SIGN_ALG_SHA256              0x0013
83*ebfedea0SLionel Sambuc 
84*ebfedea0SLionel Sambuc /* SealAlgorithm */
85*ebfedea0SLionel Sambuc #define NL_SEAL_ALG_RC4                 0x007A
86*ebfedea0SLionel Sambuc #define NL_SEAL_ALG_AES128              0x001A
87*ebfedea0SLionel Sambuc #define NL_SEAL_ALG_NONE                0xFFFF
88*ebfedea0SLionel Sambuc 
89*ebfedea0SLionel Sambuc typedef struct {
90*ebfedea0SLionel Sambuc     uint16_t SignatureAlgorithm;
91*ebfedea0SLionel Sambuc     uint16_t SealAlgorithm;
92*ebfedea0SLionel Sambuc     uint16_t Pad;
93*ebfedea0SLionel Sambuc     uint16_t Flags;
94*ebfedea0SLionel Sambuc     uint8_t SequenceNumber[8];
95*ebfedea0SLionel Sambuc     uint8_t Checksum[8];
96*ebfedea0SLionel Sambuc     uint8_t Confounder[8];
97*ebfedea0SLionel Sambuc } NL_AUTH_SIGNATURE;
98*ebfedea0SLionel Sambuc 
99*ebfedea0SLionel Sambuc #define NL_AUTH_SIGNATURE_HEADER_LENGTH 8
100*ebfedea0SLionel Sambuc #define NL_AUTH_SIGNATURE_COMMON_LENGTH 16
101*ebfedea0SLionel Sambuc #define NL_AUTH_SIGNATURE_LENGTH        32
102*ebfedea0SLionel Sambuc 
103*ebfedea0SLionel Sambuc typedef struct {
104*ebfedea0SLionel Sambuc     uint16_t SignatureAlgorithm;
105*ebfedea0SLionel Sambuc     uint16_t SealAlgorithm;
106*ebfedea0SLionel Sambuc     uint16_t Pad;
107*ebfedea0SLionel Sambuc     uint16_t Flags;
108*ebfedea0SLionel Sambuc     uint8_t SequenceNumber[8];
109*ebfedea0SLionel Sambuc     uint8_t Checksum[32];
110*ebfedea0SLionel Sambuc     uint8_t Confounder[8];
111*ebfedea0SLionel Sambuc } NL_AUTH_SHA2_SIGNATURE;
112*ebfedea0SLionel Sambuc 
113*ebfedea0SLionel Sambuc #define NL_AUTH_SHA2_SIGNATURE_LENGTH   56
114*ebfedea0SLionel Sambuc 
115*ebfedea0SLionel Sambuc typedef union {
116*ebfedea0SLionel Sambuc     NL_AUTH_SIGNATURE Signature;
117*ebfedea0SLionel Sambuc     NL_AUTH_SHA2_SIGNATURE SHA2Signature;
118*ebfedea0SLionel Sambuc } NL_AUTH_SIGNATURE_U;
119*ebfedea0SLionel Sambuc 
120*ebfedea0SLionel Sambuc #define NL_AUTH_SIGNATURE_P(_u)         (&(_u)->Signature)
121*ebfedea0SLionel Sambuc 
122*ebfedea0SLionel Sambuc typedef struct gssnetlogon_name {
123*ebfedea0SLionel Sambuc     gss_buffer_desc NetbiosName;
124*ebfedea0SLionel Sambuc     gss_buffer_desc DnsName;
125*ebfedea0SLionel Sambuc } *gssnetlogon_name;
126*ebfedea0SLionel Sambuc 
127*ebfedea0SLionel Sambuc typedef struct gssnetlogon_cred {
128*ebfedea0SLionel Sambuc     gssnetlogon_name *Name;
129*ebfedea0SLionel Sambuc     uint16_t SignatureAlgorithm;
130*ebfedea0SLionel Sambuc     uint16_t SealAlgorithm;
131*ebfedea0SLionel Sambuc     uint8_t SessionKey[16];
132*ebfedea0SLionel Sambuc } *gssnetlogon_cred;
133*ebfedea0SLionel Sambuc 
134*ebfedea0SLionel Sambuc typedef struct gssnetlogon_ctx {
135*ebfedea0SLionel Sambuc     HEIMDAL_MUTEX Mutex;
136*ebfedea0SLionel Sambuc     enum { NL_AUTH_NEGOTIATE, NL_AUTH_ESTABLISHED } State;
137*ebfedea0SLionel Sambuc     OM_uint32 GssFlags;
138*ebfedea0SLionel Sambuc     uint8_t LocallyInitiated;
139*ebfedea0SLionel Sambuc     uint32_t MessageBlockSize;
140*ebfedea0SLionel Sambuc     uint16_t SignatureAlgorithm;
141*ebfedea0SLionel Sambuc     uint16_t SealAlgorithm;
142*ebfedea0SLionel Sambuc     uint64_t SequenceNumber;
143*ebfedea0SLionel Sambuc     gssnetlogon_name SourceName;
144*ebfedea0SLionel Sambuc     gssnetlogon_name TargetName;
145*ebfedea0SLionel Sambuc     uint8_t SessionKey[16];
146*ebfedea0SLionel Sambuc } *gssnetlogon_ctx;
147*ebfedea0SLionel Sambuc 
148*ebfedea0SLionel Sambuc #include <netlogon-private.h>
149*ebfedea0SLionel Sambuc 
150*ebfedea0SLionel Sambuc #endif /* NETLOGON_NETLOGON_H */
151