public HFCACertificateResponse getHFCACertificates ( User registrar , HFCACertificateRequest req ) throws HFCACertificateException { try { logger . debug ( format ( "certificate url: %s, registrar: %s" , HFCA_CERTIFICATE , registrar . getName ( ) ) ) ; JsonObject result = httpGet ( HFCA_CERTIFICATE , registrar , req . getQueryParameters ( ) ) ; int statusCode = result . getInt ( "statusCode" ) ; Collection < HFCACredential > certs = new ArrayList <> ( ) ; if ( statusCode < 400 ) { JsonArray certificates = result . getJsonArray ( "certs" ) ; if ( certificates != null && ! certificates . isEmpty ( ) ) { for ( int i = 0 ; i < certificates . size ( ) ; i ++ ) { String certPEM = certificates . getJsonObject ( i ) . getString ( "PEM" ) ; certs . add ( new HFCAX509Certificate ( certPEM ) ) ; } } logger . debug ( format ( "certificate url: %s, registrar: %s done." , HFCA_CERTIFICATE , registrar ) ) ; } return new HFCACertificateResponse ( statusCode , certs ) ; } catch ( HTTPException e ) { String msg = format ( "[Code: %d] - Error while getting certificates from url '%s': %s" , e . getStatusCode ( ) , HFCA_CERTIFICATE , e . getMessage ( ) ) ; HFCACertificateException certificateException = new HFCACertificateException ( msg , e ) ; logger . error ( msg ) ; throw certificateException ; } catch ( Exception e ) { String msg = format ( "Error while getting certificates from url '%s': %s" , HFCA_CERTIFICATE , e . getMessage ( ) ) ; HFCACertificateException certificateException = new HFCACertificateException ( msg , e ) ; logger . error ( msg ) ; throw certificateException ; } }
Gets all certificates that the registrar is allowed to see and based on filter parameters that are part of the certificate request .