Explorar el Código

Ensure that the credentials passed to prepare and handle are for the right protocol (CMZ14 or µCMZ)

Ian Goldberg hace 10 meses
padre
commit
3e329df9b6
Se han modificado 2 ficheros con 20 adiciones y 4 borrados
  1. 18 4
      cmzcred_derive/src/lib.rs
  2. 2 0
      src/lib.rs

+ 18 - 4
cmzcred_derive/src/lib.rs

@@ -588,21 +588,28 @@ fn protocol_macro(
         let cred_str = iss_cred.id.to_string();
 
         // Check that fill_creds filled in the private key for this
-        // credential
+        // credential and that it's for the right protocol (CMZ14 or
+        // µCMZ)
         handle_code_post_fill = quote! {
             #handle_code_post_fill
             if #iss_cred_id.privkey.x.len() != #iss_cred_type::num_attrs() {
                 return Err(CMZError::PrivkeyMissing(#cred_str));
             }
+            if #iss_cred_id.privkey.muCMZ != #use_muCMZ {
+                return Err(CMZError::WrongProtocol(#cred_str));
+            }
         };
 
         // Check that the credential passed to prepare has its public
-        // key set
+        // key set and that it's for the right protocol (CMZ14 or µCMZ)
         prepare_code = quote! {
             #prepare_code
             if #iss_cred_id.pubkey.X.len() != #iss_cred_type::num_attrs() {
                 return Err(CMZError::PubkeyMissing(#cred_str));
             }
+            if #iss_cred_id.pubkey.Xr.is_some() != #use_muCMZ {
+                return Err(CMZError::WrongProtocol(#cred_str));
+            }
         };
 
         // Stash the public key in prepare and use it to fill in the
@@ -896,21 +903,28 @@ fn protocol_macro(
         let cred_str = show_cred.id.to_string();
 
         // Check that fill_creds filled in the private key for this
-        // credential
+        // credential and that it's for the right protocol (CMZ14 or
+        // µCMZ)
         handle_code_post_fill = quote! {
             #handle_code_post_fill
             if #show_cred_id.privkey.x.len() != #show_cred_type::num_attrs() {
                 return Err(CMZError::PrivkeyMissing(#cred_str));
             }
+            if #show_cred_id.privkey.muCMZ != #use_muCMZ {
+                return Err(CMZError::WrongProtocol(#cred_str));
+            }
         };
 
         // Check that the credential passed to prepare has its public
-        // key set
+        // key set and that it's for the right protocol (CMZ14 or µCMZ)
         prepare_code = quote! {
             #prepare_code
             if #show_cred_id.pubkey.X.len() != #show_cred_type::num_attrs() {
                 return Err(CMZError::PubkeyMissing(#cred_str));
             }
+            if #show_cred_id.pubkey.Xr.is_some() != #use_muCMZ {
+                return Err(CMZError::WrongProtocol(#cred_str));
+            }
         };
 
         // Rerandomize the MAC and construct a Pedersen commitment to Q

+ 2 - 0
src/lib.rs

@@ -430,6 +430,8 @@ pub enum CMZError {
     PrivkeyMissing(&'static str),
     #[error("public key for credential {0} was not passed to prepare")]
     PubkeyMissing(&'static str),
+    #[error("credential initialized with wrong protocol")]
+    WrongProtocol(&'static str),
     #[error("unknown CMZ proof error")]
     Unknown,
 }