Example #1
0
 def do_login(self, crap ):
         global session
         with open('config.json') as data_file:
             data = json.load(data_file)
         binKey = base64.b64decode(data["private_key"])
         pbinKey = base64.b64decode(data["public_key"])
         theKey = ecdsa.SigningKey.from_der(binKey)
         vKey = ecdsa.VerifyingKey.from_der(pbinKey)
         loginStruct["source"] = data["source"]
         loginStruct["signature"] = ""
         self.prompt = data["source"] + " > "
         loginStruct["current_time"] = int(time.time())
         print censusprotocollib.serialize(loginStruct)
         m = hashlib.sha256()
         m.update(censusprotocollib.serialize(loginStruct))
         txhash = m.digest()
         SIG = theKey.sign_digest(txhash, sigencode=ecdsa.util.sigencode_string )
         result = vKey.verify_digest(SIG,txhash)
         print result
         print "HASH"
         print dump(txhash)
         print "Public Key"
         print dump(pbinKey)
         print "SIGNATURE"
         print dump(SIG)
         print "SIGNED ITEM"
         print dump(censusprotocollib.serialize(loginStruct))
         print base64.b64encode(SIG)
         loginStruct["signature"] = base64.b64encode(SIG)
         params = censusprotocollib.serialize(loginStruct)
         headers = {"Content-type": "application/json"}
         conn = httplib.HTTPConnection("localhost", 3000)
         conn.request("POST", "/api/v1/login", params, headers)
         response = conn.getresponse()
         print "-----------------------------------"
         print response.status, response.reason
         print "-----------------------------------"
         data = response.read()
         print data
         outFile = open("session.json", "wt")
         outFile.write(data)
         outFile.close()
         session = json.loads(data)
Example #2
0
    def do_buy(self, key ):
        print "Buying item " + key
        headers = {'user-agent': 'censusshell',
                   'X-Census-User':session['source'],
                   'X-Census-Token': session['token']}
        global session
        with open('config.json') as data_file:
            data = json.load(data_file)
        binKey = base64.b64decode(data["private_key"])
        theKey = ecdsa.SigningKey.from_der(binKey)

        buyStruct["block_in"] = 0
        buyStruct["buy_type"] = "sale"
        buyStruct["source"] = data["source"]
#        buyStruct["target"] = owner
        buyStruct["created"] = int(time.time())
        buyStruct["expiration"] = int(time.time())+(60*60*24*365)
        buyStruct["price"] = 1000
        buyStruct["sale_type"] = "fixed"
        buyStruct["tips"] = 10
        buyStruct["signature"] = ""
        buyStruct["txid"] = str(uuid.uuid4())
        buyStruct["vend_item"] = key
        buyStruct["version"] = 1
        m = hashlib.sha256()
        m.update(censusprotocollib.serialize(buyStruct))
        txhash = m.digest()
        SIG = theKey.sign_digest(txhash, sigencode=ecdsa.util.sigencode_string )
        print "SIGNED ITEM BEING SENT"
        print dump(censusprotocollib.serialize(vendStruct))
        vendStruct["signature"] = base64.b64encode(SIG)
        params = censusprotocollib.serialize(buyStruct)
        headers = {"Content-type": "application/json"}
        conn = httplib.HTTPConnection("localhost", 3000)
        conn.request("POST", "/api/v1/buy", params, headers)
        response = conn.getresponse()
        print "-----------------------------------"
        print response.status, response.reason
        print "-----------------------------------"
        data = response.read()
        print data
Example #3
0
    def onToggle(self, event):
        btnLabel = self.toggleBtn.GetLabel()
        if btnLabel == "Login":
            print "Logging in"
            with open('config.json') as data_file:
                data = json.load(data_file)
            print(data)
            binKey = base64.b64decode(data["private_key"])
            textKey =  binascii.hexlify(bytearray(binKey))
            pbinKey = base64.b64decode(data["public_key"])
            print textKey
            print len(textKey)
            theKey = ecdsa.SigningKey.from_der(binKey)
            vKey = ecdsa.VerifyingKey.from_der(pbinKey)
            print theKey
            loginStruct["source"] = data["source"]
            self.address.SetLabel(data["source"])
            loginStruct["current_time"] = int(time.time())
            print censusprotocollib.serialize(loginStruct)
            m = hashlib.sha256()
            m.update(censusprotocollib.serialize(loginStruct))
            txhash = m.digest()
            SIG = theKey.sign_digest(txhash, sigencode=ecdsa.util.sigencode_string )
            SIGDER = theKey.sign_digest(txhash, sigencode=ecdsa.util.sigencode_der )

            print "LENGTHS"
            result = vKey.verify_digest(SIG,txhash)
            print len(SIG)
            print "HASH"
            print hexdump.dump(txhash)
            print result
#            result = vKey.verify(SIG2,censusprotocollib.serialize(loginStruct))
            print result
            print "OMG OMG OMG"
            NEWSIG = SIG[32:] + SIG[:32]
            print "Public Key"
            print dump(pbinKey)
            print "SIGNAURE"
            print dump(SIG)
            print "SIGNED ITEM"
            print dump(censusprotocollib.serialize(loginStruct))
            print base64.b64encode(SIG)
            print len(SIGDER)
            print base64.b64encode(SIGDER)
            print "LENGTHS"
            loginStruct["signature"] = base64.b64encode(SIG)
            params = censusprotocollib.serialize(loginStruct)
            print "PACKET BEING SENT:\n"
            print binascii.hexlify(bytearray(params))
            headers = {"Content-type": "application/json", "X-Cats": "Cats-rule"}
            conn = httplib.HTTPConnection("localhost", 3000)
            conn.request("POST", "/api/v1/login", params, headers)
            response = conn.getresponse()
            print "-----------------------------------"
            print response
            print response.status, response.reason
            print "-----------------------------------"

            self.toggleBtn.SetLabel("Logout")
        else:
            self.toggleBtn.SetLabel("Login")