Skip to content

Commit 1bc4a2f

Browse files
authored
Update dependencies to latest (#117)
1 parent e9b1c53 commit 1bc4a2f

File tree

9 files changed

+309
-166
lines changed

9 files changed

+309
-166
lines changed

Cargo-1.65.lock

Lines changed: 152 additions & 83 deletions
Large diffs are not rendered by default.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ log = "0.4"
4040
oauth2 = { version = "4.4.1", default-features = false }
4141
rand = "0.8.5"
4242
hmac = "0.12.1"
43-
rsa = "0.7.2"
43+
rsa = "0.9.2"
4444
sha2 = { version = "0.10.6", features = ["oid"] } # Object ID needed for pkcs1v15 padding
45-
p256 = "0.11.1"
46-
p384 = "0.11.2"
45+
p256 = "0.13.2"
46+
p384 = "0.13.0"
4747
dyn-clone = "1.0.10"
4848
serde = "1.0"
4949
serde_derive = "1.0"
5050
serde_json = "1.0"
5151
serde_path_to_error = "0.1"
5252
serde_plain = "1.0"
53-
serde_with = "1.13"
53+
serde_with = "3"
5454
serde-value = "0.7"
55-
url = { version = "2.1", features = ["serde"] }
55+
url = { version = "2.4", features = ["serde"] }
5656
subtle = "2.4"
5757

5858
[dev-dependencies]

src/core/crypto.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ fn ec_public_key(
5454

5555
pub fn verify_rsa_signature(
5656
key: &CoreJsonWebKey,
57-
padding: rsa::PaddingScheme,
57+
padding: impl rsa::traits::SignatureScheme,
5858
msg: &[u8],
5959
signature: &[u8],
6060
) -> Result<(), SignatureVerificationError> {
61-
use rsa::PublicKey;
62-
6361
let (n, e) = rsa_public_key(key).map_err(SignatureVerificationError::InvalidKey)?;
6462
// let's n and e as a big integers to prevent issues with leading zeros
6563
// according to https://datatracker.ietf.org/doc/html/rfc7518#section-6.3.1.1
@@ -86,7 +84,7 @@ pub fn verify_ec_signature(
8684
msg: &[u8],
8785
signature: &[u8],
8886
) -> Result<(), SignatureVerificationError> {
89-
use p256::ecdsa::signature::{Signature, Verifier};
87+
use p256::ecdsa::signature::Verifier;
9088

9189
let (x, y, crv) = ec_public_key(key).map_err(SignatureVerificationError::InvalidKey)?;
9290
let mut pk = vec![0x04];
@@ -99,7 +97,7 @@ pub fn verify_ec_signature(
9997
public_key
10098
.verify(
10199
msg,
102-
&p256::ecdsa::Signature::from_bytes(signature).map_err(|_| {
100+
&p256::ecdsa::Signature::from_slice(signature).map_err(|_| {
103101
SignatureVerificationError::CryptoError("Invalid signature".to_string())
104102
})?,
105103
)
@@ -113,7 +111,7 @@ pub fn verify_ec_signature(
113111
public_key
114112
.verify(
115113
msg,
116-
&p384::ecdsa::Signature::from_bytes(signature).map_err(|_| {
114+
&p384::ecdsa::Signature::from_slice(signature).map_err(|_| {
117115
SignatureVerificationError::CryptoError("Invalid signature".to_string())
118116
})?,
119117
)
@@ -157,7 +155,7 @@ mod tests {
157155
assert! {
158156
verify_rsa_signature(
159157
&key,
160-
rsa::PaddingScheme::new_pkcs1v15_sign::<sha2::Sha256>(),
158+
rsa::Pkcs1v15Sign::new::<sha2::Sha256>(),
161159
&hash,
162160
&signature,
163161
).is_ok()

src/core/jwk.rs

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl JsonWebKey<CoreJwsSigningAlgorithm, CoreJsonWebKeyType, CoreJsonWebKeyUse>
182182
};
183183
crypto::verify_rsa_signature(
184184
self,
185-
rsa::PaddingScheme::new_pkcs1v15_sign::<sha2::Sha256>(),
185+
rsa::Pkcs1v15Sign::new::<sha2::Sha256>(),
186186
message,
187187
signature,
188188
)
@@ -195,7 +195,7 @@ impl JsonWebKey<CoreJwsSigningAlgorithm, CoreJsonWebKeyType, CoreJsonWebKeyUse>
195195
};
196196
crypto::verify_rsa_signature(
197197
self,
198-
rsa::PaddingScheme::new_pkcs1v15_sign::<sha2::Sha384>(),
198+
rsa::Pkcs1v15Sign::new::<sha2::Sha384>(),
199199
message,
200200
signature,
201201
)
@@ -208,7 +208,7 @@ impl JsonWebKey<CoreJwsSigningAlgorithm, CoreJsonWebKeyType, CoreJsonWebKeyUse>
208208
};
209209
crypto::verify_rsa_signature(
210210
self,
211-
rsa::PaddingScheme::new_pkcs1v15_sign::<sha2::Sha512>(),
211+
rsa::Pkcs1v15Sign::new::<sha2::Sha512>(),
212212
message,
213213
signature,
214214
)
@@ -221,7 +221,7 @@ impl JsonWebKey<CoreJwsSigningAlgorithm, CoreJsonWebKeyType, CoreJsonWebKeyUse>
221221
};
222222
crypto::verify_rsa_signature(
223223
self,
224-
rsa::PaddingScheme::new_pss::<sha2::Sha256>(),
224+
rsa::Pss::new::<sha2::Sha256>(),
225225
message,
226226
signature,
227227
)
@@ -234,7 +234,7 @@ impl JsonWebKey<CoreJwsSigningAlgorithm, CoreJsonWebKeyType, CoreJsonWebKeyUse>
234234
};
235235
crypto::verify_rsa_signature(
236236
self,
237-
rsa::PaddingScheme::new_pss::<sha2::Sha384>(),
237+
rsa::Pss::new::<sha2::Sha384>(),
238238
message,
239239
signature,
240240
)
@@ -247,7 +247,7 @@ impl JsonWebKey<CoreJwsSigningAlgorithm, CoreJsonWebKeyType, CoreJsonWebKeyUse>
247247
};
248248
crypto::verify_rsa_signature(
249249
self,
250-
rsa::PaddingScheme::new_pss::<sha2::Sha512>(),
250+
rsa::Pss::new::<sha2::Sha512>(),
251251
message,
252252
signature,
253253
)
@@ -449,82 +449,99 @@ impl
449449
signature_alg: &CoreJwsSigningAlgorithm,
450450
msg: &[u8],
451451
) -> Result<Vec<u8>, SigningError> {
452-
let (padding_alg, hash) = match *signature_alg {
452+
match *signature_alg {
453453
CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha256 => {
454454
let mut hasher = sha2::Sha256::new();
455455
hasher.update(msg);
456456
let hash = hasher.finalize().to_vec();
457-
(
458-
rsa::PaddingScheme::new_pkcs1v15_sign::<sha2::Sha256>(),
459-
hash,
460-
)
457+
458+
self.key_pair
459+
.sign_with_rng(
460+
&mut dyn_clone::clone_box(&self.rng),
461+
rsa::Pkcs1v15Sign::new::<sha2::Sha256>(),
462+
&hash,
463+
)
464+
.map_err(|_| SigningError::CryptoError)
461465
}
462466
CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha384 => {
463467
let mut hasher = sha2::Sha384::new();
464468
hasher.update(msg);
465469
let hash = hasher.finalize().to_vec();
466-
(
467-
rsa::PaddingScheme::new_pkcs1v15_sign::<sha2::Sha384>(),
468-
hash,
469-
)
470+
471+
self.key_pair
472+
.sign_with_rng(
473+
&mut dyn_clone::clone_box(&self.rng),
474+
rsa::Pkcs1v15Sign::new::<sha2::Sha384>(),
475+
&hash,
476+
)
477+
.map_err(|_| SigningError::CryptoError)
470478
}
471479
CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha512 => {
472480
let mut hasher = sha2::Sha512::new();
473481
hasher.update(msg);
474482
let hash = hasher.finalize().to_vec();
475-
(
476-
rsa::PaddingScheme::new_pkcs1v15_sign::<sha2::Sha512>(),
477-
hash,
478-
)
483+
484+
self.key_pair
485+
.sign_with_rng(
486+
&mut dyn_clone::clone_box(&self.rng),
487+
rsa::Pkcs1v15Sign::new::<sha2::Sha512>(),
488+
&hash,
489+
)
490+
.map_err(|_| SigningError::CryptoError)
479491
}
480492
CoreJwsSigningAlgorithm::RsaSsaPssSha256 => {
481493
let mut hasher = sha2::Sha256::new();
482494
hasher.update(msg);
483495
let hash = hasher.finalize().to_vec();
484-
(
485-
rsa::PaddingScheme::new_pss_with_salt::<sha2::Sha256>(hash.len()),
486-
hash,
487-
)
496+
497+
self.key_pair
498+
.sign_with_rng(
499+
&mut dyn_clone::clone_box(&self.rng),
500+
rsa::Pss::new_with_salt::<sha2::Sha256>(hash.len()),
501+
&hash,
502+
)
503+
.map_err(|_| SigningError::CryptoError)
488504
}
489505
CoreJwsSigningAlgorithm::RsaSsaPssSha384 => {
490506
let mut hasher = sha2::Sha384::new();
491507
hasher.update(msg);
492508
let hash = hasher.finalize().to_vec();
493-
(
494-
rsa::PaddingScheme::new_pss_with_salt::<sha2::Sha384>(hash.len()),
495-
hash,
496-
)
509+
510+
self.key_pair
511+
.sign_with_rng(
512+
&mut dyn_clone::clone_box(&self.rng),
513+
rsa::Pss::new_with_salt::<sha2::Sha384>(hash.len()),
514+
&hash,
515+
)
516+
.map_err(|_| SigningError::CryptoError)
497517
}
498518
CoreJwsSigningAlgorithm::RsaSsaPssSha512 => {
499519
let mut hasher = sha2::Sha512::new();
500520
hasher.update(msg);
501521
let hash = hasher.finalize().to_vec();
502-
(
503-
rsa::PaddingScheme::new_pss_with_salt::<sha2::Sha512>(hash.len()),
504-
hash,
505-
)
506-
}
507-
ref other => {
508-
return Err(SigningError::UnsupportedAlg(
509-
serde_plain::to_string(other).unwrap_or_else(|err| {
510-
panic!(
511-
"signature alg {:?} failed to serialize to a string: {}",
512-
other, err
513-
)
514-
}),
515-
))
516-
}
517-
};
518522

519-
let sig = self
520-
.key_pair
521-
.sign_blinded(&mut dyn_clone::clone_box(&self.rng), padding_alg, &hash)
522-
.map_err(|_| SigningError::CryptoError)?;
523-
Ok(sig)
523+
self.key_pair
524+
.sign_with_rng(
525+
&mut dyn_clone::clone_box(&self.rng),
526+
rsa::Pss::new_with_salt::<sha2::Sha512>(hash.len()),
527+
&hash,
528+
)
529+
.map_err(|_| SigningError::CryptoError)
530+
}
531+
ref other => Err(SigningError::UnsupportedAlg(
532+
serde_plain::to_string(other).unwrap_or_else(|err| {
533+
panic!(
534+
"signature alg {:?} failed to serialize to a string: {}",
535+
other, err
536+
)
537+
}),
538+
)),
539+
}
524540
}
525541

526542
fn as_verification_key(&self) -> CoreJsonWebKey {
527-
use rsa::PublicKeyParts;
543+
use rsa::traits::PublicKeyParts;
544+
528545
let public_key = self.key_pair.to_public_key();
529546
CoreJsonWebKey {
530547
kty: CoreJsonWebKeyType::RSA,

src/id_token.rs

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,18 @@ mod tests {
483483
*claims.audiences(),
484484
vec![Audience::new("s6BhdRkqt3".to_string())]
485485
);
486-
assert_eq!(claims.expiration(), Utc.timestamp(1311281970, 0));
487-
assert_eq!(claims.issue_time(), Utc.timestamp(1311280970, 0));
486+
assert_eq!(
487+
claims.expiration(),
488+
Utc.timestamp_opt(1311281970, 0)
489+
.single()
490+
.expect("valid timestamp")
491+
);
492+
assert_eq!(
493+
claims.issue_time(),
494+
Utc.timestamp_opt(1311280970, 0)
495+
.single()
496+
.expect("valid timestamp")
497+
);
488498
assert_eq!(
489499
*claims.subject(),
490500
SubjectIdentifier::new("24400320".to_string())
@@ -524,8 +534,18 @@ mod tests {
524534
*claims.audiences(),
525535
vec![Audience::new("s6BhdRkqt3".to_string())]
526536
);
527-
assert_eq!(claims.expiration(), Utc.timestamp(1311281970, 0));
528-
assert_eq!(claims.issue_time(), Utc.timestamp(1311280970, 0));
537+
assert_eq!(
538+
claims.expiration(),
539+
Utc.timestamp_opt(1311281970, 0)
540+
.single()
541+
.expect("valid timestamp")
542+
);
543+
assert_eq!(
544+
claims.issue_time(),
545+
Utc.timestamp_opt(1311280970, 0)
546+
.single()
547+
.expect("valid timestamp")
548+
);
529549
assert_eq!(
530550
*claims.subject(),
531551
SubjectIdentifier::new("24400320".to_string())
@@ -542,8 +562,12 @@ mod tests {
542562
let new_claims = CoreIdTokenClaims::new(
543563
IssuerUrl::new("https://server.example.com".to_string()).unwrap(),
544564
vec![Audience::new("s6BhdRkqt3".to_string())],
545-
Utc.timestamp(1311281970, 0),
546-
Utc.timestamp(1311280970, 0),
565+
Utc.timestamp_opt(1311281970, 0)
566+
.single()
567+
.expect("valid timestamp"),
568+
Utc.timestamp_opt(1311280970, 0)
569+
.single()
570+
.expect("valid timestamp"),
547571
StandardClaims::new(SubjectIdentifier::new("24400320".to_string())),
548572
EmptyAdditionalClaims {},
549573
);
@@ -666,8 +690,12 @@ mod tests {
666690
let new_claims = CoreIdTokenClaims::new(
667691
IssuerUrl::new("https://server.example.com".to_string()).unwrap(),
668692
vec![Audience::new("s6BhdRkqt3".to_string())],
669-
Utc.timestamp(1311281970, 0),
670-
Utc.timestamp(1311280970, 0),
693+
Utc.timestamp_opt(1311281970, 0)
694+
.single()
695+
.expect("valid timestamp"),
696+
Utc.timestamp_opt(1311280970, 0)
697+
.single()
698+
.expect("valid timestamp"),
671699
StandardClaims {
672700
sub: SubjectIdentifier::new("24400320".to_string()),
673701
name: Some(
@@ -794,11 +822,19 @@ mod tests {
794822
postal_code: Some(AddressPostalCode::new("90210".to_string())),
795823
country: Some(AddressCountry::new("US".to_string())),
796824
}),
797-
updated_at: Some(Utc.timestamp(1311283970, 0)),
825+
updated_at: Some(
826+
Utc.timestamp_opt(1311283970, 0)
827+
.single()
828+
.expect("valid timestamp"),
829+
),
798830
},
799831
EmptyAdditionalClaims {},
800832
)
801-
.set_auth_time(Some(Utc.timestamp(1311282970, 0)))
833+
.set_auth_time(Some(
834+
Utc.timestamp_opt(1311282970, 0)
835+
.single()
836+
.expect("valid timestamp"),
837+
))
802838
.set_nonce(Some(Nonce::new("Zm9vYmFy".to_string())))
803839
.set_auth_context_ref(Some(AuthenticationContextClass::new(
804840
"urn:mace:incommon:iap:silver".to_string(),
@@ -884,7 +920,14 @@ mod tests {
884920
}",
885921
)
886922
.expect("failed to deserialize");
887-
assert_eq!(claims.updated_at(), Some(Utc.timestamp(1640139037, 0)));
923+
assert_eq!(
924+
claims.updated_at(),
925+
Some(
926+
Utc.timestamp_opt(1640139037, 0)
927+
.single()
928+
.expect("valid timestamp")
929+
)
930+
);
888931
}
889932

890933
#[test]

0 commit comments

Comments
 (0)