Skip to content

Commit c0cff2a

Browse files
committed
address Elena's review
1 parent 4ca4ca9 commit c0cff2a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

transports/tls/src/certificate.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const P2P_EXT_OID: [u64; 9] = [1, 3, 6, 1, 4, 1, 53594, 1, 1];
4040
/// in possession of the private host key at the time the certificate was signed.
4141
const P2P_SIGNING_PREFIX: [u8; 21] = *b"libp2p-tls-handshake:";
4242

43+
// Certificates MUST use the NamedCurve encoding for elliptic curve parameters.
44+
// Similarly, hash functions with an output length less than 256 bits MUST NOT be used.
45+
static P2P_SIGNATURE_ALGORITHM: &rcgen::SignatureAlgorithm = &rcgen::PKCS_ECDSA_P256_SHA256;
46+
4347
#[derive(Debug)]
4448
pub(crate) struct AlwaysResolvesCert(Arc<rustls::sign::CertifiedKey>);
4549

@@ -95,7 +99,7 @@ pub fn generate(
9599
// Endpoints MAY generate a new key and certificate
96100
// for every connection attempt, or they MAY reuse the same key
97101
// and certificate for multiple connections.
98-
let certificate_keypair = rcgen::KeyPair::generate()?;
102+
let certificate_keypair = rcgen::KeyPair::generate_for(P2P_SIGNATURE_ALGORITHM)?;
99103
let rustls_key = rustls::pki_types::PrivateKeyDer::from(
100104
rustls::pki_types::PrivatePkcs8KeyDer::from(certificate_keypair.serialize_der()),
101105
);
@@ -110,7 +114,7 @@ pub fn generate(
110114
params.self_signed(&certificate_keypair)?
111115
};
112116

113-
Ok((certificate.der().clone(), rustls_key))
117+
Ok((certificate.into(), rustls_key))
114118
}
115119

116120
/// Attempts to parse the provided bytes as a [`P2pCertificate`].

0 commit comments

Comments
 (0)