Skip to content

Commit 9558722

Browse files
Upgrade rcgen 0.10.0 -> 0.14.5 (#450)
1 parent 01be359 commit 9558722

File tree

3 files changed

+60
-23
lines changed

3 files changed

+60
-23
lines changed

Cargo.lock

Lines changed: 50 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ quinn = { version = "0.9.3", default-features = false, features = ["tls-rustls",
6060
rustls = { version = "0.20.7", default-features = false, features = ["dangerous_configuration"], optional = true }
6161
ring = { version = "0.17.14", optional = true }
6262
webpki = { version = "0.22.4", optional = true }
63-
rcgen = { version = "0.10.0", optional = true }
63+
rcgen = { version = "0.14.5", optional = true }
6464
# End of Quic related dependencies.
6565

6666
# WebRTC related dependencies. WebRTC is an experimental feature flag. The dependencies must be updated.

src/crypto/tls/certificate.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,20 @@ pub fn generate(
5757
// Endpoints MAY generate a new key and certificate
5858
// for every connection attempt, or they MAY reuse the same key
5959
// and certificate for multiple connections.
60-
let certificate_keypair = rcgen::KeyPair::generate(P2P_SIGNATURE_ALGORITHM)?;
60+
let certificate_keypair = rcgen::KeyPair::generate_for(P2P_SIGNATURE_ALGORITHM)?;
6161
let rustls_key = rustls::PrivateKey(certificate_keypair.serialize_der());
6262

6363
let certificate = {
64-
let mut params = rcgen::CertificateParams::new(vec![]);
64+
let mut params = rcgen::CertificateParams::new(vec![])?;
6565
params.distinguished_name = rcgen::DistinguishedName::new();
6666
params.custom_extensions.push(make_libp2p_extension(
6767
identity_keypair,
6868
&certificate_keypair,
6969
)?);
70-
params.alg = P2P_SIGNATURE_ALGORITHM;
71-
params.key_pair = Some(certificate_keypair);
72-
rcgen::Certificate::from_params(params)?
70+
params.self_signed(&certificate_keypair)?
7371
};
7472

75-
let rustls_certificate = rustls::Certificate(certificate.serialize_der()?);
73+
let rustls_certificate = rustls::Certificate(certificate.der().to_vec());
7674

7775
Ok((rustls_certificate, rustls_key))
7876
}
@@ -113,7 +111,7 @@ pub struct P2pExtension {
113111

114112
#[derive(Debug, thiserror::Error)]
115113
#[error(transparent)]
116-
pub struct GenError(#[from] rcgen::RcgenError);
114+
pub struct GenError(#[from] rcgen::Error);
117115

118116
#[derive(Debug, thiserror::Error)]
119117
#[error(transparent)]
@@ -200,15 +198,15 @@ fn parse_unverified<'a>(der_input: &'a [u8]) -> Result<P2pCertificate<'a>, webpk
200198

201199
fn make_libp2p_extension(
202200
identity_keypair: &Keypair,
203-
certificate_keypair: &rcgen::KeyPair,
204-
) -> Result<rcgen::CustomExtension, rcgen::RcgenError> {
201+
certificate_pubkey: &impl rcgen::PublicKeyData,
202+
) -> Result<rcgen::CustomExtension, rcgen::Error> {
205203
// The peer signs the concatenation of the string `libp2p-tls-handshake:`
206-
// and the public key that it used to generate the certificate carrying
204+
// and the public key (in SPKI DER format) that it used to generate the certificate carrying
207205
// the libp2p Public Key Extension, using its private host key.
208206
let signature = {
209207
let mut msg = vec![];
210208
msg.extend(P2P_SIGNING_PREFIX);
211-
msg.extend(certificate_keypair.public_key_der());
209+
msg.extend(certificate_pubkey.subject_public_key_info());
212210

213211
identity_keypair.sign(&msg)
214212
};

0 commit comments

Comments
 (0)