- 
                Notifications
    You must be signed in to change notification settings 
- Fork 63
tcti: Adds support for libtpms backend #535
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -21,6 +21,7 @@ const DEVICE: &str = "device"; | |
| const MSSIM: &str = "mssim"; | ||
| const SWTPM: &str = "swtpm"; | ||
| const TABRMD: &str = "tabrmd"; | ||
| const LIBTPMS: &str = "libtpms"; | ||
|  | ||
| /// TCTI Context created via a TCTI Loader Library. | ||
| /// Wrapper around the TSS2_TCTI_CONTEXT structure. | ||
|  | @@ -139,6 +140,10 @@ pub enum TctiNameConf { | |
| /// | ||
| /// For more information about configuration, see [this page](https://www.mankier.com/3/Tss2_Tcti_Mssim_Init) | ||
| Swtpm(TpmSimulatorConfig), | ||
| /// Connect to a TPM (simulator) available as a library | ||
| /// | ||
| /// This allows for an optional state file | ||
| LibTpms { state: Option<PathBuf> }, | ||
| /// Connect to a TPM through an Access Broker/Resource Manager daemon | ||
| /// | ||
| /// For more information about configuration, see [this page](https://www.mankier.com/3/Tss2_Tcti_Tabrmd_Init) | ||
|  | @@ -174,6 +179,7 @@ impl TryFrom<TctiNameConf> for CString { | |
| TctiNameConf::Mssim(..) => MSSIM, | ||
| TctiNameConf::Swtpm(..) => SWTPM, | ||
| TctiNameConf::Tabrmd(..) => TABRMD, | ||
| TctiNameConf::LibTpms { .. } => LIBTPMS, | ||
| }; | ||
|  | ||
| let tcti_conf = match tcti { | ||
|  | @@ -204,6 +210,9 @@ impl TryFrom<TctiNameConf> for CString { | |
| TctiNameConf::Tabrmd(config) => { | ||
| format!("bus_name={},bus_type={}", config.bus_name, config.bus_type) | ||
| } | ||
| TctiNameConf::LibTpms { state } => { | ||
| state.map(|s| s.display().to_string()).unwrap_or_default() | ||
| } | ||
| }; | ||
|  | ||
| if tcti_conf.is_empty() { | ||
|  | @@ -247,6 +256,15 @@ impl FromStr for TctiNameConf { | |
| )?)); | ||
| } | ||
|  | ||
| let libtpms_pattern = Regex::new(r"^libtpms(:(.*))?$").unwrap(); //should not fail | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too bad we've got parsing all these regexes here, instead of some static variable... but the same happens with others so it's 👍 | ||
| if let Some(captures) = libtpms_pattern.captures(config_str) { | ||
| return Ok(TctiNameConf::LibTpms { | ||
| state: captures | ||
| .get(2) | ||
| .and_then(|s| PathBuf::from_str(s.as_str()).ok()), | ||
| }); | ||
| } | ||
|  | ||
| Err(Error::WrapperError(WrapperErrorKind::InvalidParam)) | ||
| } | ||
| } | ||
|  | @@ -327,6 +345,17 @@ fn validate_from_str_tcti() { | |
|  | ||
| let tcti = TctiNameConf::from_str("tabrmd").unwrap(); | ||
| assert_eq!(tcti, TctiNameConf::Tabrmd(Default::default())); | ||
|  | ||
| let tcti = TctiNameConf::from_str("libtpms:/try/this/path").unwrap(); | ||
| assert_eq!( | ||
| tcti, | ||
| TctiNameConf::LibTpms { | ||
| state: Some(PathBuf::from("/try/this/path")) | ||
| } | ||
| ); | ||
|  | ||
| let tcti = TctiNameConf::from_str("libtpms").unwrap(); | ||
| assert_eq!(tcti, TctiNameConf::LibTpms { state: None }); | ||
| } | ||
|  | ||
| /// Configuration for a Device TCTI context | ||
|  | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.