def update_pkcs12(device, cookie = None, fiona_id = None, pkcs12_bytes = None): if cookie: device.last_cookie = cookie[:64] if fiona_id: device.fiona_id = fiona_id if pkcs12_bytes: test_context = _certificate.make_context(device.serial, pkcs12_bytes) if not test_context: logging.error("%s tried to update PKCS12 key with invalid data -- ignored") else: logging.warn("%s updated its PKCS12 client key", device) device.p12 = pkcs12_bytes # Even though we're updating the client certificate, active connections will still work with the old one. # Actually, the old certificate will still be able to open new connections for an unknown amount of time. # So there's no point in destroying the current SSL context and creating a new one. _db.update(device)
def _update(device, ip = None, cookie = None, kind = None): cookie_matches = cookie == device.last_cookie if not cookie_matches and cookie and device.last_cookie: cookie_matches = cookie.startswith(device.last_cookie) kind_matches = kind == device.kind if not kind_matches and kind and device.kind: kind_matches = device.kind.startswith(kind) if ip == device.last_ip and cookie_matches and kind_matches: # only bother writing to the db if any of them changed return device logging.debug("updating device %s with ip %s and cookie %s", device, ip, cookie[:12] if cookie else None) device.last_ip = ip if cookie: device.last_cookie = cookie[:64] if not kind_matches: # only update the device kind when it's more specific than the one we knew device.kind = kind _db.update(device) return device
def update(device, alias=None, cookie=None, fiona_id=None, pkcs12_bytes=None): if alias: device.alias = alias if cookie: device.last_cookie = cookie[:64] if fiona_id: device.fiona_id = fiona_id if pkcs12_bytes: test_context = _certificate.make_context(device.serial, pkcs12_bytes) if not test_context: logging.error( "%s tried to update PKCS12 key with invalid data -- ignored") else: logging.warn("%s updated its PKCS12 client key", device) device.p12 = pkcs12_bytes # Even though we're updating the client certificate, active connections will still work with the old one. # Actually, the old certificate will still be able to open new connections for an unknown amount of time. # So there's no point in destroying the current SSL context and creating a new one. _db.update(device)
def _update(device, ip=None, cookie=None, kind=None): cookie_matches = cookie == device.last_cookie if not cookie_matches and cookie and device.last_cookie: cookie_matches = cookie.startswith(device.last_cookie) kind_matches = kind == device.kind if not kind_matches and kind and device.kind: kind_matches = device.kind.startswith(kind) if ip == device.last_ip and cookie_matches and kind_matches: # only bother writing to the db if any of them changed return device logging.debug("updating device %s with ip %s and cookie %s", device, ip, cookie[:12] if cookie else None) device.last_ip = ip if cookie: device.last_cookie = cookie[:64] if kind and not kind_matches: # only update the device kind when it's more specific than the one we knew device.kind = kind _db.update(device) return device
if args.device_id: d = devices.get(args.device_id) if not d: for k, v in devices.items(): if k.startswith(args.device_id): d = v break else: d = None if args.device_id and not d: logging.warn("Device %s not found", args.device_id) elif args.delete: if not args.device_id: logging.warn("--device parameter required") else: logging.warn("Deleting device %s", d) _db.delete(d) elif args.new_name: if not args.device_id: logging.warn("--device parameter required") else: logging.warn("Renaming device %s to %s", d, args.new_name) d.alias = args.new_name _db.update(d) elif d: check_device(d) else: for d in devices.values(): check_device(d)
if args.device_id: d = devices.get(args.device_id) if not d: for k,v in devices.items(): if k.startswith(args.device_id): d = v break else: d = None if args.device_id and not d: logging.warn("Device %s not found", args.device_id) elif args.delete: if not args.device_id: logging.warn("--device parameter required") else: logging.warn("Deleting device %s", d) _db.delete(d) elif args.new_name: if not args.device_id: logging.warn("--device parameter required") else: logging.warn("Renaming device %s to %s", d, args.new_name) d.alias = args.new_name _db.update(d) elif d: check_device(d) else: for d in devices.values(): check_device(d)