@@ -17,6 +17,7 @@ use RESTAPI\Validators\X509Validator;
1717class Certificate extends Model {
1818 public StringField $ descr ;
1919 public UIDField $ refid ;
20+ public StringField $ caref ;
2021 public StringField $ type ;
2122 public Base64Field $ csr ;
2223 public Base64Field $ crt ;
@@ -37,6 +38,13 @@ class Certificate extends Model {
3738 help_text: 'The unique ID assigned to this certificate for internal system use. This value is generated ' .
3839 'by this system and cannot be changed. ' ,
3940 );
41+ $ this ->caref = new StringField (
42+ default: null ,
43+ allow_null: true ,
44+ read_only: true ,
45+ help_text: 'The unique ID of the existing pfSense Certificate Authority that signed this certificate. ' .
46+ 'This value is assigned by this system and cannot be changed. ' ,
47+ );
4048 $ this ->type = new StringField (
4149 default: 'server ' ,
4250 choices: ['server ' , 'user ' ],
@@ -83,6 +91,19 @@ class Certificate extends Model {
8391 return $ prv ;
8492 }
8593
94+ /**
95+ * Extends the default _create() method to ensure the certificate is fully imported before creating it.
96+ */
97+ public function _create (): void {
98+ # Import the cert first using pfSense's cert_import function and relink CAs (if necessary)
99+ $ config_data = $ this ->to_internal ();
100+ cert_import ($ config_data , $ this ->crt ->value , $ this ->prv ->value );
101+ $ this ->caref ->value = $ config_data ['caref ' ] ?? null ;
102+
103+ # Create the Certificate object
104+ parent ::_create ();
105+ }
106+
86107 /**
87108 * Extends the default _update() method to ensure any `csr` value is removed before updating a Certificate.
88109 */
0 commit comments