Clarify the documentation. Add the hash config to the example config. Uses duration in the delay field instead of the seconds.
This commit is contained in:
@@ -70,21 +70,31 @@ There is only one exception: [`POST /_matrix/identity/v2/terms`](https://matrix.
|
|||||||
|
|
||||||
## [Hash lookup](https://github.com/matrix-org/matrix-doc/blob/hs/hash-identity/proposals/2134-identity-hash-lookup.md)
|
## [Hash lookup](https://github.com/matrix-org/matrix-doc/blob/hs/hash-identity/proposals/2134-identity-hash-lookup.md)
|
||||||
|
|
||||||
|
Hashes and the pepper updates together according to the `rotationPolicy`.
|
||||||
|
|
||||||
```.yaml
|
```.yaml
|
||||||
hashing:
|
hashing:
|
||||||
enabled: true # enable or disable the hash lookup MSC2140 (default to false)
|
enabled: true # enable or disable the hash lookup MSC2140 (default is false)
|
||||||
pepperLength: 20 # length of the pepper value (default is 20)
|
pepperLength: 20 # length of the pepper value (default is 20)
|
||||||
rotationPolicy: per_requests # or `per_seconds` how often the hashes will be updating
|
rotationPolicy: per_requests # or `per_seconds` how often the hashes will be updating
|
||||||
hashStorageType: sql # or `in_memory` where the hashes will be stored
|
hashStorageType: sql # or `in_memory` where the hashes will be stored
|
||||||
algorithms:
|
algorithms:
|
||||||
- none # the same as v1 bulk lookup
|
- none # the same as v1 bulk lookup
|
||||||
- sha256 # hash the 3PID and pepper.
|
- sha256 # hash the 3PID and pepper.
|
||||||
delay: 10 # how often hashes will be updated if rotation policy = per_seconds (default is 10)
|
delay: 2m # how often hashes will be updated if rotation policy = per_seconds (default is 10s)
|
||||||
requests: 10 # how many lookup requests will be performed before updating hashes if rotation policy = per_requests (default is 10)
|
requests: 10 # how many lookup requests will be performed before updating hashes if rotation policy = per_requests (default is 10)
|
||||||
```
|
```
|
||||||
|
|
||||||
When enabled and client requests the `none` algorithms then hash lookups works as v1 bulk lookup.
|
When enabled and client requests the `none` algorithms then hash lookups works as v1 bulk lookup.
|
||||||
|
|
||||||
|
Delay specified in the format: `2d 4h 12m 34s` - this means 2 days 4 hours 12 minutes and 34 seconds. Zero units may be omitted. For example:
|
||||||
|
|
||||||
|
- 12s - 12 seconds
|
||||||
|
- 3m - 3 minutes
|
||||||
|
- 5m 6s - 5 minutes and 6 seconds
|
||||||
|
- 6h 3s - 6 hours and 3 seconds
|
||||||
|
|
||||||
|
|
||||||
Sha256 algorithm supports only sql, memory and exec 3PID providers.
|
Sha256 algorithm supports only sql, memory and exec 3PID providers.
|
||||||
For sql provider (i.e. for the `synapseSql`):
|
For sql provider (i.e. for the `synapseSql`):
|
||||||
```.yaml
|
```.yaml
|
||||||
|
5
gradle/wrapper/gradle-wrapper.properties
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#Thu Dec 05 22:39:36 MSK 2019
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-all.zip
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
@@ -21,6 +21,8 @@
|
|||||||
#
|
#
|
||||||
matrix:
|
matrix:
|
||||||
domain: ''
|
domain: ''
|
||||||
|
v1: true # deprecated
|
||||||
|
v2: true # MSC2140 API v2
|
||||||
|
|
||||||
|
|
||||||
################
|
################
|
||||||
@@ -109,3 +111,40 @@ threepid:
|
|||||||
|
|
||||||
# Password for the account
|
# Password for the account
|
||||||
password: "ThePassword"
|
password: "ThePassword"
|
||||||
|
|
||||||
|
|
||||||
|
#### MSC2134 (hash lookup)
|
||||||
|
|
||||||
|
hashing:
|
||||||
|
enabled: false # enable or disable the hash lookup MSC2140 (default is false)
|
||||||
|
pepperLength: 20 # length of the pepper value (default is 20)
|
||||||
|
rotationPolicy: per_requests # or `per_seconds` how often the hashes will be updating
|
||||||
|
hashStorageType: sql # or `in_memory` where the hashes will be stored
|
||||||
|
algorithms:
|
||||||
|
- none # the same as v1 bulk lookup
|
||||||
|
- sha256 # hash the 3PID and pepper.
|
||||||
|
delay: 2m # how often hashes will be updated if rotation policy = per_seconds (default is 10s)
|
||||||
|
requests: 10 # how many lookup requests will be performed before updating hashes if rotation policy = per_requests (default is 10)
|
||||||
|
|
||||||
|
### hash lookup for synapseSql provider.
|
||||||
|
# synapseSql:
|
||||||
|
# lookup:
|
||||||
|
# query: 'select user_id as mxid, medium, address from user_threepids' # query for retrive 3PIDs for hashes.
|
||||||
|
|
||||||
|
#### MSC2140 (Terms)
|
||||||
|
policy:
|
||||||
|
policies:
|
||||||
|
term_name: # term name
|
||||||
|
version: 1.0 # version
|
||||||
|
terms:
|
||||||
|
en: # lang
|
||||||
|
name: term name en # localized name
|
||||||
|
url: https://ma1sd.host.tld/term_en.html # localized url
|
||||||
|
fe: # lang
|
||||||
|
name: term name fr # localized name
|
||||||
|
url: https://ma1sd.host.tld/term_fr.html # localized url
|
||||||
|
regexp:
|
||||||
|
- '/_matrix/identity/v2/account.*'
|
||||||
|
- '/_matrix/identity/v2/hash_details'
|
||||||
|
- '/_matrix/identity/v2/lookup'
|
||||||
|
|
||||||
|
@@ -0,0 +1,30 @@
|
|||||||
|
package io.kamax.mxisd.config;
|
||||||
|
|
||||||
|
public class DurationDeserializer {
|
||||||
|
|
||||||
|
public long deserialize(String argument) {
|
||||||
|
long duration = 0L;
|
||||||
|
for (String part : argument.split(" ")) {
|
||||||
|
String unit = part.substring(part.length() - 1);
|
||||||
|
long value = Long.parseLong(part.substring(0, part.length() - 1));
|
||||||
|
switch (unit) {
|
||||||
|
case "s":
|
||||||
|
duration += value;
|
||||||
|
break;
|
||||||
|
case "m":
|
||||||
|
duration += value * 60;
|
||||||
|
break;
|
||||||
|
case "h":
|
||||||
|
duration += value * 60 * 60;
|
||||||
|
break;
|
||||||
|
case "d":
|
||||||
|
duration += value * 60 * 60 * 24;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException(String.format("Unknown duration unit: %s", unit));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
}
|
@@ -14,7 +14,8 @@ public class HashingConfig {
|
|||||||
private int pepperLength = 20;
|
private int pepperLength = 20;
|
||||||
private RotationPolicyEnum rotationPolicy;
|
private RotationPolicyEnum rotationPolicy;
|
||||||
private HashStorageEnum hashStorageType;
|
private HashStorageEnum hashStorageType;
|
||||||
private long delay = 10;
|
private String delay = "10s";
|
||||||
|
private transient long delayInSeconds = 10;
|
||||||
private int requests = 10;
|
private int requests = 10;
|
||||||
private List<Algorithm> algorithms = new ArrayList<>();
|
private List<Algorithm> algorithms = new ArrayList<>();
|
||||||
|
|
||||||
@@ -24,13 +25,15 @@ public class HashingConfig {
|
|||||||
LOGGER.info(" Pepper length: {}", getPepperLength());
|
LOGGER.info(" Pepper length: {}", getPepperLength());
|
||||||
LOGGER.info(" Rotation policy: {}", getRotationPolicy());
|
LOGGER.info(" Rotation policy: {}", getRotationPolicy());
|
||||||
LOGGER.info(" Hash storage type: {}", getHashStorageType());
|
LOGGER.info(" Hash storage type: {}", getHashStorageType());
|
||||||
if (RotationPolicyEnum.per_seconds == rotationPolicy) {
|
if (RotationPolicyEnum.per_seconds == getRotationPolicy()) {
|
||||||
LOGGER.info(" Rotation delay: {}", delay);
|
setDelayInSeconds(new DurationDeserializer().deserialize(getDelay()));
|
||||||
|
LOGGER.info(" Rotation delay: {}", getDelay());
|
||||||
|
LOGGER.info(" Rotation delay in seconds: {}", getDelayInSeconds());
|
||||||
}
|
}
|
||||||
if (RotationPolicyEnum.per_requests == rotationPolicy) {
|
if (RotationPolicyEnum.per_requests == getRotationPolicy()) {
|
||||||
LOGGER.info(" Rotation after requests: {}", requests);
|
LOGGER.info(" Rotation after requests: {}", getRequests());
|
||||||
}
|
}
|
||||||
LOGGER.info(" Algorithms: {}", algorithms);
|
LOGGER.info(" Algorithms: {}", getAlgorithms());
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("Hash configuration disabled, used only `none` pepper.");
|
LOGGER.info("Hash configuration disabled, used only `none` pepper.");
|
||||||
}
|
}
|
||||||
@@ -83,14 +86,22 @@ public class HashingConfig {
|
|||||||
this.hashStorageType = hashStorageType;
|
this.hashStorageType = hashStorageType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDelay() {
|
public String getDelay() {
|
||||||
return delay;
|
return delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDelay(long delay) {
|
public void setDelay(String delay) {
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getDelayInSeconds() {
|
||||||
|
return delayInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDelayInSeconds(long delayInSeconds) {
|
||||||
|
this.delayInSeconds = delayInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
public int getRequests() {
|
public int getRequests() {
|
||||||
return requests;
|
return requests;
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,7 @@ public class HashManager {
|
|||||||
this.rotationStrategy = new RotationPerRequests(config.getRequests());
|
this.rotationStrategy = new RotationPerRequests(config.getRequests());
|
||||||
break;
|
break;
|
||||||
case per_seconds:
|
case per_seconds:
|
||||||
this.rotationStrategy = new TimeBasedRotation(config.getDelay());
|
this.rotationStrategy = new TimeBasedRotation(config.getDelayInSeconds());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown rotation type: " + config.getHashStorageType());
|
throw new IllegalArgumentException("Unknown rotation type: " + config.getHashStorageType());
|
||||||
|
@@ -0,0 +1,20 @@
|
|||||||
|
package io.kamax.mxisd.test.config;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import io.kamax.mxisd.config.DurationDeserializer;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class DurationDeserializerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void durationLoadTest() {
|
||||||
|
DurationDeserializer deserializer = new DurationDeserializer();
|
||||||
|
|
||||||
|
assertEquals(4, deserializer.deserialize("4s"));
|
||||||
|
assertEquals((60 * 60) + 4, deserializer.deserialize("1h 4s"));
|
||||||
|
assertEquals((2 * 60) + 4, deserializer.deserialize("2m 4s"));
|
||||||
|
assertEquals((2 * 60 * 60) + (7 * 60) + 4, deserializer.deserialize("2h 7m 4s"));
|
||||||
|
assertEquals((60 * 60 * 24) + (2 * 60 * 60) + (7 * 60) + 4, deserializer.deserialize("1d 2h 7m 4s"));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user