commit b3fd09f6fc0326dd73ee2927fd70b6afa592738a Author: George Kadianakis desnacked@riseup.net Date: Mon Apr 14 15:08:52 2014 +0300
Add TicketTest unittest. --- obfsproxy/test/transports/test_scramblesuit.py | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
diff --git a/obfsproxy/test/transports/test_scramblesuit.py b/obfsproxy/test/transports/test_scramblesuit.py index df7f69b..3392b5f 100644 --- a/obfsproxy/test/transports/test_scramblesuit.py +++ b/obfsproxy/test/transports/test_scramblesuit.py @@ -20,6 +20,7 @@ import obfsproxy.transports.scramblesuit.uniformdh as uniformdh import obfsproxy.transports.scramblesuit.scramblesuit as scramblesuit import obfsproxy.transports.scramblesuit.message as message import obfsproxy.transports.scramblesuit.state as state +import obfsproxy.transports.scramblesuit.ticket as ticket
# Disable all logging as it would yield plenty of warning and error @@ -167,6 +168,30 @@ class UniformDHTest( unittest.TestCase ):
self.failIf(self.udh.receivePublicKey(buf, lambda x: x) == True)
+ def test4_extractPublicKey( self ): + + # Create UniformDH authentication message. + sharedSecret = "A" * const.SHARED_SECRET_LENGTH + + realEpoch = util.getEpoch + + # Try three valid and one invalid epoch value. + for epoch in util.expandedEpoch() + ["000000"]: + udh = uniformdh.new(sharedSecret, True) + + util.getEpoch = lambda: epoch + authMsg = udh.createHandshake() + util.getEpoch = realEpoch + + buf = obfs_buf.Buffer() + buf.write(authMsg) + + if epoch == "000000": + self.assertFalse(udh.extractPublicKey(buf)) + else: + self.assertTrue(udh.extractPublicKey(buf)) + + class UtilTest( unittest.TestCase ):
def test1_isValidHMAC( self ): @@ -360,6 +385,38 @@ class MessageTest( unittest.TestCase ): self.assertRaises(base.PluggableTransportError, message.ProtocolMessage, "1", paddingLen=const.MPU)
+class TicketTest( unittest.TestCase ): + + def test1_authentication( self ): + srvState = state.State() + srvState.genState() + + ss = scramblesuit.ScrambleSuitTransport() + ss.srvState = srvState + + realEpoch = util.getEpoch + + # Try three valid and one invalid epoch value. + for epoch in util.expandedEpoch() + ["000000"]: + + util.getEpoch = lambda: epoch + + # Prepare ticket message. + blurb = ticket.issueTicketAndKey(srvState) + rawTicket = blurb[const.MASTER_KEY_LENGTH:] + masterKey = blurb[:const.MASTER_KEY_LENGTH] + ss.deriveSecrets(masterKey) + ticketMsg = ticket.createTicketMessage(rawTicket, ss.recvHMAC) + + util.getEpoch = realEpoch + + buf = obfs_buf.Buffer() + buf.write(ticketMsg) + + if epoch == "000000": + self.assertFalse(ss.receiveTicket(buf)) + else: + self.assertTrue(ss.receiveTicket(buf))
if __name__ == '__main__': unittest.main()
tor-commits@lists.torproject.org