示例#1
0
 def __init__(self, s6a_proxy_stub: s6a_proxy_pb2_grpc.S6aProxyStub):
     logging.info("starting brokerd servicer")
     self._s6a_proxy_stub = s6a_proxy_stub
     key_dir = os.getenv('KEY_DIR', '/var/opt/magma/key_files')
     self.br_rsa_pri_key =  RSA.load_key(os.path.join(key_dir, 'br_rsa_pri.pem'))
     self.br_ecdsa_pri_key =  EC.load_key(os.path.join(key_dir, 'br_ec_pri.pem'))
     self.ue_rsa_pub_key = RSA.load_pub_key(os.path.join(key_dir, 'ue_rsa_pub.pem'))
     self.ue_ecdsa_pub_key = EC.load_pub_key(os.path.join(key_dir, 'ue_ec_pub.pem'))
     self.ut_rsa_pub_key = RSA.load_pub_key(os.path.join(key_dir, 'ut_rsa_pub.pem'))
     self.ut_ecdsa_pub_key = EC.load_pub_key(os.path.join(key_dir, 'ut_ec_pub.pem'))
     self.br_id = 0
     logging.info("done loading broker keys")
示例#2
0
  def __init__(self, cpr, publisher, callback=None):
    self._cpr = cpr
    self._callback = callback
    self.pub_key=EC.load_pub_key("/home/paultpt/Documents/eckeys/ec_pubkey.pem")
    self.last_key=""
    self.last_key_interval=1
    self.sync=-1

    #sub to every function that starts with "handle"
    self._fns = [int(l[6:]) for l in dir(self) if l.startswith("handle")]
    for i in self._fns:
      publisher.subscribe("type%i_dl" % i, getattr(self, "handle%i" % i))
    
    publisher.subscribe("modes_dl", self.catch_nohandler)
示例#3
0
def read_pub_key(pubfilename):
    return EC.load_pub_key(pubfilename)
示例#4
0
 def test_verify_dsa(self):
     ec = EC.load_key(self.privkey)
     r, s = ec.sign_dsa(self.data)
     ec2 = EC.load_pub_key(self.pubkey)
     assert ec2.verify_dsa(self.data, r, s)
     assert not ec2.verify_dsa(self.data, s, r)
示例#5
0
 def test_loadpubkey(self):
     # XXX more work needed
     ec = EC.load_pub_key(self.pubkey)
     assert len(ec) == 256
     self.assertRaises(EC.ECError, EC.load_pub_key, self.errkey)
示例#6
0
 def test_verify_dsa(self):
     ec = EC.load_key(self.privkey)
     r, s = ec.sign_dsa(self.data)
     ec2 = EC.load_pub_key(self.pubkey)
     assert ec2.verify_dsa(self.data, r, s)
     assert not ec2.verify_dsa(self.data, s, r)
示例#7
0
 def test_loadpubkey(self):
     # XXX more work needed
     ec = EC.load_pub_key(self.pubkey)
     assert len(ec) == 233
     self.assertRaises(EC.ECError, EC.load_pub_key, self.errkey)
示例#8
0
 def test_loadpubkey(self):
     # XXX more work needed
     ec = EC.load_pub_key(self.pubkey)
     self.assertEqual(len(ec), tested_curve[1])
     with self.assertRaises(EC.ECError):
         EC.load_pub_key(self.errkey)
示例#9
0
文件: cs.py 项目: sr-gi/paysense
    def coinjoin_reputation_exchange(self, amount, fee=1000):

        # Get onion server address and the mixing amount from the ACA
        data = loads(urlopen(ACA + '/get_tor_address').read())
        tor_server = data.get("address")
        mixing_amount = data.get("amount")

        if mixing_amount == amount:

            utxo = self.get_mixing_utxo(amount, fee)

            if utxo is not None:

                # Create the address that will be used as a new pseudonym
                new_btc_addr_pk, new_btc_addr = self.generate_keys()

                # Build the output of the mixing transaction
                mixing_output = [{'value': amount, 'address': new_btc_addr}]

                # Build the input of the mixing transaction
                mixing_input = [{'output': utxo, 'value': amount + fee}]

                print "Connecting to " + tor_server
                # ToDo: Uncomment, actually running tor from terminal since testing server and client from the same machine
                # print(term.format("Starting Tor:\n", term.Attr.BOLD))
                # tor_process, controller = init_tor()

                # ToDo: Delete the following two lines when the above one is uncommented
                controller = Controller.from_port()
                controller.authenticate()

                headers = ['Content-type: application/json', 'Accept: text/plain']
                # Send reputation exchange output
                data = dumps({'outputs': mixing_output})
                code, response = tor_query(tor_server + "/outputs", 'POST', data, headers)

                if code is 200:
                    print "Output correctly sent. Resetting tor connection"
                    controller.new_circuit()

                    timer = float(loads(response).get("data"))
                    print "Waiting " + str(timer) + " for sending the input"
                    sleep(timer)

                    # Send reputation exchange input
                    data = dumps({'inputs': mixing_input})
                    code, response = tor_query(tor_server + "/inputs", 'POST', data, headers)

                    if code is 200:
                        print "Input correctly sent. Resetting tor connection"
                        controller.new_circuit()

                        timer = float(loads(response).get("data"))
                        print "Waiting " + str(timer) + " for getting the tx to be signed"
                        sleep(timer)

                        # Get tx hash to sign it
                        code, response = tor_query(tor_server + '/signatures')

                        if code is 200:
                            private_key_hex = get_priv_key_hex(self.data_path + S_KEY)
                            public_key = EC.load_pub_key(self.data_path + P_KEY)
                            public_key_hex = get_pub_key_hex(public_key.pub())

                            signature, index = get_tx_signature(response, private_key_hex, self.btc_address)

                            data = {'signature': signature, 'index': index, 'public_key': public_key_hex}
                            data = dumps({'data': data})

                            code, response = tor_query(tor_server + "/signatures", 'POST', data, headers)

                            if code is 200:
                                timer = float(loads(response).get("data"))
                                print "Waiting " + str(timer) + " for the transaction to be completed"
                                sleep(timer)
                                confirmed = False

                                while not confirmed:
                                    code, response = tor_query(tor_server + '/confirmation')
                                    data = loads(response)
                                    confirmed = bool(data.get("confirmation"))
                                    timer = float(data.get("time"))
                                    print "Waiting " + str(timer) + " for the transaction correctness confirmation"
                                    sleep(timer)

                                print "Transaction confirmed"
                                self.generate_new_identity(new_btc_addr, new_btc_addr_pk)
                                data = loads(response).get("data")
                                result = data
                            else:
                                try:
                                    data = loads(response).get("data")
                                    result = data
                                except ValueError:
                                    result = "Error sending signatures. " + str(response)
                        else:
                            try:
                                data = loads(response).get("data")
                                result = data
                            except ValueError:
                                result = "Error getting signatures. " + str(response)
                    else:
                        try:
                            data = loads(response).get("data")
                            result = data
                        except ValueError:
                            result = "Error sending inputs. " + str(response)
                else:
                    try:
                        data = loads(response).get("data")
                        result = data
                    except ValueError:
                        result = "Error sending outputs. " + str(response)

            else:
                result = "You have not enough reputation to perform a reputation exchange. Minimum amount: " + str(amount) + " + " + str(fee) + " (transaction fee)."
        else:
            result = "The mixing server does not provide a mixing process for the chosen reputation amount"

        return result
示例#10
0
文件: cs.py 项目: sr-gi/paysense
    def coinjoin_reputation_exchange(self, amount, fee=1000):

        # Get onion server address and the mixing amount from the ACA
        data = loads(urlopen(ACA + '/get_tor_address').read())
        tor_server = data.get("address")
        mixing_amount = data.get("amount")

        if mixing_amount == amount:

            utxo = self.get_mixing_utxo(amount, fee)

            if utxo is not None:

                # Create the address that will be used as a new pseudonym
                new_btc_addr_pk, new_btc_addr = self.generate_keys()

                # Build the output of the mixing transaction
                mixing_output = [{'value': amount, 'address': new_btc_addr}]

                # Build the input of the mixing transaction
                mixing_input = [{'output': utxo, 'value': amount + fee}]

                print "Connecting to " + tor_server
                # ToDo: Uncomment, actually running tor from terminal since testing server and client from the same machine
                # print(term.format("Starting Tor:\n", term.Attr.BOLD))
                # tor_process, controller = init_tor()

                # ToDo: Delete the following two lines when the above one is uncommented
                controller = Controller.from_port()
                controller.authenticate()

                headers = [
                    'Content-type: application/json', 'Accept: text/plain'
                ]
                # Send reputation exchange output
                data = dumps({'outputs': mixing_output})
                code, response = tor_query(tor_server + "/outputs", 'POST',
                                           data, headers)

                if code is 200:
                    print "Output correctly sent. Resetting tor connection"
                    controller.new_circuit()

                    timer = float(loads(response).get("data"))
                    print "Waiting " + str(timer) + " for sending the input"
                    sleep(timer)

                    # Send reputation exchange input
                    data = dumps({'inputs': mixing_input})
                    code, response = tor_query(tor_server + "/inputs", 'POST',
                                               data, headers)

                    if code is 200:
                        print "Input correctly sent. Resetting tor connection"
                        controller.new_circuit()

                        timer = float(loads(response).get("data"))
                        print "Waiting " + str(
                            timer) + " for getting the tx to be signed"
                        sleep(timer)

                        # Get tx hash to sign it
                        code, response = tor_query(tor_server + '/signatures')

                        if code is 200:
                            private_key_hex = get_priv_key_hex(self.data_path +
                                                               S_KEY)
                            public_key = EC.load_pub_key(self.data_path +
                                                         P_KEY)
                            public_key_hex = get_pub_key_hex(public_key.pub())

                            signature, index = get_tx_signature(
                                response, private_key_hex, self.btc_address)

                            data = {
                                'signature': signature,
                                'index': index,
                                'public_key': public_key_hex
                            }
                            data = dumps({'data': data})

                            code, response = tor_query(
                                tor_server + "/signatures", 'POST', data,
                                headers)

                            if code is 200:
                                timer = float(loads(response).get("data"))
                                print "Waiting " + str(
                                    timer
                                ) + " for the transaction to be completed"
                                sleep(timer)
                                confirmed = False

                                while not confirmed:
                                    code, response = tor_query(tor_server +
                                                               '/confirmation')
                                    data = loads(response)
                                    confirmed = bool(data.get("confirmation"))
                                    timer = float(data.get("time"))
                                    print "Waiting " + str(
                                        timer
                                    ) + " for the transaction correctness confirmation"
                                    sleep(timer)

                                print "Transaction confirmed"
                                self.generate_new_identity(
                                    new_btc_addr, new_btc_addr_pk)
                                data = loads(response).get("data")
                                result = data
                            else:
                                try:
                                    data = loads(response).get("data")
                                    result = data
                                except ValueError:
                                    result = "Error sending signatures. " + str(
                                        response)
                        else:
                            try:
                                data = loads(response).get("data")
                                result = data
                            except ValueError:
                                result = "Error getting signatures. " + str(
                                    response)
                    else:
                        try:
                            data = loads(response).get("data")
                            result = data
                        except ValueError:
                            result = "Error sending inputs. " + str(response)
                else:
                    try:
                        data = loads(response).get("data")
                        result = data
                    except ValueError:
                        result = "Error sending outputs. " + str(response)

            else:
                result = "You have not enough reputation to perform a reputation exchange. Minimum amount: " + str(
                    amount) + " + " + str(fee) + " (transaction fee)."
        else:
            result = "The mixing server does not provide a mixing process for the chosen reputation amount"

        return result
示例#11
0
def read_pub_key(pubfilename):
    return EC.load_pub_key(pubfilename)