@@ -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
201199fn 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