Beispiel #1
0
def test_encryption():
    addr = 'tcp://127.0.0.1:55055'
    pub, sec = curve_keypair()
    publickey, secretkey = encode_key(pub), encode_key(sec)
    auth = {'allow': [{'credentials': 'CURVE:{}'.format(publickey)}]}

    plat = PlatformWrapper()
    plat.startup_platform(vip_address=addr, auth_dict=auth, encrypt=True)

    agent_addr = '{}?serverkey={}&publickey={}&secretkey=' \
                 '{}'.format(addr, plat.publickey, publickey, secretkey)

    agent1 = plat.build_agent(agent_addr, identity='agent1')
    peers = agent1.vip.peerlist.list().get(timeout=2)
    plat.shutdown_platform()
    print('PEERS: ', peers)
    assert len(peers) > 0
Beispiel #2
0
    def _get_discovery(self, environ, start_response, data=None):
        q = query.Query(self.core)

        self.instance_name = q.query('instance-name').get(timeout=60)
        addreses = q.query('addresses').get(timeout=60)
        external_vip = None
        for x in addreses:
            try:
                if not is_ip_private(x):
                    external_vip = x
                    break
            except IndexError:
                pass

        return_dict = {}

        if external_vip and self.serverkey:
            return_dict['serverkey'] = encode_key(self.serverkey)
            return_dict['vip-address'] = external_vip

        if self.instance_name:
            return_dict['instance-name'] = self.instance_name

        if self.core.messagebus == 'rmq':
            config = RMQConfig()
            rmq_address = None
            if config.is_ssl:
                rmq_address = "amqps://{host}:{port}/{vhost}".format(
                    host=config.hostname,
                    port=config.amqp_port_ssl,
                    vhost=config.virtual_host)
            else:
                rmq_address = "amqp://{host}:{port}/{vhost}".format(
                    host=config.hostname,
                    port=config.amqp_port,
                    vhost=config.virtual_host)
            return_dict['rmq-address'] = rmq_address
            return_dict['rmq-ca-cert'] = self._certs.cert(
                self._certs.root_ca_name).public_bytes(
                    serialization.Encoding.PEM)
        return Response(jsonapi.dumps(return_dict),
                        content_type="application/json")
Beispiel #3
0
def read_curve_key(infile):
    key = infile.read(80)
    publickey = key[:40]
    secretkey = key[40:]
    return encode_key(publickey), encode_key(secretkey)
Beispiel #4
0
 def generate_key(self):
     key = ''.join(zmq.curve_keypair())
     with open(os.path.join(self.volttron_home, 'curve.key'), 'w') as fd:
         fd.write(key)
     return encode_key(key[:40])  # public key
Beispiel #5
0
 def generate_key(self):
     key = ''.join(zmq.curve_keypair())
     with open(os.path.join(self.volttron_home, 'curve.key'), 'w') as fd:
         fd.write(key)
     return encode_key(key[:40]) # public key
Beispiel #6
0
def read_curve_key(infile):
    key = infile.read(80)
    publickey = key[:40]
    secretkey = key[40:]
    return encode_key(publickey), encode_key(secretkey)