2 Unix SMB/CIFS implementation.
4 Copyright (C) Jeremy Allison 2003.
5 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2002-2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /* Lookup a packet's MID (multiplex id) and figure out it's sequence number */
24 struct outstanding_packet_lookup
{
25 struct outstanding_packet_lookup
*prev
, *next
;
30 struct smb_basic_signing_context
{
33 struct outstanding_packet_lookup
*outstanding_packet_list
;
36 static bool store_sequence_for_reply(struct outstanding_packet_lookup
**list
,
37 uint16 mid
, uint32 reply_seq_num
)
39 struct outstanding_packet_lookup
*t
;
41 /* Ensure we only add a mid once. */
42 for (t
= *list
; t
; t
= t
->next
) {
44 DLIST_REMOVE(*list
, t
);
50 t
= SMB_XMALLOC_P(struct outstanding_packet_lookup
);
54 t
->reply_seq_num
= reply_seq_num
;
57 * Add to the *start* of the list not the end of the list.
58 * This ensures that the *last* send sequence with this mid
59 * is returned by preference.
60 * This can happen if the mid wraps and one of the early
61 * mid numbers didn't get a reply and is still lurking on
62 * the list. JRA. Found by Fran Fabrizio <fran@cis.uab.edu>.
66 DEBUG(10,("store_sequence_for_reply: stored seq = %u mid = %u\n",
67 (unsigned int)reply_seq_num
, (unsigned int)mid
));
71 static bool get_sequence_for_reply(struct outstanding_packet_lookup
**list
,
72 uint16 mid
, uint32
*reply_seq_num
)
74 struct outstanding_packet_lookup
*t
;
76 for (t
= *list
; t
; t
= t
->next
) {
78 *reply_seq_num
= t
->reply_seq_num
;
79 DEBUG(10,("get_sequence_for_reply: found seq = %u mid = %u\n",
80 (unsigned int)t
->reply_seq_num
, (unsigned int)t
->mid
));
81 DLIST_REMOVE(*list
, t
);
89 /***********************************************************
90 SMB signing - Common code before we set a new signing implementation
91 ************************************************************/
93 static bool cli_set_smb_signing_common(struct cli_state
*cli
)
95 if (!cli
->sign_info
.allow_smb_signing
) {
99 if (!cli
->sign_info
.negotiated_smb_signing
100 && !cli
->sign_info
.mandatory_signing
) {
104 if (cli
->sign_info
.doing_signing
) {
108 if (cli
->sign_info
.free_signing_context
)
109 cli
->sign_info
.free_signing_context(&cli
->sign_info
);
111 /* These calls are INCOMPATIBLE with SMB signing */
112 cli
->readbraw_supported
= False
;
113 cli
->writebraw_supported
= False
;
118 /***********************************************************
119 SMB signing - Common code for 'real' implementations
120 ************************************************************/
122 static bool set_smb_signing_real_common(struct smb_sign_info
*si
)
124 if (si
->mandatory_signing
) {
125 DEBUG(5, ("Mandatory SMB signing enabled!\n"));
128 si
->doing_signing
= True
;
129 DEBUG(5, ("SMB signing enabled!\n"));
134 static void mark_packet_signed(char *outbuf
)
137 flags2
= SVAL(outbuf
,smb_flg2
);
138 flags2
|= FLAGS2_SMB_SECURITY_SIGNATURES
;
139 SSVAL(outbuf
,smb_flg2
, flags2
);
142 /***********************************************************
143 SMB signing - NULL implementation - calculate a MAC to send.
144 ************************************************************/
146 static void null_sign_outgoing_message(char *outbuf
, struct smb_sign_info
*si
)
148 /* we can't zero out the sig, as we might be trying to send a
149 session request - which is NBT-level, not SMB level and doesn't
154 /***********************************************************
155 SMB signing - NULL implementation - check a MAC sent by server.
156 ************************************************************/
158 static bool null_check_incoming_message(const char *inbuf
,
159 struct smb_sign_info
*si
,
165 /***********************************************************
166 SMB signing - NULL implementation - free signing context
167 ************************************************************/
169 static void null_free_signing_context(struct smb_sign_info
*si
)
175 SMB signing - NULL implementation - setup the MAC key.
177 @note Used as an initialisation only - it will not correctly
178 shut down a real signing mechanism
181 static bool null_set_signing(struct smb_sign_info
*si
)
183 si
->signing_context
= NULL
;
185 si
->sign_outgoing_message
= null_sign_outgoing_message
;
186 si
->check_incoming_message
= null_check_incoming_message
;
187 si
->free_signing_context
= null_free_signing_context
;
193 * Free the signing context
196 static void free_signing_context(struct smb_sign_info
*si
)
198 if (si
->free_signing_context
) {
199 si
->free_signing_context(si
);
200 si
->signing_context
= NULL
;
203 null_set_signing(si
);
207 static bool signing_good(const char *inbuf
, struct smb_sign_info
*si
,
208 bool good
, uint32 seq
, bool must_be_ok
)
212 if (!si
->doing_signing
) {
213 si
->doing_signing
= True
;
216 if (!si
->seen_valid
) {
217 si
->seen_valid
= True
;
221 if (!si
->mandatory_signing
&& !si
->seen_valid
) {
226 /* Non-mandatory signing - just turn off if this is the first bad packet.. */
227 DEBUG(5, ("srv_check_incoming_message: signing negotiated but not required and peer\n"
228 "isn't sending correct signatures. Turning off.\n"));
229 si
->negotiated_smb_signing
= False
;
230 si
->allow_smb_signing
= False
;
231 si
->doing_signing
= False
;
232 free_signing_context(si
);
234 } else if (!must_be_ok
) {
235 /* This packet is known to be unsigned */
238 /* Mandatory signing or bad packet after signing started - fail and disconnect. */
240 DEBUG(0, ("signing_good: BAD SIG: seq %u\n", (unsigned int)seq
));
247 /***********************************************************
248 SMB signing - Simple implementation - calculate a MAC on the packet
249 ************************************************************/
251 static void simple_packet_signature(struct smb_basic_signing_context
*data
,
252 const uchar
*buf
, uint32 seq_number
,
253 unsigned char calc_md5_mac
[16])
255 const size_t offset_end_of_sig
= (smb_ss_field
+ 8);
256 unsigned char sequence_buf
[8];
257 struct MD5Context md5_ctx
;
259 /* JRA - apparently this is incorrect. */
260 unsigned char key_buf
[16];
264 * Firstly put the sequence number into the first 4 bytes.
265 * and zero out the next 4 bytes.
267 * We do this here, to avoid modifying the packet.
270 DEBUG(10,("simple_packet_signature: sequence number %u\n", seq_number
));
272 SIVAL(sequence_buf
, 0, seq_number
);
273 SIVAL(sequence_buf
, 4, 0);
275 /* Calculate the 16 byte MAC - but don't alter the data in the
278 This makes for a bit of fussing about, but it's not too bad.
282 /* intialise with the key */
283 MD5Update(&md5_ctx
, data
->mac_key
.data
, data
->mac_key
.length
);
285 /* JRA - apparently this is incorrect. */
286 /* NB. When making and verifying SMB signatures, Windows apparently
287 zero-pads the key to 128 bits if it isn't long enough.
288 From Nalin Dahyabhai <nalin@redhat.com> */
289 if (data
->mac_key
.length
< sizeof(key_buf
)) {
290 memset(key_buf
, 0, sizeof(key_buf
));
291 MD5Update(&md5_ctx
, key_buf
, sizeof(key_buf
) - data
->mac_key
.length
);
295 /* copy in the first bit of the SMB header */
296 MD5Update(&md5_ctx
, buf
+ 4, smb_ss_field
- 4);
298 /* copy in the sequence number, instead of the signature */
299 MD5Update(&md5_ctx
, sequence_buf
, sizeof(sequence_buf
));
301 /* copy in the rest of the packet in, skipping the signature */
302 MD5Update(&md5_ctx
, buf
+ offset_end_of_sig
,
303 smb_len(buf
) - (offset_end_of_sig
- 4));
305 /* calculate the MD5 sig */
306 MD5Final(calc_md5_mac
, &md5_ctx
);
310 /***********************************************************
311 SMB signing - Client implementation - send the MAC.
312 ************************************************************/
314 static void client_sign_outgoing_message(char *outbuf
, struct smb_sign_info
*si
)
316 unsigned char calc_md5_mac
[16];
317 struct smb_basic_signing_context
*data
=
318 (struct smb_basic_signing_context
*)si
->signing_context
;
320 if (!si
->doing_signing
)
323 /* JRA Paranioa test - we should be able to get rid of this... */
324 if (smb_len(outbuf
) < (smb_ss_field
+ 8 - 4)) {
325 DEBUG(1, ("client_sign_outgoing_message: Logic error. Can't check signature on short packet! smb_len = %u\n",
330 /* mark the packet as signed - BEFORE we sign it...*/
331 mark_packet_signed(outbuf
);
333 simple_packet_signature(data
, (const unsigned char *)outbuf
,
334 data
->send_seq_num
, calc_md5_mac
);
336 DEBUG(10, ("client_sign_outgoing_message: sent SMB signature of\n"));
337 dump_data(10, calc_md5_mac
, 8);
339 memcpy(&outbuf
[smb_ss_field
], calc_md5_mac
, 8);
341 /* cli->outbuf[smb_ss_field+2]=0;
342 Uncomment this to test if the remote server actually verifies signatures...*/
344 /* Instead of re-introducing the trans_info_conect we
345 used to have here, we use the fact that during a
346 SMBtrans/SMBtrans2/SMBnttrans send that the mid stays
347 constant. This means that calling store_sequence_for_reply()
348 will return False for all trans secondaries, as the mid is already
349 on the stored sequence list. As the send_seqence_number must
350 remain constant for all primary+secondary trans sends, we
351 only increment the send sequence number when we successfully
352 add a new entry to the outstanding sequence list. This means
353 I can isolate the fix here rather than re-adding the trans
354 signing on/off calls in libsmb/clitrans2.c JRA.
357 if (store_sequence_for_reply(&data
->outstanding_packet_list
, SVAL(outbuf
,smb_mid
), data
->send_seq_num
+ 1)) {
358 data
->send_seq_num
+= 2;
362 /***********************************************************
363 SMB signing - Client implementation - check a MAC sent by server.
364 ************************************************************/
366 static bool client_check_incoming_message(const char *inbuf
,
367 struct smb_sign_info
*si
,
371 uint32 reply_seq_number
;
372 unsigned char calc_md5_mac
[16];
373 unsigned char *server_sent_mac
;
375 struct smb_basic_signing_context
*data
=
376 (struct smb_basic_signing_context
*)si
->signing_context
;
378 if (!si
->doing_signing
)
381 if (smb_len(inbuf
) < (smb_ss_field
+ 8 - 4)) {
382 DEBUG(1, ("client_check_incoming_message: Can't check signature on short packet! smb_len = %u\n", smb_len(inbuf
)));
386 if (!get_sequence_for_reply(&data
->outstanding_packet_list
, SVAL(inbuf
, smb_mid
), &reply_seq_number
)) {
387 DEBUG(1, ("client_check_incoming_message: received message "
388 "with mid %u with no matching send record.\n", (unsigned int)SVAL(inbuf
, smb_mid
) ));
392 simple_packet_signature(data
, (const unsigned char *)inbuf
,
393 reply_seq_number
, calc_md5_mac
);
395 server_sent_mac
= (unsigned char *)&inbuf
[smb_ss_field
];
396 good
= (memcmp(server_sent_mac
, calc_md5_mac
, 8) == 0);
399 DEBUG(5, ("client_check_incoming_message: BAD SIG: wanted SMB signature of\n"));
400 dump_data(5, calc_md5_mac
, 8);
402 DEBUG(5, ("client_check_incoming_message: BAD SIG: got SMB signature of\n"));
403 dump_data(5, server_sent_mac
, 8);
407 for (i
= -5; i
< 5; i
++) {
408 simple_packet_signature(data
, (const unsigned char *)inbuf
, reply_seq_number
+i
, calc_md5_mac
);
409 if (memcmp(server_sent_mac
, calc_md5_mac
, 8) == 0) {
410 DEBUG(0,("client_check_incoming_message: out of seq. seq num %u matches. \
411 We were expecting seq %u\n", reply_seq_number
+i
, reply_seq_number
));
419 DEBUG(10, ("client_check_incoming_message: seq %u: got good SMB signature of\n", (unsigned int)reply_seq_number
));
420 dump_data(10, server_sent_mac
, 8);
422 return signing_good(inbuf
, si
, good
, reply_seq_number
, must_be_ok
);
425 /***********************************************************
426 SMB signing - Simple implementation - free signing context
427 ************************************************************/
429 static void simple_free_signing_context(struct smb_sign_info
*si
)
431 struct smb_basic_signing_context
*data
=
432 (struct smb_basic_signing_context
*)si
->signing_context
;
433 struct outstanding_packet_lookup
*list
;
434 struct outstanding_packet_lookup
*next
;
436 for (list
= data
->outstanding_packet_list
; list
; list
= next
) {
438 DLIST_REMOVE(data
->outstanding_packet_list
, list
);
442 data_blob_free(&data
->mac_key
);
444 SAFE_FREE(si
->signing_context
);
449 /***********************************************************
450 SMB signing - Simple implementation - setup the MAC key.
451 ************************************************************/
453 bool cli_simple_set_signing(struct cli_state
*cli
,
454 const DATA_BLOB user_session_key
,
455 const DATA_BLOB response
)
457 struct smb_basic_signing_context
*data
;
459 if (!user_session_key
.length
)
462 if (!cli_set_smb_signing_common(cli
)) {
466 if (!set_smb_signing_real_common(&cli
->sign_info
)) {
470 data
= SMB_XMALLOC_P(struct smb_basic_signing_context
);
471 memset(data
, '\0', sizeof(*data
));
473 cli
->sign_info
.signing_context
= data
;
475 data
->mac_key
= data_blob(NULL
, response
.length
+ user_session_key
.length
);
477 memcpy(&data
->mac_key
.data
[0], user_session_key
.data
, user_session_key
.length
);
479 DEBUG(10, ("cli_simple_set_signing: user_session_key\n"));
480 dump_data(10, user_session_key
.data
, user_session_key
.length
);
482 if (response
.length
) {
483 memcpy(&data
->mac_key
.data
[user_session_key
.length
],response
.data
, response
.length
);
484 DEBUG(10, ("cli_simple_set_signing: response_data\n"));
485 dump_data(10, response
.data
, response
.length
);
487 DEBUG(10, ("cli_simple_set_signing: NULL response_data\n"));
490 dump_data_pw("MAC ssession key is:\n", data
->mac_key
.data
, data
->mac_key
.length
);
492 /* Initialise the sequence number */
493 data
->send_seq_num
= 0;
495 /* Initialise the list of outstanding packets */
496 data
->outstanding_packet_list
= NULL
;
498 cli
->sign_info
.sign_outgoing_message
= client_sign_outgoing_message
;
499 cli
->sign_info
.check_incoming_message
= client_check_incoming_message
;
500 cli
->sign_info
.free_signing_context
= simple_free_signing_context
;
505 /***********************************************************
506 SMB signing - TEMP implementation - calculate a MAC to send.
507 ************************************************************/
509 static void temp_sign_outgoing_message(char *outbuf
, struct smb_sign_info
*si
)
511 /* mark the packet as signed - BEFORE we sign it...*/
512 mark_packet_signed(outbuf
);
514 /* I wonder what BSRSPYL stands for - but this is what MS
516 memcpy(&outbuf
[smb_ss_field
], "BSRSPYL ", 8);
520 /***********************************************************
521 SMB signing - TEMP implementation - check a MAC sent by server.
522 ************************************************************/
524 static bool temp_check_incoming_message(const char *inbuf
,
525 struct smb_sign_info
*si
, bool foo
)
530 /***********************************************************
531 SMB signing - TEMP implementation - free signing context
532 ************************************************************/
534 static void temp_free_signing_context(struct smb_sign_info
*si
)
539 /***********************************************************
540 SMB signing - NULL implementation - setup the MAC key.
541 ************************************************************/
543 bool cli_null_set_signing(struct cli_state
*cli
)
545 return null_set_signing(&cli
->sign_info
);
548 /***********************************************************
549 SMB signing - temp implementation - setup the MAC key.
550 ************************************************************/
552 bool cli_temp_set_signing(struct cli_state
*cli
)
554 if (!cli_set_smb_signing_common(cli
)) {
558 cli
->sign_info
.signing_context
= NULL
;
560 cli
->sign_info
.sign_outgoing_message
= temp_sign_outgoing_message
;
561 cli
->sign_info
.check_incoming_message
= temp_check_incoming_message
;
562 cli
->sign_info
.free_signing_context
= temp_free_signing_context
;
567 void cli_free_signing_context(struct cli_state
*cli
)
569 free_signing_context(&cli
->sign_info
);
573 * Sign a packet with the current mechanism
576 void cli_calculate_sign_mac(struct cli_state
*cli
, char *buf
)
578 cli
->sign_info
.sign_outgoing_message(buf
, &cli
->sign_info
);
582 * Check a packet with the current mechanism
583 * @return False if we had an established signing connection
584 * which had a bad checksum, True otherwise.
587 bool cli_check_sign_mac(struct cli_state
*cli
, char *buf
)
589 if (!cli
->sign_info
.check_incoming_message(buf
, &cli
->sign_info
, True
)) {
590 free_signing_context(&cli
->sign_info
);
596 /***********************************************************
597 Is client signing on ?
598 ************************************************************/
600 bool client_is_signing_on(struct cli_state
*cli
)
602 struct smb_sign_info
*si
= &cli
->sign_info
;
603 return si
->doing_signing
;
606 /***********************************************************
607 SMB signing - Server implementation - send the MAC.
608 ************************************************************/
610 static void srv_sign_outgoing_message(char *outbuf
, struct smb_sign_info
*si
)
612 unsigned char calc_md5_mac
[16];
613 struct smb_basic_signing_context
*data
=
614 (struct smb_basic_signing_context
*)si
->signing_context
;
615 uint32 send_seq_number
= data
->send_seq_num
-1;
618 if (!si
->doing_signing
) {
622 /* JRA Paranioa test - we should be able to get rid of this... */
623 if (smb_len(outbuf
) < (smb_ss_field
+ 8 - 4)) {
624 DEBUG(1, ("srv_sign_outgoing_message: Logic error. Can't send signature on short packet! smb_len = %u\n",
629 /* mark the packet as signed - BEFORE we sign it...*/
630 mark_packet_signed(outbuf
);
632 mid
= SVAL(outbuf
, smb_mid
);
634 /* See if this is a reply for a deferred packet. */
635 get_sequence_for_reply(&data
->outstanding_packet_list
, mid
, &send_seq_number
);
637 simple_packet_signature(data
, (const unsigned char *)outbuf
, send_seq_number
, calc_md5_mac
);
639 DEBUG(10, ("srv_sign_outgoing_message: seq %u: sent SMB signature of\n", (unsigned int)send_seq_number
));
640 dump_data(10, calc_md5_mac
, 8);
642 memcpy(&outbuf
[smb_ss_field
], calc_md5_mac
, 8);
644 /* cli->outbuf[smb_ss_field+2]=0;
645 Uncomment this to test if the remote client actually verifies signatures...*/
648 /***********************************************************
649 SMB signing - Server implementation - check a MAC sent by server.
650 ************************************************************/
652 static bool srv_check_incoming_message(const char *inbuf
,
653 struct smb_sign_info
*si
,
657 struct smb_basic_signing_context
*data
=
658 (struct smb_basic_signing_context
*)si
->signing_context
;
659 uint32 reply_seq_number
= data
->send_seq_num
;
661 unsigned char calc_md5_mac
[16];
662 unsigned char *server_sent_mac
;
664 if (!si
->doing_signing
)
667 if (smb_len(inbuf
) < (smb_ss_field
+ 8 - 4)) {
668 DEBUG(1, ("srv_check_incoming_message: Can't check signature on short packet! smb_len = %u\n", smb_len(inbuf
)));
672 /* We always increment the sequence number. */
673 data
->send_seq_num
+= 2;
675 saved_seq
= reply_seq_number
;
676 simple_packet_signature(data
, (const unsigned char *)inbuf
, reply_seq_number
, calc_md5_mac
);
678 server_sent_mac
= (unsigned char *)&inbuf
[smb_ss_field
];
679 good
= (memcmp(server_sent_mac
, calc_md5_mac
, 8) == 0);
684 DEBUG(0, ("srv_check_incoming_message: BAD SIG: seq %u wanted SMB signature of\n",
685 (unsigned int)saved_seq
));
686 dump_data(5, calc_md5_mac
, 8);
688 DEBUG(0, ("srv_check_incoming_message: BAD SIG: seq %u got SMB signature of\n",
689 (unsigned int)reply_seq_number
));
690 dump_data(5, server_sent_mac
, 8);
696 reply_seq_number
-= 5;
697 for (i
= 0; i
< 10; i
++, reply_seq_number
++) {
698 simple_packet_signature(data
, (const unsigned char *)inbuf
, reply_seq_number
, calc_md5_mac
);
699 if (memcmp(server_sent_mac
, calc_md5_mac
, 8) == 0) {
700 DEBUG(0,("srv_check_incoming_message: out of seq. seq num %u matches. \
701 We were expecting seq %u\n", reply_seq_number
, saved_seq
));
709 DEBUG(10, ("srv_check_incoming_message: seq %u: (current is %u) got good SMB signature of\n", (unsigned int)reply_seq_number
, (unsigned int)data
->send_seq_num
));
710 dump_data(10, server_sent_mac
, 8);
713 return (signing_good(inbuf
, si
, good
, saved_seq
, must_be_ok
));
716 /***********************************************************
717 SMB signing - server API's.
718 ************************************************************/
720 static struct smb_sign_info srv_sign_info
= {
721 null_sign_outgoing_message
,
722 null_check_incoming_message
,
723 null_free_signing_context
,
731 /***********************************************************
732 Turn signing off or on for oplock break code.
733 ************************************************************/
735 bool srv_oplock_set_signing(bool onoff
)
737 bool ret
= srv_sign_info
.doing_signing
;
738 srv_sign_info
.doing_signing
= onoff
;
742 /***********************************************************
743 Called to validate an incoming packet from the client.
744 ************************************************************/
746 bool srv_check_sign_mac(const char *inbuf
, bool must_be_ok
)
748 /* Check if it's a non-session message. */
753 return srv_sign_info
.check_incoming_message(inbuf
, &srv_sign_info
, must_be_ok
);
756 /***********************************************************
757 Called to sign an outgoing packet to the client.
758 ************************************************************/
760 void srv_calculate_sign_mac(char *outbuf
)
762 /* Check if it's a non-session message. */
767 srv_sign_info
.sign_outgoing_message(outbuf
, &srv_sign_info
);
770 /***********************************************************
771 Called by server to defer an outgoing packet.
772 ************************************************************/
774 void srv_defer_sign_response(uint16 mid
)
776 struct smb_basic_signing_context
*data
;
778 if (!srv_sign_info
.doing_signing
)
781 data
= (struct smb_basic_signing_context
*)srv_sign_info
.signing_context
;
787 * Ensure we only store this mid reply once...
790 store_sequence_for_reply(&data
->outstanding_packet_list
, mid
,
791 data
->send_seq_num
-1);
794 /***********************************************************
795 Called to remove sequence records when a deferred packet is
796 cancelled by mid. This should never find one....
797 ************************************************************/
799 void srv_cancel_sign_response(uint16 mid
)
801 struct smb_basic_signing_context
*data
;
804 if (!srv_sign_info
.doing_signing
)
807 data
= (struct smb_basic_signing_context
*)srv_sign_info
.signing_context
;
812 DEBUG(10,("srv_cancel_sign_response: for mid %u\n", (unsigned int)mid
));
814 while (get_sequence_for_reply(&data
->outstanding_packet_list
, mid
, &dummy_seq
))
817 /* cancel doesn't send a reply so doesn't burn a sequence number. */
818 data
->send_seq_num
-= 1;
821 /***********************************************************
822 Called by server negprot when signing has been negotiated.
823 ************************************************************/
825 void srv_set_signing_negotiated(void)
827 srv_sign_info
.allow_smb_signing
= True
;
828 srv_sign_info
.negotiated_smb_signing
= True
;
829 if (lp_server_signing() == Required
)
830 srv_sign_info
.mandatory_signing
= True
;
832 srv_sign_info
.sign_outgoing_message
= temp_sign_outgoing_message
;
833 srv_sign_info
.check_incoming_message
= temp_check_incoming_message
;
834 srv_sign_info
.free_signing_context
= temp_free_signing_context
;
837 /***********************************************************
838 Returns whether signing is active. We can't use sendfile or raw
839 reads/writes if it is.
840 ************************************************************/
842 bool srv_is_signing_active(void)
844 return srv_sign_info
.doing_signing
;
848 /***********************************************************
849 Returns whether signing is negotiated. We can't use it unless it was
851 ************************************************************/
853 bool srv_is_signing_negotiated(void)
855 return srv_sign_info
.negotiated_smb_signing
;
858 /***********************************************************
859 Returns whether signing is actually happening
860 ************************************************************/
862 bool srv_signing_started(void)
864 struct smb_basic_signing_context
*data
;
866 if (!srv_sign_info
.doing_signing
) {
870 data
= (struct smb_basic_signing_context
*)srv_sign_info
.signing_context
;
874 if (data
->send_seq_num
== 0) {
881 /***********************************************************
882 Turn on signing from this packet onwards.
883 ************************************************************/
885 void srv_set_signing(const DATA_BLOB user_session_key
, const DATA_BLOB response
)
887 struct smb_basic_signing_context
*data
;
889 if (!user_session_key
.length
)
892 if (!srv_sign_info
.negotiated_smb_signing
&& !srv_sign_info
.mandatory_signing
) {
893 DEBUG(5,("srv_set_signing: signing negotiated = %u, mandatory_signing = %u. Not allowing smb signing.\n",
894 (unsigned int)srv_sign_info
.negotiated_smb_signing
,
895 (unsigned int)srv_sign_info
.mandatory_signing
));
899 /* Once we've turned on, ignore any more sessionsetups. */
900 if (srv_sign_info
.doing_signing
) {
904 if (srv_sign_info
.free_signing_context
)
905 srv_sign_info
.free_signing_context(&srv_sign_info
);
907 srv_sign_info
.doing_signing
= True
;
909 data
= SMB_XMALLOC_P(struct smb_basic_signing_context
);
910 memset(data
, '\0', sizeof(*data
));
912 srv_sign_info
.signing_context
= data
;
914 data
->mac_key
= data_blob(NULL
, response
.length
+ user_session_key
.length
);
916 memcpy(&data
->mac_key
.data
[0], user_session_key
.data
, user_session_key
.length
);
918 memcpy(&data
->mac_key
.data
[user_session_key
.length
],response
.data
, response
.length
);
920 dump_data_pw("MAC ssession key is:\n", data
->mac_key
.data
, data
->mac_key
.length
);
922 DEBUG(3,("srv_set_signing: turning on SMB signing: signing negotiated = %s, mandatory_signing = %s.\n",
923 BOOLSTR(srv_sign_info
.negotiated_smb_signing
),
924 BOOLSTR(srv_sign_info
.mandatory_signing
) ));
926 /* Initialise the sequence number */
927 data
->send_seq_num
= 0;
929 /* Initialise the list of outstanding packets */
930 data
->outstanding_packet_list
= NULL
;
932 srv_sign_info
.sign_outgoing_message
= srv_sign_outgoing_message
;
933 srv_sign_info
.check_incoming_message
= srv_check_incoming_message
;
934 srv_sign_info
.free_signing_context
= simple_free_signing_context
;