コード例 #1
0
ファイル: chat-demo.py プロジェクト: rauljim/tgs-pc
    def dispersy(self, callback):
        # start Dispersy
        dispersy = Dispersy.get_instance(callback, u".")
        dispersy.socket = communication.get_socket(callback, dispersy)

        # load/join discovery community
        public_key = "3081a7301006072a8648ce3d020106052b81040027038192000406b34f060c416e452fd31fb1770c2f475e928effce751f2f82565bec35c46a97fb8b375cca4ac5dc7d93df1ba594db335350297f003a423e207b53709e6163b7688c0f60a9cf6599037829098d5fbbfe786e0cb95194292f241ff6ae4d27c6414f94de7ed1aa62f0eb6ef70d2f5af97c9aade8266eb85b14296ed2004646838c056d1d9ad8a509b69f81fbc726201b57".decode("HEX")
        if True:
            # when crypto.py is disabled a public key is slightly
            # different...
            public_key = ";".join(("60", public_key[:60].encode("HEX"), ""))
        master = Member(public_key)
        try:
            self._discovery = DiscoveryCommunity.load_community(master)
        except ValueError:
            ec = ec_generate_key(u"low")
            self._my_member = Member(ec_to_public_bin(ec), ec_to_private_bin(ec))
            self._discovery = DiscoveryCommunity.join_community(master, self._my_member)
        else:
            self._my_member = self._discovery.my_member

        dispersy.define_auto_load(PreviewCommunity, (self._discovery,))
        dispersy.define_auto_load(SquareCommunity, (self._discovery,))

        # load squares
        for master in SquareCommunity.get_master_members():
            yield 1.0
            community = dispersy.get_community(master.mid)
            self._communities.append(community)
コード例 #2
0
ファイル: createkey.py プロジェクト: xemasiv/dispersy
def create_key(curves):
    for index, curve in enumerate(curves):
        if index > 0:
            print

        ec = ec_generate_key(curve)
        private_pem = ec_to_private_pem(ec)
        public_pem = ec_to_public_pem(ec)
        public_bin = ec_to_public_bin(ec)
        private_bin = ec_to_private_bin(ec)
        print "generated:", time.ctime()
        print "curve:", ec_name(curve)
        print "len:", len(ec), "bits ~", ec_signature_length(ec), "bytes signature"
        print "pub:", len(public_bin), public_bin.encode("HEX")
        print "prv:", len(private_bin), private_bin.encode("HEX")
        print "pub-sha1", sha1(public_bin).digest().encode("HEX")
        print "prv-sha1", sha1(private_bin).digest().encode("HEX")
        print public_pem.strip()
        print private_pem.strip()