Package com.mapr.util

Class AwsV4Signer


  • public class AwsV4Signer
    extends java.lang.Object
    Amazon AWS S3 signature V4 signer.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.time.format.DateTimeFormatter AMZ_DATE_FORMAT  
      static java.time.format.DateTimeFormatter SIGNER_DATE_FORMAT  
      static java.time.ZoneId UTC  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String credential​(java.lang.String accessKey, java.time.ZonedDateTime date, java.lang.String region)
      Returns credential string of given access key, date and region.
      static java.lang.String getChunkSignature​(java.lang.String chunkSha256, java.time.ZonedDateTime date, java.lang.String region, java.lang.String secretKey, java.lang.String prevSignature)
      Returns chunk signature calculated using given arguments.
      static java.lang.String postPresignV4​(java.lang.String stringToSign, java.lang.String secretKey, java.time.ZonedDateTime date, java.lang.String region)
      Returns pre-signed post policy string for given stringToSign, secret key, date and region.
      static java.lang.String sha256Hash​(byte[] data, int length)
      Returns SHA-256 hash of byte array.
      static java.lang.String sha256Hash​(java.lang.String string)
      Returns SHA-256 hash of given string.
      static okhttp3.Request signV4S3​(okhttp3.Request request, java.lang.String region, java.lang.String accessKey, java.lang.String secretKey, java.lang.String contentSha256)
      Returns signed request of given request for S3 service.
      static okhttp3.Request signV4Service​(java.lang.String serviceName, okhttp3.Request request, java.lang.String region, java.lang.String accessKey, java.lang.String secretKey, java.lang.String contentSha256)  
      static okhttp3.Request signV4Sts​(okhttp3.Request request, java.lang.String region, java.lang.String accessKey, java.lang.String secretKey, java.lang.String contentSha256)
      Returns signed request of given request for STS service.
      static byte[] sumHmac​(byte[] key, byte[] data)
      Returns HMacSHA256 digest of given key and data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UTC

        public static final java.time.ZoneId UTC
      • AMZ_DATE_FORMAT

        public static final java.time.format.DateTimeFormatter AMZ_DATE_FORMAT
      • SIGNER_DATE_FORMAT

        public static final java.time.format.DateTimeFormatter SIGNER_DATE_FORMAT
    • Method Detail

      • sha256Hash

        public static java.lang.String sha256Hash​(byte[] data,
                                                  int length)
                                           throws java.security.NoSuchAlgorithmException
        Returns SHA-256 hash of byte array.
        Throws:
        java.security.NoSuchAlgorithmException
      • sha256Hash

        public static java.lang.String sha256Hash​(java.lang.String string)
                                           throws java.security.NoSuchAlgorithmException
        Returns SHA-256 hash of given string.
        Throws:
        java.security.NoSuchAlgorithmException
      • getChunkSignature

        public static java.lang.String getChunkSignature​(java.lang.String chunkSha256,
                                                         java.time.ZonedDateTime date,
                                                         java.lang.String region,
                                                         java.lang.String secretKey,
                                                         java.lang.String prevSignature)
                                                  throws java.security.NoSuchAlgorithmException,
                                                         java.security.InvalidKeyException
        Returns chunk signature calculated using given arguments.
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.InvalidKeyException
      • signV4Service

        public static okhttp3.Request signV4Service​(java.lang.String serviceName,
                                                    okhttp3.Request request,
                                                    java.lang.String region,
                                                    java.lang.String accessKey,
                                                    java.lang.String secretKey,
                                                    java.lang.String contentSha256)
                                             throws java.security.NoSuchAlgorithmException,
                                                    java.security.InvalidKeyException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.InvalidKeyException
      • signV4S3

        public static okhttp3.Request signV4S3​(okhttp3.Request request,
                                               java.lang.String region,
                                               java.lang.String accessKey,
                                               java.lang.String secretKey,
                                               java.lang.String contentSha256)
                                        throws java.security.NoSuchAlgorithmException,
                                               java.security.InvalidKeyException
        Returns signed request of given request for S3 service.
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.InvalidKeyException
      • signV4Sts

        public static okhttp3.Request signV4Sts​(okhttp3.Request request,
                                                java.lang.String region,
                                                java.lang.String accessKey,
                                                java.lang.String secretKey,
                                                java.lang.String contentSha256)
                                         throws java.security.NoSuchAlgorithmException,
                                                java.security.InvalidKeyException
        Returns signed request of given request for STS service.
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.InvalidKeyException
      • credential

        public static java.lang.String credential​(java.lang.String accessKey,
                                                  java.time.ZonedDateTime date,
                                                  java.lang.String region)
        Returns credential string of given access key, date and region.
      • postPresignV4

        public static java.lang.String postPresignV4​(java.lang.String stringToSign,
                                                     java.lang.String secretKey,
                                                     java.time.ZonedDateTime date,
                                                     java.lang.String region)
                                              throws java.security.NoSuchAlgorithmException,
                                                     java.security.InvalidKeyException
        Returns pre-signed post policy string for given stringToSign, secret key, date and region.
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.InvalidKeyException
      • sumHmac

        public static byte[] sumHmac​(byte[] key,
                                     byte[] data)
                              throws java.security.NoSuchAlgorithmException,
                                     java.security.InvalidKeyException
        Returns HMacSHA256 digest of given key and data.
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.InvalidKeyException