Class TranslatorKeys
TranslationTrial, until the developer configures the engines with keys of their own.The sources carry no key. Each key is a tag in this class (oEeHGzZGKo93EFlcTmEgZSunpdWAi0PQcvANoFkyY1SyPbIDFmw7ZqRQWw== and 2DfIGwNbWLQZPnUaTiUsYlL34N+B3wCHLIZ/lRFmKXiQYWR+) that the build replaces, in the source of the build tree only, with the key hidden against the build: the UTF-8 bytes of the key followed by the first four bytes of their SHA-256 digest, every byte XOR:ed with the SHA-256 digest of the salt, Base64 encoded. The salt is the string <version>.<build>|<yyyy-MM-dd HH:mm>, built here from SystemConfig.VERSION_BUILD and SystemConfig.buildDateTime, and by the build from the version, the build number and the timestamp it gives the same build (ConvertTo-HiddenTranslatorKey in BuildUtil/mindus.psm1, run by BuildUtil/jenkins-build-translator-keys.ps1). The four check bytes tell a key decoded with the right salt from the noise of a wrong one.
This hides the keys from a look at the jar with strings; it is not security. The jar carries the salt (in META-INF/sysconf.properties) and this class, so anyone with the jar has the keys; the quotas of the keys cap the abuse. A jar whose tags were not replaced (a build without the secrets), or whose salt does not match, has no free keys: nothing fails, the translators are simply not configured until the developer configures them.
In development mode (SystemConfig.isDevelopmentMode: the sources, not a build, so the tags are in place) the keys come from the system properties GOOGLE_PROPERTY and MICROSOFT_PROPERTY (-Diizi.google.xlate=<key> -Diizi.microsoft.xlate=<key> in the launch configuration); a translator without one has no free key.
- Author:
- Christopher Mindus
Field Summary
FieldsMethod Summary
Modifier and TypeMethodDescriptionstatic StringDecodes a hidden key.static StringGets the free Google Translate key.static StringGets the free Microsoft Translator key.static StringResolves a free key.static Stringsalt(String versionBuild, LocalDateTime buildDateTime) Builds the salt of a build:<version>.<build>|<yyyy-MM-dd HH:mm>.
Field Details
GOOGLE_PROPERTY
The system property holding the free Google Translate key in development mode:iizi.google.xlate.- See Also:
MICROSOFT_PROPERTY
The system property holding the free Microsoft Translator key in development mode:iizi.microsoft.xlate.- See Also:
Method Details
getGoogleKey
Gets the free Google Translate key.- Returns:
- The key, null for none.
getMicrosoftKey
Gets the free Microsoft Translator key.- Returns:
- The key, null for none.
salt
Builds the salt of a build:<version>.<build>|<yyyy-MM-dd HH:mm>.- Parameters:
versionBuild- The version and build number, e.g. "5.0.0.20700".buildDateTime- The build date and time.- Returns:
- The salt.
resolve
public static String resolve(boolean isDevelopmentMode, String property, String hidden, String salt) Resolves a free key.- Parameters:
isDevelopmentMode- Development mode: the key comes from the system property, never from the hidden form.property- The value of the system property, null or empty for none.hidden- The hidden key of the build, or the tag when the build did not replace it.salt- The salt of this build.- Returns:
- The key, null for none.
decode
Decodes a hidden key.- Parameters:
hidden- The hidden key, or the tag when the build did not replace it.salt- The salt.- Returns:
- The key, or null when the tag is in place, the salt does not match or the value is not a hidden key. Nothing is thrown.