def verify(self):
     if self.expire_time and self.expire_time < time.mktime(time.gmtime()):
         raise POAExpiredException('Expired')
     try:
         lst = [self.torrent_id, self.torrent_pub_key, self.node_pub_key]
         b_list = bencode(lst)
         digest = permid.sha(b_list).digest()
         pub = pub_key_from_der(self.torrent_pub_key)
         if not pub.verify_dsa_asn1(digest, self.signature):
             raise InvalidPOAException('Proof of access verification failed')
     except Exception as e:
         raise InvalidPOAException('Bad POA: %s' % e)
 def verify(self):
     if self.expire_time and self.expire_time < time.mktime(time.gmtime()):
         raise POAExpiredException('Expired')
     try:
         lst = [self.torrent_id, self.torrent_pub_key, self.node_pub_key]
         b_list = bencode(lst)
         digest = permid.sha(b_list).digest()
         pub = pub_key_from_der(self.torrent_pub_key)
         if not pub.verify_dsa_asn1(digest, self.signature):
             raise InvalidPOAException(
                 'Proof of access verification failed')
     except Exception as e:
         raise InvalidPOAException('Bad POA: %s' % e)
Exemple #3
0
    def verify(self):
        """
        Throws an exception if the POA does not hold or has expired
        """

        if self.expire_time and self.expire_time < time.mktime(time.gmtime()):
            raise POAExpiredException("Expired")

        try:
            lst = [self.torrent_id, self.torrent_pub_key, self.node_pub_key]
            b_list = bencode(lst)
            digest = permid.sha(b_list).digest()
            pub = pub_key_from_der(self.torrent_pub_key)
            if not pub.verify_dsa_asn1(digest, self.signature):
                raise InvalidPOAException("Proof of access verification failed")
        except Exception, e:
            raise InvalidPOAException("Bad POA: %s" % e)
Exemple #4
0
    def verify(self):
        """
        Throws an exception if the POA does not hold or has expired
        """

        if self.expire_time and \
               self.expire_time < time.mktime(time.gmtime()):
            raise POAExpiredException("Expired")

        try:
            lst = [self.torrent_id, self.torrent_pub_key, self.node_pub_key]
            b_list = bencode(lst)
            digest = permid.sha(b_list).digest()
            pub = pub_key_from_der(self.torrent_pub_key)
            if not pub.verify_dsa_asn1(digest, self.signature):
                raise InvalidPOAException(
                    "Proof of access verification failed")
        except Exception, e:
            raise InvalidPOAException("Bad POA: %s" % e)
Exemple #5
0
    def _validate_poa_message(self, lst, nonce_a, nonce_b):
        """
        Validate an incoming POA message - throw exception if bad.
        Returns the POA if successful
        """
        assert nonce_a
        assert nonce_b
        
        if len(lst) != 7:
            raise BadMessageException("Require 7 elements, got %d"%len(lst))
        
        poa = POA.deserialize_from_list(lst[1:-1])
        sig = lst[-1]
        assert poa.node_pub_key
        
        if poa.torrent_id != self.torrent_id:
            raise WrongSwarmException("Wrong swarm")

        if poa.get_torrent_pub_key() not in self.torrent_pubkeys:
            raise InvalidPOAException("Bad POA for this torrent")

        # Check the signature
        lst = [nonce_a,
               nonce_b,
               poa.serialize()]
        import sys
        b_list = bencode(lst)
        digest = permid.sha(b_list).digest()
        try:
            pub = pub_key_from_der(poa.node_pub_key)
        except:
            print >> sys.stderr, time.asctime(),'-', "The node_pub_key is no good"
            print >> sys.stderr, time.asctime(),'-', poa.node_pub_key
            raise Exception("Node's public key is no good...")
            
        if not pub.verify_dsa_asn1(digest, sig):
            raise InvalidSignatureException("Freshness test failed")
            
        # Passed the freshness test, now check the certificate
        poa.verify() # Throws exception if bad
        return poa
Exemple #6
0
    def _validate_poa_message(self, lst, nonce_a, nonce_b):
        """
        Validate an incoming POA message - throw exception if bad.
        Returns the POA if successful
        """
        assert nonce_a
        assert nonce_b

        if len(lst) != 7:
            raise BadMessageException("Require 7 elements, got %d" % len(lst))

        poa = POA.deserialize_from_list(lst[1:-1])
        sig = lst[-1]
        assert poa.node_pub_key

        if poa.torrent_id != self.torrent_id:
            raise WrongSwarmException("Wrong swarm")

        if poa.get_torrent_pub_key() not in self.torrent_pubkeys:
            raise InvalidPOAException("Bad POA for this torrent")

        # Check the signature
        lst = [nonce_a, nonce_b, poa.serialize()]
        import sys
        b_list = bencode(lst)
        digest = permid.sha(b_list).digest()
        try:
            pub = pub_key_from_der(poa.node_pub_key)
        except:
            print >> sys.stderr, "The node_pub_key is no good"
            print >> sys.stderr, poa.node_pub_key
            raise Exception("Node's public key is no good...")

        if not pub.verify_dsa_asn1(digest, sig):
            raise InvalidSignatureException("Freshness test failed")

        # Passed the freshness test, now check the certificate
        poa.verify()  # Throws exception if bad
        return poa
    def _validate_poa_message(self, lst, nonce_a, nonce_b):
        if len(lst) != 7:
            raise BadMessageException('Require 7 elements, got %d' % len(lst))
        poa = POA.deserialize_from_list(lst[1:-1])
        sig = lst[-1]
        if poa.torrent_id != self.torrent_id:
            raise WrongSwarmException('Wrong swarm')
        if poa.get_torrent_pub_key() not in self.torrent_pubkeys:
            raise InvalidPOAException('Bad POA for this torrent')
        lst = [nonce_a, nonce_b, poa.serialize()]
        import sys
        b_list = bencode(lst)
        digest = permid.sha(b_list).digest()
        try:
            pub = pub_key_from_der(poa.node_pub_key)
        except:
            print >> sys.stderr, 'The node_pub_key is no good'
            print >> sys.stderr, poa.node_pub_key
            raise Exception("Node's public key is no good...")

        if not pub.verify_dsa_asn1(digest, sig):
            raise InvalidSignatureException('Freshness test failed')
        poa.verify()
        return poa
    def _validate_poa_message(self, lst, nonce_a, nonce_b):
        if len(lst) != 7:
            raise BadMessageException('Require 7 elements, got %d' % len(lst))
        poa = POA.deserialize_from_list(lst[1:-1])
        sig = lst[-1]
        if poa.torrent_id != self.torrent_id:
            raise WrongSwarmException('Wrong swarm')
        if poa.get_torrent_pub_key() not in self.torrent_pubkeys:
            raise InvalidPOAException('Bad POA for this torrent')
        lst = [nonce_a, nonce_b, poa.serialize()]
        import sys
        b_list = bencode(lst)
        digest = permid.sha(b_list).digest()
        try:
            pub = pub_key_from_der(poa.node_pub_key)
        except:
            print >> sys.stderr, 'The node_pub_key is no good'
            print >> sys.stderr, poa.node_pub_key
            raise Exception("Node's public key is no good...")

        if not pub.verify_dsa_asn1(digest, sig):
            raise InvalidSignatureException('Freshness test failed')
        poa.verify()
        return poa
def pubkey_from_der(der_key):
    return pub_key_from_der(decodestring(der_key))
Exemple #10
0
def pubkey_from_der(der_key):
    """
    Return a public key object from a DER encoded key
    """
    return pub_key_from_der(decodestring(der_key))
def pubkey_from_der(der_key):
    return pub_key_from_der(decodestring(der_key))
Exemple #12
0
def pubkey_from_der(der_key):
    """
    Return a public key object from a DER encoded key
    """
    return pub_key_from_der(decodestring(der_key))