Ejemplo n.º 1
0
def validate_key(key_object):
    """
    """
    data256 = os.urandom(256)
    hash_base = key.Hash(data256)
    signature256 = key_object.sign(hash_base)
    return key_object.verify(signature256, hash_base)
Ejemplo n.º 2
0
def sign_key_info(key_info):
    key_info['signature_pubkey'] = key.MyPublicKey()
    sorted_fields = sorted(key_info.keys())
    hash_items = []
    for field in sorted_fields:
        if field not in ['include_private', 'signature', 'private', ]:
            hash_items.append(strng.to_text(key_info[field]))
    hash_text = '-'.join(hash_items)
    hash_bin = key.Hash(strng.to_bin(hash_text))
    key_info['signature'] = strng.to_text(key.Sign(hash_bin))
    return key_info
Ejemplo n.º 3
0
def verify_key_info_signature(key_info):
    if 'signature' not in key_info or 'signature_pubkey' not in key_info:
        return False
    sorted_fields = sorted(key_info.keys())
    hash_items = []
    for field in sorted_fields:
        if field not in ['include_private', 'signature', 'private', ]:
            hash_items.append(strng.to_text(key_info[field]))
    hash_text = '-'.join(hash_items)
    hash_bin = key.Hash(strng.to_bin(hash_text))
    signature_bin = strng.to_bin(key_info['signature'])
    result = key.VerifySignature(key_info['signature_pubkey'], hash_bin, signature_bin)
    return result
Ejemplo n.º 4
0
def prepare_broadcast_message(owner, payload):
    tm = utime.utcnow_to_sec1970()
    rnd = ''.join(random.choice(string.ascii_uppercase) for _ in range(4))
    msgid = '%s:%s:%s' % (tm, rnd, owner)
    msg = [
        ('owner', owner),
        ('started', tm),
        ('id', msgid),
        ('payload', payload),
    ]
    owner_sign = key.Sign(key.Hash(str(msg)))
    msg = {k: v for k, v in msg}
    msg['owner_sign'] = owner_sign
    return msg
Ejemplo n.º 5
0
def sign_key_info(key_info):
    key_info['signature_pubkey'] = key.MyPublicKey()
    hash_items = []
    for field in [
            'alias',
            'public',
            'signature_pubkey',
    ]:
        hash_items.append(strng.to_text(key_info[field]))
    hash_text = '-'.join(hash_items)
    if _Debug:
        lg.dbg(_DebugLevel, hash_text)
    hash_bin = key.Hash(strng.to_bin(hash_text))
    key_info['signature'] = strng.to_text(key.Sign(hash_bin))
    return key_info
Ejemplo n.º 6
0
 def makehash_old(self):
     """
     
     """
     sep = "-"
     c = ''
     for i in self.contacts:
         c += i
     s = ''
     for i in self.scrubbers:
         s += i
     sr = ''
     for i in self.sources:
         sr += i
     stufftohash = c + sep + s + sep + sr + sep + self.version + sep + self.postage + sep + self.date.replace(
         ' ', '_')
     hashcode = key.Hash(stufftohash)
     return hashcode
Ejemplo n.º 7
0
def verify_key_info_signature(key_info):
    if 'signature' not in key_info or 'signature_pubkey' not in key_info:
        lg.warn('signature was not found in the key info')
        return False
    hash_items = []
    for field in [
            'alias',
            'public',
            'signature_pubkey',
    ]:
        hash_items.append(strng.to_text(key_info[field]))
    hash_text = '-'.join(hash_items)
    if _Debug:
        lg.dbg(_DebugLevel, hash_text)
    hash_bin = key.Hash(strng.to_bin(hash_text))
    signature_bin = strng.to_bin(key_info['signature'])
    result = key.VerifySignature(key_info['signature_pubkey'], hash_bin,
                                 signature_bin)
    return result
Ejemplo n.º 8
0
 def makehash(self):
     """
     http://docs.python.org/lib/module-urlparse.html Note that certificates
     and signatures are not part of what is hashed. PREPRO Thinking of
     standard that fields have labels and empty fields are left out,
     including label, so future versions could have same signatures as older
     which had fewer fields - can just do this for fields after these, so
     maybe don't need to change anything for now.
     Don't include certificate - so identity server can just add it.
     """
     sep = "-"
     hsh = ''
     hsh += sep + sep.join(self.sources)
     hsh += sep + sep.join(self.contacts)
     # hsh += sep + sep.join(self.certificates)
     hsh += sep + sep.join(self.scrubbers)
     hsh += sep + self.postage
     hsh += sep + self.date.replace(' ', '_')
     hsh += sep + self.version
     hsh += sep + self.revision
     hashcode = key.Hash(hsh)
     return hashcode
Ejemplo n.º 9
0
 def GenerateHash(self):
     """
     Call ``crypt.key.Hash`` to create a hash code for that ``packet``.
     """
     return key.Hash(self.GenerateHashBase())
Ejemplo n.º 10
0
from system import bpio
from crypt import key
from crypt import signed
from main import settings
from lib import misc
from userid import my_id

bpio.init()
lg.set_debug_level(18)
settings.init()
key.InitMyKey()
if len(sys.argv) > 1:
    print 'reading'
    data1 = bpio.ReadBinaryFile(sys.argv[1])
    print '%d bytes long, hash: %s' % (
        len(data1), misc.BinaryToAscii(key.Hash(data1)).strip())
    p1 = signed.Packet('Data', my_id.getLocalID(), my_id.getLocalID(),
                       'SomeID', data1, 'RemoteID:abc')
else:
    print 'unserialize from "input"'
    p1 = signed.Unserialize(bpio.ReadBinaryFile('input'))
    data1 = p1.Payload
print 'serialize', p1
print '  Command:', p1.Command, type(p1.Command)
print '  OwnerID:', p1.OwnerID, type(p1.OwnerID)
print '  CreatorID:', p1.CreatorID, type(p1.CreatorID)
print '  PacketID:', p1.PacketID, type(p1.PacketID)
print '  Date:', p1.Date, type(p1.Date)
print '  Payload:', len(p1.Payload), misc.BinaryToAscii(key.Hash(
    p1.Payload)).strip(), type(p1.Payload)
print '  RemoteID:', p1.RemoteID, type(p1.RemoteID)
Ejemplo n.º 11
0
 def GenerateHash(self):
     """
     Create a hash for that ``encrypted_block`` using ``crypt.key.Hash()``.
     """
     return key.Hash(self.GenerateHashBase())
Ejemplo n.º 12
0
def get_coin_hash(coin_json):
    coin_hashbase = coin_to_string(coin_json)
    return key.Hash(coin_hashbase, hexdigest=True)
Ejemplo n.º 13
0
def get_message_hash(message_json):
    coin_hashbase = message_to_string(message_json)
    return key.Hash(coin_hashbase, hexdigest=True)
Ejemplo n.º 14
0
from system import bpio
from crypt import key
from crypt import signed
from main import settings
from lib import misc
from userid import my_id

bpio.init()
lg.set_debug_level(18)
settings.init()
key.InitMyKey()
if len(sys.argv) > 1:
    print('reading')
    data1 = bpio.ReadBinaryFile(sys.argv[1])
    print('%d bytes long, hash: %s' %
          (len(data1), misc.BinaryToAscii(key.Hash(data1)).strip()))
    p1 = signed.Packet('Data', my_id.getLocalID(), my_id.getLocalID(),
                       'SomeID', data1, 'RemoteID:abc')
else:
    print('unserialize from "input"')
    p1 = signed.Unserialize(bpio.ReadBinaryFile('input'))
    data1 = p1.Payload
print('serialize', p1)
print('  Command:', p1.Command, type(p1.Command))
print('  OwnerID:', p1.OwnerID, type(p1.OwnerID))
print('  CreatorID:', p1.CreatorID, type(p1.CreatorID))
print('  PacketID:', p1.PacketID, type(p1.PacketID))
print('  Date:', p1.Date, type(p1.Date))
print('  Payload:', len(p1.Payload),
      misc.BinaryToAscii(key.Hash(p1.Payload)).strip(), type(p1.Payload))
print('  RemoteID:', p1.RemoteID, type(p1.RemoteID))