Esempio n. 1
0
    def receiveSignatures(self, r, sigs):
        assert self.status == "OK"
        assert r == self.lastRound + 1

        for i, sig in enumerate(sigs):
            verify_signature(self.addrs[i], self.h, sig)

        self.lastCommit = sigs, self.lastProposed
        self.lastRound += 1
def checksig(stack, transaction, index):
    public_key = stack.pop()
    signature = stack.pop()
    stack.append(
        verify_signature(transaction.get_raw_signature(index), public_key,
                         signature))
    return stack
Esempio n. 3
0
    def check_sign(self, file):
        if self.source is None:
            print("\nRecuerde introducir el id del emisor con --source_id\n")
            return

        print('\nEstá en el sistema como ' + self.user.user_short())

        # Leer dichero
        f = open(file, 'rb').read()

        # Obtener clave publica del origen
        # k = open(source_id+'.pem', 'r').read()
        # user = user_database.User(source_id, None,
        # None, None, 0)
        public_key = RSA.import_key(
            securebox.getPublicKey(self.user, self.source))

        # Dividmos la firma del cuerpo del mensaje
        signature = f[:256]
        mes = f[256:]

        # Lo guardamos con su nombre original solo si la firma coincide
        file = file.split('/')[-1]
        name = 'Archivos/' + file[:-4]

        if crypto.verify_signature(mes, public_key, signature) == True:
            print('\nLa firma digital es correcta, fichero guardado en ' +
                  name)
            r = open(name, 'wb')
            r.write(mes)
            r.close()
        else:
            print(
                '\nLa firma digital no es correcta, el fichero no ha sido guardado\n'
            )
Esempio n. 4
0
 def receive_signed_rebalance_set(self, req):
     assert (req['leader'] == self)
     assert (req['participant'].public_address
             in self.rebalance_participants)
     assert (verify_signature(req['participant'].public_address,
                              self.instance_hash, req['signature']))
     self.rebalance_signatures[
         req['participant'].public_address] = req['signature']
Esempio n. 5
0
    def receive_set_signatures(self, req):
        assert (req['participant'] == self)
        signatures = req['signatures']
        assert (set(self.rebalance_participants).issubset(signatures.keys()))
        for public_address in signatures:
            assert (verify_signature(public_address, self.instance_hash,
                                     signatures[public_address]))
        self.rebalance_signatures = req['signatures']

        for transaction in self.rebalance_transactions:
            if transaction[0] not in self.contract_player:
                continue
            player = self.contract_player[transaction[0]]
            player.lastCommit = [], transaction[2:]
            player.lastRound += 1
Esempio n. 6
0
    def respond_to_challenge(self, contract):
        player = self.contract_player[contract]
        V, R, S = [], [], []
        for public_address in self.rebalance_participants:
            v, r, s = self.rebalance_signatures[public_address]
            V.append(v)
            R.append(r.to_bytes(32, byteorder='big'))
            S.append(s.to_bytes(32, byteorder='big'))
            assert (verify_signature(public_address, self.instance_hash,
                                     (v, r, s)))

        idx = next(i for i, v in enumerate(self.rebalance_transactions)
                   if v[0] == contract)
        chain, sides = merkle_chain(self.transactions_merkle_tree, idx)

        player.respond_to_challenge(V, R, S, self.rebalance_participants,
                                    chain[-1])
Esempio n. 7
0
def validate_RRSET(keys, rrsig_set, rr_set, domain_name):
    """
    Validates the signature on an RRset
    :param keys: The DNSKEYS to check with
    :param rrsig_set: A set of RRSIGs to check
    :param rr_set: The RRset
    :param domain_name: The domain name of the RRset
    :return: The RRSIG record that verified
    """
    for sig in rrsig_set:
        if sig.algorithm != DNSPacket.ALGO_TYPE_RSASHA256:
            dprint("ERROR\tUNKNOWN ALGORITHM", sig.algorithm)
            return None
        for set_ordering in itertools.permutations(rr_set, len(rr_set)):
            rrset_data = crypto.createRRSetData(set_ordering, sig, domain_name)
            for key in keys:
                if crypto.verify_signature(sig.signature, key, rrset_data):
                    return sig
    return None
Esempio n. 8
0
def test_sign():
    priv = crypto.generate_rsa_key(complexity=512)
    message = "Secret wish list"
    sig = crypto.sign(message, priv)
    assert crypto.verify_signature(sig, message, priv.public_key())
Esempio n. 9
0
decrypted = crypto.decrypt_RSA(encrypted, private_key)

if text == decrypted:
    print("Cifrado RSA exitoso\n")
else:
    print("Cifrado RSA fallido\n")

# Test de cifrado de fichero

f = 'ideas'
file = open(f, 'r')
content = file.read()
file.close()

encrypted = crypto.encrypt_file(f, public_key)
decrypted = crypto.decrypt_file(encrypted, private_key)

if content == decrypted:
    print("Cifrado fichero exitoso\n")
else:
    print("Cifrado fichero fallido\n")

# Test de firma digital

signature = crypto.digital_signature(text, private_key)

if crypto.verify_signature(text, public_key, signature):
    print("Firma digital verificada\n")
else:
    print("Firma digital rechazada\n")