def test_unseq_raises(self): ctx = InitContext( Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_SEQUENCE_FLAG,) ) self._handshake(self.sockfile, ctx) self._writeline(b'!UNSEQTEST') msg1 = ctx.wrap(b'msg_from_client1') msg2 = ctx.wrap(b'msg_from_client2') msg3 = ctx.wrap(b'msg_from_client3') self._writeline(base64.b64encode(msg1)) self._writeline(base64.b64encode(msg3)) self._writeline(base64.b64encode(msg2)) in1 = self.sockfile.readline() in2 = self.sockfile.readline() in3 = self.sockfile.readline() msg1 = ctx.unwrap(base64.b64decode(in1)) self.assertEqual(msg1, b'msg_from_server1') try: ctx.unwrap(base64.b64decode(in2)) except GSSCException as exc: self.assertEqual(S_GAP_TOKEN, (S_GAP_TOKEN & exc.maj_status)) else: self.fail("Detecting a gap token must raise GSSCException") try: ctx.unwrap(base64.b64decode(in3)) except GSSCException as exc: self.assertEqual(S_UNSEQ_TOKEN, (S_UNSEQ_TOKEN & exc.maj_status)) else: self.fail("Detecting an unseq token must raise GSSCException")
def test_unseq_raises(self): ctx = InitContext(Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_SEQUENCE_FLAG, )) self._handshake(self.sockfile, ctx) self._writeline(b'!UNSEQTEST') msg1 = ctx.wrap(b'msg_from_client1') msg2 = ctx.wrap(b'msg_from_client2') msg3 = ctx.wrap(b'msg_from_client3') self._writeline(base64.b64encode(msg1)) self._writeline(base64.b64encode(msg3)) self._writeline(base64.b64encode(msg2)) in1 = self.sockfile.readline() in2 = self.sockfile.readline() in3 = self.sockfile.readline() msg1 = ctx.unwrap(base64.b64decode(in1)) self.assertEqual(msg1, b'msg_from_server1') try: ctx.unwrap(base64.b64decode(in2)) except GSSCException as exc: self.assertEqual(S_GAP_TOKEN, (S_GAP_TOKEN & exc.maj_status)) else: self.fail("Detecting a gap token must raise GSSCException") try: ctx.unwrap(base64.b64decode(in3)) except GSSCException as exc: self.assertEqual(S_UNSEQ_TOKEN, (S_UNSEQ_TOKEN & exc.maj_status)) else: self.fail("Detecting an unseq token must raise GSSCException")
def test_replay(self): ctx = InitContext(Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_REPLAY_FLAG, )) self._handshake(self.sockfile, ctx) self._writeline(b'!REPLAYTEST') msg1 = ctx.wrap(b'msg_from_client1') msg2 = ctx.wrap(b'msg_from_client2') self._writeline(base64.b64encode(msg1)) self._writeline(base64.b64encode(msg2)) self._writeline(base64.b64encode(msg1)) in1 = self.sockfile.readline() in2 = self.sockfile.readline() in3 = self.sockfile.readline() msg1, supp1 = ctx.unwrap(base64.b64decode(in1), supplementary=True) msg2, supp2 = ctx.unwrap(base64.b64decode(in2), supplementary=True) msg3, supp3 = ctx.unwrap(base64.b64decode(in3), supplementary=True) self.assertEqual(msg1, b'msg_from_server1') self.assertEqual(msg2, b'msg_from_server2') self.assertEqual(msg3, b'msg_from_server1') self.assertIn(S_DUPLICATE_TOKEN, supp3) try: ctx.unwrap(base64.b64decode(in3)) except GSSCException as exc: self.assertEqual(S_DUPLICATE_TOKEN, (S_DUPLICATE_TOKEN & exc.maj_status)) else: self.fail("Detecting a dupe token must raise GSSCException") try: ctx.unwrap(base64.b64decode(in2)) except GSSCException as exc: self.assertEqual(S_DUPLICATE_TOKEN, (S_DUPLICATE_TOKEN & exc.maj_status)) else: self.fail("Detecting a dupe token must raise GSSCException")
def test_replay(self): ctx = InitContext( Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_REPLAY_FLAG,) ) self._handshake(self.sockfile, ctx) self._writeline(b'!REPLAYTEST') msg1 = ctx.wrap(b'msg_from_client1') msg2 = ctx.wrap(b'msg_from_client2') self._writeline(base64.b64encode(msg1)) self._writeline(base64.b64encode(msg2)) self._writeline(base64.b64encode(msg1)) in1 = self.sockfile.readline() in2 = self.sockfile.readline() in3 = self.sockfile.readline() msg1, supp1 = ctx.unwrap(base64.b64decode(in1), supplementary=True) msg2, supp2 = ctx.unwrap(base64.b64decode(in2), supplementary=True) msg3, supp3 = ctx.unwrap(base64.b64decode(in3), supplementary=True) self.assertEqual(msg1, b'msg_from_server1') self.assertEqual(msg2, b'msg_from_server2') self.assertEqual(msg3, b'msg_from_server1') self.assertIn(S_DUPLICATE_TOKEN, supp3) try: ctx.unwrap(base64.b64decode(in3)) except GSSCException as exc: self.assertEqual(S_DUPLICATE_TOKEN, (S_DUPLICATE_TOKEN & exc.maj_status)) else: self.fail("Detecting a dupe token must raise GSSCException") try: ctx.unwrap(base64.b64decode(in2)) except GSSCException as exc: self.assertEqual(S_DUPLICATE_TOKEN, (S_DUPLICATE_TOKEN & exc.maj_status)) else: self.fail("Detecting a dupe token must raise GSSCException")
def test_gap(self): ctx = InitContext( Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_REPLAY_FLAG, C_SEQUENCE_FLAG) ) self._handshake(self.sockfile, ctx) self._writeline(b'!GAPTEST') msg1 = ctx.wrap(b'msg_from_client1') msg2 = ctx.wrap(b'msg_from_client2') msg3 = ctx.wrap(b'msg_from_client3') self._writeline(base64.b64encode(msg1)) self._writeline(base64.b64encode(msg3)) msg1, supp1 = ctx.unwrap(base64.b64decode(self.sockfile.readline()), supplementary=True) msg2, supp2 = ctx.unwrap(base64.b64decode(self.sockfile.readline()), supplementary=True) self.assertEqual(msg1, b'msg_from_server1') self.assertEqual(msg2, b'msg_from_server3') self.assertIn(S_GAP_TOKEN, supp2)
def test_gap(self): ctx = InitContext(Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_REPLAY_FLAG, C_SEQUENCE_FLAG)) self._handshake(self.sockfile, ctx) self._writeline(b'!GAPTEST') msg1 = ctx.wrap(b'msg_from_client1') msg2 = ctx.wrap(b'msg_from_client2') msg3 = ctx.wrap(b'msg_from_client3') self._writeline(base64.b64encode(msg1)) self._writeline(base64.b64encode(msg3)) msg1, supp1 = ctx.unwrap(base64.b64decode(self.sockfile.readline()), supplementary=True) msg2, supp2 = ctx.unwrap(base64.b64decode(self.sockfile.readline()), supplementary=True) self.assertEqual(msg1, b'msg_from_server1') self.assertEqual(msg2, b'msg_from_server3') self.assertIn(S_GAP_TOKEN, supp2)
def test_wrapping(self): ctx = InitContext( Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_CONF_FLAG,) ) self._handshake(self.sockfile, ctx) assert ctx.confidentiality_negotiated self._writeline(b'!WRAPTEST') self._writeline(base64.b64encode(ctx.wrap(b'msg_from_client'))) self.assertEqual(self.sockfile.readline().strip(), b'!OK') self.assertEqual(ctx.unwrap(base64.b64decode(self.sockfile.readline())), b'msg_from_server')
def test_get_wrap_size_limit(self): ctx = InitContext(Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_CONF_FLAG, )) self._handshake(self.sockfile, ctx) assert ctx.confidentiality_negotiated wrap_size_limit = ctx.get_wrap_size_limit(512) self.assertLessEqual(wrap_size_limit, 512) msg = b'*' * wrap_size_limit self.assertLessEqual(len(ctx.wrap(msg)), 512) self._writeline(b'!NOOP')
def test_get_wrap_size_limit(self): ctx = InitContext( Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_CONF_FLAG,) ) self._handshake(self.sockfile, ctx) assert ctx.confidentiality_negotiated wrap_size_limit = ctx.get_wrap_size_limit(512) self.assertLessEqual(wrap_size_limit, 512) msg = b'*' * wrap_size_limit self.assertLessEqual(len(ctx.wrap(msg)), 512) self._writeline(b'!NOOP')
def test_wrapping(self): ctx = InitContext(Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_CONF_FLAG, )) self._handshake(self.sockfile, ctx) assert ctx.confidentiality_negotiated self._writeline(b'!WRAPTEST') self._writeline(base64.b64encode(ctx.wrap(b'msg_from_client'))) self.assertEqual(self.sockfile.readline().strip(), b'!OK') self.assertEqual( ctx.unwrap(base64.b64decode(self.sockfile.readline())), b'msg_from_server')
def test_unseq(self): ctx = InitContext(Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_SEQUENCE_FLAG, )) self._handshake(self.sockfile, ctx) self._writeline(b'!UNSEQTEST') msg1 = ctx.wrap(b'msg_from_client1') msg2 = ctx.wrap(b'msg_from_client2') msg3 = ctx.wrap(b'msg_from_client3') self._writeline(base64.b64encode(msg1)) self._writeline(base64.b64encode(msg3)) self._writeline(base64.b64encode(msg2)) in1 = self.sockfile.readline() in2 = self.sockfile.readline() in3 = self.sockfile.readline() msg1, supp1 = ctx.unwrap(base64.b64decode(in1), supplementary=True) msg2, supp2 = ctx.unwrap(base64.b64decode(in2), supplementary=True) msg3, supp3 = ctx.unwrap(base64.b64decode(in3), supplementary=True) self.assertEqual(msg1, b'msg_from_server1') self.assertEqual(msg2, b'msg_from_server3') self.assertEqual(msg3, b'msg_from_server2') self.assertIn(S_UNSEQ_TOKEN, supp3)
def test_unseq(self): ctx = InitContext( Name("*****@*****.**", C_NT_HOSTBASED_SERVICE), req_flags=(C_SEQUENCE_FLAG,) ) self._handshake(self.sockfile, ctx) self._writeline(b'!UNSEQTEST') msg1 = ctx.wrap(b'msg_from_client1') msg2 = ctx.wrap(b'msg_from_client2') msg3 = ctx.wrap(b'msg_from_client3') self._writeline(base64.b64encode(msg1)) self._writeline(base64.b64encode(msg3)) self._writeline(base64.b64encode(msg2)) in1 = self.sockfile.readline() in2 = self.sockfile.readline() in3 = self.sockfile.readline() msg1, supp1 = ctx.unwrap(base64.b64decode(in1), supplementary=True) msg2, supp2 = ctx.unwrap(base64.b64decode(in2), supplementary=True) msg3, supp3 = ctx.unwrap(base64.b64decode(in3), supplementary=True) self.assertEqual(msg1, b'msg_from_server1') self.assertEqual(msg2, b'msg_from_server3') self.assertEqual(msg3, b'msg_from_server2') self.assertIn(S_UNSEQ_TOKEN, supp3)