Class UserFilesKey
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
FieldsModifier and TypeFieldDescriptionstatic final StringThe atom of the key below the secrets context: "$userFilesKey".static final intThe length of the key in bytes: 32 (256 bits).static final intThe length of a subject in bytes before its Base64 encoding: 16 (128 bits), 22 characters encoded.Method Summary
Modifier and TypeMethodDescriptionstatic 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 Stringsubject(long uid, byte[] key) Gets the URL subject of a user's files under a key:base64url(HMAC-SHA256(key,"ud:"+uid))truncated toSUBJECT_LENGTHbytes, without padding.static Stringsubject(long uid, ServerSettings settings) Gets the URL subject of a user's files under this process's key: seesubject(long,byte[]).
Field Details
ATOM
The atom of the key below the secrets context: "$userFilesKey".- See Also:
KEY_LENGTH
public static final int KEY_LENGTHThe length of the key in bytes: 32 (256 bits).- See Also:
SUBJECT_LENGTH
public static final int SUBJECT_LENGTHThe length of a subject in bytes before its Base64 encoding: 16 (128 bits), 22 characters encoded.- See Also:
Method Details
get
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_LENGTHbytes. The caller never changes or logs it.
subject
Gets the URL subject of a user's files under this process's key: seesubject(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
Gets the URL subject of a user's files under a key:base64url(HMAC-SHA256(key,"ud:"+uid))truncated toSUBJECT_LENGTHbytes, 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_LENGTHbytes.- Returns:
- The subject, 22 characters of
A-Z a-z 0-9 - _. - Throws:
IllegalArgumentException- If the key is notKEY_LENGTHbytes.