You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@teaclave.apache.org by GitBox <gi...@apache.org> on 2020/06/05 06:17:37 UTC

[GitHub] [incubator-teaclave] qinkunbao opened a new pull request #339: [cli] Update Teaclave Command Line Tool so it can output cmac

qinkunbao opened a new pull request #339:
URL: https://github.com/apache/incubator-teaclave/pull/339


   ## Description
   
   Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
   
   Fixes # (issue)
   
   ## Type of change (select or add applied and delete the others)
   
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [ ] API change with a documentation update
   - [ ] Additional test coverage
   - [ ] Code cleanup or just sync with upstream third-party crates
   
   ## How has this been tested?
   
   ## Checklist
   
   - [ ] Fork the repo and create your branch from `master`.
   - [ ] If you've added code that should be tested, add tests.
   - [ ] If you've changed APIs, update the documentation.
   - [ ] Ensure the tests pass (see CI results).
   - [ ] Make sure your code lints/format.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@teaclave.apache.org
For additional commands, e-mail: notifications-help@teaclave.apache.org


[GitHub] [incubator-teaclave] mssun commented on a change in pull request #339: [cli] Update Teaclave Command Line Tool so it can output cmac

Posted by GitBox <gi...@apache.org>.
mssun commented on a change in pull request #339:
URL: https://github.com/apache/incubator-teaclave/pull/339#discussion_r435713920



##########
File path: cli/src/main.rs
##########
@@ -71,69 +77,88 @@ struct Opt {
     command: Command,
 }
 
-fn decrypt(opt: EncryptDecryptOpt) -> Result<()> {
+fn decrypt(opt: EncryptDecryptOpt) -> Result<CMac> {
     let key = opt.key;
+    let mut cmac: CMac = [0u8; FILE_AUTH_TAG_LENGTH];
     match opt.algorithm.as_str() {
         AesGcm128Key::SCHEMA => {
             let iv = opt.iv.expect("IV is required.");
             let key = AesGcm128Key::new(&key, &iv)?;
             let mut content = fs::read(opt.input_file)?;
-            key.decrypt(&mut content)?;
+            let res = key.decrypt(&mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         AesGcm256Key::SCHEMA => {
             let iv = opt.iv.expect("IV is required.");
             let key = AesGcm256Key::new(&key, &iv)?;
             let mut content = fs::read(opt.input_file)?;
-            key.decrypt(&mut content)?;
+            let res = key.decrypt(&mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         TeaclaveFile128Key::SCHEMA => {
             let key = TeaclaveFile128Key::new(&key)?;
             let mut content = vec![];
-            key.decrypt(opt.input_file, &mut content)?;
+            let res = key.decrypt(opt.input_file, &mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         _ => bail!("Invalid crypto algorithm"),
     }
 
-    Ok(())
+    Ok(cmac)
 }
 
-fn encrypt(opt: EncryptDecryptOpt) -> Result<()> {
+fn encrypt(opt: EncryptDecryptOpt) -> Result<CMac> {
     let key = opt.key;
+    let mut cmac: CMac = [0u8; FILE_AUTH_TAG_LENGTH];
     match opt.algorithm.as_str() {
         AesGcm128Key::SCHEMA => {
             let iv = opt.iv.expect("IV is required.");
             let key = AesGcm128Key::new(&key, &iv)?;
             let mut content = fs::read(opt.input_file)?;
-            key.encrypt(&mut content)?;
+            let res = key.encrypt(&mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         AesGcm256Key::SCHEMA => {
             let iv = opt.iv.expect("IV is required.");
             let key = AesGcm256Key::new(&key, &iv)?;
             let mut content = fs::read(opt.input_file)?;
-            key.encrypt(&mut content)?;
+            let res = key.encrypt(&mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         TeaclaveFile128Key::SCHEMA => {
             let key = TeaclaveFile128Key::new(&key)?;
             let content = fs::read(opt.input_file)?;
-            key.encrypt(opt.output_file, &content)?;
+            let res = key.encrypt(opt.output_file, &content)?;
+            cmac.copy_from_slice(&res);
         }
         _ => bail!("Invalid crypto algorithm"),
     }
 
-    Ok(())
+    Ok(cmac)
 }
 
 fn main() -> Result<()> {
     let args = Opt::from_args();
-    match args.command {
-        Command::Decrypt(opt) => decrypt(opt)?,
-        Command::Encrypt(opt) => encrypt(opt)?,
-    }
+    let flag: bool;
+    let cmac = match args.command {
+        Command::Decrypt(opt) => {
+            flag = opt.cmac_flag;
+            decrypt(opt)?
+        }
+        Command::Encrypt(opt) => {
+            flag = opt.cmac_flag;
+            encrypt(opt)?
+        }
+    };
 
+    if flag {
+        let cmac_string = hex::encode(cmac);
+        println!("{}", cmac_string);
+    }

Review comment:
       You can move the this into `Command::Decrypt` and `Command::Encrypt`.
   
   Since the CLI is not only designed for the decrypt/encrypt two sub-commands, there will be more other sub-commands which may have totally different arguments. Let's keep all logics only inside a sub-command branch.
   
   I think it's ok to have two redundant cmac output code in these two sub command. What do you think?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@teaclave.apache.org
For additional commands, e-mail: notifications-help@teaclave.apache.org


[GitHub] [incubator-teaclave] qinkunbao commented on a change in pull request #339: [cli] Update Teaclave Command Line Tool so it can output cmac

Posted by GitBox <gi...@apache.org>.
qinkunbao commented on a change in pull request #339:
URL: https://github.com/apache/incubator-teaclave/pull/339#discussion_r435969049



##########
File path: cli/src/main.rs
##########
@@ -71,69 +77,88 @@ struct Opt {
     command: Command,
 }
 
-fn decrypt(opt: EncryptDecryptOpt) -> Result<()> {
+fn decrypt(opt: EncryptDecryptOpt) -> Result<CMac> {
     let key = opt.key;
+    let mut cmac: CMac = [0u8; FILE_AUTH_TAG_LENGTH];
     match opt.algorithm.as_str() {
         AesGcm128Key::SCHEMA => {
             let iv = opt.iv.expect("IV is required.");
             let key = AesGcm128Key::new(&key, &iv)?;
             let mut content = fs::read(opt.input_file)?;
-            key.decrypt(&mut content)?;
+            let res = key.decrypt(&mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         AesGcm256Key::SCHEMA => {
             let iv = opt.iv.expect("IV is required.");
             let key = AesGcm256Key::new(&key, &iv)?;
             let mut content = fs::read(opt.input_file)?;
-            key.decrypt(&mut content)?;
+            let res = key.decrypt(&mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         TeaclaveFile128Key::SCHEMA => {
             let key = TeaclaveFile128Key::new(&key)?;
             let mut content = vec![];
-            key.decrypt(opt.input_file, &mut content)?;
+            let res = key.decrypt(opt.input_file, &mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         _ => bail!("Invalid crypto algorithm"),
     }
 
-    Ok(())
+    Ok(cmac)
 }
 
-fn encrypt(opt: EncryptDecryptOpt) -> Result<()> {
+fn encrypt(opt: EncryptDecryptOpt) -> Result<CMac> {
     let key = opt.key;
+    let mut cmac: CMac = [0u8; FILE_AUTH_TAG_LENGTH];
     match opt.algorithm.as_str() {
         AesGcm128Key::SCHEMA => {
             let iv = opt.iv.expect("IV is required.");
             let key = AesGcm128Key::new(&key, &iv)?;
             let mut content = fs::read(opt.input_file)?;
-            key.encrypt(&mut content)?;
+            let res = key.encrypt(&mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         AesGcm256Key::SCHEMA => {
             let iv = opt.iv.expect("IV is required.");
             let key = AesGcm256Key::new(&key, &iv)?;
             let mut content = fs::read(opt.input_file)?;
-            key.encrypt(&mut content)?;
+            let res = key.encrypt(&mut content)?;
+            cmac.copy_from_slice(&res);
             fs::write(opt.output_file, content)?;
         }
         TeaclaveFile128Key::SCHEMA => {
             let key = TeaclaveFile128Key::new(&key)?;
             let content = fs::read(opt.input_file)?;
-            key.encrypt(opt.output_file, &content)?;
+            let res = key.encrypt(opt.output_file, &content)?;
+            cmac.copy_from_slice(&res);
         }
         _ => bail!("Invalid crypto algorithm"),
     }
 
-    Ok(())
+    Ok(cmac)
 }
 
 fn main() -> Result<()> {
     let args = Opt::from_args();
-    match args.command {
-        Command::Decrypt(opt) => decrypt(opt)?,
-        Command::Encrypt(opt) => encrypt(opt)?,
-    }
+    let flag: bool;
+    let cmac = match args.command {
+        Command::Decrypt(opt) => {
+            flag = opt.cmac_flag;
+            decrypt(opt)?
+        }
+        Command::Encrypt(opt) => {
+            flag = opt.cmac_flag;
+            encrypt(opt)?
+        }
+    };
 
+    if flag {
+        let cmac_string = hex::encode(cmac);
+        println!("{}", cmac_string);
+    }

Review comment:
       Thanks for the suggestion. Please see the latest commit.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@teaclave.apache.org
For additional commands, e-mail: notifications-help@teaclave.apache.org


[GitHub] [incubator-teaclave] mssun commented on pull request #339: [cli] Update Teaclave Command Line Tool so it can output cmac

Posted by GitBox <gi...@apache.org>.
mssun commented on pull request #339:
URL: https://github.com/apache/incubator-teaclave/pull/339#issuecomment-639656132


   Merged. You can safely delete this branch. Thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@teaclave.apache.org
For additional commands, e-mail: notifications-help@teaclave.apache.org


[GitHub] [incubator-teaclave] mssun merged pull request #339: [cli] Update Teaclave Command Line Tool so it can output cmac

Posted by GitBox <gi...@apache.org>.
mssun merged pull request #339:
URL: https://github.com/apache/incubator-teaclave/pull/339


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@teaclave.apache.org
For additional commands, e-mail: notifications-help@teaclave.apache.org