1313//! that clients and nodes can authenticate each other and build a secure
1414//! channel via mTLS (mutual-auth TLS).
1515
16+ use asn1_rs:: FromDer ;
1617use rcgen:: {
1718 date_time_ymd, BasicConstraints , CertificateParams , DnType , IsCa ,
1819 RcgenError , SanType ,
1920} ;
21+ use x509_parser:: x509:: X509Name ;
2022
2123use crate :: { constants, ed25519} ;
2224
@@ -41,10 +43,30 @@ pub struct NodeCert(rcgen::Certificate);
4143
4244// -- impl CaCert -- //
4345
46+ /// Parse CommonName from x509 DistinguishedName DER bytes
47+ fn is_matching_issuer_der ( der : & [ u8 ] , expected : & str ) -> Option < ( ) > {
48+ let ( _rest, name) = X509Name :: from_der ( der) . ok ( ) ?;
49+ let common_name = name. iter_common_name ( ) . next ( ) ?;
50+ let common_name = common_name. as_str ( ) . ok ( ) ?;
51+ if common_name == expected {
52+ Some ( ( ) )
53+ } else {
54+ None
55+ }
56+ }
57+
4458impl CaCert {
59+ const COMMON_NAME : & ' static str = "lexe node-client CA" ;
60+
61+ /// Returns `true` if the given DER bytes are an x509 DistinguishedName with
62+ /// a CommonName matching the standard node-client CA CommonName.
63+ pub fn is_matching_issuer_der ( issuer_der : & [ u8 ] ) -> bool {
64+ is_matching_issuer_der ( issuer_der, Self :: COMMON_NAME ) . is_some ( )
65+ }
66+
4567 pub fn from_key_pair ( key_pair : rcgen:: KeyPair ) -> Result < Self , RcgenError > {
4668 let mut name = constants:: lexe_distinguished_name_prefix ( ) ;
47- name. push ( DnType :: CommonName , "client CA cert" ) ;
69+ name. push ( DnType :: CommonName , Self :: COMMON_NAME ) ;
4870
4971 let mut params = CertificateParams :: default ( ) ;
5072 params. alg = & rcgen:: PKCS_ED25519 ;
@@ -74,7 +96,7 @@ impl CaCert {
7496impl ClientCert {
7597 pub fn from_key_pair ( key_pair : rcgen:: KeyPair ) -> Result < Self , RcgenError > {
7698 let mut name = constants:: lexe_distinguished_name_prefix ( ) ;
77- name. push ( DnType :: CommonName , "client cert" ) ;
99+ name. push ( DnType :: CommonName , "lexe client cert" ) ;
78100
79101 let mut params = CertificateParams :: default ( ) ;
80102 params. alg = & rcgen:: PKCS_ED25519 ;
@@ -116,7 +138,7 @@ impl NodeCert {
116138 dns_names : Vec < String > ,
117139 ) -> Result < Self , RcgenError > {
118140 let mut name = constants:: lexe_distinguished_name_prefix ( ) ;
119- name. push ( DnType :: CommonName , "node cert" ) ;
141+ name. push ( DnType :: CommonName , "lexe node cert" ) ;
120142
121143 let subject_alt_names = dns_names
122144 . into_iter ( )
0 commit comments