Coverage Report

Created: 2026-07-25 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/auth/gensec/schannel.c
Line
Count
Source
1
/*
2
   Unix SMB/CIFS implementation.
3
4
   dcerpc schannel operations
5
6
   Copyright (C) Andrew Tridgell 2004
7
   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8
9
   This program is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 3 of the License, or
12
   (at your option) any later version.
13
14
   This program is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
19
   You should have received a copy of the GNU General Public License
20
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
*/
22
23
#include "includes.h"
24
#include <tevent.h>
25
#include "lib/util/tevent_ntstatus.h"
26
#include "librpc/gen_ndr/ndr_schannel.h"
27
#include "auth/auth.h"
28
#include "auth/credentials/credentials.h"
29
#include "auth/gensec/gensec.h"
30
#include "auth/gensec/gensec_internal.h"
31
#include "auth/gensec/gensec_proto.h"
32
#include "../libcli/auth/schannel.h"
33
#include "librpc/gen_ndr/dcerpc.h"
34
#include "param/param.h"
35
#include "auth/gensec/gensec_toplevel_proto.h"
36
#include "libds/common/roles.h"
37
38
#include "lib/crypto/gnutls_helpers.h"
39
#include <gnutls/gnutls.h>
40
#include <gnutls/crypto.h>
41
42
#undef DBGC_CLASS
43
0
#define DBGC_CLASS DBGC_AUTH
44
45
struct schannel_state {
46
  struct gensec_security *gensec;
47
  uint64_t seq_num;
48
  bool initiator;
49
  struct netlogon_creds_CredentialState *creds;
50
  struct auth_user_info_dc *user_info_dc;
51
};
52
53
0
#define SETUP_SEQNUM(state, buf, initiator) do { \
54
0
  uint8_t *_buf = buf; \
55
0
  uint32_t _seq_num_low = (state)->seq_num & UINT32_MAX; \
56
0
  uint32_t _seq_num_high = (state)->seq_num >> 32; \
57
0
  if (initiator) { \
58
0
    _seq_num_high |= 0x80000000; \
59
0
  } \
60
0
  RSIVAL(_buf, 0, _seq_num_low); \
61
0
  RSIVAL(_buf, 4, _seq_num_high); \
62
0
} while(0)
63
64
static struct schannel_state *netsec_create_state(
65
        struct gensec_security *gensec,
66
        struct netlogon_creds_CredentialState *creds,
67
        bool initiator)
68
0
{
69
0
  struct schannel_state *state;
70
71
0
  state = talloc_zero(gensec, struct schannel_state);
72
0
  if (state == NULL) {
73
0
    return NULL;
74
0
  }
75
76
0
  state->gensec = gensec;
77
0
  state->initiator = initiator;
78
0
  state->creds = netlogon_creds_copy(state, creds);
79
0
  if (state->creds == NULL) {
80
0
    talloc_free(state);
81
0
    return NULL;
82
0
  }
83
84
0
  gensec->private_data = state;
85
86
0
  return state;
87
0
}
88
89
static void netsec_offset_and_sizes(struct schannel_state *state,
90
            bool do_seal,
91
            uint32_t *_min_sig_size,
92
            uint32_t *_used_sig_size,
93
            uint32_t *_checksum_length,
94
            uint32_t *_confounder_ofs)
95
0
{
96
0
  uint32_t min_sig_size;
97
0
  uint32_t used_sig_size;
98
0
  uint32_t checksum_length;
99
0
  uint32_t confounder_ofs;
100
101
0
  if (state->creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
102
0
    min_sig_size = 48;
103
0
    used_sig_size = 56;
104
    /*
105
     * Note: windows has a bug here and uses the old values...
106
     *
107
     * checksum_length = 32;
108
     * confounder_ofs = 48;
109
     */
110
0
    checksum_length = 8;
111
0
    confounder_ofs = 24;
112
0
  } else {
113
0
    min_sig_size = 24;
114
0
    used_sig_size = 32;
115
0
    checksum_length = 8;
116
0
    confounder_ofs = 24;
117
0
  }
118
119
0
  if (do_seal) {
120
0
    min_sig_size += 8;
121
0
  }
122
123
0
  if (_min_sig_size) {
124
0
    *_min_sig_size = min_sig_size;
125
0
  }
126
127
0
  if (_used_sig_size) {
128
0
    *_used_sig_size = used_sig_size;
129
0
  }
130
131
0
  if (_checksum_length) {
132
0
    *_checksum_length = checksum_length;
133
0
  }
134
135
0
  if (_confounder_ofs) {
136
0
    *_confounder_ofs = confounder_ofs;
137
0
  }
138
0
}
139
140
/*******************************************************************
141
 Encode or Decode the sequence number (which is symmetric)
142
 ********************************************************************/
143
static NTSTATUS netsec_do_seq_num(struct schannel_state *state,
144
          const uint8_t *checksum,
145
          uint32_t checksum_length,
146
          uint8_t seq_num[8])
147
0
{
148
0
  if (state->creds->authenticate_kerberos) {
149
0
    DBG_WARNING("Called with authenticate_kerberos from %s %s\n",
150
0
          state->creds->account_name,
151
0
          state->creds->computer_name);
152
0
    return NT_STATUS_ACCESS_DENIED;
153
0
  }
154
155
0
  if (state->creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
156
0
    gnutls_cipher_hd_t cipher_hnd = NULL;
157
0
    gnutls_datum_t key = {
158
0
      .data = state->creds->session_key,
159
0
      .size = sizeof(state->creds->session_key),
160
0
    };
161
0
    uint32_t iv_size =
162
0
      gnutls_cipher_get_iv_size(GNUTLS_CIPHER_AES_128_CFB8);
163
0
    uint8_t _iv[iv_size];
164
0
    gnutls_datum_t iv = {
165
0
      .data = _iv,
166
0
      .size = iv_size,
167
0
    };
168
0
    int rc;
169
170
0
    ZERO_ARRAY(_iv);
171
172
0
    memcpy(iv.data + 0, checksum, 8);
173
0
    memcpy(iv.data + 8, checksum, 8);
174
175
0
    rc = gnutls_cipher_init(&cipher_hnd,
176
0
          GNUTLS_CIPHER_AES_128_CFB8,
177
0
          &key,
178
0
          &iv);
179
0
    if (rc < 0) {
180
0
      return gnutls_error_to_ntstatus(rc,
181
0
              NT_STATUS_CRYPTO_SYSTEM_INVALID);
182
0
    }
183
184
0
    rc = gnutls_cipher_encrypt(cipher_hnd, seq_num, 8);
185
0
    gnutls_cipher_deinit(cipher_hnd);
186
0
    if (rc < 0) {
187
0
      return gnutls_error_to_ntstatus(rc,
188
0
              NT_STATUS_CRYPTO_SYSTEM_INVALID);
189
0
    }
190
191
0
  } else {
192
0
    static const uint8_t zeros[4];
193
0
    uint8_t _sequence_key[16];
194
0
    gnutls_cipher_hd_t cipher_hnd;
195
0
    gnutls_datum_t sequence_key = {
196
0
      .data = _sequence_key,
197
0
      .size = sizeof(_sequence_key),
198
0
    };
199
0
    uint8_t digest1[16];
200
0
    int rc;
201
202
0
    rc = gnutls_hmac_fast(GNUTLS_MAC_MD5,
203
0
              state->creds->session_key,
204
0
              sizeof(state->creds->session_key),
205
0
              zeros,
206
0
              sizeof(zeros),
207
0
              digest1);
208
0
    if (rc < 0) {
209
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
210
0
    }
211
212
0
    rc = gnutls_hmac_fast(GNUTLS_MAC_MD5,
213
0
              digest1,
214
0
              sizeof(digest1),
215
0
              checksum,
216
0
              checksum_length,
217
0
              _sequence_key);
218
0
    ZERO_ARRAY(digest1);
219
0
    if (rc < 0) {
220
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
221
0
    }
222
223
0
    rc = gnutls_cipher_init(&cipher_hnd,
224
0
          GNUTLS_CIPHER_ARCFOUR_128,
225
0
          &sequence_key,
226
0
          NULL);
227
0
    if (rc < 0) {
228
0
      ZERO_ARRAY(_sequence_key);
229
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
230
0
    }
231
232
0
    rc = gnutls_cipher_encrypt(cipher_hnd,
233
0
             seq_num,
234
0
             8);
235
0
    gnutls_cipher_deinit(cipher_hnd);
236
0
    ZERO_ARRAY(_sequence_key);
237
0
    if (rc < 0) {
238
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
239
0
    }
240
0
  }
241
242
0
  state->seq_num++;
243
244
0
  return NT_STATUS_OK;
245
0
}
246
247
static NTSTATUS netsec_do_seal(struct schannel_state *state,
248
             const uint8_t seq_num[8],
249
             uint8_t confounder[8],
250
             uint8_t *data, uint32_t length,
251
             bool forward)
252
0
{
253
0
  if (state->creds->authenticate_kerberos) {
254
0
    DBG_WARNING("Called with authenticate_kerberos from %s %s\n",
255
0
          state->creds->account_name,
256
0
          state->creds->computer_name);
257
0
    return NT_STATUS_ACCESS_DENIED;
258
0
  }
259
260
0
  if (state->creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
261
0
    gnutls_cipher_hd_t cipher_hnd = NULL;
262
0
    uint8_t sess_kf0[16] = {0};
263
0
    gnutls_datum_t key = {
264
0
      .data = sess_kf0,
265
0
      .size = sizeof(sess_kf0),
266
0
    };
267
0
    uint32_t iv_size =
268
0
      gnutls_cipher_get_iv_size(GNUTLS_CIPHER_AES_128_CFB8);
269
0
    uint8_t _iv[iv_size];
270
0
    gnutls_datum_t iv = {
271
0
      .data = _iv,
272
0
      .size = iv_size,
273
0
    };
274
0
    uint32_t i;
275
0
    int rc;
276
277
0
    for (i = 0; i < key.size; i++) {
278
0
      key.data[i] = state->creds->session_key[i] ^ 0xf0;
279
0
    }
280
281
0
    ZERO_ARRAY(_iv);
282
283
0
    memcpy(iv.data + 0, seq_num, 8);
284
0
    memcpy(iv.data + 8, seq_num, 8);
285
286
0
    rc = gnutls_cipher_init(&cipher_hnd,
287
0
          GNUTLS_CIPHER_AES_128_CFB8,
288
0
          &key,
289
0
          &iv);
290
0
    ZERO_ARRAY(sess_kf0);
291
0
    if (rc < 0) {
292
0
      DBG_ERR("ERROR: gnutls_cipher_init: %s\n",
293
0
        gnutls_strerror(rc));
294
0
      return NT_STATUS_NO_MEMORY;
295
0
    }
296
297
0
    if (forward) {
298
0
      rc = gnutls_cipher_encrypt(cipher_hnd,
299
0
               confounder,
300
0
               8);
301
0
      if (rc < 0) {
302
0
        gnutls_cipher_deinit(cipher_hnd);
303
0
        return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
304
0
      }
305
306
0
      rc = gnutls_cipher_encrypt(cipher_hnd,
307
0
               data,
308
0
               length);
309
0
      if (rc < 0) {
310
0
        gnutls_cipher_deinit(cipher_hnd);
311
0
        return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
312
0
      }
313
0
    } else {
314
315
      /*
316
       * Workaround bug present in gnutls 3.6.8:
317
       *
318
       * gnutls_cipher_decrypt() uses an optimization
319
       * internally that breaks decryption when processing
320
       * buffers with their length not being a multiple
321
       * of the blocksize.
322
       */
323
324
0
      uint8_t tmp[16] = { 0, };
325
0
      uint32_t tmp_dlength = MIN(length, sizeof(tmp) - 8);
326
327
0
      memcpy(tmp, confounder, 8);
328
0
      memcpy(tmp + 8, data, tmp_dlength);
329
330
0
      rc = gnutls_cipher_decrypt(cipher_hnd,
331
0
               tmp,
332
0
               8 + tmp_dlength);
333
0
      if (rc < 0) {
334
0
        ZERO_STRUCT(tmp);
335
0
        gnutls_cipher_deinit(cipher_hnd);
336
0
        return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
337
0
      }
338
339
0
      memcpy(confounder, tmp, 8);
340
0
      memcpy(data, tmp + 8, tmp_dlength);
341
0
      ZERO_STRUCT(tmp);
342
343
0
      if (length > tmp_dlength) {
344
0
        rc = gnutls_cipher_decrypt(cipher_hnd,
345
0
                 data + tmp_dlength,
346
0
                 length - tmp_dlength);
347
0
        if (rc < 0) {
348
0
          gnutls_cipher_deinit(cipher_hnd);
349
0
          return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
350
0
        }
351
0
      }
352
0
    }
353
0
    gnutls_cipher_deinit(cipher_hnd);
354
0
  } else {
355
0
    gnutls_cipher_hd_t cipher_hnd;
356
0
    uint8_t _sealing_key[16];
357
0
    gnutls_datum_t sealing_key = {
358
0
      .data = _sealing_key,
359
0
      .size = sizeof(_sealing_key),
360
0
    };
361
0
    static const uint8_t zeros[4];
362
0
    uint8_t digest2[16];
363
0
    uint8_t sess_kf0[16];
364
0
    int rc;
365
0
    int i;
366
367
0
    for (i = 0; i < 16; i++) {
368
0
      sess_kf0[i] = state->creds->session_key[i] ^ 0xf0;
369
0
    }
370
371
0
    rc = gnutls_hmac_fast(GNUTLS_MAC_MD5,
372
0
              sess_kf0,
373
0
              sizeof(sess_kf0),
374
0
              zeros,
375
0
              4,
376
0
              digest2);
377
0
    ZERO_ARRAY(sess_kf0);
378
0
    if (rc < 0) {
379
0
      ZERO_ARRAY(digest2);
380
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
381
0
    }
382
383
0
    rc = gnutls_hmac_fast(GNUTLS_MAC_MD5,
384
0
              digest2,
385
0
              sizeof(digest2),
386
0
              seq_num,
387
0
              8,
388
0
              _sealing_key);
389
390
0
    ZERO_ARRAY(digest2);
391
0
    if (rc < 0) {
392
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
393
0
    }
394
395
0
    rc = gnutls_cipher_init(&cipher_hnd,
396
0
          GNUTLS_CIPHER_ARCFOUR_128,
397
0
          &sealing_key,
398
0
          NULL);
399
0
    if (rc < 0) {
400
0
      ZERO_ARRAY(_sealing_key);
401
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
402
0
    }
403
0
    rc = gnutls_cipher_encrypt(cipher_hnd,
404
0
             confounder,
405
0
             8);
406
0
    if (rc < 0) {
407
0
      ZERO_ARRAY(_sealing_key);
408
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
409
0
    }
410
0
    gnutls_cipher_deinit(cipher_hnd);
411
0
    rc = gnutls_cipher_init(&cipher_hnd,
412
0
          GNUTLS_CIPHER_ARCFOUR_128,
413
0
          &sealing_key,
414
0
          NULL);
415
0
    if (rc < 0) {
416
0
      ZERO_ARRAY(_sealing_key);
417
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
418
0
    }
419
0
    rc = gnutls_cipher_encrypt(cipher_hnd,
420
0
             data,
421
0
             length);
422
0
    gnutls_cipher_deinit(cipher_hnd);
423
0
    ZERO_ARRAY(_sealing_key);
424
0
    if (rc < 0) {
425
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
426
0
    }
427
0
  }
428
429
0
  return NT_STATUS_OK;
430
0
}
431
432
/*******************************************************************
433
 Create a digest over the entire packet (including the data), and
434
 MD5 it with the session key.
435
 ********************************************************************/
436
static NTSTATUS netsec_do_sign(struct schannel_state *state,
437
             const uint8_t *confounder,
438
             const uint8_t *data, size_t length,
439
             uint8_t header[8],
440
             uint8_t *checksum)
441
0
{
442
0
  if (state->creds->authenticate_kerberos) {
443
0
    DBG_WARNING("Called with authenticate_kerberos from %s %s\n",
444
0
          state->creds->account_name,
445
0
          state->creds->computer_name);
446
0
    return NT_STATUS_ACCESS_DENIED;
447
0
  }
448
449
0
  if (state->creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
450
0
    gnutls_hmac_hd_t hmac_hnd = NULL;
451
0
    int rc;
452
453
0
    rc = gnutls_hmac_init(&hmac_hnd,
454
0
              GNUTLS_MAC_SHA256,
455
0
              state->creds->session_key,
456
0
              sizeof(state->creds->session_key));
457
0
    if (rc < 0) {
458
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
459
0
    }
460
461
0
    if (confounder) {
462
0
      SSVAL(header, 0, NL_SIGN_HMAC_SHA256);
463
0
      SSVAL(header, 2, NL_SEAL_AES128);
464
0
      SSVAL(header, 4, 0xFFFF);
465
0
      SSVAL(header, 6, 0x0000);
466
467
0
      rc = gnutls_hmac(hmac_hnd, header, 8);
468
0
      if (rc < 0) {
469
0
        gnutls_hmac_deinit(hmac_hnd, NULL);
470
0
        return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
471
0
      }
472
0
      rc = gnutls_hmac(hmac_hnd, confounder, 8);
473
0
      if (rc < 0) {
474
0
        gnutls_hmac_deinit(hmac_hnd, NULL);
475
0
        return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
476
0
      }
477
0
    } else {
478
0
      SSVAL(header, 0, NL_SIGN_HMAC_SHA256);
479
0
      SSVAL(header, 2, NL_SEAL_NONE);
480
0
      SSVAL(header, 4, 0xFFFF);
481
0
      SSVAL(header, 6, 0x0000);
482
483
0
      rc = gnutls_hmac(hmac_hnd, header, 8);
484
0
      if (rc < 0) {
485
0
        gnutls_hmac_deinit(hmac_hnd, NULL);
486
0
        return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
487
0
      }
488
0
    }
489
490
0
    rc = gnutls_hmac(hmac_hnd, data, length);
491
0
    if (rc < 0) {
492
0
      gnutls_hmac_deinit(hmac_hnd, NULL);
493
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
494
0
    }
495
496
0
    gnutls_hmac_deinit(hmac_hnd, checksum);
497
0
  } else {
498
0
    uint8_t packet_digest[16];
499
0
    static const uint8_t zeros[4];
500
0
    gnutls_hash_hd_t hash_hnd = NULL;
501
0
    int rc;
502
503
0
    rc = gnutls_hash_init(&hash_hnd, GNUTLS_DIG_MD5);
504
0
    if (rc < 0) {
505
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
506
0
    }
507
508
0
    rc = gnutls_hash(hash_hnd, zeros, sizeof(zeros));
509
0
    if (rc < 0) {
510
0
      gnutls_hash_deinit(hash_hnd, NULL);
511
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
512
0
    }
513
0
    if (confounder) {
514
0
      SSVAL(header, 0, NL_SIGN_HMAC_MD5);
515
0
      SSVAL(header, 2, NL_SEAL_RC4);
516
0
      SSVAL(header, 4, 0xFFFF);
517
0
      SSVAL(header, 6, 0x0000);
518
519
0
      rc = gnutls_hash(hash_hnd, header, 8);
520
0
      if (rc < 0) {
521
0
        gnutls_hash_deinit(hash_hnd, NULL);
522
0
        return gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
523
0
      }
524
0
      rc = gnutls_hash(hash_hnd, confounder, 8);
525
0
      if (rc < 0) {
526
0
        gnutls_hash_deinit(hash_hnd, NULL);
527
0
        return gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
528
0
      }
529
0
    } else {
530
0
      SSVAL(header, 0, NL_SIGN_HMAC_MD5);
531
0
      SSVAL(header, 2, NL_SEAL_NONE);
532
0
      SSVAL(header, 4, 0xFFFF);
533
0
      SSVAL(header, 6, 0x0000);
534
535
0
      rc = gnutls_hash(hash_hnd, header, 8);
536
0
      if (rc < 0) {
537
0
        gnutls_hash_deinit(hash_hnd, NULL);
538
0
        return gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
539
0
      }
540
0
    }
541
0
    rc = gnutls_hash(hash_hnd, data, length);
542
0
    if (rc < 0) {
543
0
      gnutls_hash_deinit(hash_hnd, NULL);
544
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
545
0
    }
546
0
    gnutls_hash_deinit(hash_hnd, packet_digest);
547
548
0
    rc = gnutls_hmac_fast(GNUTLS_MAC_MD5,
549
0
              state->creds->session_key,
550
0
              sizeof(state->creds->session_key),
551
0
              packet_digest,
552
0
              sizeof(packet_digest),
553
0
              checksum);
554
0
    ZERO_ARRAY(packet_digest);
555
0
    if (rc < 0) {
556
0
      return gnutls_error_to_ntstatus(rc, NT_STATUS_HMAC_NOT_SUPPORTED);
557
0
    }
558
0
  }
559
560
0
  return NT_STATUS_OK;
561
0
}
562
563
static NTSTATUS netsec_incoming_packet(struct schannel_state *state,
564
        bool do_unseal,
565
        uint8_t *data, size_t length,
566
        const uint8_t *whole_pdu, size_t pdu_length,
567
        const DATA_BLOB *sig)
568
0
{
569
0
  uint32_t min_sig_size = 0;
570
0
  uint8_t header[8];
571
0
  uint8_t checksum[32];
572
0
  uint32_t checksum_length = sizeof(checksum_length);
573
0
  uint8_t _confounder[8];
574
0
  uint8_t *confounder = NULL;
575
0
  uint32_t confounder_ofs = 0;
576
0
  uint8_t seq_num[8];
577
0
  bool ret;
578
0
  const uint8_t *sign_data = NULL;
579
0
  size_t sign_length = 0;
580
0
  NTSTATUS status;
581
582
0
  netsec_offset_and_sizes(state,
583
0
        do_unseal,
584
0
        &min_sig_size,
585
0
        NULL,
586
0
        &checksum_length,
587
0
        &confounder_ofs);
588
589
0
  if (sig->length < min_sig_size) {
590
0
    return NT_STATUS_ACCESS_DENIED;
591
0
  }
592
593
0
  if (do_unseal) {
594
0
    confounder = _confounder;
595
0
    memcpy(confounder, sig->data+confounder_ofs, 8);
596
0
  } else {
597
0
    confounder = NULL;
598
0
  }
599
600
0
  SETUP_SEQNUM(state, seq_num, !state->initiator);
601
602
0
  if (do_unseal) {
603
0
    status = netsec_do_seal(state,
604
0
          seq_num,
605
0
          confounder,
606
0
          data,
607
0
          length,
608
0
          false);
609
0
    if (!NT_STATUS_IS_OK(status)) {
610
0
      DBG_WARNING("netsec_do_seal failed: %s\n", nt_errstr(status));
611
0
      return NT_STATUS_ACCESS_DENIED;
612
0
    }
613
0
  }
614
615
0
  if (state->gensec->want_features & GENSEC_FEATURE_SIGN_PKT_HEADER) {
616
0
    sign_data = whole_pdu;
617
0
    sign_length = pdu_length;
618
0
  } else {
619
0
    sign_data = data;
620
0
    sign_length = length;
621
0
  }
622
623
0
  status = netsec_do_sign(state,
624
0
        confounder,
625
0
        sign_data,
626
0
        sign_length,
627
0
        header,
628
0
        checksum);
629
0
  if (!NT_STATUS_IS_OK(status)) {
630
0
    DBG_WARNING("netsec_do_sign failed: %s\n", nt_errstr(status));
631
0
    return NT_STATUS_ACCESS_DENIED;
632
0
  }
633
634
0
  ret = mem_equal_const_time(checksum, sig->data+16, checksum_length);
635
0
  if (!ret) {
636
0
    dump_data_pw("calc digest:", checksum, checksum_length);
637
0
    dump_data_pw("wire digest:", sig->data+16, checksum_length);
638
0
    return NT_STATUS_ACCESS_DENIED;
639
0
  }
640
641
0
  status = netsec_do_seq_num(state, checksum, checksum_length, seq_num);
642
0
  if (!NT_STATUS_IS_OK(status)) {
643
0
    DBG_WARNING("netsec_do_seq_num failed: %s\n",
644
0
          nt_errstr(status));
645
0
    return status;
646
0
  }
647
648
0
  ZERO_ARRAY(checksum);
649
650
0
  ret = mem_equal_const_time(seq_num, sig->data+8, 8);
651
0
  if (!ret) {
652
0
    dump_data_pw("calc seq num:", seq_num, 8);
653
0
    dump_data_pw("wire seq num:", sig->data+8, 8);
654
0
    return NT_STATUS_ACCESS_DENIED;
655
0
  }
656
657
0
  return NT_STATUS_OK;
658
0
}
659
660
static uint32_t netsec_outgoing_sig_size(struct schannel_state *state)
661
0
{
662
0
  uint32_t sig_size = 0;
663
664
0
  netsec_offset_and_sizes(state,
665
0
        true,
666
0
        NULL,
667
0
        &sig_size,
668
0
        NULL,
669
0
        NULL);
670
671
0
  return sig_size;
672
0
}
673
674
static NTSTATUS netsec_outgoing_packet(struct schannel_state *state,
675
        TALLOC_CTX *mem_ctx,
676
        bool do_seal,
677
        uint8_t *data, size_t length,
678
        const uint8_t *whole_pdu, size_t pdu_length,
679
        DATA_BLOB *sig)
680
0
{
681
0
  uint32_t min_sig_size = 0;
682
0
  uint32_t used_sig_size = 0;
683
0
  uint8_t header[8];
684
0
  uint8_t checksum[32];
685
0
  uint32_t checksum_length = sizeof(checksum_length);
686
0
  uint8_t _confounder[8];
687
0
  uint8_t *confounder = NULL;
688
0
  uint32_t confounder_ofs = 0;
689
0
  uint8_t seq_num[8];
690
0
  const uint8_t *sign_data = NULL;
691
0
  size_t sign_length = 0;
692
0
  NTSTATUS status;
693
694
0
  netsec_offset_and_sizes(state,
695
0
        do_seal,
696
0
        &min_sig_size,
697
0
        &used_sig_size,
698
0
        &checksum_length,
699
0
        &confounder_ofs);
700
701
0
  SETUP_SEQNUM(state, seq_num, state->initiator);
702
703
0
  if (do_seal) {
704
0
    confounder = _confounder;
705
0
    generate_random_buffer(confounder, 8);
706
0
  } else {
707
0
    confounder = NULL;
708
0
  }
709
710
0
  if (state->gensec->want_features & GENSEC_FEATURE_SIGN_PKT_HEADER) {
711
0
    sign_data = whole_pdu;
712
0
    sign_length = pdu_length;
713
0
  } else {
714
0
    sign_data = data;
715
0
    sign_length = length;
716
0
  }
717
718
0
  status = netsec_do_sign(state,
719
0
        confounder,
720
0
        sign_data,
721
0
        sign_length,
722
0
        header,
723
0
        checksum);
724
0
  if (!NT_STATUS_IS_OK(status)) {
725
0
    DBG_WARNING("netsec_do_sign failed: %s\n", nt_errstr(status));
726
0
    return NT_STATUS_ACCESS_DENIED;
727
0
  }
728
729
0
  if (do_seal) {
730
0
    status = netsec_do_seal(state,
731
0
          seq_num,
732
0
          confounder,
733
0
          data,
734
0
          length,
735
0
          true);
736
0
    if (!NT_STATUS_IS_OK(status)) {
737
0
      DBG_WARNING("netsec_do_seal failed: %s\n",
738
0
            nt_errstr(status));
739
0
      return status;
740
0
    }
741
0
  }
742
743
0
  status = netsec_do_seq_num(state, checksum, checksum_length, seq_num);
744
0
  if (!NT_STATUS_IS_OK(status)) {
745
0
    DBG_WARNING("netsec_do_seq_num failed: %s\n",
746
0
          nt_errstr(status));
747
0
    return status;
748
0
  }
749
750
0
  (*sig) = data_blob_talloc_zero(mem_ctx, used_sig_size);
751
752
0
  memcpy(sig->data, header, 8);
753
0
  memcpy(sig->data+8, seq_num, 8);
754
0
  memcpy(sig->data+16, checksum, checksum_length);
755
756
0
  if (confounder) {
757
0
    memcpy(sig->data+confounder_ofs, confounder, 8);
758
0
  }
759
760
0
  dump_data_pw("signature:", sig->data+ 0, 8);
761
0
  dump_data_pw("seq_num  :", sig->data+ 8, 8);
762
0
  dump_data_pw("digest   :", sig->data+16, checksum_length);
763
0
  dump_data_pw("confound :", sig->data+confounder_ofs, 8);
764
765
0
  return NT_STATUS_OK;
766
0
}
767
768
_PUBLIC_ NTSTATUS gensec_schannel_init(TALLOC_CTX *ctx);
769
770
static size_t schannel_sig_size(struct gensec_security *gensec_security, size_t data_size)
771
0
{
772
0
  struct schannel_state *state =
773
0
    talloc_get_type_abort(gensec_security->private_data,
774
0
    struct schannel_state);
775
776
0
  return netsec_outgoing_sig_size(state);
777
0
}
778
779
struct schannel_update_state {
780
  NTSTATUS status;
781
  DATA_BLOB out;
782
};
783
784
static NTSTATUS schannel_update_internal(struct gensec_security *gensec_security,
785
           TALLOC_CTX *out_mem_ctx,
786
           const DATA_BLOB in, DATA_BLOB *out);
787
788
static struct tevent_req *schannel_update_send(TALLOC_CTX *mem_ctx,
789
                 struct tevent_context *ev,
790
                 struct gensec_security *gensec_security,
791
                 const DATA_BLOB in)
792
0
{
793
0
  struct tevent_req *req;
794
0
  struct schannel_update_state *state = NULL;
795
0
  NTSTATUS status;
796
797
0
  req = tevent_req_create(mem_ctx, &state,
798
0
        struct schannel_update_state);
799
0
  if (req == NULL) {
800
0
    return NULL;
801
0
  }
802
803
0
  status = schannel_update_internal(gensec_security,
804
0
            state, in,
805
0
            &state->out);
806
0
  state->status = status;
807
0
  if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
808
0
    status = NT_STATUS_OK;
809
0
  }
810
0
  if (tevent_req_nterror(req, status)) {
811
0
    return tevent_req_post(req, ev);
812
0
  }
813
814
0
  tevent_req_done(req);
815
0
  return tevent_req_post(req, ev);
816
0
}
817
818
static NTSTATUS schannel_update_internal(struct gensec_security *gensec_security,
819
           TALLOC_CTX *out_mem_ctx,
820
           const DATA_BLOB in, DATA_BLOB *out)
821
0
{
822
0
  struct schannel_state *state =
823
0
    talloc_get_type(gensec_security->private_data,
824
0
    struct schannel_state);
825
0
  NTSTATUS status;
826
0
  enum ndr_err_code ndr_err;
827
0
  struct NL_AUTH_MESSAGE bind_schannel = {
828
0
    .Flags = 0,
829
0
  };
830
0
  struct NL_AUTH_MESSAGE bind_schannel_ack;
831
0
  struct netlogon_creds_CredentialState *creds;
832
0
  const char *workstation;
833
0
  const char *domain;
834
835
0
  *out = data_blob(NULL, 0);
836
837
0
  if (gensec_security->dcerpc_auth_level < DCERPC_AUTH_LEVEL_INTEGRITY) {
838
0
    switch (gensec_security->gensec_role) {
839
0
    case GENSEC_CLIENT:
840
0
      return NT_STATUS_INVALID_PARAMETER_MIX;
841
0
    case GENSEC_SERVER:
842
0
      return NT_STATUS_INVALID_PARAMETER;
843
0
    }
844
0
    return NT_STATUS_INTERNAL_ERROR;
845
0
  }
846
847
0
  switch (gensec_security->gensec_role) {
848
0
  case GENSEC_CLIENT:
849
0
    if (state != NULL) {
850
      /* we could parse the bind ack, but we don't know what it is yet */
851
0
      return NT_STATUS_OK;
852
0
    }
853
854
0
    creds = cli_credentials_get_netlogon_creds(gensec_security->credentials);
855
0
    if (creds == NULL) {
856
0
      return NT_STATUS_INVALID_PARAMETER_MIX;
857
0
    }
858
859
0
    if (creds->authenticate_kerberos) {
860
0
      DBG_ERR("attempted schannel connection with "
861
0
        "authenticate_kerberos from %s %s\n",
862
0
        creds->account_name,
863
0
        creds->computer_name);
864
0
      NDR_PRINT_DEBUG(netlogon_creds_CredentialState, creds);
865
0
      log_stack_trace();
866
0
      return NT_STATUS_INVALID_PARAMETER_MIX;
867
0
    }
868
869
0
    state = netsec_create_state(gensec_security,
870
0
              creds, true /* initiator */);
871
0
    if (state == NULL) {
872
0
      return NT_STATUS_NO_MEMORY;
873
0
    }
874
875
0
    bind_schannel.MessageType = NL_NEGOTIATE_REQUEST;
876
877
0
    bind_schannel.Flags = NL_FLAG_OEM_NETBIOS_DOMAIN_NAME |
878
0
              NL_FLAG_OEM_NETBIOS_COMPUTER_NAME;
879
0
    bind_schannel.oem_netbios_domain.a = cli_credentials_get_domain(gensec_security->credentials);
880
0
    bind_schannel.oem_netbios_computer.a = creds->computer_name;
881
882
0
    if (creds->secure_channel_type == SEC_CHAN_DNS_DOMAIN) {
883
0
      bind_schannel.Flags |= NL_FLAG_UTF8_DNS_DOMAIN_NAME;
884
0
      bind_schannel.utf8_dns_domain.u = cli_credentials_get_realm(gensec_security->credentials);
885
886
0
      bind_schannel.Flags |= NL_FLAG_UTF8_NETBIOS_COMPUTER_NAME;
887
0
      bind_schannel.utf8_netbios_computer.u = creds->computer_name;
888
0
    }
889
890
0
    ndr_err = ndr_push_struct_blob(out, out_mem_ctx, &bind_schannel,
891
0
                 (ndr_push_flags_fn_t)ndr_push_NL_AUTH_MESSAGE);
892
0
    if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
893
0
      status = ndr_map_error2ntstatus(ndr_err);
894
0
      DEBUG(3, ("Could not create schannel bind: %s\n",
895
0
          nt_errstr(status)));
896
0
      return status;
897
0
    }
898
899
0
    return NT_STATUS_MORE_PROCESSING_REQUIRED;
900
0
  case GENSEC_SERVER:
901
902
0
    if (state != NULL) {
903
      /* no third leg on this protocol */
904
0
      return NT_STATUS_INVALID_PARAMETER;
905
0
    }
906
907
    /* parse the schannel startup blob */
908
0
    ndr_err = ndr_pull_struct_blob(&in, out_mem_ctx, &bind_schannel,
909
0
      (ndr_pull_flags_fn_t)ndr_pull_NL_AUTH_MESSAGE);
910
0
    if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
911
0
      status = ndr_map_error2ntstatus(ndr_err);
912
0
      DEBUG(3, ("Could not parse incoming schannel bind: %s\n",
913
0
          nt_errstr(status)));
914
0
      return status;
915
0
    }
916
917
0
    if (bind_schannel.Flags & NL_FLAG_OEM_NETBIOS_DOMAIN_NAME) {
918
0
      domain = bind_schannel.oem_netbios_domain.a;
919
0
      if (strcasecmp_m(domain, lpcfg_workgroup(gensec_security->settings->lp_ctx)) != 0) {
920
0
        DEBUG(3, ("Request for schannel to incorrect domain: %s != our domain %s\n",
921
0
            domain, lpcfg_workgroup(gensec_security->settings->lp_ctx)));
922
0
        return NT_STATUS_LOGON_FAILURE;
923
0
      }
924
0
    } else if (bind_schannel.Flags & NL_FLAG_UTF8_DNS_DOMAIN_NAME) {
925
0
      domain = bind_schannel.utf8_dns_domain.u;
926
0
      if (strcasecmp_m(domain, lpcfg_dnsdomain(gensec_security->settings->lp_ctx)) != 0) {
927
0
        DEBUG(3, ("Request for schannel to incorrect domain: %s != our domain %s\n",
928
0
            domain, lpcfg_dnsdomain(gensec_security->settings->lp_ctx)));
929
0
        return NT_STATUS_LOGON_FAILURE;
930
0
      }
931
0
    } else {
932
0
      DEBUG(3, ("Request for schannel to without domain\n"));
933
0
      return NT_STATUS_LOGON_FAILURE;
934
0
    }
935
936
0
    if (bind_schannel.Flags & NL_FLAG_OEM_NETBIOS_COMPUTER_NAME) {
937
0
      workstation = bind_schannel.oem_netbios_computer.a;
938
0
    } else if (bind_schannel.Flags & NL_FLAG_UTF8_NETBIOS_COMPUTER_NAME) {
939
0
      workstation = bind_schannel.utf8_netbios_computer.u;
940
0
    } else {
941
0
      DEBUG(3, ("Request for schannel to without netbios workstation\n"));
942
0
      return NT_STATUS_LOGON_FAILURE;
943
0
    }
944
945
0
    status = schannel_get_creds_state(out_mem_ctx,
946
0
              gensec_security->settings->lp_ctx,
947
0
              workstation, &creds);
948
0
    if (!NT_STATUS_IS_OK(status)) {
949
0
      DEBUG(3, ("Could not find session key for attempted schannel connection from %s: %s\n",
950
0
          workstation, nt_errstr(status)));
951
0
      if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
952
0
        return NT_STATUS_LOGON_FAILURE;
953
0
      }
954
0
      return status;
955
0
    }
956
957
0
    state = netsec_create_state(gensec_security,
958
0
              creds, false /* not initiator */);
959
0
    if (state == NULL) {
960
0
      return NT_STATUS_NO_MEMORY;
961
0
    }
962
963
0
    status = auth_anonymous_user_info_dc(state,
964
0
        lpcfg_netbios_name(gensec_security->settings->lp_ctx),
965
0
        &state->user_info_dc);
966
0
    if (!NT_STATUS_IS_OK(status)) {
967
0
      return status;
968
0
    }
969
970
0
    bind_schannel_ack.MessageType = NL_NEGOTIATE_RESPONSE;
971
0
    bind_schannel_ack.Flags = 0;
972
0
    bind_schannel_ack.Buffer.dummy = 0x6c0000; /* actually I think
973
                  * this does not have
974
                  * any meaning here
975
                  * - gd */
976
977
0
    ndr_err = ndr_push_struct_blob(out, out_mem_ctx, &bind_schannel_ack,
978
0
                 (ndr_push_flags_fn_t)ndr_push_NL_AUTH_MESSAGE);
979
0
    if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
980
0
      status = ndr_map_error2ntstatus(ndr_err);
981
0
      DEBUG(3, ("Could not return schannel bind ack for client %s: %s\n",
982
0
          workstation, nt_errstr(status)));
983
0
      return status;
984
0
    }
985
986
0
    return NT_STATUS_OK;
987
0
  }
988
0
  return NT_STATUS_INVALID_PARAMETER;
989
0
}
990
991
static NTSTATUS schannel_update_recv(struct tevent_req *req,
992
             TALLOC_CTX *out_mem_ctx,
993
             DATA_BLOB *out)
994
0
{
995
0
  struct schannel_update_state *state =
996
0
    tevent_req_data(req,
997
0
    struct schannel_update_state);
998
0
  NTSTATUS status;
999
1000
0
  *out = data_blob_null;
1001
1002
0
  if (tevent_req_is_nterror(req, &status)) {
1003
0
    tevent_req_received(req);
1004
0
    return status;
1005
0
  }
1006
1007
0
  status = state->status;
1008
0
  talloc_steal(out_mem_ctx, state->out.data);
1009
0
  *out = state->out;
1010
0
  tevent_req_received(req);
1011
0
  return status;
1012
0
}
1013
1014
/**
1015
 * Returns anonymous credentials for schannel, matching Win2k3.
1016
 *
1017
 */
1018
1019
static NTSTATUS schannel_session_info(struct gensec_security *gensec_security,
1020
              TALLOC_CTX *mem_ctx,
1021
              struct auth_session_info **_session_info)
1022
0
{
1023
0
  struct schannel_state *state =
1024
0
    talloc_get_type(gensec_security->private_data,
1025
0
    struct schannel_state);
1026
0
  struct auth4_context *auth_ctx = gensec_security->auth_context;
1027
0
  struct auth_session_info *session_info = NULL;
1028
0
  uint32_t session_info_flags = 0;
1029
0
  NTSTATUS status;
1030
1031
0
  if (auth_ctx == NULL) {
1032
0
    DEBUG(0, ("Cannot generate a session_info without the auth_context\n"));
1033
0
    return NT_STATUS_INTERNAL_ERROR;
1034
0
  }
1035
1036
0
  if (auth_ctx->generate_session_info == NULL) {
1037
0
    DEBUG(0, ("Cannot generate a session_info without the generate_session_info hook\n"));
1038
0
    return NT_STATUS_INTERNAL_ERROR;
1039
0
  }
1040
1041
0
  if (gensec_security->want_features & GENSEC_FEATURE_UNIX_TOKEN) {
1042
0
    session_info_flags |= AUTH_SESSION_INFO_UNIX_TOKEN;
1043
0
  }
1044
1045
0
  session_info_flags |= AUTH_SESSION_INFO_SIMPLE_PRIVILEGES;
1046
1047
0
  status = auth_ctx->generate_session_info(
1048
0
        auth_ctx,
1049
0
        mem_ctx,
1050
0
        state->user_info_dc,
1051
0
        state->user_info_dc->info->account_name,
1052
0
        session_info_flags,
1053
0
        &session_info);
1054
0
  if (!NT_STATUS_IS_OK(status)) {
1055
0
    return status;
1056
0
  }
1057
1058
0
  *_session_info = session_info;
1059
0
  return NT_STATUS_OK;
1060
0
}
1061
1062
/*
1063
 * Reduce the attack surface by ensuring schannel is not available when
1064
 * we are not a DC
1065
 */
1066
static NTSTATUS schannel_server_start(struct gensec_security *gensec_security)
1067
0
{
1068
0
  enum server_role server_role
1069
0
    = lpcfg_server_role(gensec_security->settings->lp_ctx);
1070
1071
0
  switch (server_role) {
1072
0
  case ROLE_DOMAIN_BDC:
1073
0
  case ROLE_DOMAIN_PDC:
1074
0
  case ROLE_ACTIVE_DIRECTORY_DC:
1075
0
  case ROLE_IPA_DC:
1076
0
    return NT_STATUS_OK;
1077
0
  default:
1078
0
    return NT_STATUS_NOT_IMPLEMENTED;
1079
0
  }
1080
0
}
1081
1082
static NTSTATUS schannel_client_start(struct gensec_security *gensec_security)
1083
0
{
1084
0
  return NT_STATUS_OK;
1085
0
}
1086
1087
static bool schannel_have_feature(struct gensec_security *gensec_security,
1088
           uint32_t feature)
1089
0
{
1090
0
  if (gensec_security->dcerpc_auth_level >= DCERPC_AUTH_LEVEL_INTEGRITY) {
1091
0
    if (feature & GENSEC_FEATURE_SIGN) {
1092
0
      return true;
1093
0
    }
1094
0
  }
1095
0
  if (gensec_security->dcerpc_auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
1096
0
    if (feature & GENSEC_FEATURE_SEAL) {
1097
0
      return true;
1098
0
    }
1099
0
  }
1100
0
  if (feature & GENSEC_FEATURE_DCE_STYLE) {
1101
0
    return true;
1102
0
  }
1103
0
  if (feature & GENSEC_FEATURE_SIGN_PKT_HEADER) {
1104
0
    return true;
1105
0
  }
1106
0
  return false;
1107
0
}
1108
1109
/*
1110
  unseal a packet
1111
*/
1112
static NTSTATUS schannel_unseal_packet(struct gensec_security *gensec_security,
1113
               uint8_t *data, size_t length,
1114
               const uint8_t *whole_pdu, size_t pdu_length,
1115
               const DATA_BLOB *sig)
1116
0
{
1117
0
  struct schannel_state *state =
1118
0
    talloc_get_type_abort(gensec_security->private_data,
1119
0
    struct schannel_state);
1120
1121
0
  return netsec_incoming_packet(state, true,
1122
0
              discard_const_p(uint8_t, data),
1123
0
              length,
1124
0
              whole_pdu, pdu_length,
1125
0
              sig);
1126
0
}
1127
1128
/*
1129
  check the signature on a packet
1130
*/
1131
static NTSTATUS schannel_check_packet(struct gensec_security *gensec_security,
1132
              const uint8_t *data, size_t length,
1133
              const uint8_t *whole_pdu, size_t pdu_length,
1134
              const DATA_BLOB *sig)
1135
0
{
1136
0
  struct schannel_state *state =
1137
0
    talloc_get_type_abort(gensec_security->private_data,
1138
0
    struct schannel_state);
1139
1140
0
  return netsec_incoming_packet(state, false,
1141
0
              discard_const_p(uint8_t, data),
1142
0
              length,
1143
0
              whole_pdu, pdu_length,
1144
0
              sig);
1145
0
}
1146
/*
1147
  seal a packet
1148
*/
1149
static NTSTATUS schannel_seal_packet(struct gensec_security *gensec_security,
1150
             TALLOC_CTX *mem_ctx,
1151
             uint8_t *data, size_t length,
1152
             const uint8_t *whole_pdu, size_t pdu_length,
1153
             DATA_BLOB *sig)
1154
0
{
1155
0
  struct schannel_state *state =
1156
0
    talloc_get_type_abort(gensec_security->private_data,
1157
0
    struct schannel_state);
1158
1159
0
  return netsec_outgoing_packet(state, mem_ctx, true,
1160
0
              data, length,
1161
0
              whole_pdu, pdu_length,
1162
0
              sig);
1163
0
}
1164
1165
/*
1166
  sign a packet
1167
*/
1168
static NTSTATUS schannel_sign_packet(struct gensec_security *gensec_security,
1169
             TALLOC_CTX *mem_ctx,
1170
             const uint8_t *data, size_t length,
1171
             const uint8_t *whole_pdu, size_t pdu_length,
1172
             DATA_BLOB *sig)
1173
0
{
1174
0
  struct schannel_state *state =
1175
0
    talloc_get_type_abort(gensec_security->private_data,
1176
0
    struct schannel_state);
1177
1178
0
  return netsec_outgoing_packet(state, mem_ctx, false,
1179
0
              discard_const_p(uint8_t, data),
1180
0
              length,
1181
0
              whole_pdu, pdu_length,
1182
0
              sig);
1183
0
}
1184
1185
static const struct gensec_security_ops gensec_schannel_security_ops = {
1186
  .name   = "schannel",
1187
  .auth_type  = DCERPC_AUTH_TYPE_SCHANNEL,
1188
  .client_start   = schannel_client_start,
1189
  .server_start   = schannel_server_start,
1190
  .update_send  = schannel_update_send,
1191
  .update_recv  = schannel_update_recv,
1192
  .seal_packet  = schannel_seal_packet,
1193
  .sign_packet    = schannel_sign_packet,
1194
  .check_packet = schannel_check_packet,
1195
  .unseal_packet  = schannel_unseal_packet,
1196
  .session_info = schannel_session_info,
1197
  .sig_size = schannel_sig_size,
1198
  .have_feature   = schannel_have_feature,
1199
  .enabled        = true,
1200
  .priority       = GENSEC_SCHANNEL
1201
};
1202
1203
_PUBLIC_ NTSTATUS gensec_schannel_init(TALLOC_CTX *ctx)
1204
0
{
1205
0
  NTSTATUS ret;
1206
0
  ret = gensec_register(ctx, &gensec_schannel_security_ops);
1207
0
  if (!NT_STATUS_IS_OK(ret)) {
1208
0
    DEBUG(0,("Failed to register '%s' gensec backend!\n",
1209
0
      gensec_schannel_security_ops.name));
1210
0
    return ret;
1211
0
  }
1212
1213
0
  return ret;
1214
0
}