Ejemplo n.º 1
0
def write_signature(output, ):
    # calls si.signature
    # outputs a signature to output
    with open(output, 'w') as outfh:
        fig = si.signature(target_name, primary_compounds,
                           nonprimary_compounds, cell_lines)
        outfh.write(fig)
Ejemplo n.º 2
0
def write_signature(output, ):
    # calls si.signature
    # outputs a signature to output
    with open(output, 'w') as outfh:
        fig = si.signature(target_name, primary_compounds,
                           nonprimary_compounds, cell_lines)
        outfh.write(fig)
Ejemplo n.º 3
0
    def verify_sign(self,message,sign):
        try:
            if type(sign) == type(""):
                j = serializer.loads(sign)
            else:
                j = sign
            
            keyindex = 1
            for key in self.keys:
                signer = signature.signature(key.get_publickey())
                if j.has_key(keyindex):
                    sig = j[keyindex]
                elif j.has_key(str(keyindex)):
                    sig = j[str(keyindex)]
                else:
                    return False
                if not signer.verify(sig,message):
                    return False
                keyindex += 1
        except Exception,e:

            log.warning("Failed verifying a sign, returning False. More details: %s",e)

            print "Error: %s" % e
            return False
Ejemplo n.º 4
0
    def do_sign(self,message,raw=True):
        # 通用的签名方法
        if not self.is_ours:
            raise Exception("This is not a private certificate that can be used for signing.")
        ret = {}
        keyindex = 1
        for key in self.keys:
            signer = signature.signature(key.get_privatekey())
            signlimit = key.sign_limit()

            hashalgo = Hash().consult(signlimit)
            if len(hashalgo) < 1:
                raise Exception("No suitable hash functions found.")
            maxhash = hashalgo[max(hashalgo.keys())]
            choosenalgo = maxhash[random.randint(0,len(maxhash) - 1)]

            sig = signer.new(message,choosenalgo,raw)   # XXX 安全泄漏。应当考虑一种提供选择的方法
            ret[str(keyindex)] = sig
            keyindex += 1
        if raw:
            return ret
        else:
            return serializer.dumps(ret)

        log.info("Successfully made a sign.")
Ejemplo n.º 5
0
def test_signature_py2(f, sig):
    assert signature(f) == sig, sig
Ejemplo n.º 6
0
def main():
    """
    DISTRIBUTE KEY
    """
    print "########## DISTRIBUTE KEY #################"
    # GIVE ALICE A KEY ... init with none key
    alice = elgamal()
    alice.create_key(10)
    # GIVE BOB KEY . .other  init with 10 bits key
    bob = elgamal(10)
    print "ALICE:\n", alice
    print "BOB:\n", bob
    print "################################"
    """
    END DISTRIBUTE KEY
    """
##########################################################################################################
    """
    ALICE'S TASK
    """
    print "########## ALICE's task ###########"
    # ALICE have a text
    text = "hello bob"
    print "TEXT: ", text
    # ALICE use public_key of BOB to encrypt that text
    cipher = bob.encrypt(text)
    #print "CIPHER: \n", cipher
    # give ALICE a pen
    alice_pen = signature(alice.private_key)
    #print alice_pen
    # create signature with ALICE's pen
    sig_of_alice = alice_pen.sign(text)
    #print "SIGNATURE: \n", sig
    ### alice send a pair contain cipher and her signature to bob
    pair = [cipher, sig_of_alice]
    print "PAIR[cipher, signature]: \n", pair    
    print "################################"
    """
    END ALICE'S TASK
    """
############################################################################################################
    """
    DARTH'S TASK
    """
    print "###### DARTH's task ###################"
    # DARTH have public_key of bob. He find private key
    darth = attack()
    k = darth.find_private_key(bob.public_key)
    print "DARTH found private key is: ", k
    pr = [bob.public_key[0], bob.public_key[1], k] # pr = [p, q, k]
    darth_crypto = elgamal()
    darth_crypto.set_key([],pr) ### darth only need private key to decrypt cipher
    print "Darth try to decrypt: ", darth_crypto.decrypt(pair[0])
    print "HAHAHAHAHAHAHA :)"
    print "################################"
    """
    DARTH'S TASK
    """
############################################################################################################
    """
    BOB'S TASK
    """
    print "########### BOB's task ###############"
    ###########bob receive the pair. bob take a accuracy of alice's signature
    ca_alice = verification(alice.public_key)
    t_text = bob.decrypt(cipher)
    print "BOB decrypt: ", t_text
    print "VERIFY: " ,ca_alice.verify(t_text,pair[1])
    """
Ejemplo n.º 7
0
def test_signature_py3(f, sig):
    s = signature(f)
    assert s == sig, s