Skip to content

Commit 656531c

Browse files
bump
1 parent cb56a03 commit 656531c

File tree

3 files changed

+13
-99
lines changed

3 files changed

+13
-99
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface HttpsSSLPinningOptions {
109109
Option | Description
110110
------------ | -------------
111111
`host: string` | This must be the request domain name eg `sales.company.org`.
112-
`commonName?: string` | Default: options.host, set if certificate CN is different from the host eg `*.company.org`
112+
`commonName?: string` | Default: options.host, set if certificate CN is different from the host eg `*.company.org` (Android specific)
113113
`certificate: string` | The uri path to your `.cer` certificate file.
114114
`allowInvalidCertificates?: boolean` | Default: `false`. This should **always** be `false` if you are using SSL pinning. Set this to `true` if you're using a self-signed certificate.
115115
`validatesDomainName?: boolean` | Default: `true`. Determines if the domain name should be validated with your pinned certificate.

src/https.ios.ts

Lines changed: 9 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@ policies.def.allowInvalidCertificates = true;
1616
policies.def.validatesDomainName = false;
1717

1818
export function enableSSLPinning(options: Https.HttpsSSLPinningOptions) {
19-
// console.log('options', options)
2019
if (!policies.secure) {
2120
policies.secure = AFSecurityPolicy.policyWithPinningMode(AFSSLPinningMode.PublicKey);
2221
policies.secure.allowInvalidCertificates = (isDefined(options.allowInvalidCertificates)) ? options.allowInvalidCertificates : false;
2322
policies.secure.validatesDomainName = (isDefined(options.validatesDomainName)) ? options.validatesDomainName : true;
2423
let data = NSData.dataWithContentsOfFile(options.certificate);
25-
// console.log('data.description', data.description)
26-
// console.log('data.bytes', data.bytes)
27-
// console.log('data.base64Encoding()', data.base64Encoding())
28-
// console.log('data.length', data.length)
2924
policies.secure.pinnedCertificates = NSSet.setWithObject(data);
3025
}
3126
policies.secured = true;
@@ -40,44 +35,20 @@ export function disableSSLPinning() {
4035
console.info('nativescript-https > Disabled SSL pinning by default');
4136

4237
function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary<string, any> & NSData & NSArray<any>) {
43-
// console.log('AFSuccess')
4438
let content: any;
4539
if (data && data.class) {
46-
// console.log('data.class().name', data.class().name)
4740
if (data.enumerateKeysAndObjectsUsingBlock || (<any>data) instanceof NSArray) {
48-
// content = {}
49-
// data.enumerateKeysAndObjectsUsingBlock(function(k, v) {
50-
// console.log('v.description', v.description)
51-
// content[k] = v
52-
// })
5341
let serial = NSJSONSerialization.dataWithJSONObjectOptionsError(data, NSJSONWritingOptions.PrettyPrinted);
5442
content = NSString.alloc().initWithDataEncoding(serial, NSUTF8StringEncoding).toString();
55-
// console.log('content', content)
5643
} else if ((<any>data) instanceof NSData) {
5744
content = NSString.alloc().initWithDataEncoding(data, NSASCIIStringEncoding).toString();
58-
// } else if (data.class().name == 'NSArray') {
59-
// content = []
60-
// let i: number, len: number = data.count
61-
// for (i = 0; i < len; i++) {
62-
// let item
63-
// let result: NSDictionary<string, any> = data[i]
64-
// if (result.enumerateKeysAndObjectsUsingBlock) {
65-
// item = {}
66-
// result.enumerateKeysAndObjectsUsingBlock(function(k, v) {
67-
// item[k] = v
68-
// })
69-
// } else {
70-
// item = data[i]
71-
// }
72-
// content.push(item)
73-
// }
7445
} else {
7546
content = data;
7647
}
7748

7849
try {
7950
content = JSON.parse(content);
80-
} catch (e) {
51+
} catch (ignore) {
8152
}
8253

8354
} else {
@@ -88,47 +59,25 @@ function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary<strin
8859
}
8960

9061
function AFFailure(resolve, reject, task: NSURLSessionDataTask, error: NSError) {
91-
// console.error('AFFailure')
92-
// console.log('error.description', error.description)
93-
// console.log('error.userInfo.description', error.userInfo.description)
94-
// console.log('error.localizedDescription', error.localizedDescription)
9562
let data: NSData = error.userInfo.valueForKey(AFNetworkingOperationFailingURLResponseDataErrorKey);
9663
let body = NSString.alloc().initWithDataEncoding(data, NSUTF8StringEncoding).toString();
64+
9765
try {
9866
body = JSON.parse(body);
99-
} catch (e) {
67+
} catch (ignore) {
10068
}
69+
10170
let content: any = {
10271
body,
10372
description: error.description,
10473
reason: error.localizedDescription,
10574
url: error.userInfo.objectForKey('NSErrorFailingURLKey').description
10675
};
107-
// console.log('content.url', content.url)
108-
// try {
109-
// content.body = JSON.parse(body.description)
110-
// } catch (e) {
76+
11177
if (policies.secured === true) {
112-
// console.log('error.description', error.description)
113-
// console.log('error.userInfo.description', error.userInfo.description)
11478
content.description = 'nativescript-https > Invalid SSL certificate! ' + content.description;
115-
// return reject(content)
11679
}
117-
// }
118-
// console.log('error.description', error.description)
119-
// console.keys('error', error)
120-
// console.keys('error.userInfo', error.userInfo)
121-
// error.userInfo.enumerateKeysAndObjectsUsingBlock(function(k, v) {
122-
// console.log('k', k)
123-
// console.log('v.description', v.description)
124-
// })
125-
// let keys = error.userInfo.allKeysForObject(error.userInfo)
126-
// console.log('keys.description', keys.description)
127-
// let url = error.valueForKey('URL')
128-
// console.error('url', url)
129-
// if (!isNullOrUndefined(task.response)) {
130-
// content.URL = task.response.URL
131-
// }
80+
13281
let reason = error.localizedDescription;
13382
resolve({task, content, reason});
13483
}
@@ -138,14 +87,11 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
13887
try {
13988
const manager = AFHTTPSessionManager.alloc().initWithBaseURL(NSURL.URLWithString(opts.url));
14089
if (opts.headers && (<any>opts.headers['Content-Type']).substring(0, 16) === 'application/json') {
141-
manager.requestSerializer = AFJSONRequestSerializer.serializer();
142-
manager.responseSerializer = AFJSONResponseSerializer.serializerWithReadingOptions(NSJSONReadingOptions.AllowFragments);
90+
manager.requestSerializer = AFJSONRequestSerializer.serializer();
91+
manager.responseSerializer = AFJSONResponseSerializer.serializerWithReadingOptions(NSJSONReadingOptions.AllowFragments);
14392
} else {
14493
manager.requestSerializer = AFHTTPRequestSerializer.serializer();
145-
// manager.responseSerializer = AFXMLParserResponseSerializer.serializer()
14694
manager.responseSerializer = AFHTTPResponseSerializer.serializer();
147-
// manager.responseSerializer.acceptableContentTypes = NSSet.setWithObject('text/html')
148-
// manager.responseSerializer.acceptableContentTypes = NSSet.setWithObject('application/json')
14995
}
15096
manager.requestSerializer.allowsCellularAccess = true;
15197
manager.securityPolicy = (policies.secured === true) ? policies.secure : policies.def;
@@ -185,20 +131,6 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
185131
AFFailure(resolve, reject, task, error);
186132
});
187133

188-
// if (opts.method == 'GET') {
189-
// manager.GETParametersSuccessFailure(opts.url, dict, function success(task: NSURLSessionDataTask, data: any) {
190-
// AFSuccess(resolve, task, data)
191-
// }, function failure(task, error) {
192-
// AFFailure(resolve, reject, task, error)
193-
// })
194-
// } else if (opts.method == 'POST') {
195-
// manager.POSTParametersSuccessFailure(opts.url, dict, function success(task: NSURLSessionDataTask, data: any) {
196-
// AFSuccess(resolve, task, data)
197-
// }, function failure(task, error) {
198-
// AFFailure(resolve, reject, task, error)
199-
// })
200-
// }
201-
202134
} catch (error) {
203135
reject(error);
204136
}
@@ -208,7 +140,6 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
208140
content: any
209141
reason?: string
210142
}) => {
211-
212143
let sendi: Https.HttpsResponse = {
213144
content: AFResponse.content,
214145
headers: {},
@@ -224,23 +155,7 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
224155
if (AFResponse.reason) {
225156
sendi.reason = AFResponse.reason;
226157
}
227-
return Promise.resolve(sendi);
228158

159+
return Promise.resolve(sendi);
229160
});
230-
231-
// {
232-
// "content": {
233-
// "code": "PreconditionFailed",
234-
// "message": "!x-uuid"
235-
// },
236-
// "statusCode": 412,
237-
// "headers": {
238-
// "Content-Length": "49",
239-
// "Server": "nginx/1.10.1",
240-
// "Content-Type": "application/json",
241-
// "Connection": "keep-alive",
242-
// "Date": "Mon, 26 Dec 2016 03:31:42 GMT"
243-
// }
244-
// }
245-
246161
}

src/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-https",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"description": "Secure HTTP client with SSL pinning for Nativescript - iOS/Android.",
55
"main": "https",
66
"typings": "index.d.ts",
@@ -29,8 +29,8 @@
2929
},
3030
"dependencies": {},
3131
"devDependencies": {
32-
"tns-core-modules": "~6.1.1",
33-
"tns-platform-declarations": "~6.1.1",
32+
"tns-core-modules": "~6.4.0",
33+
"tns-platform-declarations": "~6.4.0",
3434
"typescript": "3.4.5",
3535
"prompt": "^1.0.0",
3636
"rimraf": "^2.6.2",
@@ -49,7 +49,6 @@
4949
"email": "[email protected]",
5050
"url": "https://github.com/kefahB"
5151
}
52-
5352
],
5453
"repository": "github:gethuman/nativescript-https",
5554
"homepage": "https://github.com/gethuman/nativescript-https",

0 commit comments

Comments
 (0)