コード例 #1
0
 def sign(self,keypair):
     """
     Signs the packed version of this instance.
     
     See _packData to see what packed version means.
     
     @param keypair: an ec keypair that will be used to create
                     the signature
     """ 
     bencoding = self._packData()
     signature = sign_data(bencoding, keypair)
     self.signature = signature
コード例 #2
0
 def sign(self, keypair):
     """
     Signs the packed version of this instance.
     
     See _packData to see what packed version means.
     
     @param keypair: an ec keypair that will be used to create
                     the signature
     """
     bencoding = self._packData()
     signature = sign_data(bencoding, keypair)
     self.signature = signature
コード例 #3
0
def generateChannelCastEntry(channel, infohash, keypair):
    channel_name = u'channel-' + unichr(randint(0,255))
    torrent_name = u'torrent-' + unichr(randint(0,255))
    timestamp = int(time.time())
    msg = dict()
    msg['publisher_id'] = str(channel)
    msg['publisher_name'] = channel_name
    msg['infohash'] = str(infohash)
    msg['torrentname'] = torrent_name
    msg['timestamp'] = timestamp
    
    bencoded = bencode(msg)
    
    signature = sign_data(bencoded, keypair)
    
    return signature, msg
コード例 #4
0
    def sign(self, content):
        rtstamp = time.time()
        #print >>sys.stderr,"ECDSAAuth: sign: ts %.5f s" % rtstamp

        extra = struct.pack('>Qd', self.seqnum, rtstamp)
        self.seqnum += 1L

        sig = sign_data(content, extra, self.keypair)
        # The sig returned is either 64 or 63 bytes long (62 also possible I
        # guess). Therefore we transmit size as 1 bytes and fill to 64 bytes.
        lensig = chr(len(sig))
        if len(sig) != self.MAX_ECDSA_ASN1_SIGSIZE:
            # Note: this is not official ASN.1 padding. Also need to modify
            # the header length for that I assume.
            diff = self.MAX_ECDSA_ASN1_SIGSIZE - len(sig)
            padding = '\x00' * diff
            return [content, extra, lensig, sig, padding]
        else:
            return [content, extra, lensig, sig]
コード例 #5
0
    def sign(self,content):
        rtstamp = time.time()
        #print >>sys.stderr,"ECDSAAuth: sign: ts %.5f s" % rtstamp
        
        extra = struct.pack('>Qd', self.seqnum,rtstamp)
        self.seqnum += 1L

        sig = sign_data(content,extra,self.keypair)
        # The sig returned is either 64 or 63 bytes long (62 also possible I 
        # guess). Therefore we transmit size as 1 bytes and fill to 64 bytes.
        lensig = chr(len(sig))
        if len(sig) != self.MAX_ECDSA_ASN1_SIGSIZE:
            # Note: this is not official ASN.1 padding. Also need to modify
            # the header length for that I assume.
            diff = self.MAX_ECDSA_ASN1_SIGSIZE-len(sig)
            padding = '\x00' * diff 
            return [content,extra,lensig,sig,padding]
        else:
            return [content,extra,lensig,sig]