Check that date in Lox proof matches date in PR
This commit is contained in:
parent
3a6423d2ba
commit
cc670963c5
|
@ -25,6 +25,7 @@ serde = "1.0.195"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_with = {version = "3.5.0", features = ["json"]}
|
serde_with = {version = "3.5.0", features = ["json"]}
|
||||||
sha1 = "0.10"
|
sha1 = "0.10"
|
||||||
|
sha2 = "0.10"
|
||||||
sha3 = "0.10"
|
sha3 = "0.10"
|
||||||
sled = "0.34.7"
|
sled = "0.34.7"
|
||||||
time = "0.3.30"
|
time = "0.3.30"
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
|
|
||||||
use crate::{get_date, CONFIG, COUNTRY_CODES};
|
use crate::{get_date, CONFIG, COUNTRY_CODES};
|
||||||
|
|
||||||
use curve25519_dalek::Scalar;
|
use curve25519_dalek::{RistrettoPoint, Scalar};
|
||||||
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
|
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
|
||||||
use lox_library::{cred::Lox, proto::positive_report as lox_pr, IssuerPubKey};
|
use lox_library::{cred::Lox, proto::positive_report as lox_pr, IssuerPubKey};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha1::{Digest, Sha1};
|
use sha1::{Digest, Sha1};
|
||||||
|
use sha2::Sha512;
|
||||||
use std::option::Option;
|
use std::option::Option;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -16,6 +17,7 @@ pub enum PositiveReportError {
|
||||||
FailedToDeserialize, // couldn't deserialize to SerializablePositiveReport
|
FailedToDeserialize, // couldn't deserialize to SerializablePositiveReport
|
||||||
InvalidBridgeToken,
|
InvalidBridgeToken,
|
||||||
InvalidCountryCode,
|
InvalidCountryCode,
|
||||||
|
InvalidLoxProof,
|
||||||
MissingBridgeToken,
|
MissingBridgeToken,
|
||||||
MissingCountryCode,
|
MissingCountryCode,
|
||||||
}
|
}
|
||||||
|
@ -130,7 +132,9 @@ impl PositiveReport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Verify knowledge of bucket ID
|
// Verify knowledge of bucket ID
|
||||||
let H = self.lox_proof.H;
|
let H = RistrettoPoint::hash_from_bytes::<Sha512>(
|
||||||
|
format!("{}{}", lox_pr::H_GENERATOR_STRING, self.lox_proof.date).as_bytes(),
|
||||||
|
);
|
||||||
let BP = self.lox_proof.BP;
|
let BP = self.lox_proof.BP;
|
||||||
if bucket * H != BP {
|
if bucket * H != BP {
|
||||||
return false;
|
return false;
|
||||||
|
@ -162,9 +166,13 @@ impl SerializablePositiveReport {
|
||||||
if !COUNTRY_CODES.contains(self.country.as_str()) {
|
if !COUNTRY_CODES.contains(self.country.as_str()) {
|
||||||
return Err(PositiveReportError::InvalidCountryCode);
|
return Err(PositiveReportError::InvalidCountryCode);
|
||||||
}
|
}
|
||||||
if self.date > get_date().into() {
|
let date: u32 = get_date().into();
|
||||||
|
if self.date > date {
|
||||||
return Err(PositiveReportError::DateInFuture);
|
return Err(PositiveReportError::DateInFuture);
|
||||||
}
|
}
|
||||||
|
if self.lox_proof.date != date {
|
||||||
|
return Err(PositiveReportError::InvalidLoxProof);
|
||||||
|
}
|
||||||
let bridge_token = if self.bridge_token.is_none() {
|
let bridge_token = if self.bridge_token.is_none() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue