@@ -11,7 +11,7 @@ use anyhow::{anyhow, bail, Context, Result};
1111use fs_err as fs;
1212use rcgen:: {
1313 BasicConstraints , Certificate , CertificateParams , CustomExtension , DistinguishedName , DnType ,
14- ExtendedKeyUsagePurpose , IsCa , KeyPair , KeyUsagePurpose , PublicKeyData , SanType ,
14+ ExtendedKeyUsagePurpose , IsCa , KeyPair , KeyUsagePurpose , PublicKeyData ,
1515} ;
1616use ring:: rand:: SystemRandom ;
1717use ring:: signature:: {
@@ -351,7 +351,7 @@ pub struct CertRequest<'a, Key> {
351351
352352impl < Key > CertRequest < ' _ , Key > {
353353 fn into_cert_params ( self ) -> Result < CertificateParams > {
354- let mut params = CertificateParams :: new ( vec ! [ ] ) ?;
354+ let mut params = CertificateParams :: new ( self . alt_names . unwrap_or_default ( ) . to_vec ( ) ) ?;
355355 let mut dn = DistinguishedName :: new ( ) ;
356356 if let Some ( org_name) = self . org_name {
357357 dn. push ( DnType :: OrganizationName , org_name) ;
@@ -369,13 +369,6 @@ impl<Key> CertRequest<'_, Key> {
369369 . extended_key_usages
370370 . push ( ExtendedKeyUsagePurpose :: ClientAuth ) ;
371371 }
372- if let Some ( alt_names) = self . alt_names {
373- for alt_name in alt_names {
374- params
375- . subject_alt_names
376- . push ( SanType :: DnsName ( alt_name. clone ( ) . try_into ( ) ?) ) ;
377- }
378- }
379372 if let Some ( app_id) = self . app_id {
380373 add_ext ( & mut params, PHALA_RATLS_APP_ID , app_id) ;
381374 }
@@ -578,8 +571,9 @@ pub fn generate_ra_cert_with_app_id(
578571mod tests {
579572 use super :: * ;
580573 use dstack_attest:: attestation:: { AttestationQuote , TdxQuote } ;
581- use rcgen:: PKCS_ECDSA_P256_SHA256 ;
574+ use rcgen:: { SanType , PKCS_ECDSA_P256_SHA256 } ;
582575 use scale:: Encode ;
576+ use std:: net:: IpAddr ;
583577
584578 #[ test]
585579 fn test_csr_signing_and_verification ( ) {
@@ -633,6 +627,26 @@ mod tests {
633627 assert ! ( csr. verify( & signature) . is_err( ) ) ;
634628 }
635629
630+ #[ test]
631+ fn test_cert_request_parses_ip_alt_names_as_ip_sans ( ) {
632+ let key_pair = KeyPair :: generate_for ( & PKCS_ECDSA_P256_SHA256 ) . unwrap ( ) ;
633+ let ip = "203.0.113.10" . parse :: < IpAddr > ( ) . unwrap ( ) ;
634+ let alt_names = vec ! [ "203.0.113.10" . to_string( ) , "test.example.com" . to_string( ) ] ;
635+
636+ let params = CertRequest :: builder ( )
637+ . key ( & key_pair)
638+ . subject ( "test.example.com" )
639+ . alt_names ( & alt_names)
640+ . build ( )
641+ . into_cert_params ( )
642+ . unwrap ( ) ;
643+
644+ assert ! ( params. subject_alt_names. contains( & SanType :: IpAddress ( ip) ) ) ;
645+ assert ! ( params. subject_alt_names. iter( ) . any(
646+ |san| matches!( san, SanType :: DnsName ( name) if name. as_str( ) == "test.example.com" )
647+ ) ) ;
648+ }
649+
636650 #[ test]
637651 fn test_event_log_compression ( ) {
638652 // Test with typical event log JSON data
0 commit comments