Skip to content

Commit 7f1f05b

Browse files
committed
Fixed keysalt's key length
1 parent 7fcf964 commit 7f1f05b

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/main/java/com/uid2/admin/salt/SaltRotation.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
public class SaltRotation {
2020
private static final long THIRTY_DAYS_IN_MS = Duration.ofDays(30).toMillis();
2121
private static final double MAX_SALT_PERCENTAGE = 0.8;
22-
private final boolean ENABLE_V4_RAW_UID;
22+
private final boolean enableV4RawUid;
2323

2424
private final IKeyGenerator keyGenerator;
2525

2626
private static final Logger LOGGER = LoggerFactory.getLogger(SaltRotation.class);
2727

2828
public SaltRotation(IKeyGenerator keyGenerator, JsonObject config) {
2929
this.keyGenerator = keyGenerator;
30-
this.ENABLE_V4_RAW_UID = config.getBoolean(AdminConst.ENABLE_V4_RAW_UID, false);
30+
this.enableV4RawUid = config.getBoolean(AdminConst.ENABLE_V4_RAW_UID, false);
3131
}
3232

3333
public Result rotateSalts(
@@ -143,10 +143,9 @@ private long calculateRefreshFrom(SaltEntry bucket, TargetDate targetDate) {
143143

144144
private String calculateCurrentSalt(SaltEntry bucket, boolean shouldRotate) throws Exception {
145145
if (shouldRotate) {
146-
if (ENABLE_V4_RAW_UID) {
146+
if (enableV4RawUid) {
147147
return null;
148-
}
149-
else {
148+
} else {
150149
return this.keyGenerator.generateRandomKeyString(32);
151150
}
152151
}
@@ -165,10 +164,10 @@ private String calculatePreviousSalt(SaltEntry bucket, boolean shouldRotate, Tar
165164

166165
private SaltEntry.KeyMaterial calculateCurrentKeySalt(SaltEntry bucket, boolean shouldRotate, KeyIdGenerator keyIdGenerator) throws Exception {
167166
if (shouldRotate) {
168-
if (ENABLE_V4_RAW_UID) {
167+
if (enableV4RawUid) {
169168
return new SaltEntry.KeyMaterial(
170169
keyIdGenerator.getNextKeyId(),
171-
this.keyGenerator.generateRandomKeyString(32),
170+
this.keyGenerator.generateRandomKeyString(24),
172171
this.keyGenerator.generateRandomKeyString(32)
173172
);
174173
} else {
@@ -253,7 +252,6 @@ private void logSaltAges(String saltCountType, TargetDate targetDate, Collection
253252
}
254253
}
255254

256-
257255
/** Logging to monitor migration of buckets from salts (old format - v2/v3) to encryption keys (new format - v4) **/
258256
private void logBucketFormatCount(TargetDate targetDate, SaltEntry[] postRotationBuckets) {
259257
int totalKeys = 0, totalSalts = 0, totalPreviousKeys = 0, totalPreviousSalts = 0;

0 commit comments

Comments
 (0)