2727namespace web_eid \web_eid_authtoken_validation_php \certificate ;
2828
2929use phpseclib3 \File \X509 ;
30- use UnexpectedValueException ;
3130use BadFunctionCallException ;
3231
3332final class CertificateData
@@ -40,66 +39,56 @@ public function __construct()
4039
4140 /**
4241 * Get commonName from x509 certificate
43- *
44- * @throws UnexpectedValueException
4542 */
46- public static function getSubjectCN (X509 $ certificate ): string
43+ public static function getSubjectCN (X509 $ certificate ): ? string
4744 {
4845 return self ::getField ($ certificate , 'id-at-commonName ' );
4946 }
5047
5148 /**
5249 * Get surname from x509 certificate
53- *
54- * @throws UnexpectedValueException
5550 */
56- public static function getSubjectSurname (X509 $ certificate ): string
51+ public static function getSubjectSurname (X509 $ certificate ): ? string
5752 {
5853 return self ::getField ($ certificate , 'id-at-surname ' );
5954 }
6055
6156 /**
6257 * Get given name from x509 certificate
63- *
64- * @throws UnexpectedValueException
6558 */
66- public static function getSubjectGivenName (X509 $ certificate ): string
59+ public static function getSubjectGivenName (X509 $ certificate ): ? string
6760 {
6861 return self ::getField ($ certificate , 'id-at-givenName ' );
6962 }
7063
7164 /**
7265 * Get serialNumber (ID-code) from x509 certificate
73- *
74- * @throws UnexpectedValueException
7566 */
76- public static function getSubjectIdCode (X509 $ certificate ): string
67+ public static function getSubjectIdCode (X509 $ certificate ): ? string
7768 {
7869 return self ::getField ($ certificate , 'id-at-serialNumber ' );
7970 }
8071
8172 /**
8273 * Get country code from x509 certificate
83- *
84- * @throws UnexpectedValueException
8574 */
86- public static function getSubjectCountryCode (X509 $ certificate ): string
75+ public static function getSubjectCountryCode (X509 $ certificate ): ? string
8776 {
8877 return self ::getField ($ certificate , 'id-at-countryName ' );
8978 }
9079
9180 /**
9281 * Get specified subject field from x509 certificate
9382 *
94- * @throws UnexpectedValueException field identifier not found
95- * @return string
83+ * @return ?string
9684 */
97- private static function getField (X509 $ certificate , string $ fieldId ): string
85+ private static function getField (X509 $ certificate , string $ fieldId ): ? string
9886 {
9987 $ result = $ certificate ->getSubjectDNProp ($ fieldId );
10088 if ($ result ) {
101- return $ result [0 ];
89+ return join (", " , $ result );
90+ } else {
91+ return null ;
10292 }
103- throw new UnexpectedValueException ("fieldId " . $ fieldId . " not found in certificate subject " );
10493 }
10594}
0 commit comments