Class UserFilesKey

java.lang.Object
com.iizix.server.wsfile.UserFilesKey

public final class UserFilesKey extends Object
The key of the user file URLs (CC-FIX-URN-LOCKDOWN, ruling UR-5 of order 515): the subject a URNResourceType.USER_DATABASE_FILES provider is published under, /$$ud/<subject>/, is base64url(HMAC-SHA256(k,"ud:"+uid)) truncated to 128 bits - 22 characters that name neither the user ID nor the user name, that cannot be guessed, and that stay the same from one start of the server to the next, so a Browser's cache of a profile picture survives a restart. Until this order the subject was <uid>-<userName>: every profile picture was served, with no credential, at a URL anyone could predict from a sequential user ID and a user name, and the URL told whoever saw it the user name, often an e-mail address (U515-30, measured by order 517's probe P-2).

The key. 256 bits of SecureRandom, kept in this machine's secrets store under <$secretsContext>/$userFilesKey - the secrets context of the server configuration (ServerSettings.SECRETS_CONTEXT) - generated and stored at its first use, never written into a source, a log line or a URL. A server whose configuration has no secrets context, a process without a secrets store, or a read-only store that holds no key, gets a key held in memory for this run only: the URLs are as safe, but they change at the next start (one cache miss per client), which is said once at INFO. Every test rig and every reactor runs that way, since their configurations carry no context: no test ever writes the owner's store.

The key is resolved once per process, at the first user file provider.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The atom of the key below the secrets context: "$userFilesKey".
    static final int
    The length of the key in bytes: 32 (256 bits).
    static final int
    The length of a subject in bytes before its Base64 encoding: 16 (128 bits), 22 characters encoded.
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    get(ServerSettings settings)
    Gets the key of this process: resolved at the first call as the class comment says, the same bytes at every later call.
    static String
    subject(long uid, byte[] key)
    Gets the URL subject of a user's files under a key: base64url(HMAC-SHA256(key,"ud:"+uid)) truncated to SUBJECT_LENGTH bytes, without padding.
    static String
    subject(long uid, ServerSettings settings)
    Gets the URL subject of a user's files under this process's key: see subject(long,byte[]).
  • Field Details

    • ATOM

      public static final String ATOM
      The atom of the key below the secrets context: "$userFilesKey".
      See Also:
    • KEY_LENGTH

      public static final int KEY_LENGTH
      The length of the key in bytes: 32 (256 bits).
      See Also:
    • SUBJECT_LENGTH

      public static final int SUBJECT_LENGTH
      The length of a subject in bytes before its Base64 encoding: 16 (128 bits), 22 characters encoded.
      See Also:
  • Method Details

    • get

      public static byte[] get(ServerSettings settings)
      Gets the key of this process: resolved at the first call as the class comment says, the same bytes at every later call.
      Parameters:
      settings - The server settings naming the secrets context, null for none.
      Returns:
      The key, KEY_LENGTH bytes. The caller never changes or logs it.
    • subject

      public static String subject(long uid, ServerSettings settings)
      Gets the URL subject of a user's files under this process's key: see subject(long,byte[]).
      Parameters:
      uid - The user ID.
      settings - The server settings naming the secrets context, null for none.
      Returns:
      The subject, 22 characters of A-Z a-z 0-9 - _.
    • subject

      public static String subject(long uid, byte[] key)
      Gets the URL subject of a user's files under a key: base64url(HMAC-SHA256(key,"ud:"+uid)) truncated to SUBJECT_LENGTH bytes, without padding. The same key and user ID always give the same subject; another key or another user ID gives one that cannot be related to it.
      Parameters:
      uid - The user ID.
      key - The key, KEY_LENGTH bytes.
      Returns:
      The subject, 22 characters of A-Z a-z 0-9 - _.
      Throws:
      IllegalArgumentException - If the key is not KEY_LENGTH bytes.