示例#1
0
 def test_compute_totp_offset(self):
     pat = re.compile(r"\d\d\d\d\d\d")
     secret = "MFRGGZDFMZTWQ2LK"
     for offset in range(-10, 10):
         signature = auth.compute_totp(secret, offset)
         self.assertEqual(type(signature), str)
         self.assertTrue(pat.match(signature) is not None)
 def test_compute_totp_offset(self):
     pat = re.compile(u"\d{6}")
     secret = u"MFRGGZDFMZTWQ2LK"
     for offset in range(-10, 10):
         signature = auth.compute_totp(secret, offset)
         self.assertEqual(type(signature), six.text_type)
         self.assertTrue(pat.match(signature) is not None)
示例#3
0
    def onAuthenticate(self, signature, extra):
        """
        Callback fired when a client responds to an authentication challenge.
        """
        print("onAuthenticate: {} {}".format(signature, extra))

        # if there is a pending auth, and the signature provided by client matches ..
        if self._pending_auth:
            if signature == auth.compute_totp(self._pending_auth.secret) or \
               signature == auth.compute_totp(self._pending_auth.secret, 1) or \
               signature == auth.compute_totp(self._pending_auth.secret, -1):
                # accept the client
                return types.Accept(authid=self._pending_auth.authid,
                                    authrole=self._pending_auth.authrole,
                                    authmethod=self._pending_auth.authmethod,
                                    authprovider=self._pending_auth.authprovider)

        # deny client
        return types.Deny()
示例#4
0
    def onAuthenticate(self, signature, extra):
        """
      Callback fired when a client responds to an authentication challenge.
      """
        print("onAuthenticate: {} {}".format(signature, extra))

        ## if there is a pending auth, and the signature provided by client matches ..
        if self._pending_auth:
            if signature == auth.compute_totp(self._pending_auth.secret) or \
               signature == auth.compute_totp(self._pending_auth.secret, 1) or \
               signature == auth.compute_totp(self._pending_auth.secret, -1):
                ## accept the client
                return types.Accept(
                    authid=self._pending_auth.authid,
                    authrole=self._pending_auth.authrole,
                    authmethod=self._pending_auth.authmethod,
                    authprovider=self._pending_auth.authprovider)

        ## deny client
        return types.Deny()
示例#5
0
from time import sleep
from autobahn.util import utcnow
from autobahn.wamp.auth import generate_totp_secret, compute_totp, qrcode_from_totp

from authenticator import PRINCIPALS_DB

# generate SVGs for the QR codes of the principals
for principal in PRINCIPALS_DB:
    seed = PRINCIPALS_DB[principal][u'seed']
    issuer = u'Crossbar.io'
    qrcode_data = qrcode_from_totp(seed, principal, issuer)
    filename = u'{}.svg'.format(principal)
    with open(filename, 'wb') as f:
        f.write(qrcode_data)
        print('QR Code for principal {} written to {}'.format(
            principal, filename))

# generate current TOTP values for all principals each 10s
while True:
    print("\n{}".format(utcnow()))
    for principal in PRINCIPALS_DB:
        seed = PRINCIPALS_DB[principal][u'seed']
        print("{}: {}".format(principal, compute_totp(seed)))
    sleep(10)
示例#6
0
 def test_compute_totp(self):
     pat = re.compile(r"\d\d\d\d\d\d")
     secret = "MFRGGZDFMZTWQ2LK"
     signature = auth.compute_totp(secret)
     self.assertEqual(type(signature), str)
     self.assertTrue(pat.match(signature) is not None)
示例#7
0
from time import sleep
from autobahn.util import utcnow
from autobahn.wamp.auth import generate_totp_secret, compute_totp, qrcode_from_totp

from authenticator import PRINCIPALS_DB

# generate SVGs for the QR codes of the principals
for principal in PRINCIPALS_DB:
    seed = PRINCIPALS_DB[principal][u'seed']
    issuer = u'Crossbar.io'
    qrcode_data = qrcode_from_totp(seed, principal, issuer)
    filename = u'{}.svg'.format(principal)
    with open(filename, 'wb') as f:
        f.write(qrcode_data)
        print('QR Code for principal {} written to {}'.format(principal, filename))

# generate current TOTP values for all principals each 10s
while True:
    print("\n{}".format(utcnow()))
    for principal in PRINCIPALS_DB:
        seed = PRINCIPALS_DB[principal][u'seed']
        print("{}: {}".format(principal, compute_totp(seed)))
    sleep(10)
示例#8
0
 def test_compute_totp(self):
     pat = re.compile(r"\d\d\d\d\d\d")
     secret = u"MFRGGZDFMZTWQ2LK"
     signature = auth.compute_totp(secret)
     self.assertEqual(type(signature), six.text_type)
     self.assertTrue(pat.match(signature) is not None)
 def test_compute_totp(self):
    pat = re.compile(b"\d{6,6}")
    secret = b"MFRGGZDFMZTWQ2LK"
    signature = auth.compute_totp(secret)
    self.assertEqual(type(signature), bytes)
    self.assertTrue(pat.match(signature) is not None)
示例#10
0
 def test_compute_totp(self):
     pat = re.compile(u"\d{6}")
     secret = u"MFRGGZDFMZTWQ2LK"
     signature = auth.compute_totp(secret)
     self.assertEqual(type(signature), six.text_type)
     self.assertTrue(pat.match(signature) is not None)
示例#11
0
from autobahn.util import utcnow
from autobahn.wamp.auth import generate_totp_secret, compute_totp

TOTP_SEEDS = [
    {'user': '******', 'seed': 'CACKN3GRF3KQZMEK'},
    {'user': '******', 'seed': 'BKIV3FXPRA67N4Q5'}
]

print([compute_totp(s['seed']) for s in TOTP_SEEDS])
示例#12
0
from autobahn.util import utcnow
from autobahn.wamp.auth import generate_totp_secret, compute_totp

TOTP_SEEDS = [{
    'user': '******',
    'seed': 'CACKN3GRF3KQZMEK'
}, {
    'user': '******',
    'seed': 'BKIV3FXPRA67N4Q5'
}]

print([compute_totp(s['seed']) for s in TOTP_SEEDS])