@ Override public SignatureVerifier getSignatureVerifier ( ) throws Exception { try { HttpEntity < Void > request = new HttpEntity <> ( new HttpHeaders ( ) ) ; String content = restTemplate . exchange ( getPublicKeyEndpoint ( ) , HttpMethod . GET , request , String . class ) . getBody ( ) ; if ( StringUtils . isEmpty ( content ) ) { log . info ( "Public key not fetched" ) ; return null ; } InputStream fin = new ByteArrayInputStream ( content . getBytes ( ) ) ; CertificateFactory f = CertificateFactory . getInstance ( "X.509" ) ; X509Certificate certificate = ( X509Certificate ) f . generateCertificate ( fin ) ; PublicKey pk = certificate . getPublicKey ( ) ; return new RsaVerifier ( String . format ( PUBLIC_KEY , new String ( Base64 . getEncoder ( ) . encode ( pk . getEncoded ( ) ) ) ) ) ; } catch ( IllegalStateException ex ) { log . warn ( "could not contact Config to get public key" ) ; return null ; } }
Fetches the public key from the MS Config .