Skip to content

Commit dfc94bb

Browse files
Replace cosey with ctap-types
1 parent b5aa5b5 commit dfc94bb

File tree

8 files changed

+53
-47
lines changed

8 files changed

+53
-47
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "solo/src/ext"]
22
path = solo/src/ext
33
url = https://github.com/AlfioEmanueleFresta/solo.git
4-
[submodule "cosey"]
5-
path = cosey
6-
url = https://github.com/AlfioEmanueleFresta/cosey.git
4+
[submodule "ctap-types"]
5+
path = ctap-types
6+
url = https://github.com/AlfioEmanueleFresta/ctap-types.git

cosey

Lines changed: 0 additions & 1 deletion
This file was deleted.

ctap-types

Submodule ctap-types added at 295dca4

libwebauthn/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ aes = "0.8.2"
5151
hmac = "0.12.1"
5252
cbc = { version = "0.1", features = ["alloc"] }
5353
hkdf = "0.12"
54-
cosey = { path = "../cosey" }
54+
ctap-types = { path = "../ctap-types", features = ["alloc"] }
5555
solo = { path = "../solo", optional = true }
5656
text_io = "0.1"
5757

libwebauthn/src/ops/u2f.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use serde_cbor::to_vec;
66
use sha2::{Digest, Sha256};
77
use tracing::{error, trace};
88
use x509_parser::nom::AsBytes;
9+
use ctap_types::cose;
910

1011
use super::webauthn::MakeCredentialRequest;
1112
use crate::ops::webauthn::{GetAssertionResponse, MakeCredentialResponse};
@@ -40,6 +41,7 @@ impl SignRequest {
4041
}
4142
}
4243
}
44+
4345
pub trait UpgradableResponse<T, R> {
4446
fn try_upgrade(&self, request: &R) -> Result<T, Error>;
4547
}
@@ -68,15 +70,15 @@ impl UpgradableResponse<MakeCredentialResponse, MakeCredentialRequest> for Regis
6870
.expect("Not the identity point")
6971
.as_bytes(),
7072
)
71-
.unwrap();
73+
.unwrap();
7274
let y: heapless::Vec<u8, 32> = heapless::Vec::from_slice(
7375
encoded_point
7476
.y()
7577
.expect("Not identity nor compressed")
7678
.as_bytes(),
7779
)
78-
.unwrap();
79-
let cose_public_key = cosey::PublicKey::P256Key(cosey::P256PublicKey {
80+
.unwrap();
81+
let cose_public_key = cose::PublicKey::P256Key(cose::P256PublicKey {
8082
x: x.into(),
8183
y: y.into(),
8284
});
@@ -159,7 +161,7 @@ impl UpgradableResponse<GetAssertionResponse, SignRequest> for SignResponse {
159161
// See also Authenticator Data section of [WebAuthn].
160162
let mut flags: u8 = 0;
161163
flags |= 0b00000001; // up always set
162-
// bit 1 is unused, ignoring
164+
// bit 1 is unused, ignoring
163165

164166
// Let signCount be a 4-byte unsigned integer initialized with CTAP1/U2F response counter field.
165167
let sign_count = self.counter;
@@ -188,7 +190,7 @@ impl UpgradableResponse<GetAssertionResponse, SignRequest> for SignResponse {
188190
credentials_count: None,
189191
user_selected: None,
190192
}
191-
.into();
193+
.into();
192194

193195
trace!(?upgraded_response);
194196
Ok(upgraded_response)

libwebauthn/src/pin.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rand::{rngs::OsRng, thread_rng, Rng};
1313
use sha2::{Digest, Sha256};
1414
use tracing::{error, info, instrument, warn};
1515
use x509_parser::nom::AsBytes;
16+
use ctap_types::cose;
1617

1718
use crate::proto::{ctap2::Ctap2PinUvAuthProtocol, CtapError};
1819

@@ -108,8 +109,8 @@ pub trait PinUvAuthProtocol: Send + Sync {
108109
/// shared secret.
109110
fn encapsulate(
110111
&self,
111-
peer_public_key: &cosey::PublicKey,
112-
) -> Result<(cosey::PublicKey, Vec<u8>), Error>;
112+
peer_public_key: &cose::PublicKey,
113+
) -> Result<(cose::PublicKey, Vec<u8>), Error>;
113114

114115
// encrypt(key, demPlaintext) → ciphertext
115116
// Encrypts a plaintext to produce a ciphertext, which may be longer than the plaintext.
@@ -130,14 +131,15 @@ trait ECPrivateKeyPinUvAuthProtocol {
130131
fn public_key(&self) -> &P256PublicKey;
131132
fn kdf(&self, bytes: &[u8]) -> Vec<u8>;
132133
}
134+
133135
/// Common functionality between ECDH-based PIN/UV auth protocols (1 & 2)
134136
trait ECDHPinUvAuthProtocol {
135-
fn ecdh(&self, peer_public_key: &cosey::PublicKey) -> Result<Vec<u8>, Error>;
137+
fn ecdh(&self, peer_public_key: &cose::PublicKey) -> Result<Vec<u8>, Error>;
136138
fn encapsulate(
137139
&self,
138-
peer_public_key: &cosey::PublicKey,
139-
) -> Result<(cosey::PublicKey, Vec<u8>), Error>;
140-
fn get_public_key(&self) -> cosey::PublicKey;
140+
peer_public_key: &cose::PublicKey,
141+
) -> Result<(cose::PublicKey, Vec<u8>), Error>;
142+
fn get_public_key(&self) -> cose::PublicKey;
141143
}
142144

143145
pub struct PinUvAuthProtocolOne {
@@ -174,14 +176,14 @@ impl ECPrivateKeyPinUvAuthProtocol for PinUvAuthProtocolOne {
174176
}
175177

176178
impl<P> ECDHPinUvAuthProtocol for P
177-
where
178-
P: ECPrivateKeyPinUvAuthProtocol,
179+
where
180+
P: ECPrivateKeyPinUvAuthProtocol,
179181
{
180182
#[instrument(skip_all)]
181183
fn encapsulate(
182184
&self,
183-
peer_public_key: &cosey::PublicKey,
184-
) -> Result<(cosey::PublicKey, Vec<u8>), Error> {
185+
peer_public_key: &cose::PublicKey,
186+
) -> Result<(cose::PublicKey, Vec<u8>), Error> {
185187
// Let sharedSecret be the result of calling ecdh(peerCoseKey). Return any resulting error.
186188
let shared_secret = self.ecdh(peer_public_key)?;
187189

@@ -190,10 +192,10 @@ where
190192
}
191193

192194
/// ecdh(peerCoseKey) → sharedSecret | error
193-
fn ecdh(&self, peer_public_key: &cosey::PublicKey) -> Result<Vec<u8>, Error> {
195+
fn ecdh(&self, peer_public_key: &cose::PublicKey) -> Result<Vec<u8>, Error> {
194196
// Parse peerCoseKey as specified for getPublicKey, below, and produce a P-256 point, Y.
195197
// If unsuccessful, or if the resulting point is not on the curve, return error.
196-
let cosey::PublicKey::EcdhEsHkdf256Key(peer_public_key) = peer_public_key else {
198+
let cose::PublicKey::EcdhEsHkdf256Key(peer_public_key) = peer_public_key else {
197199
error!(
198200
?peer_public_key,
199201
"Unsupported peerCoseKey format. Only EcdhEsHkdf256Key is supported."
@@ -219,15 +221,15 @@ where
219221
}
220222

221223
/// getPublicKey()
222-
fn get_public_key(&self) -> cosey::PublicKey {
224+
fn get_public_key(&self) -> cose::PublicKey {
223225
let point = EncodedPoint::from(self.public_key());
224226
let x: heapless::Vec<u8, 32> =
225227
heapless::Vec::from_slice(point.x().expect("Not the identity point").as_bytes())
226228
.unwrap();
227229
let y: heapless::Vec<u8, 32> =
228230
heapless::Vec::from_slice(point.y().expect("Not identity nor compressed").as_bytes())
229231
.unwrap();
230-
cosey::PublicKey::P256Key(cosey::P256PublicKey {
232+
cose::PublicKey::P256Key(cose::P256PublicKey {
231233
x: x.into(),
232234
y: y.into(),
233235
})
@@ -284,8 +286,8 @@ impl PinUvAuthProtocol for PinUvAuthProtocolOne {
284286

285287
fn encapsulate(
286288
&self,
287-
peer_public_key: &cosey::PublicKey,
288-
) -> Result<(cosey::PublicKey, Vec<u8>), Error> {
289+
peer_public_key: &cose::PublicKey,
290+
) -> Result<(cose::PublicKey, Vec<u8>), Error> {
289291
<Self as ECDHPinUvAuthProtocol>::encapsulate(self, peer_public_key)
290292
}
291293
}
@@ -335,8 +337,8 @@ impl PinUvAuthProtocol for PinUvAuthProtocolTwo {
335337
#[instrument(skip_all)]
336338
fn encapsulate(
337339
&self,
338-
peer_public_key: &cosey::PublicKey,
339-
) -> Result<(cosey::PublicKey, Vec<u8>), Error> {
340+
peer_public_key: &cose::PublicKey,
341+
) -> Result<(cose::PublicKey, Vec<u8>), Error> {
340342
<Self as ECDHPinUvAuthProtocol>::encapsulate(self, peer_public_key)
341343
}
342344

libwebauthn/src/proto/ctap2/model.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::convert::TryFrom;
33
use std::io::Cursor as IOCursor;
44

55
use byteorder::{BigEndian, ReadBytesExt};
6-
use cosey::PublicKey;
76
use num_enum::{IntoPrimitive, TryFromPrimitive};
87
use serde_bytes::ByteBuf;
98
use serde_derive::{Deserialize, Serialize};
@@ -12,12 +11,14 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
1211
use tracing::debug;
1312
use tracing::warn;
1413

14+
use ctap_types::cose::PublicKey;
15+
1516
use crate::ops::webauthn::GetAssertionRequest;
1617
use crate::ops::webauthn::MakeCredentialRequest;
1718
use crate::proto::ctap1::Ctap1Transport;
1819
use crate::transport::error::CtapError;
1920

20-
// 32 (rpIdHash) + 1 (flags) + 4 (signCount) + 16 (aaguid)
21+
// 32 (rpIdHash) + 1 (flags) + 4 (signCount) + 16 (aaguid
2122
const AUTHENTICATOR_DATA_PUBLIC_KEY_OFFSET: usize = 53;
2223

2324
#[derive(Debug, IntoPrimitive, TryFromPrimitive, Copy, Clone, PartialEq, Serialize_repr)]
@@ -115,6 +116,7 @@ impl From<&Ctap1Transport> for Ctap2Transport {
115116
}
116117
}
117118
}
119+
118120
#[derive(Debug, Clone, Serialize, Deserialize)]
119121
pub struct Ctap2PublicKeyCredentialDescriptor {
120122
pub r#type: Ctap2PublicKeyCredentialType,
@@ -622,8 +624,8 @@ impl Ctap2GetInfoResponse {
622624
/// and either clientPin option ID is present and set to true or uv option ID is present and set to true or both.
623625
pub fn is_uv_protected(&self) -> bool {
624626
self.option_enabled("uv") || // Deprecated no-op UV
625-
self.option_enabled("clientPin") ||
626-
(self.option_enabled("pinUvAuthToken") && self.option_enabled("uv"))
627+
self.option_enabled("clientPin") ||
628+
(self.option_enabled("pinUvAuthToken") && self.option_enabled("uv"))
627629
}
628630

629631
pub fn uv_operation(&self) -> Ctap2UserVerificationOperation {

libwebauthn/src/webauthn.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::time::Duration;
22

33
use async_trait::async_trait;
4-
use cosey::PublicKey;
54
use tracing::{debug, error, info, instrument, trace, warn};
65

6+
use ctap_types::cose::PublicKey;
7+
78
use crate::fido::FidoProtocol;
89
use crate::ops::u2f::{RegisterRequest, SignRequest, UpgradableResponse};
910
use crate::ops::webauthn::{
@@ -19,7 +20,6 @@ use crate::proto::ctap2::{
1920
Ctap2MakeCredentialRequest, Ctap2UserVerifiableRequest, Ctap2UserVerificationOperation,
2021
};
2122
use crate::transport::Channel;
22-
2323
pub use crate::transport::error::{CtapError, Error, TransportError};
2424

2525
#[async_trait]
@@ -74,10 +74,10 @@ async fn select_uv_proto(
7474

7575
#[async_trait]
7676
impl<C> WebAuthn for C
77-
where
78-
C: Channel,
77+
where
78+
C: Channel,
7979
{
80-
#[instrument(skip_all, fields(dev = %self))]
80+
#[instrument(skip_all, fields(dev = % self))]
8181
async fn webauthn_make_credential(
8282
&mut self,
8383
op: &MakeCredentialRequest,
@@ -104,7 +104,7 @@ where
104104
pin_provider,
105105
op.timeout,
106106
)
107-
.await?;
107+
.await?;
108108
self.ctap2_make_credential(&ctap2_request, op.timeout).await
109109
}
110110

@@ -118,7 +118,7 @@ where
118118
.try_upgrade(op)
119119
}
120120

121-
#[instrument(skip_all, fields(dev = %self))]
121+
#[instrument(skip_all, fields(dev = % self))]
122122
async fn webauthn_get_assertion(
123123
&mut self,
124124
op: &GetAssertionRequest,
@@ -145,7 +145,7 @@ where
145145
pin_provider,
146146
op.timeout,
147147
)
148-
.await?;
148+
.await?;
149149

150150
let response = self.ctap2_get_assertion(&ctap2_request, op.timeout).await?;
151151
let count = response.credentials_count.unwrap_or(1);
@@ -221,9 +221,9 @@ async fn user_verification<R, C>(
221221
pin_provider: &Box<dyn PinProvider>,
222222
timeout: Duration,
223223
) -> Result<(), Error>
224-
where
225-
C: Channel,
226-
R: Ctap2UserVerifiableRequest,
224+
where
225+
C: Channel,
226+
R: Ctap2UserVerifiableRequest,
227227
{
228228
let get_info_response = channel.ctap2_get_info().await?;
229229

@@ -325,8 +325,8 @@ async fn obtain_shared_secret<C>(
325325
pin_proto: &Box<dyn PinUvAuthProtocol>,
326326
timeout: Duration,
327327
) -> Result<(PublicKey, Vec<u8>), Error>
328-
where
329-
C: Channel,
328+
where
329+
C: Channel,
330330
{
331331
let client_pin_request = Ctap2ClientPinRequest::new_get_key_agreement(pin_proto.version());
332332
let client_pin_response = channel
@@ -344,8 +344,8 @@ async fn obtain_pin<C>(
344344
pin_provider: &Box<dyn PinProvider>,
345345
timeout: Duration,
346346
) -> Result<Vec<u8>, Error>
347-
where
348-
C: Channel,
347+
where
348+
C: Channel,
349349
{
350350
let attempts_left = channel
351351
.ctap2_client_pin(&Ctap2ClientPinRequest::new_get_pin_retries(), timeout)

0 commit comments

Comments
 (0)