Skip to content

Commit 34714f7

Browse files
author
Yosuke Matsuda
committed
The AWS SDK for iOS v2 Developer Preview 1.
1 parent 3da2c6a commit 34714f7

File tree

151 files changed

+94677
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+94677
-2
lines changed

.gitignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# OS generated files #
2+
######################
3+
.DS_Store
4+
.DS_Store?
5+
._*
6+
.Spotlight-V100
7+
.Trashes
8+
Icon?
9+
ehthumbs.db
10+
Thumbs.db
11+
src/Documentation/*
12+
src/docs/docset/*
13+
src/docs/docset-installed.txt
14+
src/aws-ios-sdk-*.zip
15+
16+
# Xcode generated files #
17+
######################
18+
xcuserdata
19+
*.xccheckout
20+
21+
# Patched code #
22+
######################
23+
*.bak
24+
25+
# Built assets #
26+
######################
27+
build
28+
AWS*.framework
29+
30+
# Stuff that can't be committed #
31+
######################
32+
credentials.json
33+
Pods
34+
Podfile.lock

AWSCore/AWSCore.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2010-2014 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+
16+
#import <Foundation/Foundation.h>
17+
18+
#import "AmazonCore.h"
19+
20+
#import "AWSService.h"
21+
#import "AWSNetworking.h"
22+
#import "AWSCredentialsProvider.h"
23+
#import "AWSValidation.h"
24+
#import "AWSURLRequestSerialization.h"
25+
#import "AWSURLResponseSerialization.h"
26+
27+
#import "STS.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2010-2014 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+
16+
#import <Foundation/Foundation.h>
17+
18+
@class BFTask;
19+
20+
@protocol AWSCredentialsProvider <NSObject>
21+
22+
@optional
23+
@property (nonatomic, readonly) NSString *accessKey;
24+
@property (nonatomic, readonly) NSString *secretKey;
25+
@property (nonatomic, readonly) NSString *sessionKey;
26+
27+
- (BFTask *)refresh;
28+
29+
@end
30+
31+
@interface AWSStaticCredentialsProvider : NSObject <AWSCredentialsProvider>
32+
33+
+ (instancetype)credentialsWithAccessKey:(NSString *)accessKey
34+
secretKey:(NSString *)secretKey;
35+
+ (instancetype)credentialsWithCredentialsFilename:(NSString *)credentialsFilename;
36+
37+
- (instancetype)initWithAccessKey:(NSString *)accessKey
38+
secretKey:(NSString *)secretKey;
39+
40+
@end
41+
42+
@interface AWSAnonymousCreentialsProvider : NSObject <AWSCredentialsProvider>
43+
44+
@end
45+
46+
@interface AWSWebIdentityCredentialsProvider : NSObject <AWSCredentialsProvider>
47+
48+
@property (nonatomic, strong) NSString *webIdentityToken;
49+
@property (nonatomic, strong) NSString *roleArn;
50+
@property (nonatomic, strong) NSString *provider;
51+
52+
@property (nonatomic, strong, readonly) NSError *error;
53+
54+
+ (instancetype)credentialsWithProvider:(NSString *)provider
55+
webIdentityToken:(NSString *)webIdentityToken
56+
roleArn:(NSString *)roleArn;
57+
58+
- (instancetype)initWithProvider:(NSString *)provider
59+
webIdentityToken:(NSString *)webIdentityToken
60+
roleArn:(NSString *)roleArn;
61+
62+
- (BFTask *)refresh;
63+
64+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright 2010-2014 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+
16+
#import "AWSCredentialsProvider.h"
17+
#import "STS.h"
18+
#import "UICKeyChainStore.h"
19+
20+
@interface AWSStaticCredentialsProvider()
21+
22+
@property (nonatomic, strong) NSString *accessKey;
23+
@property (nonatomic, strong) NSString *secretKey;
24+
25+
@end
26+
27+
@implementation AWSStaticCredentialsProvider
28+
29+
+ (instancetype)credentialsWithAccessKey:(NSString *)accessKey secretKey:(NSString *)secretKey {
30+
AWSStaticCredentialsProvider *credentials = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:accessKey
31+
secretKey:secretKey];
32+
return credentials;
33+
}
34+
35+
+ (instancetype)credentialsWithCredentialsFilename:(NSString *)credentialsFilename {
36+
NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:credentialsFilename ofType:@"json"];
37+
NSDictionary *credentialsJson = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:filePath]
38+
options:NSJSONReadingMutableContainers
39+
error:nil];
40+
AWSStaticCredentialsProvider *credentials = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:[credentialsJson objectForKey:@"accessKey"]
41+
secretKey:[credentialsJson objectForKey:@"secretKey"]];
42+
return credentials;
43+
}
44+
45+
- (instancetype)initWithAccessKey:(NSString *)accessKey
46+
secretKey:(NSString *)secretKey {
47+
if (self = [super init]) {
48+
_accessKey = accessKey;
49+
_secretKey = secretKey;
50+
}
51+
return self;
52+
}
53+
54+
@end
55+
56+
@interface AWSAnonymousCreentialsProvider()
57+
58+
@end
59+
60+
@implementation AWSAnonymousCreentialsProvider
61+
62+
@end
63+
64+
@interface AWSWebIdentityCredentialsProvider()
65+
66+
@property (nonatomic, strong) NSString *accessKey;
67+
@property (nonatomic, strong) NSString *secretKey;
68+
@property (nonatomic, strong) NSString *sessionKey;
69+
@property (nonatomic, strong) NSError *error;
70+
@property (nonatomic, strong) AWSSTS *sts;
71+
72+
@end
73+
74+
@implementation AWSWebIdentityCredentialsProvider
75+
76+
+ (instancetype)credentialsWithProvider:(NSString *)provider
77+
webIdentityToken:(NSString *)webIdentityToken
78+
roleArn:(NSString *)roleArn {
79+
AWSWebIdentityCredentialsProvider *credentials = [[AWSWebIdentityCredentialsProvider alloc] initWithProvider:provider
80+
webIdentityToken:webIdentityToken
81+
roleArn:roleArn];
82+
return credentials;
83+
}
84+
85+
- (instancetype)initWithProvider:(NSString *)provider
86+
webIdentityToken:(NSString *)webIdentityToken
87+
roleArn:(NSString *)roleArn {
88+
if (self = [super init]) {
89+
_provider = provider;
90+
_webIdentityToken = webIdentityToken;
91+
_roleArn = roleArn;
92+
93+
AWSAnonymousCreentialsProvider *credentialsProvider = [AWSAnonymousCreentialsProvider new];
94+
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1
95+
credentialsProvider:credentialsProvider];
96+
97+
_sts = [[AWSSTS new] initWithConfiguration:configuration];
98+
}
99+
100+
return self;
101+
}
102+
103+
- (BFTask *)refresh {
104+
// reset the values for the credenails
105+
self.accessKey = nil;
106+
self.secretKey = nil;
107+
self.sessionKey = nil;
108+
109+
// request new credentials
110+
AWSSTSAssumeRoleWithWebIdentityRequest *wifRequest = [AWSSTSAssumeRoleWithWebIdentityRequest new];
111+
wifRequest.roleArn = self.roleArn;
112+
wifRequest.webIdentityToken = self.webIdentityToken;
113+
wifRequest.roleSessionName = @"iOS-Provider";
114+
return [[self.sts assumeRoleWithWebIdentity:wifRequest] continueWithBlock:^id(BFTask *task) {
115+
self.error = task.error;
116+
if (task.error) {
117+
return nil;
118+
}
119+
120+
AWSSTSAssumeRoleWithWebIdentityResponse *wifResponse = task.result;
121+
self.accessKey = wifResponse.credentials.accessKeyId;
122+
self.secretKey = wifResponse.credentials.secretAccessKey;
123+
self.sessionKey = wifResponse.credentials.sessionToken;
124+
125+
return nil;
126+
}];
127+
}
128+
129+
@end

AWSCore/Authentication/AWSSignature.h

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2010-2014 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+
16+
#import <Foundation/Foundation.h>
17+
#import "AZNetworking.h"
18+
19+
@class AWSEndpoint;
20+
21+
@protocol AWSCredentialsProvider;
22+
23+
@interface AWSSignatureSignerUtility : NSObject
24+
25+
+ (NSData *)sha256HMacWithData:(NSData *)data withKey:(NSData *)key;
26+
+ (NSString *)hashString:(NSString *)stringToHash;
27+
+ (NSData *)hash:(NSData *)dataToHash;
28+
+ (NSString *)hexEncode:(NSString *)string;
29+
30+
@end
31+
32+
@interface AWSSignatureV4Signer : NSObject <AZNetworkingRequestInterceptor>
33+
34+
@property (nonatomic, strong, readonly) id<AWSCredentialsProvider> credentialsProvider;
35+
36+
+ (instancetype)signerWithCredentialsProvider:(id<AWSCredentialsProvider>)credentialsProvider
37+
endpoint:(AWSEndpoint *)endpoint;
38+
39+
- (instancetype)initWithCredentialsProvider:(id<AWSCredentialsProvider>)credentialsProvider
40+
endpoint:(AWSEndpoint *)endpoint;
41+
42+
@end
43+
44+
@interface AWSSignatureV2Signer : NSObject <AZNetworkingRequestInterceptor>
45+
46+
@property (nonatomic, strong, readonly) id<AWSCredentialsProvider> credentialsProvider;
47+
48+
+ (instancetype)signerWithCredentialsProvider:(id<AWSCredentialsProvider>)credentialsProvider
49+
endpoint:(AWSEndpoint *)endpoint;
50+
51+
- (instancetype)initWithCredentialsProvider:(id<AWSCredentialsProvider>)credentialsProvider
52+
endpoint:(AWSEndpoint *)endpoint;
53+
54+
@end
55+
56+
/**
57+
* A subclass of NSInputStream that wraps an input stream and adds
58+
* signature of chunk data.
59+
**/
60+
@interface S3ChunkedEncodingInputStream : NSInputStream <NSStreamDelegate>
61+
62+
@property (nonatomic,assign) id<NSStreamDelegate> myDelegate;
63+
64+
/**
65+
* Initialize the input stream with date, scope, signing key and signature
66+
* of request headers.
67+
**/
68+
- (id)initWithInputStream:(NSInputStream *)stream
69+
date:(NSDate *)date
70+
scope:(NSString *)scope
71+
kSigning:(NSData *)kSigning
72+
headerSignature:(NSString *)headerSignature;
73+
74+
/**
75+
* Computes new content length after data being chunked encoded.
76+
**/
77+
+ (NSUInteger)computeContentLengthForChunkedData:(NSUInteger)dataLength;
78+
79+
@end

0 commit comments

Comments
 (0)