2626package org .niis .xroad .signer .core .certmanager ;
2727
2828import ee .ria .xroad .common .CodedException ;
29- import ee .ria .xroad .common .DiagnosticsErrorCodes ;
29+ import ee .ria .xroad .common .DiagnosticStatus ;
3030import ee .ria .xroad .common .crypto .identifier .SignAlgorithm ;
3131import ee .ria .xroad .common .util .CertUtils ;
3232import ee .ria .xroad .common .util .CryptoUtils ;
3636import lombok .extern .slf4j .Slf4j ;
3737import org .bouncycastle .cert .ocsp .OCSPException ;
3838import org .bouncycastle .cert .ocsp .OCSPResp ;
39+ import org .niis .xroad .common .core .exception .ErrorCode ;
3940import org .niis .xroad .globalconf .GlobalConfProvider ;
4041import org .niis .xroad .globalconf .cert .CertChain ;
4142import org .niis .xroad .globalconf .impl .ocsp .OcspVerifier ;
@@ -265,7 +266,7 @@ OCSPResp queryCertStatus(X509Certificate subject, OcspVerifierOptions verifierOp
265266 final OffsetDateTime prevUpdate = TimeUtils .offsetDateTimeNow ();
266267 final OffsetDateTime nextUpdate = prevUpdate
267268 .plusSeconds (globalConfProvider .getGlobalConfExtensions ().getOcspFetchInterval ());
268- int errorCode = DiagnosticsErrorCodes . ERROR_CODE_OCSP_RESPONSE_INVALID ;
269+ ErrorCode errorCode = null ;
269270
270271 try {
271272 log .debug ("Fetching response from: {}" , responderURI );
@@ -277,35 +278,38 @@ OCSPResp queryCertStatus(X509Certificate subject, OcspVerifierOptions verifierOp
277278 verifier .verifyValidity (response , subject , issuer );
278279 log .debug ("Verified OCSP response for certificate '{}'" , subject .getSubjectX500Principal ());
279280
280- reportOcspDiagnostics (issuer , responderURI , DiagnosticsErrorCodes . RETURN_SUCCESS , prevUpdate ,
281- nextUpdate );
281+ reportOcspDiagnostics (issuer , responderURI , DiagnosticStatus . OK , prevUpdate ,
282+ nextUpdate , null );
282283
283284 return response ;
284285 }
285286 } catch (OCSPException e ) {
286287 log .error ("Parsing OCSP response from {} failed" , responderURI , e );
287- errorCode = DiagnosticsErrorCodes . ERROR_CODE_OCSP_RESPONSE_INVALID ;
288+ errorCode = ErrorCode . OCSP_RESPONSE_PARSING_FAILURE ;
288289 } catch (IOException e ) {
289290 log .error ("Unable to connect to responder at {}" , responderURI , e );
290- errorCode = DiagnosticsErrorCodes . ERROR_CODE_OCSP_CONNECTION_ERROR ;
291+ errorCode = ErrorCode . OCSP_CONNECTION_ERROR ;
291292 } catch (CodedException e ) {
292293 log .warn ("Received OCSP response that failed verification" , e );
293- errorCode = DiagnosticsErrorCodes . ERROR_CODE_OCSP_RESPONSE_UNVERIFIED ;
294+ errorCode = ErrorCode . OCSP_RESPONSE_VERIFICATION_FAILURE ;
294295 } catch (Exception e ) {
295296 log .error ("Unable to fetch response from responder at {}" , responderURI , e );
296- errorCode = DiagnosticsErrorCodes . ERROR_CODE_OCSP_RESPONSE_INVALID ;
297+ errorCode = ErrorCode . OCSP_FAILED ;
297298 }
298299
299- reportOcspDiagnostics (issuer , responderURI , errorCode , prevUpdate , nextUpdate );
300+ reportOcspDiagnostics (issuer , responderURI , DiagnosticStatus . ERROR , prevUpdate , nextUpdate , errorCode );
300301 }
301302
302303 return null ;
303304 }
304305
305- private void reportOcspDiagnostics (X509Certificate issuer , String responderURI , int statusCode ,
306- OffsetDateTime prevUpdate , OffsetDateTime nextUpdate ) {
306+ private void reportOcspDiagnostics (X509Certificate issuer , String responderURI , DiagnosticStatus statusCode ,
307+ OffsetDateTime prevUpdate , OffsetDateTime nextUpdate , ErrorCode errorCode ) {
307308
308309 OcspResponderStatus responderStatus = new OcspResponderStatus (statusCode , responderURI , prevUpdate , nextUpdate );
310+ if (errorCode != null ) {
311+ responderStatus .setErrorCode (errorCode );
312+ }
309313
310314 String subjectName = issuer .getSubjectDN ().toString ();
311315
@@ -393,13 +397,13 @@ private void initializeDiagnostics() {
393397
394398 final Collection <X509Certificate > caCerts = globalConfProvider .getAllCaCerts ();
395399 serviceStatusMap .keySet ().retainAll (caCerts .stream ()
396- .map (X509Certificate ::getSubjectDN )
400+ .map (X509Certificate ::getSubjectX500Principal )
397401 .map (Principal ::toString )
398402 .collect (Collectors .toSet ()));
399403
400404 for (X509Certificate caCertificate : caCerts ) {
401405 try {
402- final String key = caCertificate .getSubjectDN ().toString ();
406+ final String key = caCertificate .getSubjectX500Principal ().toString ();
403407 final CertificationServiceStatus serviceStatus = serviceStatusMap
404408 .computeIfAbsent (key , CertificationServiceStatus ::new );
405409
@@ -408,7 +412,7 @@ private void initializeDiagnostics() {
408412 responderStatusMap .keySet ().retainAll (addresses );
409413
410414 addresses .forEach (responderURI -> responderStatusMap .computeIfAbsent (responderURI ,
411- uri -> new OcspResponderStatus (DiagnosticsErrorCodes . ERROR_CODE_OCSP_UNINITIALIZED , uri , null ,
415+ uri -> new OcspResponderStatus (DiagnosticStatus . UNINITIALIZED , uri , null ,
412416 TimeUtils .offsetDateTimeNow ().plusSeconds (fetchInterval ))));
413417 } catch (Exception e ) {
414418 log .error ("Error while initializing diagnostics" , e );
0 commit comments