Ejemplo n.º 1
0
def generatedata(n, owner="freeconet", keyfile="freeconet.priv.pem"):
    start = 48600000000
    end = 48699999999
    thissip = "sip.freeconet.pl"
    prevsip = "new.freeconet.pl"
    thisdate = datetime.datetime(2009, 2, 14, 12).isoformat()
    prevdate = datetime.datetime(2009, 2, 15, 9).isoformat()
    from random import randrange

    # no duplicates
    points = list(set(randrange(start, end) for i in xrange(n)))
    points.sort()
    first = ["+%s" % start, "+%s" % points[0], thissip, owner, thisdate]
    from M2Crypto import DSA

    dsa = DSA.load_key(keyfile)
    first.append(crypto.sign_record(dsa, *first))
    data = [first]
    for i in xrange(n - 1):
        print i, i + 1, len(points), points[i]
        s = points[i]
        e = points[i + 1] - 1
        thissip, prevsip = prevsip, thissip
        thisdate, prevdate = prevdate, thisdate
        r = ["+%s" % s, "+%s" % e, thissip, owner, thisdate]
        r.append(crypto.sign_record(dsa, *r))
        data.append(r)
    return data
Ejemplo n.º 2
0
 def test_csv_signature(self):
     v = ["+48581234", "+48581999", "sip.freeconet.pl", "freeconet", datetime.datetime.now()]
     v1 = crypto.make_csv_record(*v)
     s = crypto.sign_record(self.dsa, *v)
     self.assert_(crypto.check_signature(self.dsa, s, *v))
     s1 = crypto.sign_csv_record(self.dsa, v1)
     self.assert_(crypto.check_csv_signature(self.dsa, s1, v1))
Ejemplo n.º 3
0
 def _populate_example_ranges(self, c, keys = None):
     if keys is None:
         keys = {}
     from datetime import datetime, timedelta
     td1 = timedelta(-10)
     td2 = timedelta(-5)
     now = datetime(2009, 1, 13, 23, 59, 30, 123456)
     data = [('+481234', '+481299', 'sip.freeconet.pl', 'freeconet', now + td1),
             ('+4820000', '+4820999', 'sip.freeconet.pl', 'freeconet', now + td1),
             ('+4830000', '+4830099', 'sip.freeconet.pl', 'freeconet', now + td2),
             ('+4821000', '+4821111', 'sip.freeconet.pl', 'freeconet', now + td2),
             ]
     for r in data:
         if r[3] in keys:
             sig = crypto.sign_record(keys[r[3]], *r)
         else:
             sig = ''
         assert isinstance(r[4], datetime)
         c.execute('''insert into numbex_ranges (start, end, sip, owner, date_changed, signature, _s, _e)
             values (?, ?, ?, ?, ?, ?, ?, ?)''', (list(r)+[sig, int(r[0]), int(r[1])]))
     self.conn.commit()
Ejemplo n.º 4
0
def recsign(r, keyfile="freeconet.priv.pem"):
    from M2Crypto import DSA
    import crypto

    dsa = DSA.load_key(keyfile)
    return crypto.sign_record(dsa, *r)
Ejemplo n.º 5
0
 def test_pubkey_signature(self):
     v = ["+48581234", "+48581999", "sip.freeconet.pl", "freeconet", datetime.datetime.now()]
     dsapub = crypto.parse_pub_key(self.pubkey)
     sig = crypto.sign_record(self.dsa, *v)
     self.assert_(crypto.check_signature(dsapub, sig, *v))
Ejemplo n.º 6
0
 def test_basic_signature(self):
     v = ["+48581234", "+48581999", "sip.freeconet.pl", "freeconet", datetime.datetime.now()]
     sig = crypto.sign_record(self.dsa, *v)
     self.assert_(crypto.check_signature(self.dsa, sig, *v))