Skip to content
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

add hash of SALT to healthcheck, for change detection #853

Open
wants to merge 2 commits into
base: rc-v0.5.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public void setVersion(String version) {

String callerIp;

/**
* A SHA-256 hash of the salt, to aid in detecting changes to the salt value.
*
* If salt changes, client needs to know; as all subsequent pseudonyms produced by proxy instance from that point
* will be inconsistent with the prior ones.
*/
String saltSha256Hash;

public boolean passed() {
return getConfiguredSource() != null
&& getNonDefaultSalt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.worklytics.psoxy.gateway.impl;

import co.worklytics.psoxy.ControlHeader;
import co.worklytics.psoxy.HashUtils;
import co.worklytics.psoxy.HealthCheckResult;
import co.worklytics.psoxy.gateway.*;
import co.worklytics.psoxy.gateway.impl.oauth.OAuthRefreshTokenSourceAuthStrategy;
Expand Down Expand Up @@ -33,6 +34,18 @@ public class HealthCheckRequestHandler {

static final String JAVA_SOURCE_CODE_VERSION = "rc-v0.5.1";

/**
* a random UUID used to salt the hash of the salt. Purpose of this is to invalidate any non-purpose built rainbow table solution.
* (Eg, if we just directly hashed the salt, a general rainbow table of hashes could be used to determine the salt value)
*
* That said, if salt is 20+ random characters, there is no *general* rainbow table of that length in existence and one is impossible to
* build, as storing it requires ~10e25 petabytes - which is about 10e20 more storage than humanity actually has. So this additional
* protection isn't so necessary, but whatever.
*
* do NOT change this value. if you do, we won't be able to detect that proxy-side salts of changed.
*/
static final String SALT_FOR_SALT = "f33c366c-ae91-4819-b221-f9794ebb8145";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static final String SALT_FOR_SALT = "f33c366c-ae91-4819-b221-f9794ebb8145";
private static final String SALT_FOR_SALT = "f33c366c-ae91-4819-b221-f9794ebb8145";


@Inject
EnvVarsConfigService envVarsConfigService;
@Inject
Expand All @@ -45,6 +58,8 @@ public class HealthCheckRequestHandler {
ObjectMapper objectMapper;
@Inject
RulesUtils rulesUtils;
@Inject
HashUtils hashUtils;

public Optional<HttpEventResponse> handleIfHealthCheck(HttpEventRequest request) {
if (isHealthCheckRequest(request)) {
Expand Down Expand Up @@ -153,6 +168,12 @@ private HttpEventResponse handle(HttpEventRequest request) {
logInDev("Failed to add rules to health check", e);
}

// if SALT configured, as a hash of it to the health check, to enable detection of changes
// (if salt changes, client needs to know; as all subsequent pseudonyms produced by proxy instance from that point
// will be inconsistent with the prior ones)
config.getConfigPropertyAsOptional(ProxyConfigProperty.PSOXY_SALT)
.ifPresent(salt -> healthCheckResult.saltSha256Hash(hashUtils.hash(salt, SALT_FOR_SALT)));

HttpEventResponse.HttpEventResponseBuilder responseBuilder = HttpEventResponse.builder();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void json() throws JsonProcessingException {
" \"nonDefaultSalt\" : true,\n" +
" \"pseudonymImplementation\" : null,\n" +
" \"pseudonymizeAppIds\" : null,\n" +
" \"saltSha256Hash\" : null,\n" +
" \"sourceAuthGrantType\" : null,\n" +
" \"sourceAuthStrategy\" : null,\n" +
" \"version\" : \"rc-v0.1.15\"\n" +
Expand Down
Loading