|
1 | 1 | pub use nitro_attestation_verify::{AttestationDocument, Unverified, NitroError as AttestationError}; |
2 | 2 | use nsm_io::{ErrorCode, Response, Request}; |
| 3 | +pub use nsm_io::Digest; |
3 | 4 | pub use serde_bytes::ByteBuf; |
| 5 | +use std::collections::BTreeSet; |
4 | 6 |
|
5 | 7 | pub struct Nsm(i32); |
6 | 8 |
|
@@ -102,6 +104,52 @@ impl TryFrom<Response> for Pcr { |
102 | 104 | } |
103 | 105 | } |
104 | 106 |
|
| 107 | +#[derive(Debug, PartialEq)] |
| 108 | +pub struct Description { |
| 109 | + /// Breaking API changes are denoted by `major_version` |
| 110 | + pub version_major: u16, |
| 111 | + /// Minor API changes are denoted by `minor_version`. Minor versions should be backwards compatible. |
| 112 | + pub version_minor: u16, |
| 113 | + /// Patch version. These are security and stability updates and do not affect API. |
| 114 | + pub version_patch: u16, |
| 115 | + /// `module_id` is an identifier for a singular NitroSecureModule |
| 116 | + pub module_id: String, |
| 117 | + /// The maximum number of PCRs exposed by the NitroSecureModule. |
| 118 | + pub max_pcrs: u16, |
| 119 | + /// The PCRs that are read-only. |
| 120 | + pub locked_pcrs: BTreeSet<u16>, |
| 121 | + /// The digest of the PCR Bank |
| 122 | + pub digest: Digest, |
| 123 | +} |
| 124 | + |
| 125 | +impl TryFrom<Response> for Description { |
| 126 | + type Error = Error; |
| 127 | + |
| 128 | + fn try_from(response: Response) -> Result<Self, Self::Error> { |
| 129 | + match response { |
| 130 | + Response::DescribeNSM { |
| 131 | + version_major, |
| 132 | + version_minor, |
| 133 | + version_patch, |
| 134 | + module_id, |
| 135 | + max_pcrs, |
| 136 | + locked_pcrs, |
| 137 | + digest, |
| 138 | + } => Ok(Description { |
| 139 | + version_major, |
| 140 | + version_minor, |
| 141 | + version_patch, |
| 142 | + module_id, |
| 143 | + max_pcrs, |
| 144 | + locked_pcrs, |
| 145 | + digest, |
| 146 | + }), |
| 147 | + Response::Error(code) => Err(code.into()), |
| 148 | + _ => Err(Error::InvalidResponse), |
| 149 | + } |
| 150 | + } |
| 151 | +} |
| 152 | + |
105 | 153 | impl Nsm { |
106 | 154 | pub fn new() -> Result<Self, Error> { |
107 | 155 | let fd = nsm_driver::nsm_init(); |
@@ -162,6 +210,10 @@ impl Nsm { |
162 | 210 | _ => Err(Error::InvalidResponse), |
163 | 211 | } |
164 | 212 | } |
| 213 | + |
| 214 | + pub fn describe(&self) -> Result<Description, Error> { |
| 215 | + nsm_driver::nsm_process_request(self.0, Request::DescribeNSM).try_into() |
| 216 | + } |
165 | 217 | } |
166 | 218 |
|
167 | 219 | impl Drop for Nsm { |
|
0 commit comments