Exemplo n.º 1
0
def validate_integrity(received_msg, dgs1):
    print(len(received_msg))
    msg = nacl.encoding.HexEncoder.decode(received_msg)
    print("orig", pickle.loads(msg))
    dgs0 = HASHER(msg, encoder=nacl.encoding.HexEncoder)
    print("dgs0", dgs0)
    print("dgs1", dgs1)
    if sodium_memcmp(dgs0, dgs1):
        return 1  #'equals'
    return 0  #'is different from'
Exemplo n.º 2
0
def v1_decrypt(m, k, f=None):
    h = V1_LOCAL
    m, fi = _unpack_msg(h, m, f)
    n = m[:32]  # ?
    t = m[-48:]  # ?
    c = m[32:-48]
    ek = _v1_derive_key(k, n, EK_INFO)
    ak = _v1_derive_key(k, n, AK_INFO)
    pre_auth = pae([h, n, c, fi])
    t2 = _v1_hmac_sha384(pre_auth, ak)
    if not sodium_memcmp(t, t2):
        raise pexc.InvalidKeyError("mismatching token signature (t != t2)")
    dec = _v1_aes_ctr_cipher(ek, n[-16:]).decryptor()
    return dec.update(c) + dec.finalize(), fi
Exemplo n.º 3
0
def _unpack_msg(h, m, f):
    if not m.startswith(h):
        raise pexc.ValueError("invalid message header (must be {})".format(
            h.decode("utf-8")))
    mp = m[len(h):].split(b".")
    l = len(mp)
    if l == 1:
        (m, ) = mp
        fi = b""
    elif l == 2:
        (m, fi) = mp
    else:
        raise pexc.ValueError("invalid message")
    m = unb64(m)
    fi = unb64(fi)
    if f is not None and not sodium_memcmp(fi, f):
        raise pexc.ValueError("invalid (mismatched) footer")
    return m, fi
Exemplo n.º 4
0
 def _replica_handler_2601(self, encrypt_hashresult, client, frep):
     try:
         self._state.nrs[self._state.c.index(client)] = (self._state.nrs[self._state.c.index(client)] + 1)
     except KeyError:
         self._state.nrs[self._state.c.index(client)] = 0
     for x in self._state.fail:
         if (x[0].strip() == 'result_shuttle'):
             if (int(x[1]) in self._state.nrs.keys()):
                 if ((self._state.nrs[int(x[1])] == int(x[2])) and (int(x[1]) == self._state.c.index(client))):
                     logging.info(((((((('Replica ' + str(self._state.r.index(self._state.idr))) + ' Result_shuttle failure triggered at replica ') + str(self._state.r.index(self._state.idr))) + '  for client ') + x[1]) + ' message ') + x[2]))
                     if (x[3].strip() == 'change_operation'):
                         self._state.co = 1
                     if (x[3].strip() == 'change_result'):
                         self._state.cr = 1
                     if (x[3].strip() == 'drop_result_stmt'):
                         self._state.drs = 1
                     if (x[3].strip() == 'drop'):
                         self._state.drop = 1
     self._state.s = (self._state.s + 1)
     fr_r_dkey = nacl.signing.VerifyKey(self._state.public_key_dict[frep], encoder=nacl.encoding.HexEncoder)
     try:
         fr_r_dkey.verify(encrypt_hashresult)
         temp_hr = eval(encrypt_hashresult.message.decode())
     except nacl.exceptions.BadSignatureError:
         logging.info((((((('replica ' + str(self._state.r.index(self._state.idr))) + ' : Replica ') + str(self._state.r.index(frep))) + ' -> Replica ') + str(self._state.r.index(self._state.idr))) + ' signature fail'))
     logging.info((((((('replica ' + str(self._state.r.index(self._state.idr))) + ' : Replica ') + str(self._state.r.index(frep))) + ' -> Replica ') + str(self._state.r.index(self._state.idr))) + ' signature success'))
     for h in temp_hr:
         bres = nacl.encoding.HexEncoder.decode(h[1])
         orig_dgs = nacl.hash.sha256(bres, encoder=nacl.encoding.HexEncoder)
         if sodium_memcmp(h[0], orig_dgs):
             if (not (bres.decode() == self._state.result[h[2]])):
                 logging.info((('Replica ' + str(self._state.r.index(self._state.idr))) + ' Proof of misbehaviour : Reshult_shuttle check failed'))
     self._state.hr[h[2]] = temp_hr
     logging.info(((('Replica ' + str(self._state.r.index(self._state.idr))) + ' Reshult_shuttle cached for slot ') + str(h[2])))
     j = self._state.r.index(frep)
     if ((j - 2) >= 0):
         encrypt_hashresult = self._state.pk.sign(repr(temp_hr).encode())
         self.send(('result-shuttle', encrypt_hashresult, client), to=self._state.r[(j - 2)])
     if ((j - 2) < 0):
         logging.info((('Replica ' + str(self._state.r.index(self._state.idr))) + ' Reshult_shuttle reached head'))
Exemplo n.º 5
0
def secure_compare(val1, val2):
    return sodium_memcmp(val1, val2)
Exemplo n.º 6
0
 def verifyTwoHash(self, hash1, hash2):
     if sodium_memcmp(hash1, hash2):
         return True
     else:
         return False
Exemplo n.º 7
0
 def verifyHash(self, statement, digest):
     statementdigest = self.getHash(statement)
     if sodium_memcmp(statementdigest, digest):
         return True
     else:
         return False
Exemplo n.º 8
0
Arquivo: Crypto.py Projeto: B-Rich/BCR
 def eq_chk(self, dgs0, dgs1):
     if sodium_memcmp(dgs0, dgs1):
         return True
     return False
Exemplo n.º 9
0
def eq_chk(dgs0, dgs1):
    if sodium_memcmp(dgs0, dgs1):
        return 'equals'
    return 'is different from'