New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating too-similar VM labels #2732

Open
marmarek opened this Issue Mar 28, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@marmarek
Member

marmarek commented Mar 28, 2017

If we in practice want to allow creating custom labels, it would be nice to avoid them being too similar.
Some PoC:

QubesOS/qubes-core-admin#95 (comment)

import math

GAMMA = 2.2
#THRESHOLD = 

def hex_to_float(color, gamma=1.0):
  return tuple((int(color[i:i+2], 0x10) / 255.0) ** gamma for i in range(0, len(color), 2))

untrusted_r, untrusted_g, untrusted_b = hex_to_float(untrusted_color, gamma=GAMMA)
for label in existing_labels:
  r, g, b = hex_to_float(label.color, gamma=GAMMA)
  # approximate the colour distance as Euclidean distance in linear (gamma-expanded) space
  if math.sqrt((r - untrusted_r) ** 2 + (g - untrusted_g) ** 2 + (b - untrusted_b) ** 2) < THRESHOLD:
    raise qubes.exc.QubesValueError('colour too similar to an existing one')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment