def get_key(self): if not self.key: if self.get_metadata().is_own_device: self.key = crypto.get_own_key() elif self.public_key: self.key = crypto.Key(public_key_string=self.public_key) return self.key
def register_public_key_client(request): if Device.get_own_device().get_zone(): set_as_registered() return {"already_registered": True} client = SyncClient() if client.test_connection() != "success": return {"no_internet": True} reg_response = client.register() reg_status = reg_response.get("code") if reg_status == "registered": set_as_registered() return {"newly_registered": True} if reg_status == "device_already_registered": set_as_registered() return {"already_registered": True} if reg_status == "public_key_unregistered": return { "unregistered": True, "registration_url": client.path_to_url( reverse("register_public_key") + "?" + urllib.quote(crypto.get_own_key().get_public_key_string()) ), "central_login_url": "%s://%s/accounts/login" % (settings.SECURESYNC_PROTOCOL, settings.CENTRAL_SERVER_HOST), "callback_url": request.build_absolute_uri(reverse("register_public_key")), } error_msg = reg_response.get("error", "") if error_msg: return {"error_msg": error_msg} return HttpResponse(_("Registration status: ") + reg_status)
def register_public_key_client(request): if Device.get_own_device().get_zone(): set_as_registered() return {"already_registered": True} client = SyncClient() if client.test_connection() != "success": return {"no_internet": True} reg_response = client.register() reg_status = reg_response.get("code") if reg_status == "registered": set_as_registered() return {"newly_registered": True} if reg_status == "device_already_registered": set_as_registered() return {"already_registered": True} if reg_status == "public_key_unregistered": return { "unregistered": True, "registration_url": client.path_to_url( reverse("register_public_key") + "?" + urllib.quote(crypto.get_own_key().get_public_key_string())), "central_login_url": "%s://%s/accounts/login" % (settings.SECURESYNC_PROTOCOL, settings.CENTRAL_SERVER_HOST), "callback_url": request.build_absolute_uri(reverse("register_public_key")), } error_msg = reg_response.get("error", "") if error_msg: return {"error_msg": error_msg} return HttpResponse(_("Registration status: ") + reg_status)
def initialize_own_device(**kwargs): own_device = Device(**kwargs) own_device.set_key(crypto.get_own_key()) own_device.sign(device=own_device) own_device.save(own_device=own_device) metadata = own_device.get_metadata() metadata.is_own_device = True metadata.is_trusted = settings.CENTRAL_SERVER metadata.save() return own_device
def initialize_own_device(**kwargs): own_device = Device(**kwargs) own_device.set_key(crypto.get_own_key()) own_device.sign(device=own_device) # imported=True is for when the local device should not sign the object, # and when counters should not be incremented. That's our situation here! super(Device, own_device).save(imported=True, increment_counters=False) metadata = own_device.get_metadata() metadata.is_own_device = True metadata.is_trusted = settings.CENTRAL_SERVER metadata.save() return own_device
def initialize_own_device(cls, **kwargs): """ Create a device object for the installed device. Part of installation. """ kwargs["version"] = kwargs.get("version", kalite.VERSION) kwargs["name"] = kwargs.get("name", get_host_name()) own_device = cls(**kwargs) own_device.set_key(crypto.get_own_key()) # imported=True is for when the local device should not sign the object, # and when counters should not be incremented. That's our situation here! own_device.sign(device=own_device) # must sign, in order to use imported codepath super(Device, own_device).save(imported=True, increment_counters=False) metadata = own_device.get_metadata() metadata.is_own_device = True metadata.is_trusted = settings.CENTRAL_SERVER # this is OK to set, as DeviceMetata is NEVER synced. metadata.save() return own_device
def initialize_own_device(cls, **kwargs): """ Create a device object for the installed device. Part of installation. """ kwargs["version"] = kwargs.get("version", VERSION) kwargs["name"] = kwargs.get("name", get_host_name()) own_device = cls(**kwargs) own_device.set_key(crypto.get_own_key()) # imported=True is for when the local device should not sign the object, # and when counters should not be incremented. That's our situation here! own_device.sign( device=own_device) # must sign, in order to use imported codepath super(Device, own_device).save(imported=True, increment_counters=False) metadata = own_device.get_metadata() metadata.is_own_device = True metadata.is_trusted = settings.CENTRAL_SERVER # this is OK to set, as DeviceMetata is NEVER synced. metadata.save() return own_device