Beispiel #1
0
 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")
Beispiel #2
0
 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")
Beispiel #3
0
 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')
Beispiel #5
0
 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')
Beispiel #6
0
 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")
Beispiel #7
0
 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")
Beispiel #8
0
 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)
Beispiel #9
0
 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)
Beispiel #10
0
 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)