No Description

AWSSignature.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License").
  5. // You may not use this file except in compliance with the License.
  6. // A copy of the License is located at
  7. //
  8. // http://aws.amazon.com/apache2.0
  9. //
  10. // or in the "license" file accompanying this file. This file is distributed
  11. // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. // express or implied. See the License for the specific language governing
  13. // permissions and limitations under the License.
  14. //
  15. #import <Foundation/Foundation.h>
  16. #import "AWSNetworking.h"
  17. FOUNDATION_EXPORT NSString *const AWSSignatureV4Algorithm;
  18. FOUNDATION_EXPORT NSString *const AWSSignatureV4Terminator;
  19. @class AWSEndpoint;
  20. @protocol AWSCredentialsProvider;
  21. @interface AWSSignatureSignerUtility : NSObject
  22. + (NSData *)sha256HMacWithData:(NSData *)data withKey:(NSData *)key;
  23. + (NSString *)hashString:(NSString *)stringToHash;
  24. + (NSData *)hash:(NSData *)dataToHash;
  25. + (NSString *)hexEncode:(NSString *)string;
  26. + (NSString *)HMACSign:(NSData *)data withKey:(NSString *)key usingAlgorithm:(uint32_t)algorithm;
  27. @end
  28. @interface AWSSignatureV4Signer : NSObject <AWSNetworkingRequestInterceptor>
  29. @property (nonatomic, strong, readonly) id<AWSCredentialsProvider> credentialsProvider;
  30. - (instancetype)initWithCredentialsProvider:(id<AWSCredentialsProvider>)credentialsProvider
  31. endpoint:(AWSEndpoint *)endpoint;
  32. + (AWSTask<NSURL *> *)generateQueryStringForSignatureV4WithCredentialProvider:(id<AWSCredentialsProvider>)credentialsProvider
  33. httpMethod:(AWSHTTPMethod)httpMethod
  34. expireDuration:(int32_t)expireDuration
  35. endpoint:(AWSEndpoint *)endpoint
  36. keyPath:(NSString *)keyPath
  37. requestHeaders:(NSDictionary<NSString *, NSString *> *)requestHeaders
  38. requestParameters:(NSDictionary<NSString *, id> *)requestParameters
  39. signBody:(BOOL)signBody;
  40. + (NSString *)getCanonicalizedRequest:(NSString *)method
  41. path:(NSString *)path
  42. query:(NSString *)query
  43. headers:(NSDictionary *)headers
  44. contentSha256:(NSString *)contentSha256;
  45. + (NSData *)getV4DerivedKey:(NSString *)secret
  46. date:(NSString *)dateStamp
  47. region:(NSString *)regionName
  48. service:(NSString *)serviceName;
  49. + (NSString *)getSignedHeadersString:(NSDictionary *)headers;
  50. @end
  51. @interface AWSSignatureV2Signer : NSObject <AWSNetworkingRequestInterceptor>
  52. @property (nonatomic, strong, readonly) id<AWSCredentialsProvider> credentialsProvider;
  53. + (instancetype)signerWithCredentialsProvider:(id<AWSCredentialsProvider>)credentialsProvider
  54. endpoint:(AWSEndpoint *)endpoint;
  55. - (instancetype)initWithCredentialsProvider:(id<AWSCredentialsProvider>)credentialsProvider
  56. endpoint:(AWSEndpoint *)endpoint;
  57. @end
  58. /**
  59. * A subclass of NSInputStream that wraps an input stream and adds
  60. * signature of chunk data.
  61. **/
  62. @interface AWSS3ChunkedEncodingInputStream : NSInputStream <NSStreamDelegate>
  63. @property (atomic, assign) int64_t totalLengthOfChunkSignatureSent;
  64. /**
  65. * Initialize the input stream with date, scope, signing key and signature
  66. * of request headers.
  67. **/
  68. - (instancetype)initWithInputStream:(NSInputStream *)stream
  69. date:(NSDate *)date
  70. scope:(NSString *)scope
  71. kSigning:(NSData *)kSigning
  72. headerSignature:(NSString *)headerSignature;
  73. /**
  74. * Computes new content length after data being chunked encoded.
  75. **/
  76. + (NSUInteger)computeContentLengthForChunkedData:(NSUInteger)dataLength;
  77. @end