MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / verify

Method verify

ra-tls/src/cert.rs:231–248  ·  view source on GitHub ↗

Verifies the signature of the CSR. # Arguments `signature` - The signature bytes to verify against the CSR data. # Returns `Ok(())` if the signature is valid and the magic string matches. # Errors Returns an error if: - The public key cannot be parsed - The algorithm is not ECDSA P-256 - The signature is invalid - The magic string does not match "please sign cert:"

(&self, signature: &[u8])

Source from the content-addressed store, hash-verified

229 /// - The signature is invalid
230 /// - The magic string does not match "please sign cert:"
231 fn verify(&self, signature: &[u8]) -> Result<()> {
232 let encoded = self.data_to_sign();
233 let (_rem, pki) =
234 SubjectPublicKeyInfo::from_der(self.pubkey()).context("Failed to parse pubkey")?;
235 let parsed_pki = pki.parsed().context("Failed to parse pki")?;
236 if !matches!(parsed_pki, PublicKey::EC(_)) {
237 bail!("Unsupported algorithm");
238 }
239 let key = UnparsedPublicKey::new(&ECDSA_P256_SHA256_ASN1, &pki.subject_public_key.data);
240 // verify signature
241 key.verify(&encoded, signature)
242 .ok()
243 .context("Invalid signature")?;
244 if self.magic() != "please sign cert:" {
245 bail!("Invalid confirm word");
246 }
247 Ok(())
248 }
249
250 /// Returns the data that should be signed or verified.
251 ///

Callers

nothing calls this directly

Implementers 1

cert.rsra-tls/src/cert.rs

Calls 4

from_derFunction · 0.85
data_to_signMethod · 0.80
pubkeyMethod · 0.80
magicMethod · 0.80

Tested by

no test coverage detected