Пример #1
0
    def __init__(self,
                 entity_name="gabe",
                 wave_uri="localhost:410",
                 mosquitto_url="broker.cal-sdb.org",
                 mosquitto_pass="******",
                 mosquitto_user="******",
                 on_message=None):
        # connect to WAVE agent
        self.agent = wave3.WAVEStub(grpc.insecure_channel(wave_uri))

        # set up entity and store keys
        self.entity_name = entity_name
        self.entity, newlycreated = self.createOrLoadEntity(entity_name)
        self.entityPublicDER = self.entity.PublicDER
        self.entitySecretDER = self.entity.SecretDER
        self.perspective = wave3.Perspective(entitySecret=wave3.EntitySecret(
            DER=self.entity.SecretDER))
        # publish this so others can refer to it
        if newlycreated:
            self.agent.PublishEntity(
                wave3.PublishEntityParams(DER=self.entity.PublicDER))

        # create mqtt client
        self.client = mqtt.Client(client_id=entity_name, clean_session=True)
        self._connected = False
        self._pending = []
        self._call_on_message = on_message
        self.client.on_connect = self.on_connect
        self.client.on_message = self.on_message
        self.client.username_pw_set(mosquitto_user, mosquitto_pass)
        self.client.connect(mosquitto_url, 1883, 60)
        self.client.loop_start()
Пример #2
0
    def __init__(self, nickname):
        self.nickname = nickname
        channel = grpc.insecure_channel("localhost:410")
        self.agent = wv.WAVEStub(channel)

        self.ent, newlycreated = createOrLoadEntity(self.agent, "homeserver")
        self.entityPublicDER = self.ent.PublicDER
        self.entitySecretDER = self.ent.SecretDER
        self.perspective = wv.Perspective(entitySecret=wv.EntitySecret(
            DER=self.ent.SecretDER))
        if newlycreated:
            self.agent.PublishEntity(
                wv.PublishEntityParams(DER=self.ent.PublicDER))

        # instantiate and display widgets
        self.light_widget = widgets.Light('light-1')
        self.switch_widget = widgets.Switch('light-1')
        self.thermostat_widget = widgets.Thermostat()
        self.motion_sensor_widget = widgets.MotionSensor()
        self.notificationbox = widgets.Notification()
        self.lightbox = widgets.ipw.VBox(
            [self.light_widget, self.switch_widget],
            layout=widgets.ipw.Layout(align_items='center',
                                      border='solid 2px'))
        self.mybox = widgets.ipw.VBox([
            widgets.ipw.HBox([
                self.lightbox, self.motion_sensor_widget,
                self.thermostat_widget
            ],
                             layout=widgets.ipw.Layout(width='100%')),
            self.notificationbox,
        ])
        display(self.mybox)

        # TODO: have read/write topic?
        self.tstat_entity, self.tstat_encrypt_proof, self.tstat_msg_proof = self._make_device_entity(
            'thermostat')
        self.light_entity, self.light_encrypt_proof, self.light_msg_proof = self._make_device_entity(
            'light')
        self.motion_entity, self.motion_encrypt_proof, self.motion_msg_proof = self._make_device_entity(
            'motion')
        self.light_widget.observe(self._publish_light_state, 'state')
        self.thermostat_widget.observe(self._publish_tstat_state)
        self.motion_sensor_widget.observe(self._publish_motion_sensor_state)
        # hook up triggers to report?

        self.client = mqtt.Client()
        self.client.on_connect = self.on_connect
        self.client.on_message = self.on_message
        self.client.username_pw_set("risecamp2018", "risecamp2018")
        self.client.connect("broker.cal-sdb.org", 1883, 60)
        self.client.loop_start()
Пример #3
0
def Initialize(nickname):
    """
    Set up the home server with the user's nickname,
    and open a WAVE and MQTT client
    """
    if nickname == "john-smith":
        raise Exception("you must change your nickname to something unique")
    global t_homeserver
    t_homeserver = HomeServer(nickname)
    global t_wave
    t_wave = wv.WAVEStub(grpc.insecure_channel("localhost:410"))
    mqttclient = MQTTWrapper()
    return t_wave, t_homeserver, mqttclient
Пример #4
0
import grpc
import wave3 as wv

channel = grpc.insecure_channel("localhost:410")
agent = wv.WAVEStub(channel)

# rv = stub.ListLocations(eapi_pb2.ListLocationsParams())
# print(rv)

ent = agent.CreateEntity(wv.CreateEntityParams())
agent.PublishEntity(wv.PublishEntityParams(DER=ent.PublicDER))
ent2 = agent.CreateEntity(wv.CreateEntityParams())
agent.PublishEntity(wv.PublishEntityParams(DER=ent2.PublicDER))

perspective = wv.Perspective(entitySecret=wv.EntitySecret(DER=ent.SecretDER))
att = agent.CreateAttestation(
    wv.CreateAttestationParams(
        perspective=perspective,
        subjectHash=ent2.hash,
        publish=True,
        policy=wv.Policy(
            rTreePolicy=wv.RTreePolicy(namespace=ent.hash,
                                       indirections=5,
                                       statements=[
                                           wv.RTreePolicyStatement(
                                               permissionSet=ent.hash,
                                               permissions=["foo"],
                                               resource="foo/bar",
                                           )
                                       ]))))
ent2perspective = wv.Perspective(entitySecret=wv.EntitySecret(