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

Relax validation on prover_did in a credential request #310

Merged
merged 2 commits into from
Jan 25, 2024
Merged
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
41 changes: 32 additions & 9 deletions src/data_types/cred_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::cl::{
};
use crate::error::{Result, ValidationError};
use crate::invalid;
use crate::utils::validation::{Validatable, LEGACY_DID_IDENTIFIER};
use crate::utils::validation::{is_uri_identifier, Validatable, LEGACY_DID_IDENTIFIER};

use super::{cred_def::CredentialDefinitionId, nonce::Nonce};

Expand Down Expand Up @@ -34,8 +34,10 @@ impl Validatable for CredentialRequest {
}
None => {
if self.cred_def_id.is_legacy_cred_def_identifier() {
if let Some(prover_did) = self.prover_did.clone() {
if LEGACY_DID_IDENTIFIER.captures(&prover_did).is_some() {
if let Some(prover_did) = self.prover_did.as_deref() {
swcurran marked this conversation as resolved.
Show resolved Hide resolved
if is_uri_identifier(prover_did)
|| LEGACY_DID_IDENTIFIER.captures(prover_did).is_some()
{
Ok(())
} else {
Err(invalid!("Prover did was supplied, not valid"))
Expand Down Expand Up @@ -118,7 +120,8 @@ mod cred_req_tests {
const LEGACY_CRED_DEF_IDENTIFIER: &str = "DXoTtQJNtXtiwWaZAK3rB1:3:CL:98153:default";

const ENTROPY: Option<&str> = Some("entropy");
const PROVER_DID: Option<&str> = Some(LEGACY_DID_IDENTIFIER);
const PROVER_DID_INDY: Option<&str> = Some(LEGACY_DID_IDENTIFIER);
const PROVER_DID_URI: Option<&str> = Some(NEW_IDENTIFIER);
const LINK_SECRET_ID: &str = "link:secret:id";

fn cred_def() -> Result<(CredentialDefinition, CredentialKeyCorrectnessProof)> {
Expand Down Expand Up @@ -186,14 +189,34 @@ mod cred_req_tests {
}

#[test]
fn create_credential_request_with_valid_input_legacy() -> Result<()> {
fn create_credential_request_with_valid_input_legacy_indy() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, true)?;

let res = create_credential_request(
None,
PROVER_DID,
PROVER_DID_INDY,
&cred_def,
&link_secret,
LINK_SECRET_ID,
&credential_offer,
);

assert!(res.is_ok());

Ok(())
}

#[test]
fn create_credential_request_with_valid_input_legacy_uri() -> Result<()> {
let (cred_def, correctness_proof) = cred_def()?;
let link_secret = link_secret();
let credential_offer = credential_offer(correctness_proof, true)?;

let res = create_credential_request(
None,
PROVER_DID_URI,
&cred_def,
&link_secret,
LINK_SECRET_ID,
Expand All @@ -213,7 +236,7 @@ mod cred_req_tests {

let res = create_credential_request(
None,
PROVER_DID,
PROVER_DID_INDY,
&cred_def,
&link_secret,
LINK_SECRET_ID,
Expand All @@ -233,7 +256,7 @@ mod cred_req_tests {

let res = create_credential_request(
ENTROPY,
PROVER_DID,
PROVER_DID_INDY,
&cred_def,
&link_secret,
LINK_SECRET_ID,
Expand Down Expand Up @@ -316,7 +339,7 @@ mod cred_req_tests {

let res = create_credential_request(
None,
PROVER_DID,
PROVER_DID_INDY,
&cred_def,
&link_secret,
LINK_SECRET_ID,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use regex::Regex;
// Right now everything after the first colon is allowed,
// we might want to restrict this
pub static URI_IDENTIFIER: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^[a-zA-Z0-9\+\-\.]+:.+$").unwrap());
Lazy::new(|| Regex::new(r"^[a-zA-Z][a-zA-Z0-9\+\-\.]*:.+$").unwrap());

/// base58 alpahet as defined in the [base58
/// specification](https://datatracker.ietf.org/doc/html/draft-msporny-base58#section-2) This is
Expand Down
Loading