Add check for date

This commit is contained in:
chimp1984 2022-08-01 17:07:17 +02:00
parent d8dc0371f9
commit 6aa91a4ee4
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -232,13 +232,15 @@ public class AccountAgeWitnessUtils {
try {
checkArgument(!accountAgeWitnessService.isFilteredWitness(accountAgeWitness), "Invalid account age witness");
String hashAsHex = Hex.encode(accountAgeWitness.getHash());
String message = profileId + hashAsHex + accountAgeWitness.getDate();
long date = accountAgeWitness.getDate();
checkArgument(date > 0, "Date must be > 0");
String message = profileId + hashAsHex + date;
KeyPair signatureKeyPair = keyRing.getSignatureKeyPair();
String signatureBase64 = Sig.sign(signatureKeyPair.getPrivate(), message);
String pubKeyBase64 = Base64.getEncoder().encodeToString(Sig.getPublicKeyBytes(signatureKeyPair.getPublic()));
AccountAgeWitnessDto dto = new AccountAgeWitnessDto(profileId,
hashAsHex,
accountAgeWitness.getDate(),
date,
pubKeyBase64,
signatureBase64);
return JsonUtil.objectToJson(dto);
@ -262,14 +264,17 @@ public class AccountAgeWitnessUtils {
checkArgument(witnessSignDate > 0, "Account is not signed yet");
checkArgument(ageInDays > 60, "Account must have been signed at least 61 days ago");
}
String hashAsHex = Hex.encode(accountAgeWitness.getHash());
String message = profileId + hashAsHex + accountAgeWitness.getDate() + witnessSignDate;
long date = accountAgeWitness.getDate();
checkArgument(date > 0, "AccountAgeWitness date must be > 0");
String message = profileId + hashAsHex + date + witnessSignDate;
KeyPair signatureKeyPair = keyRing.getSignatureKeyPair();
String signatureBase64 = Sig.sign(signatureKeyPair.getPrivate(), message);
String pubKeyBase64 = Base64.getEncoder().encodeToString(Sig.getPublicKeyBytes(signatureKeyPair.getPublic()));
SignedWitnessDto dto = new SignedWitnessDto(profileId,
hashAsHex,
accountAgeWitness.getDate(),
date,
witnessSignDate,
pubKeyBase64,
signatureBase64);