Home | Trees | Indices | Help |
---|
|
1 # 2 # Copyright (c) 2013, EMC Corporation 3 # All rights reserved. 4 # 5 # Redistribution and use in source and binary forms, with or without 6 # modification, are permitted provided that the following conditions are met: 7 # 8 # 1. Redistributions of source code must retain the above copyright notice, 9 # this list of conditions and the following disclaimer. 10 # 2. Redistributions in binary form must reproduce the above copyright notice, 11 # this list of conditions and the following disclaimer in the documentation 12 # and/or other materials provided with the distribution. 13 # 14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 # POSSIBILITY OF SUCH DAMAGE. 25 # 26 # Module Name: 27 # 28 # negotiate.py 29 # 30 # Abstract: 31 # 32 # Tests negotiatate responses when requests are sent with a 33 # variety of bits set 34 # 35 # Authors: Angela Bartholomaus (angela.bartholomaus@emc.com) 36 # Paul Martin (paul.o.martin@emc.com) 37 # 38 39 import pike.crypto as crypto 40 import pike.model as model 41 import pike.smb2 as smb2 42 import pike.test as test 43 import random 44 import array8648 # determine max capability and apply Required decorators 49 self.chan, self.tree = self.tree_connect() 50 self.max_dialect = self.chan.connection.negotiate_response.dialect_revision 51 self.capabilities = self.chan.connection.negotiate_response.capabilities 52 self.share_caps = self.tree.tree_connect_response.capabilities 53 self.chan.logoff() 54 self.chan.connection.close() 55 56 self.client = self.default_client 57 self.conn = self.client.connect(self.server, self.port)5860 self.conn.close()6163 """Negotiate requested dialect""" 64 self.client.dialects = [dialect, smb2.DIALECT_SMB2_002] 65 self.client.capabilities = caps 66 self.conn.negotiate() 67 68 return self.conn6971 """Test that cap is advertised by the server if the client advertises it""" 72 if exp_caps is None: 73 exp_caps = req_caps 74 conn = self.negotiate(dialect, req_caps) 75 self.assertEqual(conn.negotiate_response.capabilities & exp_caps, exp_caps)7678 """Test that cap is not advertised if we don't advertise it""" 79 conn = self.negotiate(dialect, 0) 80 self.assertEqual(conn.negotiate_response.capabilities & cap, 0)8183 """Test that cap is not advertised to downlevel dialect even if we advertise it""" 84 conn = self.negotiate(smb2.DIALECT_SMB2_002, cap) 85 self.assertEqual(conn.negotiate_response.capabilities & cap, 0)88 # persistent cap is advertised if we ask for it 89 @test.RequireDialect(smb2.DIALECT_SMB3_0) 90 @test.RequireShareCapabilities(smb2.SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) 93 94 # persistent cap is advertised if we ask for lots of caps 95 @test.RequireDialect(smb2.DIALECT_SMB3_0) 96 @test.RequireShareCapabilities(smb2.SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)11898 advertise_caps = \ 99 smb2.SMB2_GLOBAL_CAP_MULTI_CHANNEL | \ 100 smb2.SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | \ 101 smb2.SMB2_GLOBAL_CAP_DIRECTORY_LEASING | \ 102 smb2.SMB2_GLOBAL_CAP_ENCRYPTION 103 self.positive_cap(smb2.DIALECT_SMB3_0, 104 advertise_caps, 105 smb2.SMB2_GLOBAL_CAP_PERSISTENT_HANDLES)106 107 # persistent cap is not advertised if we don't advertise it 110 111 # persistent cap is not advertised if we don't advertise it (SMB 2.1) 114 115 # persistent cap is not advertised to downlevel client120 # multichannel cap is advertised if we ask for it 121 @test.RequireDialect(smb2.DIALECT_SMB3_0) 124 125 # multichannel cap is advertised if we ask for lots of caps 126 @test.RequireDialect(smb2.DIALECT_SMB3_0)148128 advertise_caps = \ 129 smb2.SMB2_GLOBAL_CAP_MULTI_CHANNEL | \ 130 smb2.SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | \ 131 smb2.SMB2_GLOBAL_CAP_DIRECTORY_LEASING | \ 132 smb2.SMB2_GLOBAL_CAP_ENCRYPTION 133 self.positive_cap(smb2.DIALECT_SMB3_0, 134 advertise_caps, 135 smb2.SMB2_GLOBAL_CAP_MULTI_CHANNEL)136 137 # multichannel cap is not advertised if we don't advertise it 140 141 # multichannel cap is not advertised if we don't advertise it (SMB 2.1) 144 145 # multichannel cap is not advertised to downlevel client150 # largemtu cap is advertised if we ask for it 151 @test.RequireDialect(smb2.DIALECT_SMB3_0) 154 155 # largemtu cap is advertised if we ask for lots of caps 156 @test.RequireDialect(smb2.DIALECT_SMB3_0)174 175 @test.RequireDialect(smb2.DIALECT_SMB3_1_1)158 advertise_caps = \ 159 smb2.SMB2_GLOBAL_CAP_MULTI_CHANNEL | \ 160 smb2.SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | \ 161 smb2.SMB2_GLOBAL_CAP_LARGE_MTU | \ 162 smb2.SMB2_GLOBAL_CAP_ENCRYPTION 163 self.positive_cap(smb2.DIALECT_SMB3_0, 164 advertise_caps, 165 smb2.SMB2_GLOBAL_CAP_LARGE_MTU)166 167 # largemtu cap is advertised if we ask for it 170 171 # multicredit cap is not advertised to downlevel client221178 self.client = self.default_client 179 self.conn = self.client.connect(self.server, self.port) 180 return self.conn.negotiate(*args, **kwds).negotiate_response181183 resp = self.negotiate(hash_algorithms=[smb2.SMB2_SHA_512]) 184 if resp.dialect_revision >= smb2.DIALECT_SMB3_1_1: 185 for ctx in resp: 186 if isinstance(ctx, smb2.PreauthIntegrityCapabilitiesResponse): 187 self.assertIn(smb2.SMB2_SHA_512, ctx.hash_algorithms) 188 self.assertGreater(len(ctx.salt), 0)189191 resp = self.negotiate(ciphers=[crypto.SMB2_AES_128_CCM, crypto.SMB2_AES_128_GCM]) 192 if resp.dialect_revision >= smb2.DIALECT_SMB3_1_1: 193 for ctx in resp: 194 if isinstance(ctx, crypto.EncryptionCapabilitiesResponse): 195 self.assertEqual(len(ctx.ciphers), 1) 196 self.assertIn(crypto.SMB2_AES_128_CCM, ctx.ciphers)197199 resp = self.negotiate(ciphers=[crypto.SMB2_AES_128_GCM, crypto.SMB2_AES_128_CCM]) 200 if resp.dialect_revision >= smb2.DIALECT_SMB3_1_1: 201 for ctx in resp: 202 if isinstance(ctx, crypto.EncryptionCapabilitiesResponse): 203 self.assertEqual(len(ctx.ciphers), 1) 204 self.assertIn(crypto.SMB2_AES_128_GCM, ctx.ciphers)205207 resp = self.negotiate(ciphers=[crypto.SMB2_AES_128_CCM]) 208 if resp.dialect_revision >= smb2.DIALECT_SMB3_1_1: 209 for ctx in resp: 210 if isinstance(ctx, crypto.EncryptionCapabilitiesResponse): 211 self.assertEqual(len(ctx.ciphers), 1) 212 self.assertIn(crypto.SMB2_AES_128_CCM, ctx.ciphers)213215 resp = self.negotiate(ciphers=[crypto.SMB2_AES_128_GCM]) 216 if resp.dialect_revision >= smb2.DIALECT_SMB3_1_1: 217 for ctx in resp: 218 if isinstance(ctx, crypto.EncryptionCapabilitiesResponse): 219 self.assertEqual(len(ctx.ciphers), 1) 220 self.assertIn(crypto.SMB2_AES_128_GCM, ctx.ciphers)
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Jun 29 08:51:26 2017 | http://epydoc.sourceforge.net |