Move certificate parsing into Metadata::extract
This commit is contained in:
@@ -134,7 +134,6 @@ impl IdentityBuilder {
|
|||||||
)],
|
)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (_, cert) = x509_parser::parse_x509_certificate(cert.as_ref()).unwrap();
|
|
||||||
let metadata = Metadata::extract(yubikey, slot, &cert, false).unwrap();
|
let metadata = Metadata::extract(yubikey, slot, &cert, false).unwrap();
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
|
|||||||
+1
-2
@@ -542,9 +542,8 @@ impl Connection {
|
|||||||
) -> io::Result<Result<(), identity::Error>> {
|
) -> io::Result<Result<(), identity::Error>> {
|
||||||
// Check if we can skip requesting a PIN.
|
// Check if we can skip requesting a PIN.
|
||||||
if self.cached_metadata.is_none() {
|
if self.cached_metadata.is_none() {
|
||||||
let (_, cert) = x509_parser::parse_x509_certificate(self.cert.as_ref()).unwrap();
|
|
||||||
self.cached_metadata =
|
self.cached_metadata =
|
||||||
match Metadata::extract(&mut self.yubikey, self.slot, &cert, true) {
|
match Metadata::extract(&mut self.yubikey, self.slot, &self.cert, true) {
|
||||||
None => {
|
None => {
|
||||||
return Ok(Err(identity::Error::Identity {
|
return Ok(Err(identity::Error::Identity {
|
||||||
index: self.identity_index,
|
index: self.identity_index,
|
||||||
|
|||||||
+4
-10
@@ -211,10 +211,7 @@ fn print_single(
|
|||||||
.ok_or(Error::SlotHasNoIdentity(slot))?;
|
.ok_or(Error::SlotHasNoIdentity(slot))?;
|
||||||
|
|
||||||
let stub = key::Stub::new(yubikey.serial(), slot, &recipient);
|
let stub = key::Stub::new(yubikey.serial(), slot, &recipient);
|
||||||
let metadata = x509_parser::parse_x509_certificate(key.certificate().as_ref())
|
let metadata = util::Metadata::extract(&mut yubikey, slot, key.certificate(), true).unwrap();
|
||||||
.ok()
|
|
||||||
.and_then(|(_, cert)| util::Metadata::extract(&mut yubikey, slot, &cert, true))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
printer(stub, recipient, metadata);
|
printer(stub, recipient, metadata);
|
||||||
|
|
||||||
@@ -252,9 +249,7 @@ fn print_multiple(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let stub = key::Stub::new(yubikey.serial(), slot, &recipient);
|
let stub = key::Stub::new(yubikey.serial(), slot, &recipient);
|
||||||
let metadata = match x509_parser::parse_x509_certificate(key.certificate().as_ref())
|
let metadata = match util::Metadata::extract(&mut yubikey, slot, key.certificate(), all)
|
||||||
.ok()
|
|
||||||
.and_then(|(_, cert)| util::Metadata::extract(&mut yubikey, slot, &cert, all))
|
|
||||||
{
|
{
|
||||||
Some(res) => res,
|
Some(res) => res,
|
||||||
None => continue,
|
None => continue,
|
||||||
@@ -479,10 +474,9 @@ fn main() -> Result<(), Error> {
|
|||||||
.interact()?
|
.interact()?
|
||||||
{
|
{
|
||||||
let stub = key::Stub::new(yubikey.serial(), slot, &recipient);
|
let stub = key::Stub::new(yubikey.serial(), slot, &recipient);
|
||||||
let (_, cert) =
|
|
||||||
x509_parser::parse_x509_certificate(key.certificate().as_ref()).unwrap();
|
|
||||||
let metadata =
|
let metadata =
|
||||||
util::Metadata::extract(&mut yubikey, slot, &cert, true).unwrap();
|
util::Metadata::extract(&mut yubikey, slot, key.certificate(), true)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
((stub, recipient, metadata), false)
|
((stub, recipient, metadata), false)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+6
-4
@@ -4,7 +4,7 @@ use std::iter;
|
|||||||
use x509_parser::{certificate::X509Certificate, der_parser::oid::Oid};
|
use x509_parser::{certificate::X509Certificate, der_parser::oid::Oid};
|
||||||
use yubikey::{
|
use yubikey::{
|
||||||
piv::{RetiredSlotId, SlotId},
|
piv::{RetiredSlotId, SlotId},
|
||||||
PinPolicy, Serial, TouchPolicy, YubiKey,
|
Certificate, PinPolicy, Serial, TouchPolicy, YubiKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::fl;
|
use crate::fl;
|
||||||
@@ -112,9 +112,11 @@ impl Metadata {
|
|||||||
pub(crate) fn extract(
|
pub(crate) fn extract(
|
||||||
yubikey: &mut YubiKey,
|
yubikey: &mut YubiKey,
|
||||||
slot: RetiredSlotId,
|
slot: RetiredSlotId,
|
||||||
cert: &X509Certificate,
|
cert: &Certificate,
|
||||||
all: bool,
|
all: bool,
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
|
let (_, cert) = x509_parser::parse_x509_certificate(cert.as_ref()).ok()?;
|
||||||
|
|
||||||
// We store the PIN and touch policies for identities in their certificates
|
// We store the PIN and touch policies for identities in their certificates
|
||||||
// using the same certificate extension as PIV attestations.
|
// using the same certificate extension as PIV attestations.
|
||||||
// https://developers.yubico.com/PIV/Introduction/PIV_attestation.html
|
// https://developers.yubico.com/PIV/Introduction/PIV_attestation.html
|
||||||
@@ -143,10 +145,10 @@ impl Metadata {
|
|||||||
.unwrap_or((None, None))
|
.unwrap_or((None, None))
|
||||||
};
|
};
|
||||||
|
|
||||||
extract_name(cert, all)
|
extract_name(&cert, all)
|
||||||
.map(|(name, ours)| {
|
.map(|(name, ours)| {
|
||||||
if ours {
|
if ours {
|
||||||
let (pin_policy, touch_policy) = policies(cert);
|
let (pin_policy, touch_policy) = policies(&cert);
|
||||||
(name, pin_policy, touch_policy)
|
(name, pin_policy, touch_policy)
|
||||||
} else {
|
} else {
|
||||||
// We can extract the PIN and touch policies via an attestation. This
|
// We can extract the PIN and touch policies via an attestation. This
|
||||||
|
|||||||
Reference in New Issue
Block a user