public static void checkRequestSignature(final byte[] serializedSpeechletRequest,final String baseEncoded64Signature,final String signingCertificateChainUrl){
  if ((baseEncoded64Signature == null) || (signingCertificateChainUrl == null)) {
    throw new SecurityException("Missing signature/certificate for the provided speechlet request");
  }
  try {
    X509Certificate signingCertificate;
    if (CERTIFICATE_CACHE.containsKey(signingCertificateChainUrl)) {
      signingCertificate=CERTIFICATE_CACHE.get(signingCertificateChainUrl);
      signingCertificate.checkValidity();
    }
 else {
      signingCertificate=retrieveAndVerifyCertificateChain(signingCertificateChainUrl);
      CERTIFICATE_CACHE.put(signingCertificateChainUrl,signingCertificate);
    }
    Signature signature=Signature.getInstance(Sdk.SIGNATURE_ALGORITHM);
    signature.initVerify(signingCertificate.getPublicKey());
    signature.update(serializedSpeechletRequest);
    if (!signature.verify(Base64.decodeBase64(baseEncoded64Signature.getBytes(Sdk.CHARACTER_ENCODING)))) {
      throw new SecurityException("Failed to verify the signature/certificate for the provided speechlet request");
    }
  }
 catch (  CertificateException|SignatureException|NoSuchAlgorithmException|InvalidKeyException|IOException ex) {
    throw new SecurityException("Failed to verify the signature/certificate for the provided speechlet request",ex);
  }
}

public static void checkRequestSignature ( final byte [ ] serializedSpeechletRequest , final String baseEncoded64Signature , final String signingCertificateChainUrl ) { if ( ( baseEncoded64Signature == null ) || ( signingCertificateChainUrl == null ) ) { throw new SecurityException ( "Missing signature/certificate for the provided speechlet request" ) ; } try { X509Certificate signingCertificate ; if ( CERTIFICATE_CACHE . containsKey ( signingCertificateChainUrl ) ) { signingCertificate = CERTIFICATE_CACHE . get ( signingCertificateChainUrl ) ; signingCertificate . checkValidity ( ) ; } else { signingCertificate = retrieveAndVerifyCertificateChain ( signingCertificateChainUrl ) ; CERTIFICATE_CACHE . put ( signingCertificateChainUrl , signingCertificate ) ; } Signature signature = Signature . getInstance ( Sdk . SIGNATURE_ALGORITHM ) ; signature . initVerify ( signingCertificate . getPublicKey ( ) ) ; signature . update ( serializedSpeechletRequest ) ; if ( ! signature . verify ( Base64 . decodeBase64 ( baseEncoded64Signature . getBytes ( Sdk . CHARACTER_ENCODING ) ) ) ) { throw new SecurityException ( "Failed to verify the signature/certificate for the provided speechlet request" ) ; } } catch ( CertificateException | SignatureException | NoSuchAlgorithmException | InvalidKeyException | IOException ex ) { throw new SecurityException ( "Failed to verify the signature/certificate for the provided speechlet request" , ex ) ; } }
verifies the certificate authenticity using the configured truststore and the signature of the speechlet request .
