2 * Copyright (c) 2020 Andreas Schneider <asn@samba.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "librpc/gen_ndr/security.h"
20 #include "librpc/gen_ndr/auth.h"
21 #include "lib/crypto/gnutls_helpers.h"
22 #include "libcli/security/dom_sid.h"
23 #include "libcli/security/security_token.h"
24 #include "libcli/smb/smb2_constants.h"
26 #include "dcerpc_helper.h"
28 static bool smb3_sid_parse(const struct dom_sid
*sid
,
37 if (sid
->sub_auths
[0] != global_sid_Samba_SMB3
.sub_auths
[0]) {
41 dialect
= sid
->sub_auths
[1];
42 if (dialect
> 0x03ff) {
46 encrypt
= sid
->sub_auths
[2];
47 if (encrypt
> 0x0002) {
51 cipher
= sid
->sub_auths
[3];
54 * It is unlikely that we
55 * ever have more then 256
56 * encryption algorithms
61 if (pdialect
!= NULL
) {
65 if (pencrypt
!= NULL
) {
69 if (pcipher
!= NULL
) {
76 bool dcerpc_is_transport_encrypted(struct auth_session_info
*session_info
)
78 struct security_token
*token
= session_info
->security_token
;
79 struct dom_sid smb3_dom_sid
= global_sid_Samba_SMB3
;
80 const struct dom_sid
*smb3_sid
= NULL
;
87 num_smb3_sids
= security_token_count_flag_sids(token
,
91 if (num_smb3_sids
> 1) {
92 DBG_ERR("ERROR: The SMB3 SID has been detected %zu times\n",
97 if (smb3_sid
== NULL
) {
101 ok
= smb3_sid_parse(smb3_sid
, &dialect
, &encrypt
, &cipher
);
103 DBG_ERR("Failed to parse SMB3 SID!\n");
107 DBG_DEBUG("SMB SID - dialect: %#04x, encrypt: %#04x, cipher: %#04x\n",
112 if (dialect
< SMB3_DIALECT_REVISION_300
) {
113 DBG_DEBUG("Invalid SMB3 dialect!\n");
117 if (encrypt
!= DCERPC_SMB_ENCRYPTION_REQUIRED
) {
118 DBG_DEBUG("Invalid SMB3 encryption!\n");
123 case SMB2_ENCRYPTION_AES128_CCM
:
124 case SMB2_ENCRYPTION_AES128_GCM
:
127 DBG_DEBUG("Invalid SMB3 cipher!\n");