Skip to content

Commit 142a37d

Browse files
committed
Remove more unused methods and fields
1 parent 2047c7b commit 142a37d

5 files changed

Lines changed: 7 additions & 181 deletions

File tree

xyz-iinuwa-credential-manager-portal-gtk/src/cbor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ where
139139
}
140140
}
141141

142+
#[allow(dead_code)]
142143
enum MajorType {
143144
PositiveInteger,
144145
NegativeInteger,
Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,14 @@
11
use libwebauthn::proto::ctap2::Ctap2COSEAlgorithmIdentifier;
2-
use ring::{
3-
rand::SystemRandom,
4-
signature::{
5-
EcdsaKeyPair, Ed25519KeyPair, KeyPair, RsaKeyPair, ECDSA_P256_SHA256_ASN1_SIGNING,
6-
},
7-
};
82
use tracing::debug;
93

104
#[derive(Clone, Copy, Debug, PartialEq)]
115
#[repr(i64)]
126
pub(super) enum CoseKeyType {
13-
ES256_P256,
14-
EDDSA_ED25519,
7+
Es256P256,
8+
EddsaEd25519,
159
RS256,
1610
}
1711

18-
impl CoseKeyType {
19-
pub fn algorithm(&self) -> CoseKeyAlgorithmIdentifier {
20-
let params: CoseKeyParameters = (*self).into();
21-
params.algorithm()
22-
}
23-
}
24-
25-
impl CoseKeyType {
26-
pub fn curve(&self) -> Option<CoseEllipticCurveIdentifier> {
27-
let params: CoseKeyParameters = (*self).into();
28-
params.curve()
29-
}
30-
}
31-
32-
pub(super) struct CoseKeyParameters {
33-
alg: CoseKeyAlgorithmIdentifier,
34-
crv: Option<CoseEllipticCurveIdentifier>,
35-
}
36-
37-
impl CoseKeyParameters {
38-
pub fn algorithm(&self) -> CoseKeyAlgorithmIdentifier {
39-
self.alg
40-
}
41-
42-
pub fn curve(&self) -> Option<CoseEllipticCurveIdentifier> {
43-
self.crv
44-
}
45-
}
46-
47-
impl From<CoseKeyType> for CoseKeyParameters {
48-
fn from(value: CoseKeyType) -> Self {
49-
match value {
50-
CoseKeyType::ES256_P256 => CoseKeyParameters {
51-
alg: CoseKeyAlgorithmIdentifier::ES256,
52-
crv: Some(CoseEllipticCurveIdentifier::P256),
53-
},
54-
CoseKeyType::EDDSA_ED25519 => CoseKeyParameters {
55-
alg: CoseKeyAlgorithmIdentifier::EdDSA,
56-
crv: Some(CoseEllipticCurveIdentifier::Ed25519),
57-
},
58-
CoseKeyType::RS256 => CoseKeyParameters {
59-
alg: CoseKeyAlgorithmIdentifier::RS256,
60-
crv: None,
61-
},
62-
}
63-
}
64-
}
65-
6612
#[derive(Clone, Copy, Debug, PartialEq)]
6713
pub enum CoseKeyAlgorithmIdentifier {
6814
ES256,
@@ -133,99 +79,3 @@ pub enum Error {
13379
InvalidKey,
13480
Unsupported,
13581
}
136-
137-
pub(super) fn encode_pkcs8_key(key_type: CoseKeyType, pkcs8_key: &[u8]) -> Result<Vec<u8>, Error> {
138-
match key_type {
139-
CoseKeyType::ES256_P256 => {
140-
let key_pair = EcdsaKeyPair::from_pkcs8(
141-
&ECDSA_P256_SHA256_ASN1_SIGNING,
142-
pkcs8_key,
143-
&SystemRandom::new(),
144-
)
145-
.unwrap();
146-
let public_key = key_pair.public_key().as_ref();
147-
// ring outputs public keys with uncompressed 32-byte x and y coordinates
148-
if public_key.len() != 65 || public_key[0] != 0x04 {
149-
return Err(Error::InvalidKey);
150-
}
151-
let (x, y) = public_key[1..].split_at(32);
152-
let mut cose_key: Vec<u8> = Vec::new();
153-
cose_key.push(0b101_00101); // map with 5 items
154-
cose_key.extend([0b000_00001, 0b000_00010]); // kty (1): EC2 (2)
155-
cose_key.extend([0b000_00011, 0b001_00110]); // alg (3): ECDSA-SHA256 (-7)
156-
cose_key.extend([0b001_00000, 0b000_00001]); // crv (-1): P256 (1)
157-
cose_key.extend([0b001_00001, 0b010_11000, 0b0010_0000]); // x (-2): <32-byte string>
158-
cose_key.extend(x);
159-
cose_key.extend([0b001_00010, 0b010_11000, 0b0010_0000]); // y (-3): <32-byte string>
160-
cose_key.extend(y);
161-
Ok(cose_key)
162-
}
163-
CoseKeyType::EDDSA_ED25519 => {
164-
let key_pair = Ed25519KeyPair::from_pkcs8(pkcs8_key).map_err(|_| Error::InvalidKey)?;
165-
let public_key = key_pair.public_key().as_ref();
166-
let mut cose_key: Vec<u8> = Vec::new();
167-
cose_key.push(0b101_00100); // map with 4 items
168-
cose_key.extend([0b000_00001, 0b000_00001]); // kty (1): OKP (1)
169-
cose_key.extend([0b000_00011, 0b001_00111]); // alg (3): EdDSA (-8)
170-
cose_key.extend([0b001_00000, 0b000_00110]); // crv (-1): ED25519 (6)
171-
cose_key.extend([0b001_00001, 0b010_11000, 0b0010_0000]); // x (-2): <32-byte string>
172-
cose_key.extend(public_key);
173-
Ok(cose_key)
174-
}
175-
CoseKeyType::RS256 => {
176-
let key_pair = RsaKeyPair::from_pkcs8(pkcs8_key).map_err(|_| Error::InvalidKey)?;
177-
let public_key = key_pair.public_key().as_ref();
178-
// TODO: This is ASN.1 with DER encoding. We could parse this to extract
179-
// the modulus and exponent properly, but the key length will
180-
// probably not change, so we're winging it
181-
// https://stackoverflow.com/a/12750816/11931787
182-
let n = &public_key[9..(9 + 256)];
183-
let e = &public_key[public_key.len() - 3..];
184-
debug_assert_eq!(n.len(), key_pair.public().modulus_len());
185-
let mut cose_key: Vec<u8> = Vec::new();
186-
cose_key.push(0b101_00100); // map with 4 items
187-
cose_key.extend([0b000_00001, 0b000_00010]); // kty (1): RSA (3)
188-
cose_key.extend([0b000_00011, 0b001_00110]); // alg (3): RSASSA-PKCS1-v1_5 using SHA-256 (-257)
189-
cose_key.extend([0b001_00000, 0b010_11001, 0b0000_0001, 0b0000_0000]); // n (-1): <256-byte string>
190-
cose_key.extend(n);
191-
cose_key.extend([0b001_00001, 0b010_00011]); // e (-2): <3-byte string>
192-
cose_key.extend(e);
193-
Ok(cose_key)
194-
}
195-
_ => todo!(),
196-
}
197-
}
198-
199-
/// returns CTAP2-serialized public key and algorithm
200-
pub(crate) fn encode_cose_key(public_key: &cosey::PublicKey) -> Result<Vec<u8>, Error> {
201-
match public_key {
202-
cosey::PublicKey::P256Key(p256_key) => {
203-
let mut cose_key: Vec<u8> = Vec::new();
204-
cose_key.push(0b101_00101); // map with 5 items
205-
cose_key.extend([0b000_00001, 0b000_00010]); // kty (1): EC2 (2)
206-
cose_key.extend([0b000_00011, 0b001_00110]); // alg (3): ECDSA-SHA256 (-7)
207-
cose_key.extend([0b001_00000, 0b000_00001]); // crv (-1): P256 (1)
208-
cose_key.extend([0b001_00001, 0b010_11000, 0b0010_0000]); // x (-2): <32-byte string>
209-
cose_key.extend(p256_key.x.clone());
210-
cose_key.extend([0b001_00010, 0b010_11000, 0b0010_0000]); // y (-3): <32-byte string>
211-
cose_key.extend(p256_key.y.clone());
212-
Ok(cose_key)
213-
}
214-
cosey::PublicKey::Ed25519Key(ed25519_key) => {
215-
// TODO: Check this
216-
let mut cose_key: Vec<u8> = Vec::new();
217-
cose_key.push(0b101_00100); // map with 4 items
218-
cose_key.extend([0b000_00001, 0b000_00001]); // kty (1): OKP (1)
219-
cose_key.extend([0b000_00011, 0b001_00111]); // alg (3): EdDSA (-8)
220-
cose_key.extend([0b001_00000, 0b000_00110]); // crv (-1): ED25519 (6)
221-
cose_key.extend([0b001_00001, 0b010_11000, 0b0010_0000]); // x (-2): <32-byte string>
222-
cose_key.extend(ed25519_key.x.clone());
223-
Ok(cose_key)
224-
}
225-
226-
_ => {
227-
debug!("Cannot serialize unknown key type {:?}", public_key);
228-
Err(Error::Unsupported)
229-
}
230-
}
231-
}

xyz-iinuwa-credential-manager-portal-gtk/src/dbus.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ impl CreatePublicKeyCredentialResponse {
503503
let registration_response_json = webauthn::CreatePublicKeyCredentialResponse::new(
504504
attested_credential.credential_id.clone(),
505505
attestation_object,
506-
authenticator_data_blob,
507506
client_data_json,
508507
Some(response.transport.clone()),
509508
unsigned_extensions,

xyz-iinuwa-credential-manager-portal-gtk/src/serde/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
pub(crate) mod b64 {
22
use base64::{self, engine::general_purpose::URL_SAFE_NO_PAD, Engine as _};
33

4-
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
5-
6-
pub(crate) fn serialize<S>(value: &Vec<u8>, serializer: S) -> Result<S::Ok, S::Error>
7-
where
8-
S: Serializer,
9-
{
10-
let s = URL_SAFE_NO_PAD.encode(value);
11-
String::serialize(&s, serializer)
12-
}
4+
use serde::{de, Deserialize, Deserializer};
135

146
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
157
where

xyz-iinuwa-credential-manager-portal-gtk/src/webauthn.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub(crate) struct MakeCredentialOptions {
8080
#[serde(rename = "authenticatorSelection")]
8181
pub authenticator_selection: Option<AuthenticatorSelectionCriteria>,
8282
/// https://www.w3.org/TR/webauthn-3/#enum-attestation-convey
83+
#[allow(dead_code)]
8384
pub attestation: Option<String>,
8485
/// extensions input as a JSON object
8586
pub extensions: Option<MakeCredentialExtensions>,
@@ -273,20 +274,9 @@ pub(crate) struct AuthenticatorSelectionCriteria {
273274
#[derive(Clone, Deserialize)]
274275
/// https://www.w3.org/TR/webauthn-3/#dictdef-publickeycredentialparameters
275276
pub(crate) struct PublicKeyCredentialParameters {
276-
#[serde(rename = "type")]
277-
pub cred_type: String,
278277
pub alg: i64,
279278
}
280279

281-
impl PublicKeyCredentialParameters {
282-
pub(crate) fn new(alg: i64) -> Self {
283-
Self {
284-
cred_type: "public-key".to_string(),
285-
alg,
286-
}
287-
}
288-
}
289-
290280
impl TryFrom<&PublicKeyCredentialParameters> for Ctap2CredentialType {
291281
type Error = Error;
292282

@@ -312,8 +302,8 @@ impl TryFrom<&PublicKeyCredentialParameters> for CoseKeyType {
312302
type Error = String;
313303
fn try_from(value: &PublicKeyCredentialParameters) -> Result<Self, Self::Error> {
314304
match value.alg {
315-
-7 => Ok(CoseKeyType::ES256_P256),
316-
-8 => Ok(CoseKeyType::EDDSA_ED25519),
305+
-7 => Ok(CoseKeyType::Es256P256),
306+
-8 => Ok(CoseKeyType::EddsaEd25519),
317307
-257 => Ok(CoseKeyType::RS256),
318308
_ => Err("Invalid or unsupported algorithm specified".to_owned()),
319309
}
@@ -453,17 +443,12 @@ pub struct AttestationResponse {
453443
///
454444
/// but others may be specified.
455445
transports: Vec<String>,
456-
457-
/// Encodes contextual bindings made by the authenticator. These bindings
458-
/// are controlled by the authenticator itself.
459-
authenticator_data: Vec<u8>,
460446
}
461447

462448
impl CreatePublicKeyCredentialResponse {
463449
pub fn new(
464450
id: Vec<u8>,
465451
attestation_object: Vec<u8>,
466-
authenticator_data: Vec<u8>,
467452
client_data_json: String,
468453
transports: Option<Vec<String>>,
469454
extension_output_json: Option<String>,
@@ -475,7 +460,6 @@ impl CreatePublicKeyCredentialResponse {
475460
client_data_json,
476461
attestation_object,
477462
transports: transports.unwrap_or_default(),
478-
authenticator_data,
479463
},
480464
extensions: extension_output_json,
481465
attachment_modality,

0 commit comments

Comments
 (0)