From 719b6553b1017b472ce7815e479e570b63216f9a Mon Sep 17 00:00:00 2001 From: James Go Date: Tue, 16 Apr 2019 17:03:55 -0700 Subject: [PATCH 01/40] US584914 : iOS - Decoupling the BLE into separate module --- MASFoundation.xcodeproj/project.pbxproj | 78 +- MASFoundation/Classes/MAS.m | 5 +- MASFoundation/Classes/MASError.h | 28 - .../Classes/MASProximityLoginDelegate.h | 135 --- .../Classes/_private_/MASConstantsPrivate.h | 9 - .../categories/CBCentralManager+MASPrivate.h | 56 -- .../categories/CBCentralManager+MASPrivate.m | 141 --- .../CBPeripheralManager+MASPrivate.h | 80 -- .../CBPeripheralManager+MASPrivate.m | 162 ---- .../_private_/categories/NSError+MASPrivate.h | 18 - .../_private_/categories/NSError+MASPrivate.m | 41 +- .../MASProximityLoginQRCode+MASPrivate.h | 49 - .../MASProximityLoginQRCode+MASPrivate.m | 279 ------ .../_private_/services/MASServiceRegistry.m | 1 - .../services/bluetooth/MASBluetoothCentral.h | 63 -- .../services/bluetooth/MASBluetoothCentral.m | 867 ------------------ .../bluetooth/MASBluetoothPeripheral.h | 52 -- .../bluetooth/MASBluetoothPeripheral.m | 539 ----------- .../services/bluetooth/MASBluetoothService.h | 41 - .../services/bluetooth/MASBluetoothService.m | 135 --- .../models/MASAuthenticationProviders.h | 5 + .../models/MASAuthenticationProviders.m | 9 + MASFoundation/Classes/models/MASDevice.h | 66 -- MASFoundation/Classes/models/MASDevice.m | 53 -- .../Classes/models/MASProximityLogin.h | 15 - .../Classes/models/MASProximityLogin.m | 29 - .../Classes/models/MASProximityLoginQRCode.h | 128 --- .../Classes/models/MASProximityLoginQRCode.m | 225 ----- MASFoundation/MASFoundation.h | 3 - 29 files changed, 17 insertions(+), 3295 deletions(-) delete mode 100644 MASFoundation/Classes/MASProximityLoginDelegate.h delete mode 100644 MASFoundation/Classes/_private_/categories/CBCentralManager+MASPrivate.h delete mode 100644 MASFoundation/Classes/_private_/categories/CBCentralManager+MASPrivate.m delete mode 100644 MASFoundation/Classes/_private_/categories/CBPeripheralManager+MASPrivate.h delete mode 100644 MASFoundation/Classes/_private_/categories/CBPeripheralManager+MASPrivate.m delete mode 100644 MASFoundation/Classes/_private_/models/MASProximityLoginQRCode+MASPrivate.h delete mode 100644 MASFoundation/Classes/_private_/models/MASProximityLoginQRCode+MASPrivate.m delete mode 100644 MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothCentral.h delete mode 100644 MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothCentral.m delete mode 100644 MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothPeripheral.h delete mode 100644 MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothPeripheral.m delete mode 100644 MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothService.h delete mode 100644 MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothService.m delete mode 100644 MASFoundation/Classes/models/MASProximityLogin.h delete mode 100644 MASFoundation/Classes/models/MASProximityLogin.m delete mode 100644 MASFoundation/Classes/models/MASProximityLoginQRCode.h delete mode 100644 MASFoundation/Classes/models/MASProximityLoginQRCode.m diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 29f7e848..d65b015c 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -64,8 +64,6 @@ A4150ED51BF16D9A00037E27 /* MASNetworkingService.m in Sources */ = {isa = PBXBuildFile; fileRef = A4150EC91BF16D9A00037E27 /* MASNetworkingService.m */; }; A4150ED91BF16DBE00037E27 /* MASLocationService.h in Headers */ = {isa = PBXBuildFile; fileRef = A4150ED71BF16DBE00037E27 /* MASLocationService.h */; }; A4150EDA1BF16DBE00037E27 /* MASLocationService.m in Sources */ = {isa = PBXBuildFile; fileRef = A4150ED81BF16DBE00037E27 /* MASLocationService.m */; }; - A4150EE01BF16E0F00037E27 /* MASBluetoothService.h in Headers */ = {isa = PBXBuildFile; fileRef = A4150EDC1BF16E0F00037E27 /* MASBluetoothService.h */; }; - A4150EE11BF16E0F00037E27 /* MASBluetoothService.m in Sources */ = {isa = PBXBuildFile; fileRef = A4150EDD1BF16E0F00037E27 /* MASBluetoothService.m */; }; A4150EE71BF16E5B00037E27 /* MASFileService.h in Headers */ = {isa = PBXBuildFile; fileRef = A4150EE51BF16E5B00037E27 /* MASFileService.h */; }; A4150EE81BF16E5B00037E27 /* MASFileService.m in Sources */ = {isa = PBXBuildFile; fileRef = A4150EE61BF16E5B00037E27 /* MASFileService.m */; }; A4150EFB1BF16EE200037E27 /* MASKeyChainService.h in Headers */ = {isa = PBXBuildFile; fileRef = A4150EF71BF16EE200037E27 /* MASKeyChainService.h */; }; @@ -141,10 +139,6 @@ A47332D01BBC61F50002A492 /* NSData+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A47332CE1BBC61F50002A492 /* NSData+MASPrivate.m */; }; A47F126C1C1D6B4B0008E3F2 /* MASURLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A47F126A1C1D6B4B0008E3F2 /* MASURLRequest.h */; }; A47F126D1C1D6B4B0008E3F2 /* MASURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = A47F126B1C1D6B4B0008E3F2 /* MASURLRequest.m */; }; - A47F127E1C1D73530008E3F2 /* MASBluetoothCentral.h in Headers */ = {isa = PBXBuildFile; fileRef = A47F127A1C1D73530008E3F2 /* MASBluetoothCentral.h */; }; - A47F127F1C1D73530008E3F2 /* MASBluetoothCentral.m in Sources */ = {isa = PBXBuildFile; fileRef = A47F127B1C1D73530008E3F2 /* MASBluetoothCentral.m */; }; - A47F12801C1D73530008E3F2 /* MASBluetoothPeripheral.h in Headers */ = {isa = PBXBuildFile; fileRef = A47F127C1C1D73530008E3F2 /* MASBluetoothPeripheral.h */; }; - A47F12811C1D73530008E3F2 /* MASBluetoothPeripheral.m in Sources */ = {isa = PBXBuildFile; fileRef = A47F127D1C1D73530008E3F2 /* MASBluetoothPeripheral.m */; }; A4831AA91BD1A551007B4AE6 /* MASApplication.h in Headers */ = {isa = PBXBuildFile; fileRef = A4831A9B1BD1A551007B4AE6 /* MASApplication.h */; settings = {ATTRIBUTES = (Public, ); }; }; A4831AAA1BD1A551007B4AE6 /* MASApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = A4831A9C1BD1A551007B4AE6 /* MASApplication.m */; }; A4831AAB1BD1A551007B4AE6 /* MASAuthenticationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = A4831A9D1BD1A551007B4AE6 /* MASAuthenticationProvider.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -171,10 +165,6 @@ A4831AFB1BD1A8E8007B4AE6 /* MASFile+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A4831AF91BD1A8E8007B4AE6 /* MASFile+MASPrivate.m */; }; A4831AFD1BD1A917007B4AE6 /* MASUser+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A4831AFC1BD1A917007B4AE6 /* MASUser+MASPrivate.h */; }; A4831AFF1BD1A922007B4AE6 /* MASUser+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A4831AFE1BD1A922007B4AE6 /* MASUser+MASPrivate.m */; }; - A483C1A31BE56BAF007572CE /* CBPeripheralManager+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A483C1A11BE56BAF007572CE /* CBPeripheralManager+MASPrivate.h */; }; - A483C1A41BE56BAF007572CE /* CBPeripheralManager+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A483C1A21BE56BAF007572CE /* CBPeripheralManager+MASPrivate.m */; }; - A483C2011BE6D0C5007572CE /* CBCentralManager+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A483C1FF1BE6D0C5007572CE /* CBCentralManager+MASPrivate.h */; }; - A483C2021BE6D0C5007572CE /* CBCentralManager+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A483C2001BE6D0C5007572CE /* CBCentralManager+MASPrivate.m */; }; A488CE751C0B97FD00B8B961 /* MASService.h in Headers */ = {isa = PBXBuildFile; fileRef = A488CE731C0B97FD00B8B961 /* MASService.h */; settings = {ATTRIBUTES = (Public, ); }; }; A488CE761C0B97FD00B8B961 /* MASService.m in Sources */ = {isa = PBXBuildFile; fileRef = A488CE741C0B97FD00B8B961 /* MASService.m */; }; A4E340EB1B9E9F2000883AD3 /* MASConstantsPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A4E340BE1B9E9F2000883AD3 /* MASConstantsPrivate.h */; }; @@ -195,15 +185,8 @@ C81CC3CD1FC2EA190058718E /* MASBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */; }; C81CC3D01FC2EFBB0058718E /* UIAlertController+MAS.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */; }; C81CC3D11FC2EFBB0058718E /* UIAlertController+MAS.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */; }; - CB0A8ADF1D01F64F00B1DCCC /* MASProximityLogin.h in Headers */ = {isa = PBXBuildFile; fileRef = CB0A8ADD1D01F64F00B1DCCC /* MASProximityLogin.h */; settings = {ATTRIBUTES = (Public, ); }; }; - CB0A8AE01D01F64F00B1DCCC /* MASProximityLogin.m in Sources */ = {isa = PBXBuildFile; fileRef = CB0A8ADE1D01F64F00B1DCCC /* MASProximityLogin.m */; }; CB0B58591E258C2A00BC0163 /* MASAuthorizationResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; CB0B585A1E258C2A00BC0163 /* MASAuthorizationResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */; }; - CB14D2191D02266D004F772E /* MASProximityLoginQRCode.h in Headers */ = {isa = PBXBuildFile; fileRef = CB14D2171D02266D004F772E /* MASProximityLoginQRCode.h */; settings = {ATTRIBUTES = (Public, ); }; }; - CB14D21A1D02266D004F772E /* MASProximityLoginQRCode.m in Sources */ = {isa = PBXBuildFile; fileRef = CB14D2181D02266D004F772E /* MASProximityLoginQRCode.m */; }; - CB14D21C1D02293B004F772E /* MASProximityLoginDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = CB14D21B1D0228DB004F772E /* MASProximityLoginDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; - CB14D2231D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CB14D2211D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.h */; }; - CB14D2241D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = CB14D2221D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.m */; }; CB1907EF1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */; }; CB1907F01C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = CB1907EE1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.m */; }; CB1907F31C1794FC00A5EF16 /* MASAccess.h in Headers */ = {isa = PBXBuildFile; fileRef = CB1907F11C1794FC00A5EF16 /* MASAccess.h */; }; @@ -450,8 +433,6 @@ A4150EC91BF16D9A00037E27 /* MASNetworkingService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASNetworkingService.m; sourceTree = ""; }; A4150ED71BF16DBE00037E27 /* MASLocationService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASLocationService.h; sourceTree = ""; }; A4150ED81BF16DBE00037E27 /* MASLocationService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASLocationService.m; sourceTree = ""; }; - A4150EDC1BF16E0F00037E27 /* MASBluetoothService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASBluetoothService.h; sourceTree = ""; }; - A4150EDD1BF16E0F00037E27 /* MASBluetoothService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASBluetoothService.m; sourceTree = ""; }; A4150EE51BF16E5B00037E27 /* MASFileService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASFileService.h; sourceTree = ""; }; A4150EE61BF16E5B00037E27 /* MASFileService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASFileService.m; sourceTree = ""; }; A4150EF71BF16EE200037E27 /* MASKeyChainService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASKeyChainService.h; sourceTree = ""; }; @@ -531,10 +512,6 @@ A47332CE1BBC61F50002A492 /* NSData+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+MASPrivate.m"; sourceTree = ""; }; A47F126A1C1D6B4B0008E3F2 /* MASURLRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASURLRequest.h; sourceTree = ""; }; A47F126B1C1D6B4B0008E3F2 /* MASURLRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASURLRequest.m; sourceTree = ""; }; - A47F127A1C1D73530008E3F2 /* MASBluetoothCentral.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASBluetoothCentral.h; sourceTree = ""; }; - A47F127B1C1D73530008E3F2 /* MASBluetoothCentral.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASBluetoothCentral.m; sourceTree = ""; }; - A47F127C1C1D73530008E3F2 /* MASBluetoothPeripheral.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASBluetoothPeripheral.h; sourceTree = ""; }; - A47F127D1C1D73530008E3F2 /* MASBluetoothPeripheral.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASBluetoothPeripheral.m; sourceTree = ""; }; A4831A9B1BD1A551007B4AE6 /* MASApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASApplication.h; sourceTree = ""; }; A4831A9C1BD1A551007B4AE6 /* MASApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASApplication.m; sourceTree = ""; }; A4831A9D1BD1A551007B4AE6 /* MASAuthenticationProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASAuthenticationProvider.h; sourceTree = ""; }; @@ -561,10 +538,6 @@ A4831AF91BD1A8E8007B4AE6 /* MASFile+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MASFile+MASPrivate.m"; sourceTree = ""; }; A4831AFC1BD1A917007B4AE6 /* MASUser+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASUser+MASPrivate.h"; sourceTree = ""; }; A4831AFE1BD1A922007B4AE6 /* MASUser+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MASUser+MASPrivate.m"; sourceTree = ""; }; - A483C1A11BE56BAF007572CE /* CBPeripheralManager+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CBPeripheralManager+MASPrivate.h"; sourceTree = ""; }; - A483C1A21BE56BAF007572CE /* CBPeripheralManager+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CBPeripheralManager+MASPrivate.m"; sourceTree = ""; }; - A483C1FF1BE6D0C5007572CE /* CBCentralManager+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CBCentralManager+MASPrivate.h"; sourceTree = ""; }; - A483C2001BE6D0C5007572CE /* CBCentralManager+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CBCentralManager+MASPrivate.m"; sourceTree = ""; }; A488CE731C0B97FD00B8B961 /* MASService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASService.h; sourceTree = ""; }; A488CE741C0B97FD00B8B961 /* MASService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASService.m; sourceTree = ""; }; A48CDD381B7D1FDD00ADABC6 /* MASFoundation_PrefixHeader.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASFoundation_PrefixHeader.pch; sourceTree = ""; }; @@ -587,15 +560,8 @@ C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASBrowserBasedAuthentication.m; sourceTree = ""; }; C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertController+MAS.h"; sourceTree = ""; }; C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertController+MAS.m"; sourceTree = ""; }; - CB0A8ADD1D01F64F00B1DCCC /* MASProximityLogin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASProximityLogin.h; sourceTree = ""; }; - CB0A8ADE1D01F64F00B1DCCC /* MASProximityLogin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASProximityLogin.m; sourceTree = ""; }; CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASAuthorizationResponse.h; sourceTree = ""; }; CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASAuthorizationResponse.m; sourceTree = ""; }; - CB14D2171D02266D004F772E /* MASProximityLoginQRCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASProximityLoginQRCode.h; sourceTree = ""; }; - CB14D2181D02266D004F772E /* MASProximityLoginQRCode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASProximityLoginQRCode.m; sourceTree = ""; }; - CB14D21B1D0228DB004F772E /* MASProximityLoginDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASProximityLoginDelegate.h; sourceTree = ""; }; - CB14D2211D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASProximityLoginQRCode+MASPrivate.h"; sourceTree = ""; }; - CB14D2221D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MASProximityLoginQRCode+MASPrivate.m"; sourceTree = ""; }; CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASIKeyChainStore+MASPrivate.h"; sourceTree = ""; }; CB1907EE1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MASIKeyChainStore+MASPrivate.m"; sourceTree = ""; }; CB1907F11C1794FC00A5EF16 /* MASAccess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASAccess.h; sourceTree = ""; }; @@ -886,19 +852,6 @@ path = location; sourceTree = ""; }; - A4150EDB1BF16E0F00037E27 /* bluetooth */ = { - isa = PBXGroup; - children = ( - A4150EDC1BF16E0F00037E27 /* MASBluetoothService.h */, - A4150EDD1BF16E0F00037E27 /* MASBluetoothService.m */, - A47F127A1C1D73530008E3F2 /* MASBluetoothCentral.h */, - A47F127B1C1D73530008E3F2 /* MASBluetoothCentral.m */, - A47F127C1C1D73530008E3F2 /* MASBluetoothPeripheral.h */, - A47F127D1C1D73530008E3F2 /* MASBluetoothPeripheral.m */, - ); - path = bluetooth; - sourceTree = ""; - }; A4150EE41BF16E5B00037E27 /* file */ = { isa = PBXGroup; children = ( @@ -1102,10 +1055,6 @@ 1046618D1C0ABDDE00A2A03C /* MASGroup.m */, CBAFD24A1F2BD46C0034DF02 /* MASSecurityConfiguration.h */, CBAFD24B1F2BD46C0034DF02 /* MASSecurityConfiguration.m */, - CB0A8ADD1D01F64F00B1DCCC /* MASProximityLogin.h */, - CB0A8ADE1D01F64F00B1DCCC /* MASProximityLogin.m */, - CB14D2171D02266D004F772E /* MASProximityLoginQRCode.h */, - CB14D2181D02266D004F772E /* MASProximityLoginQRCode.m */, CBA3EB2C1E945F2400E64D9D /* MASClaims.h */, CBA3EB2D1E945F2400E64D9D /* MASClaims.m */, CB1FD1491FB23701000AFA25 /* MASSharedStorage.h */, @@ -1122,7 +1071,6 @@ A42157171BF863480034BDC9 /* MASServiceRegistry.h */, A42157181BF863480034BDC9 /* MASServiceRegistry.m */, CB1907F51C17950700A5EF16 /* access */, - A4150EDB1BF16E0F00037E27 /* bluetooth */, A42157231BF864590034BDC9 /* configuration */, A4150EE41BF16E5B00037E27 /* file */, A898EF602182D30900CF291B /* jwt */, @@ -1148,7 +1096,6 @@ 699570E52062FF1300017244 /* MASError.m */, 699570E02060650400017244 /* MASNotifications.h */, 699570E12060650400017244 /* MASNotifications.m */, - CB14D21B1D0228DB004F772E /* MASProximityLoginDelegate.h */, 107389F21C7118F800B7E87E /* MQTT */, A419B39A1C17622E008DC88C /* categories */, A4831A9A1BD1A551007B4AE6 /* models */, @@ -1179,10 +1126,6 @@ C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */, CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */, CB1907EE1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.m */, - A483C1FF1BE6D0C5007572CE /* CBCentralManager+MASPrivate.h */, - A483C2001BE6D0C5007572CE /* CBCentralManager+MASPrivate.m */, - A483C1A11BE56BAF007572CE /* CBPeripheralManager+MASPrivate.h */, - A483C1A21BE56BAF007572CE /* CBPeripheralManager+MASPrivate.m */, A417BA4F1BF033C300EC9BCB /* CLLocation+MASPrivate.h */, A417BA501BF033C300EC9BCB /* CLLocation+MASPrivate.m */, A43BEBB01BE34D7700842522 /* CLLocationManager+MASPrivate.h */, @@ -1235,8 +1178,6 @@ 10D2D49D1C1686ED00DF8AC4 /* MASGroup+MASPrivate.m */, A898EF652182D35700CF291B /* MASJWKSet.h */, A898EF662182D35700CF291B /* MASJWKSet.m */, - CB14D2211D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.h */, - CB14D2221D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.m */, CBA3EB301E94634C00E64D9D /* MASClaims+MASPrivate.h */, CBA3EB311E94634C00E64D9D /* MASClaims+MASPrivate.m */, ); @@ -1601,12 +1542,9 @@ CB9B1207210949D5008A2075 /* NSMutableData+MASASN1Helper.h in Headers */, CBA3EB2E1E945F2400E64D9D /* MASClaims.h in Headers */, CB0B58591E258C2A00BC0163 /* MASAuthorizationResponse.h in Headers */, - CB14D21C1D02293B004F772E /* MASProximityLoginDelegate.h in Headers */, CBA3EB321E94634C00E64D9D /* MASClaims+MASPrivate.h in Headers */, CBD25AFF1E78C47C00DFB47F /* JWTClaimsSetVerifier.h in Headers */, - CB14D2191D02266D004F772E /* MASProximityLoginQRCode.h in Headers */, CBD25AF21E78C47C00DFB47F /* JWTRSAlgorithm.h in Headers */, - CB0A8ADF1D01F64F00B1DCCC /* MASProximityLogin.h in Headers */, CB6491F01FE9DAF300281288 /* MQTTPersistence.h in Headers */, 10E027A11F72B10100EAB103 /* RNCryptor+Private.h in Headers */, CBD25B0C1E78C47C00DFB47F /* JWTBase64Coder.h in Headers */, @@ -1660,7 +1598,6 @@ 10E0279E1F72B10100EAB103 /* RNCryptor-Prefix.pch in Headers */, CB6492051FE9DAF300281288 /* MQTTTransport.h in Headers */, CB6491E21FE9DAF300281288 /* MQTTCFSocketTransport.h in Headers */, - A47F127E1C1D73530008E3F2 /* MASBluetoothCentral.h in Headers */, CBD25AE41E78C47C00DFB47F /* JWTAlgorithmFactory.h in Headers */, CB1C151E1E450109002B31A5 /* NSURL+MASPrivate.h in Headers */, CB6491FD1FE9DAF300281288 /* MQTTSSLSecurityPolicyDecoder.h in Headers */, @@ -1679,14 +1616,12 @@ CB23579A1F100EC400D4C420 /* MASSessionDataTaskOperation.h in Headers */, A4831AB31BD1A551007B4AE6 /* MASObject.h in Headers */, CBD25AF71E78C47C00DFB47F /* JWTCryptoSecurity.h in Headers */, - CB14D2231D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.h in Headers */, CB58986B1F183E0A005C1E82 /* MASAuthValidationOperation.h in Headers */, A4831AB51BD1A551007B4AE6 /* MASUser.h in Headers */, A46F49F31C2F5FC500A4C370 /* MASIOrderedDictionary.h in Headers */, A42D02E41C0E240800AA1F11 /* MASAuthenticationProviders+MASPrivate.h in Headers */, A46F49E11C2F5FC500A4C370 /* UIImage+MASINetworking.h in Headers */, CB3173E01F1FFF2C00C85E47 /* MASNetworkMonitor.h in Headers */, - A47F12801C1D73530008E3F2 /* MASBluetoothPeripheral.h in Headers */, A4150EE71BF16E5B00037E27 /* MASFileService.h in Headers */, A46F49C41C2F5FC500A4C370 /* MASIHTTPRequestOperation.h in Headers */, A46F49E51C2F5FC500A4C370 /* UIProgressView+MASINetworking.h in Headers */, @@ -1694,7 +1629,6 @@ A46F49BC1C2F5FC500A4C370 /* fmemopen.h in Headers */, A4831AF21BD1A8AA007B4AE6 /* MASConfiguration+MASPrivate.h in Headers */, CBD25AE61E78C47C00DFB47F /* JWTAlgorithmNone.h in Headers */, - A483C2011BE6D0C5007572CE /* CBCentralManager+MASPrivate.h in Headers */, A4150EFB1BF16EE200037E27 /* MASKeyChainService.h in Headers */, A46F49C61C2F5FC500A4C370 /* MASIHTTPRequestOperationManager.h in Headers */, CB1EE31C2009895A0056F24A /* MASMQTTForegroundReconnection.h in Headers */, @@ -1728,7 +1662,6 @@ A46F49CF1C2F5FC500A4C370 /* MASISecurityPolicy.h in Headers */, A4831AEE1BD1A87C007B4AE6 /* MASAuthenticationProvider+MASPrivate.h in Headers */, A4831AEC1BD1A87C007B4AE6 /* MASApplication+MASPrivate.h in Headers */, - A4150EE01BF16E0F00037E27 /* MASBluetoothService.h in Headers */, CB5E4C741C1D26BA001B3B8A /* MASPatchURLRequest.h in Headers */, A42157261BF864590034BDC9 /* MASConfigurationService.h in Headers */, CB5E4C701C1D250D001B3B8A /* MASPutURLRequest.h in Headers */, @@ -1757,7 +1690,6 @@ CBD25B031E78C47C00DFB47F /* JWTCoding+VersionOne.h in Headers */, CBD25B051E78C47C00DFB47F /* JWTCoding+VersionThree.h in Headers */, CB9975561EDF5986006CEBB1 /* MASAuthCredentialsClientCredentials.h in Headers */, - A483C1A31BE56BAF007572CE /* CBPeripheralManager+MASPrivate.h in Headers */, A4150ED91BF16DBE00037E27 /* MASLocationService.h in Headers */, 10E027A61F72B10100EAB103 /* RNEncryptor.h in Headers */, CB6491E01FE9DAF300281288 /* MQTTCFSocketEncoder.h in Headers */, @@ -1900,7 +1832,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/bash; - shellScript = export; + shellScript = "export\n"; }; /* End PBXShellScriptBuildPhase section */ @@ -1911,12 +1843,9 @@ files = ( CB5E4C711C1D250D001B3B8A /* MASPutURLRequest.m in Sources */, CB2A4056209B9DA600F988AA /* MASMultiFactorHandler+MASPrivate.m in Sources */, - CB14D21A1D02266D004F772E /* MASProximityLoginQRCode.m in Sources */, A858C6661D0978A6001FB9AD /* MASOTPService.m in Sources */, CBD25AE71E78C47C00DFB47F /* JWTAlgorithmNone.m in Sources */, CB1C151F1E450109002B31A5 /* NSURL+MASPrivate.m in Sources */, - CB14D2241D02328C004F772E /* MASProximityLoginQRCode+MASPrivate.m in Sources */, - A4150EE11BF16E0F00037E27 /* MASBluetoothService.m in Sources */, 10D2D49F1C1686ED00DF8AC4 /* MASGroup+MASPrivate.m in Sources */, CB99754F1EDF5837006CEBB1 /* MASAuthCredentialsAuthorizationCode.m in Sources */, A488CE761C0B97FD00B8B961 /* MASService.m in Sources */, @@ -1947,7 +1876,6 @@ CB6492041FE9DAF300281288 /* MQTTStrict.m in Sources */, 699570E32060650400017244 /* MASNotifications.m in Sources */, A4150EFC1BF16EE200037E27 /* MASKeyChainService.m in Sources */, - A47F12811C1D73530008E3F2 /* MASBluetoothPeripheral.m in Sources */, CBD25B061E78C47C00DFB47F /* JWTCoding+VersionThree.m in Sources */, C81CC3D11FC2EFBB0058718E /* UIAlertController+MAS.m in Sources */, CBD25AED1E78C47C00DFB47F /* JWTAlgorithmDataHolderChain.m in Sources */, @@ -1979,7 +1907,6 @@ CBD25AF11E78C47C00DFB47F /* JWTAlgorithmRSBase.m in Sources */, CBD25AEF1E78C47C00DFB47F /* JWTAlgorithmHSBase.m in Sources */, CBD25AF81E78C47C00DFB47F /* JWTCryptoSecurity.m in Sources */, - A47F127F1C1D73530008E3F2 /* MASBluetoothCentral.m in Sources */, CB2A4052209A732500F988AA /* MASOTPMultiFactorAuthenticator.m in Sources */, A4831AB41BD1A551007B4AE6 /* MASObject.m in Sources */, CB6491F41FE9DAF300281288 /* MQTTSession.m in Sources */, @@ -2003,7 +1930,6 @@ CB9975531EDF591C006CEBB1 /* MASAuthCredentialsJWT.m in Sources */, CBD25B041E78C47C00DFB47F /* JWTCoding+VersionOne.m in Sources */, CB9B1208210949D5008A2075 /* NSMutableData+MASASN1Helper.m in Sources */, - CB0A8AE01D01F64F00B1DCCC /* MASProximityLogin.m in Sources */, CB99754B1EDF57D6006CEBB1 /* MASAuthCredentialsPassword.m in Sources */, A42D02E11C0E223600AA1F11 /* MASAuthenticationProviders.m in Sources */, CB5E4C691C1D21FB001B3B8A /* MASPostURLRequest.m in Sources */, @@ -2049,7 +1975,6 @@ 69B7DF691F9675600056DD3A /* MASRequest.m in Sources */, CB6492021FE9DAF300281288 /* MQTTSSLSecurityPolicyTransport.m in Sources */, CBD25B081E78C47C00DFB47F /* JWTCoding+VersionTwo.m in Sources */, - A483C2021BE6D0C5007572CE /* CBCentralManager+MASPrivate.m in Sources */, CBD25AFA1E78C47C00DFB47F /* JWTClaim.m in Sources */, A4831AFF1BD1A922007B4AE6 /* MASUser+MASPrivate.m in Sources */, CBA3EB331E94634C00E64D9D /* MASClaims+MASPrivate.m in Sources */, @@ -2071,7 +1996,6 @@ A46F49E81C2F5FC500A4C370 /* UIRefreshControl+MASINetworking.m in Sources */, CB6491DD1FE9DAF300281288 /* ForegroundReconnection.m in Sources */, CB1EE31D2009895A0056F24A /* MASMQTTForegroundReconnection.m in Sources */, - A483C1A41BE56BAF007572CE /* CBPeripheralManager+MASPrivate.m in Sources */, CB6491F21FE9DAF300281288 /* MQTTProperties.m in Sources */, 107389FE1C7119E800B7E87E /* MASMQTTHelper.m in Sources */, ); diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index 367c873a..3cdaa1a4 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -12,7 +12,6 @@ #import "MASJWTService.h" #import "MASAccessService.h" -#import "MASBluetoothService.h" #import "MASConfigurationService.h" #import "MASConstantsPrivate.h" #import "MASClaims+MASPrivate.h" @@ -1518,19 +1517,17 @@ + (void)currentStatusToConsole { MASServiceRegistry *registry = [MASServiceRegistry sharedRegistry]; MASConfigurationService *configurationService = [MASConfigurationService sharedService]; - MASBluetoothService *bluetoothService = [MASBluetoothService sharedService]; MASFileService *fileService = [MASFileService sharedService]; MASLocationService *locationService = [MASLocationService sharedService]; MASModelService *modelService = [MASModelService sharedService]; MASNetworkingService *networkingService = [MASNetworkingService sharedService]; DLog(@"\n\n\n%@\n\n ****************************** Services Summary ******************************\n\n\n" - " %@\n\n\n %@\n\n\n %@\n\n\n %@\n\n\n %@\n\n\n %@\n\n\n %@\n\n\n", + " %@\n\n\n %@\n\n\n %@\n\n\n %@\n\n\n %@\n\n\n %@\n\n\n", (registry ? [registry debugDescription] : @"(Service Registry Not Initialized"), (configurationService ? [configurationService debugDescription] : @"(Configuration Service Not Initialized)\n\n"), (networkingService ? [networkingService debugDescription] : @"(Networking Service Not Initialized)\n\n"), (locationService ? [locationService debugDescription] : @"(Location Service Not Initialized)\n\n"), - (bluetoothService ? [bluetoothService debugDescription] : @"(Bluetooth Service Not Initialized)\n\n"), (modelService ? [modelService debugDescription] : @"(Model Service Not Initialized)\n\n"), (fileService ? [fileService debugDescription] : @"(File Service Not Initialized)\n\n"), [[MASAccessService sharedService] debugSecuredDescription]); diff --git a/MASFoundation/Classes/MASError.h b/MASFoundation/Classes/MASError.h index 4ec5fe19..2b26156d 100644 --- a/MASFoundation/Classes/MASError.h +++ b/MASFoundation/Classes/MASError.h @@ -162,34 +162,6 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode) MASFoundationErrorCodeEnterpriseBrowserNativeAppCannotOpen = 140003, MASFoundationErrorCodeEnterpriseBrowserAppDoesNotExist = 140004, - // - // BLE - // - MASFoundationErrorCodeBLEUnknownState = 150001, - MASFoundationErrorCodeBLEAuthorizationFailed = 150002, - MASFoundationErrorCodeBLEAuthorizationPollingFailed = 150003, - MASFoundationErrorCodeBLECentralDeviceNotFound = 150004, - MASFoundationErrorCodeBLEDelegateNotDefined = 150005, - MASFoundationErrorCodeBLEInvalidAuthenticationProvider = 150006, - MASFoundationErrorCodeBLEPoweredOff = 150007, - MASFoundationErrorCodeBLEResetting = 150008, - MASFoundationErrorCodeBLERSSINotInRange = 150009, - MASFoundationErrorCodeBLEUnSupported = 150010, - MASFoundationErrorCodeBLEUnauthorized = 150011, - MASFoundationErrorCodeBLEUserDeclined = 150012, - MASFoundationErrorCodeBLECentral = 150013, - MASFoundationErrorCodeBLEPeripheral = 150014, - MASFoundationErrorCodeBLEPeripheralServices = 150015, - MASFoundationErrorCodeBLEPeripheralCharacteristics = 150016, - - // - // Proximity Login - // - MASFoundationErrorCodeProximityLoginAuthorizationInProgress = 150101, - MASFoundationErrorCodeProximityLoginInvalidAuthenticationURL = 150102, - MASFoundationErrorCodeQRCodeProximityLoginAuthorizationPollingFailed = 150103, - MASFoundationErrorCodeProximityLoginInvalidAuthorizeURL = 150104, - // // OTP // diff --git a/MASFoundation/Classes/MASProximityLoginDelegate.h b/MASFoundation/Classes/MASProximityLoginDelegate.h deleted file mode 100644 index 2a71e400..00000000 --- a/MASFoundation/Classes/MASProximityLoginDelegate.h +++ /dev/null @@ -1,135 +0,0 @@ -// -// MASProximityLoginDelegate.h -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -@import Foundation; - -#import "MASConstants.h" - -/** - * The enumerated MASBLEServiceState that can indicate what is current status of Device BLE - */ -typedef NS_ENUM(NSInteger, MASBLEServiceState) { - /** - * Unknown - */ - MASBLEServiceStateUnknown = -1, - /** - * BLE Central started - */ - MASBLEServiceStateCentralStarted, - /** - * BLE Central stopped - */ - MASBLEServiceStateCentralStopped, - /** - * BLE Central a device detected - */ - MASBLEServiceStateCentralDeviceDetected, - /** - * BLE Central a device connected - */ - MASBLEServiceStateCentralDeviceConnected, - /** - * BLE Central a device disconnected - */ - MASBLEServiceStateCentralDeviceDisconnected, - /** - * BLE Central service discovered - */ - MASBLEServiceStateCentralServiceDiscovered, - /** - * BLE Central characteristic discovered - */ - MASBLEServiceStateCentralCharacteristicDiscovered, - /** - * BLE Central characteristic written - */ - MASBLEServiceStateCentralCharacteristicWritten, - /** - * BLE Central authorization succeeded - */ - MASBLEServiceStateCentralAuthorizationSucceeded, - /** - * BLE Central authorization failed - */ - MASBLEServiceStateCentralAuthorizationFailed, - /** - * BLE Peripheral subscribed - */ - MASBLEServiceStatePeripheralSubscribed, - /** - * BLE Peripheral unsubscribed - */ - MASBLEServiceStatePeripheralUnsubscribed, - /** - * BLE Peripheral started - */ - MASBLEServiceStatePeripheralStarted, - /** - * BLE Peripheral stopped - */ - MASBLEServiceStatePeripheralStopped, - /** - * BLE Peripheral session authorized - */ - MASBLEServiceStatePeripheralSessionAuthorized, - /** - * BLE Peripheral session notified - */ - MASBLEServiceStatePeripheralSessionNotified -}; - - -@protocol MASProximityLoginDelegate - - -@required - -/** - * SDK callback to this method for user consent to authorize proximity login. - * - * @param completion MASCompletionErrorBlock returns boolean of consent state and error if there is any - * @param deviceName NSString of device name - */ -- (void)handleBLEProximityLoginUserConsent:(MASCompletionErrorBlock _Nullable)completion deviceName:(NSString *_Nonnull)deviceName; - - - -@optional - - - -/** - * Notify the host application that the authorization code has been received from other device. - * Alternatively, developers can subscribe notification, MASDeviceDidReceiveAuthorizationCodeFromProximityLoginNotification, to receive the authorization code. - * - * @param authorizationCode NSString of authorization code - */ -- (void)didReceiveAuthorizationCode:(NSString *_Nonnull)authorizationCode; - - - -/** - * Notify the host application on the state of the BLE proximity login. - * - * @param state enumeration of MASBLEServiceState - */ -- (void)didReceiveBLEProximityLoginStateUpdate:(MASBLEServiceState)state; - - - -/** - * Notify the host application on any error occured while proximity login - * - * @param error NSError of BLE proximity login error - */ -- (void)didReceiveProximityLoginError:(NSError *_Nonnull)error; - -@end diff --git a/MASFoundation/Classes/_private_/MASConstantsPrivate.h b/MASFoundation/Classes/_private_/MASConstantsPrivate.h index 48bd9a4a..f2c10ce0 100644 --- a/MASFoundation/Classes/_private_/MASConstantsPrivate.h +++ b/MASFoundation/Classes/_private_/MASConstantsPrivate.h @@ -15,8 +15,6 @@ #import "MASNetworkingService.h" #import "MASIOrderedDictionary.h" -#import "CBCentralManager+MASPrivate.h" -#import "CBPeripheralManager+MASPrivate.h" #import "CLLocation+MASPrivate.h" #import "CLLocationManager+MASPrivate.h" #import "MASApplication+MASPrivate.h" @@ -37,7 +35,6 @@ // Known internal MASFoundation service UUIDs static NSString *_Nonnull const MASAccessServiceUUID = @"46987e7b-a694-4b44-b02d-694c90ae6952"; -static NSString *_Nonnull const MASBluetoothServiceUUID = @"e1c58e79-3df9-4dcc-b32d-f947762450c8"; static NSString *_Nonnull const MASConfigurationServiceUUID = @"277a5b4a-b665-4ace-b23b-237c80bd7083"; static NSString *_Nonnull const MASConnectaServiceUUID = @"ce68de11-609c-42cb-9fb1-96d661e9ff17"; static NSString *_Nonnull const MASLocationServiceUUID = @"83c5830a-019f-4415-a46c-41470bc28219"; @@ -334,12 +331,6 @@ typedef void (^MASLocationMonitorBlock)(CLLocation *_Nonnull location, MASLocati typedef void (^MASSessionDataTaskCompletionBlock)(NSURLResponse *_Nonnull response, id _Nonnull responseObject, NSError *_Nonnull error); -/** - * Void code block. - */ -typedef void (^MASVoidCodeBlock)(void); - - // // MAS Notification - private // diff --git a/MASFoundation/Classes/_private_/categories/CBCentralManager+MASPrivate.h b/MASFoundation/Classes/_private_/categories/CBCentralManager+MASPrivate.h deleted file mode 100644 index 8ed23525..00000000 --- a/MASFoundation/Classes/_private_/categories/CBCentralManager+MASPrivate.h +++ /dev/null @@ -1,56 +0,0 @@ -// -// CBCentralManager+MASPrivate.h -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import - - -@interface CBCentralManager (MASPrivate) - - - -///-------------------------------------- -/// @name CBCentralManagerState -///-------------------------------------- - -# pragma mark - CBCentralManagerState - - -/** - * Simple, convenient method to determine if the peripheral is in the state 'CBCentralManagerStatePoweredOn'. - * - * This is equivalent to the code 'self.centralManager.state == CBCentralManagerStatePoweredOn'. - * - * @returns YES if powered on, NO if in any other state. - */ -- (BOOL)isPoweredOn; - - -/** - * Retrieve a human readable string value for the current CBCentralManagerState enumeration. - */ -- (NSString *)centralManagerStateAsString; - - -/** - * Retrieve a human readable string value for a CBCentralManagerState enumeration. - * - * @param status The CBCentralManagerState value. - */ -+ (NSString *)centralManagerStateToString:(CBCentralManagerState)state; - - -/** - * Retrieve a MASFoundation NSError object with MASFoundationErrorDomainLocal for its CBCentralManagerState enumeration. - * - * @return NSError object of bluetooth state error; if there no error, the method will return nil. - */ -- (NSError *)centralManagerStateToMASFoundationError; - -@end diff --git a/MASFoundation/Classes/_private_/categories/CBCentralManager+MASPrivate.m b/MASFoundation/Classes/_private_/categories/CBCentralManager+MASPrivate.m deleted file mode 100644 index 8ebcf501..00000000 --- a/MASFoundation/Classes/_private_/categories/CBCentralManager+MASPrivate.m +++ /dev/null @@ -1,141 +0,0 @@ -// -// CBCentralManager+MASPrivate.m -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "CBCentralManager+MASPrivate.h" - -#import "NSError+MASPrivate.h" -#import "MASConstants.h" - -@implementation CBCentralManager (MASPrivate) - - -# pragma mark - CBCentralManagerState - - -/** - * Simple, convenient method to determine if the peripheral is in the state 'CBCentralManagerStatePoweredOn'. - * - * This is equivalent to the code 'self.centralManager.state == CBCentralManagerStatePoweredOn'. - * - * @returns YES if powered on, NO if in any other state. - */ -- (BOOL)isPoweredOn -{ - return (self.state == CBCentralManagerStatePoweredOn); -} - - -/** - * Retrieve a human readable string value for the current CBCentralManagerState enumeration. - */ -- (NSString *)centralManagerStateAsString -{ - return [CBCentralManager centralManagerStateToString:self.state]; -} - - -/** - * Retrieve a human readable string value for a CBCentralManagerState enumeration. - * - * @param status The CBCentralManagerState value. - */ -+ (NSString *)centralManagerStateToString:(CBCentralManagerState)state -{ - // - // Detect state and respond appropriately - // - switch(state) - { - // - // Resetting - // - case CBCentralManagerStateResetting: return @"Resetting"; - - // - // Unsupported - // - case CBCentralManagerStateUnsupported: return @"Unsupported"; - - // - // Unauthorized - // - case CBCentralManagerStateUnauthorized: return @"Unauthorized"; - - // - // Powered Off - // - case CBCentralManagerStatePoweredOff: return @"Powered Off"; - - // - // Powered On - // - case CBCentralManagerStatePoweredOn: return @"Powered On"; - - // - // Default - // - default: return @"Unknown"; - } -} - - -- (NSError *)centralManagerStateToMASFoundationError -{ - // - // Detect state and respond appropriately - // - switch (self.state) { - - // - // Resetting - // - case CBCentralManagerStateResetting: - return [NSError errorForFoundationCode:MASFoundationErrorCodeBLEResetting errorDomain:MASFoundationErrorDomainLocal]; - break; - - // - // Unsupported - // - case CBCentralManagerStateUnsupported: - return [NSError errorForFoundationCode:MASFoundationErrorCodeBLEUnSupported errorDomain:MASFoundationErrorDomainLocal]; - break; - - // - // Unauthorized - // - case CBCentralManagerStateUnauthorized: - return [NSError errorForFoundationCode:MASFoundationErrorCodeBLEUnauthorized errorDomain:MASFoundationErrorDomainLocal]; - break; - - // - // Powered Off - // - case CBCentralManagerStatePoweredOff: - return [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPoweredOff errorDomain:MASFoundationErrorDomainLocal]; - break; - - // - // Powered On - // If the BLE power is on which means no error, return nil. - // - case CBCentralManagerStatePoweredOn: - break; - - // - // Default - // - default: - break; - } - - return nil; -} - -@end diff --git a/MASFoundation/Classes/_private_/categories/CBPeripheralManager+MASPrivate.h b/MASFoundation/Classes/_private_/categories/CBPeripheralManager+MASPrivate.h deleted file mode 100644 index bc1ee6e7..00000000 --- a/MASFoundation/Classes/_private_/categories/CBPeripheralManager+MASPrivate.h +++ /dev/null @@ -1,80 +0,0 @@ -// -// CBPeripheralManager+MASPrivate.h -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import - - -@interface CBPeripheralManager (MASPrivate) - - - -///-------------------------------------- -/// @name CBPeripheralAuthorizationStatus -///-------------------------------------- - -# pragma mark - CBPeripheralAuthorizationStatus - -/** - * Simple, convenient method to determine if the peripheral's application background authorization status is - * 'CBPeripheralManagerAuthorizationStatusAuthorized'. - * - * This is equivalent to the code '[CBPeripheralManager authorizationStatus] == CBPeripheralManagerAuthorizationStatusAuthorized'. - * - * @returns YES if authorized, NO if in any other status. - */ -+ (BOOL)isAuthorizedForBackground; - - -/** - * Retrieve a human readable string value for the current CBPeripheralManagerAuthorizationStatus enumeration. - */ -+ (NSString *)peripheralManagerAuthorizationStatusAsString; - - - -///-------------------------------------- -/// @name CBPeripheralManagerState -///-------------------------------------- - -# pragma mark - CBPeripheralManagerState - - -/** - * Simple, convenient method to determine if the peripheral is in the state 'CBPeripheralManagerStatePoweredOn'. - * - * This is equivalent to the code 'self.peripheralManager.state == CBPeripheralManagerStatePoweredOn'. - * - * @returns YES if powered on, NO if in any other state. - */ -- (BOOL)isPoweredOn; - - -/** - * Retrieve a human readable string value for the current CBPeripheralManagerState enumeration. - */ -- (NSString *)peripheralManagerStateAsString; - - -/** - * Retrieve a human readable string value for a CBPeripheralManagerState enumeration. - * - * @param status The CBPeripheralManagerState value. - */ -+ (NSString *)peripheralManagerStateToString:(CBPeripheralManagerState)state; - - -/** - * Retrieve a MASFoundation NSError object with MASFoundationErrorDomainLocal for its CBPeripheralManagerState enumeration. - * - * @return NSError object of bluetooth state error; if there no error, the method will return nil. - */ -- (NSError *)peripheralManagerStateToMASFoundationError; - -@end diff --git a/MASFoundation/Classes/_private_/categories/CBPeripheralManager+MASPrivate.m b/MASFoundation/Classes/_private_/categories/CBPeripheralManager+MASPrivate.m deleted file mode 100644 index 7b3c4525..00000000 --- a/MASFoundation/Classes/_private_/categories/CBPeripheralManager+MASPrivate.m +++ /dev/null @@ -1,162 +0,0 @@ -// -// CBPeripheralManager+MASPrivate.m -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "CBPeripheralManager+MASPrivate.h" - -#import "NSError+MASPrivate.h" - -@implementation CBPeripheralManager (MASPrivate) - - -# pragma mark - CBPeripheralAuthorizationStatus - -+ (BOOL)isAuthorizedForBackground -{ - return ([CBPeripheralManager authorizationStatus] == CBPeripheralManagerAuthorizationStatusAuthorized); -} - - -+ (NSString *)peripheralManagerAuthorizationStatusAsString -{ - // - // Detect status and respond appropriately - // - switch([CBPeripheralManager authorizationStatus]) - { - // - // Authorized - // - case CBPeripheralManagerAuthorizationStatusAuthorized: return @"Authorized"; - - // - // Denied - // - case CBPeripheralManagerAuthorizationStatusDenied: return @"Denied"; - - // - // Restricted - // - case CBPeripheralManagerAuthorizationStatusRestricted: return @"Restricted"; - - // - // Default (not determined) - // - default: return @"Not Determined"; - } -} - - -# pragma mark - CBPeripheralManagerState - -- (BOOL)isPoweredOn -{ - return (self.state == CBPeripheralManagerStatePoweredOn); -} - - -- (NSString *)peripheralManagerStateAsString -{ - return [CBPeripheralManager peripheralManagerStateToString:self.state]; -} - - -+ (NSString *)peripheralManagerStateToString:(CBPeripheralManagerState)state -{ - // - // Detect state and respond appropriately - // - switch(state) - { - // - // Resetting - // - case CBPeripheralManagerStateResetting: return @"Resetting"; - - // - // Unsupported - // - case CBPeripheralManagerStateUnsupported: return @"Unsupported"; - - // - // Unauthorized - // - case CBPeripheralManagerStateUnauthorized: return @"Unauthorized"; - - // - // Powered Off - // - case CBPeripheralManagerStatePoweredOff: return @"Powered Off"; - - // - // Powered On - // - case CBPeripheralManagerStatePoweredOn: return @"Powered On"; - - // - // Default - // - default: return @"Unknown"; - } -} - - -- (NSError *)peripheralManagerStateToMASFoundationError -{ - // - // Detect state and respond appropriately - // - switch (self.state) { - - // - // Resetting - // - case CBCentralManagerStateResetting: - return [NSError errorForFoundationCode:MASFoundationErrorCodeBLEResetting errorDomain:MASFoundationErrorDomainLocal]; - break; - - // - // Unsupported - // - case CBCentralManagerStateUnsupported: - return [NSError errorForFoundationCode:MASFoundationErrorCodeBLEUnSupported errorDomain:MASFoundationErrorDomainLocal]; - break; - - // - // Unauthorized - // - case CBCentralManagerStateUnauthorized: - return [NSError errorForFoundationCode:MASFoundationErrorCodeBLEUnauthorized errorDomain:MASFoundationErrorDomainLocal]; - break; - - // - // Powered Off - // - case CBCentralManagerStatePoweredOff: - return [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPoweredOff errorDomain:MASFoundationErrorDomainLocal]; - break; - - // - // Powered On - // If the BLE power is on which means no error, return nil. - // - case CBCentralManagerStatePoweredOn: - break; - - // - // Default - // - default: - break; - } - - return nil; -} - -@end diff --git a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h index cc1b760e..91029b35 100644 --- a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h +++ b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h @@ -639,24 +639,6 @@ + (NSError *)errorInvalidEndpoint; -/** - * Create MASFoundationErrorDomainLocal NSError for MASFoundationErrorCodeProximityLoginAuthorizationInProgress. - * - * @return Returns an NSError instance with the domain MASFoundationErrorDomainLocal and - * error MASFoundationErrorCodeProximityLoginAuthorizationInProgress. - */ -+ (NSError *)errorProximityLoginAuthorizationInProgress; - - -/** - * Create MASFoundationErrorDomainLocal NSError for MASFoundationErrorCodeProximityLoginInvalidAuthorizeURL. - * - * @return Returns an NSError instance with the domain MASFoundationErrorDomainLocal and - * error MASFoundationErrorCodeProximityLoginInvalidAuthorizeURL - */ -+ (NSError *)errorProximityLoginInvalidAuthroizeURL; - - /** * Create MASFoundationErrorDomainLocal NSError for MASFoundationErrorCodeBBANotEnabled. * diff --git a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m index a1733719..3219ff6d 100644 --- a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m +++ b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m @@ -828,18 +828,6 @@ + (NSError *)errorInvalidEndpoint } -+ (NSError *)errorProximityLoginAuthorizationInProgress -{ - return [self errorForFoundationCode:MASFoundationErrorCodeProximityLoginAuthorizationInProgress errorDomain:MASFoundationErrorDomainLocal]; -} - - -+ (NSError *)errorProximityLoginInvalidAuthroizeURL -{ - return [self errorForFoundationCode:MASFoundationErrorCodeProximityLoginInvalidAuthorizeURL errorDomain:MASFoundationErrorDomainLocal]; -} - - + (NSError *)errorBrowserBasedAuthenticaionNotEnabled { return [self errorForFoundationCode:MASFoundationErrorCodeBBANotEnabled errorDomain:MASFoundationErrorDomainLocal]; @@ -1086,34 +1074,7 @@ + (NSString *)descriptionForFoundationErrorCode:(MASFoundationErrorCode)errorCod case MASFoundationErrorCodeEnterpriseBrowserNativeAppDoesNotExist: return @"Native app does not exist"; case MASFoundationErrorCodeEnterpriseBrowserNativeAppCannotOpen: return @"Error loading the native app"; case MASFoundationErrorCodeEnterpriseBrowserAppDoesNotExist: return @"Enterprise Browser App does not exist"; - - // - // BLE - // - case MASFoundationErrorCodeBLEUnknownState: return @"Unknown error occurred while enabling BLE Central"; - case MASFoundationErrorCodeBLEPoweredOff: return @"Bluetooth is currently off"; - case MASFoundationErrorCodeBLEResetting: return @"Bluetooth connection is momentarily lost; resetting the connection"; - case MASFoundationErrorCodeBLEUnauthorized: return @"Bluetooth feature is not authorized for this application"; - case MASFoundationErrorCodeBLEUnSupported: return @"Bluetooth feature is not supported"; - case MASFoundationErrorCodeBLEDelegateNotDefined: return @"MASDevice's BLE delegate is not defined. Delegate is mandatory to acquire permission from the user."; - case MASFoundationErrorCodeBLEAuthorizationFailed: return @"BLE authorization failed due to invalid or expired authorization request."; - case MASFoundationErrorCodeBLECentralDeviceNotFound: return @"BLE authorization failed due to no subscribed central device."; - case MASFoundationErrorCodeBLERSSINotInRange: return @"BLE RSSI is not in range. Please refer to msso_config.json for BLE RSSI configuration."; - case MASFoundationErrorCodeBLEAuthorizationPollingFailed: return @"BLE authorization failed while polling authorization code from gateway."; - case MASFoundationErrorCodeBLEInvalidAuthenticationProvider: return @"BLE authorization failed due to invalid authentication provider."; - case MASFoundationErrorCodeBLECentral: return @"BLE Central error encountered in CBCentral with specific reason in userInfo."; - case MASFoundationErrorCodeBLEPeripheral: return @"BLE Peripheral error encountered while discovering, or connecting central device with specific reason in userInfo."; - case MASFoundationErrorCodeBLEPeripheralServices: return @"BLE Peripheral error encountered while discovering or connecting peripheral services with specific reason in userInfo."; - case MASFoundationErrorCodeBLEPeripheralCharacteristics: return @"BLE Peripheral error encountered while discovering, connecting, or writing peripheral service's characteristics with specific reason in userInfo."; - - // - // Session Sharing - // - case MASFoundationErrorCodeProximityLoginAuthorizationInProgress: return @"Authorization is currently in progress through proximity login."; - case MASFoundationErrorCodeQRCodeProximityLoginAuthorizationPollingFailed: return @"QR Code proximity login authentication failed with specific information on userInfo."; - case MASFoundationErrorCodeProximityLoginInvalidAuthenticationURL: return @"Invalid authentication URL is provided for proximity login."; - case MASFoundationErrorCodeProximityLoginInvalidAuthorizeURL: return @"Invalid authorization url."; - + // // JWT // diff --git a/MASFoundation/Classes/_private_/models/MASProximityLoginQRCode+MASPrivate.h b/MASFoundation/Classes/_private_/models/MASProximityLoginQRCode+MASPrivate.h deleted file mode 100644 index ddefb24f..00000000 --- a/MASFoundation/Classes/_private_/models/MASProximityLoginQRCode+MASPrivate.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// MASProximityLoginQRCode+MASPrivate.h -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import - -@interface MASProximityLoginQRCode (MASPrivate) - -# pragma mark - Lifecycle - -/** - * Init the object with given values. - * Property values cannot be changed once it is initialized. - * - * @param provider MASAuthenticationProvider object with authorizationURL and pollingURL for QR Code. - * @param initDelay NSNumber of initial delay in seconds to start making a request to poll for authorization. - * @param pollingInterval NSNumber of interval for polling requests. - * @param pollingLimit NSNumber of limit counter for number of polling requests. - * - * @return MASProximityLoginQRCode object - */ -- (instancetype)initPrivateWithAuthenticationUrl:(NSString *)authUrl pollingUrl:(NSString *)pollingUrl initialDelay:(NSNumber *)initDelay pollingInterval:(NSNumber *)pollingInterval pollingLimit:(NSNumber *)pollingLimit; - - -# pragma mark - Start/Stop displaying QR Code image : Private - -/** - * Generates QR Code image for proximity login based on provided authentication provider and starts polling request for authorization. - * Upon successful start display, NSNotification with notification name, MASProximityLoginQRCodeDidStartDisplayingQRCodeImage, will be sent. - * - * @return UIImage of QR Code. - */ -- (UIImage *)startPrivateDisplayingQRCodeImageForProximityLogin; - - -/** - * Stops displaying QR Code image for proximity login based on provided polling configuration. - * Upon successful stop display, NSNotification with notification name, MASProximityLoginQRCodeDidStopDisplayingQRCodeImage, will be sent. - */ -- (void)stopPrivateDisplayingQRCodeImageForProximityLogin; - - -@end diff --git a/MASFoundation/Classes/_private_/models/MASProximityLoginQRCode+MASPrivate.m b/MASFoundation/Classes/_private_/models/MASProximityLoginQRCode+MASPrivate.m deleted file mode 100644 index 3a746975..00000000 --- a/MASFoundation/Classes/_private_/models/MASProximityLoginQRCode+MASPrivate.m +++ /dev/null @@ -1,279 +0,0 @@ -// -// MASProximityLoginQRCode+MASPrivate.m -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "MASProximityLoginQRCode+MASPrivate.h" - -#import -#import "MASAccessService.h" -#import "MASNetworkingService.h" -#import "NSError+MASPrivate.h" - -@implementation MASProximityLoginQRCode (MASPrivate) - - -# pragma mark - Lifecycle - -- (instancetype)initPrivateWithAuthenticationUrl:(NSString *)authUrl pollingUrl:(NSString *)pollingUrl initialDelay:(NSNumber *)initDelay pollingInterval:(NSNumber *)pollingInterval pollingLimit:(NSNumber *)pollingLimit -{ - self = [super init]; - - if (!self) { - - return nil; - } - - [self setValue:authUrl forKey:@"authenticationUrl"]; - [self setValue:pollingUrl forKey:@"pollUrl"]; - [self setValue:initDelay forKey:@"pollingDelay"]; - [self setValue:pollingInterval forKey:@"pollingInterval"]; - [self setValue:pollingLimit forKey:@"pollingLimit"]; - - return self; -} - - -# pragma mark - Start/Stop displaying QR Code image : Private - -- (UIImage *)startPrivateDisplayingQRCodeImageForProximityLogin -{ - // Convert NSString to NSData - NSData *stringData = [self.authenticationUrl dataUsingEncoding:NSUTF8StringEncoding]; - - UIImage *qrCodeImage = nil; - - @try { - CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"]; - [qrFilter setValue:stringData forKey:@"inputMessage"]; - [qrFilter setValue:@"H" forKey:@"inputCorrectionLevel"]; - - CGImageRef cgImage = [[CIContext contextWithOptions:nil] createCGImage:qrFilter.outputImage fromRect:qrFilter.outputImage.extent]; - - UIGraphicsBeginImageContext(CGSizeMake(qrFilter.outputImage.extent.size.width * [[UIScreen mainScreen] scale], qrFilter.outputImage.extent.size.width * [[UIScreen mainScreen] scale])); - CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextSetInterpolationQuality(context, kCGInterpolationNone); - CGContextDrawImage(context, CGContextGetClipBoundingBox(context), cgImage); - // Get the image out - qrCodeImage = UIGraphicsGetImageFromCurrentImageContext(); - // Tidy up - UIGraphicsEndImageContext(); - CGImageRelease(cgImage); - - [self setValue:[NSNumber numberWithBool:YES] forKey:@"isPolling"]; - - // - // Start polling - // - dispatch_time_t pollTimer = dispatch_time(DISPATCH_TIME_NOW, [self.pollingDelay intValue] * NSEC_PER_SEC); - dispatch_after(pollTimer, dispatch_get_main_queue(), ^{ - - // - // Call polling method - // - [self makePollingRequest]; - - // - // Send notification - // - dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:MASProximityLoginQRCodeDidStartDisplayingQRCodeImage object:nil userInfo:nil]; - }); - }); - - } - @catch (NSException *exception) { - NSLog(@"exception : %@",exception); - } - - return qrCodeImage; -} - - -- (void)stopPrivateDisplayingQRCodeImageForProximityLogin -{ - [self setValue:[NSNumber numberWithBool:NO] forKey:@"isPolling"]; - - // - // Send notification that polling stopped - // - dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:MASProximityLoginQRCodeDidStopDisplayingQRCodeImage object:nil userInfo:nil]; - }); -} - - -# pragma mark - Private - -- (void)makePollingRequest -{ - - // - // If stop request was made - // - if (!self.isPolling) - { - return; - } - - // - // If authenticationUrl is being used with other session sharing (BLE), ignore it - // - if ([MASDevice currentDevice].isBeingAuthorized) - { - return; - } - - // - // Increment the polling counter - // - [self setValue:[NSNumber numberWithInt:self.currentPollingCounter+1] forKey:@"currentPollingCounter"]; - - NSString *pollPath = [self.pollUrl stringByReplacingOccurrencesOfString:[MASConfiguration currentConfiguration].gatewayUrl.absoluteString withString:@""]; - - __block MASProximityLoginQRCode *blockSelf = self; - - // - // Instead of making a request through [MAS getFrom:..] public interface, call directly the networking service to bypass validation process - // - [[MASNetworkingService sharedService] getFrom:pollPath - withParameters:nil - andHeaders:nil - requestType:MASRequestResponseTypeWwwFormUrlEncoded - responseType:MASRequestResponseTypeJson - completion:^(NSDictionary *responseInfo, NSError *error) { - - if (error) - { - NSError * pollError = [NSError errorForFoundationCode:MASFoundationErrorCodeQRCodeProximityLoginAuthorizationPollingFailed info:error.userInfo errorDomain:MASFoundationErrorDomain]; - // - // Stop polling and displaying the QR Code image - // - [blockSelf stopPrivateDisplayingQRCodeImageForProximityLogin]; - - // - // If MASDevice's BLE delegate is set, and method is implemented, notify the delegate - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(didReceiveProximityLoginError:)]) - { - [[MASDevice proximityLoginDelegate] didReceiveProximityLoginError:pollError]; - } - - // - // Send the notification with authorization code - // - [[NSNotificationCenter defaultCenter] postNotificationName:MASDeviceDidReceiveErrorFromProximityLoginNotification object:pollError]; - } - else { - - // - // Validate PKCE state value - // Only validates state when it is returned from the server for Proximity Login - // - if ([responseInfo objectForKey:MASPKCEStateRequestResponseKey]) - { - NSString *responseState = [responseInfo objectForKey:MASPKCEStateRequestResponseKey]; - NSString *requestState = [[MASAccessService sharedService].currentAccessObj retrievePKCEState]; - - NSError *pkceError = nil; - - // - // If response or request state is nil, invalid request and/or response - // - if (responseState == nil || requestState == nil) - { - pkceError = [NSError errorInvalidAuthorization]; - } - // - // verify that the state in the response is the same as the state sent in the request - // - else if (![[responseInfo objectForKey:MASPKCEStateRequestResponseKey] isEqualToString:[[MASAccessService sharedService].currentAccessObj retrievePKCEState]]) - { - pkceError = [NSError errorInvalidAuthorization]; - } - - // - // If the validation fail, notify - // - if (pkceError) - { - // - // Stop polling and displaying the QR Code image - // - [blockSelf stopPrivateDisplayingQRCodeImageForProximityLogin]; - - // - // If MASDevice's BLE delegate is set, and method is implemented, notify the delegate - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(didReceiveProximityLoginError:)]) - { - [[MASDevice proximityLoginDelegate] didReceiveProximityLoginError:pkceError]; - } - - // - // Send the notification with authorization code - // - [[NSNotificationCenter defaultCenter] postNotificationName:MASDeviceDidReceiveErrorFromProximityLoginNotification object:pkceError]; - - return; - } - } - - // - // Retrieve authorization code - // - NSString *code = [responseInfo[MASResponseInfoBodyInfoKey] valueForKey:@"code"]; - - if (code == nil || [code length] == 0) - { - - // - // re trigger polling if no authorization code is found; if the counter did not exceed the limit - // - - if (blockSelf.currentPollingCounter < [blockSelf.pollingLimit intValue]) - { - dispatch_time_t pollTimer = dispatch_time(DISPATCH_TIME_NOW, [self.pollingDelay intValue] * NSEC_PER_SEC); - dispatch_after(pollTimer, dispatch_get_main_queue(), ^{ - - [blockSelf makePollingRequest]; - }); - } - } - else { - - // - // If the delegate is set, send the authorization code to delegation method - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(didReceiveAuthorizationCode:)]) - { - [[MASDevice proximityLoginDelegate] didReceiveAuthorizationCode:code]; - } - - // - // Send the notification with authoriation code - // - [[NSNotificationCenter defaultCenter] postNotificationName:MASDeviceDidReceiveAuthorizationCodeFromProximityLoginNotification object:@{@"code" : code}]; - - } - - // - // If the current polling count exceeds pollLimit - // - if (blockSelf.currentPollingCounter >= [blockSelf.pollingLimit intValue]) - { - // - // Stop polling and displaying the QR Code image - // - [blockSelf stopPrivateDisplayingQRCodeImageForProximityLogin]; - } - } - }]; -} - -@end diff --git a/MASFoundation/Classes/_private_/services/MASServiceRegistry.m b/MASFoundation/Classes/_private_/services/MASServiceRegistry.m index 9530b98a..c34ce61b 100644 --- a/MASFoundation/Classes/_private_/services/MASServiceRegistry.m +++ b/MASFoundation/Classes/_private_/services/MASServiceRegistry.m @@ -105,7 +105,6 @@ + (void)initialize [ MASAccessServiceUUID, MASConfigurationServiceUUID, - MASBluetoothServiceUUID, MASLocationServiceUUID, MASFileServiceUUID, MASModelServiceUUID, diff --git a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothCentral.h b/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothCentral.h deleted file mode 100644 index 9f9f5231..00000000 --- a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothCentral.h +++ /dev/null @@ -1,63 +0,0 @@ -// -// MASBluetoothCentral.h -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import - - -@interface MASBluetoothCentral : MASObject - - - -///-------------------------------------- -/// @name Lifecycle -///-------------------------------------- - -# pragma mark - Lifecycle - -/** - * Create a bluetooth central. - * - * @param serviceUUID The peripheral's service UUID. - * @param characteristicUUI The peripheral's characteristic UUID. - * @param sessionId The session identifier. - * @return Returns the newly initialized 'MASBluetoothCentral'. - */ -+ (id)centralWithServiceUUID:(NSString *)serviceUUID characteristicUUID:(NSString *)characteristicUUID; - - - -///-------------------------------------- -/// @name Starting & Stopping -///-------------------------------------- - -# pragma mark - Starting and Stopping - -/** - * Start the central scanning for peripherals. - */ -- (void)startScanning; - - - -/** - * Start the central scanning for peripherals with specific authentication provider - * - * @param provider MASAuthneticationProvider to scan - */ -- (void)startScanningWithAuthenticationProvider:(MASAuthenticationProvider *)provider; - - - -/** - * Stop the central from scanning for peripherals. - */ -- (void)stopScanning; - -@end diff --git a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothCentral.m b/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothCentral.m deleted file mode 100644 index 36d7fded..00000000 --- a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothCentral.m +++ /dev/null @@ -1,867 +0,0 @@ -// -// MASBluetoothCentral.m -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "MASBluetoothCentral.h" - -#import -#import "MASAccessService.h" -#import "MASBluetoothService.h" -#import "MASConstantsPrivate.h" -#import "MASNetworkingService.h" - -@interface MASBluetoothCentral () - - -# pragma mark - Properties - -@property (nonatomic, strong, readonly) CBCentralManager *centralManager; -@property (nonatomic, strong, readonly) NSMutableArray *peripherals; - -@property (nonatomic, copy, readonly) NSString *serviceUUID; -@property (nonatomic, copy, readonly) NSString *characteristicUUID; -@property (nonatomic, copy, readonly) MASAuthenticationProvider *provider; - -@property (nonatomic, strong) NSRecursiveLock *lock; - -@property (nonatomic, strong) MASVoidCodeBlock initializeCodeBlock; - -@end - - -@implementation MASBluetoothCentral - - -# pragma mark - Central - -+ (id)centralWithServiceUUID:(NSString *)serviceUUID characteristicUUID:(NSString *)characteristicUUID -{ - // todo: validate the UUIDs??? - - MASBluetoothCentral *central = [[MASBluetoothCentral alloc] initWithServiceUUID:serviceUUID characteristicUUID:characteristicUUID]; - - return central; -} - - -# pragma mark - Private - -- (void)updateBLEState:(MASBLEServiceState)state -{ - // - // If MASDevice's BLE delegate is set, and method is implemented, notify the delegate - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(didReceiveBLEProximityLoginStateUpdate:)]) - { - [[MASDevice proximityLoginDelegate] didReceiveBLEProximityLoginStateUpdate:state]; - } -} - - -- (void)notifyErrorForBLEState:(NSError *)error -{ - // - // If MASDevice's BLE delegate is set, and method is implemented, notify the delegate - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(didReceiveProximityLoginError:)]) - { - [[MASDevice proximityLoginDelegate] didReceiveProximityLoginError:error]; - } -} - - -- (void)sendAuthURLWithAuthenticationProvider:(MASAuthenticationProvider *)authProvider characteristic:(CBCharacteristic *)characteristic -{ - // - // Notify that the device is being authorized to avoid duplicate calls - // - [[MASDevice currentDevice] setIsBeingAuthorized:YES]; - - // - // Prepare auth data request to transfer with given auth provider url and discovered characteristic - // - NSDictionary *authDictionary = @{@"provider_url" : authProvider.authenticationUrl.absoluteString , @"device_name" : [[UIDevice currentDevice] name]}; - NSData *authData = [NSJSONSerialization dataWithJSONObject:authDictionary options:NSJSONWritingPrettyPrinted error:nil]; - - NSData *authRequest = [[[NSString alloc] initWithBytes:[authData bytes] length:[authData length] encoding:NSUTF8StringEncoding] dataUsingEncoding:NSUTF8StringEncoding]; - - NSInteger sendDataIndex = 0; - - BOOL isSending = YES; - - while (isSending) - { - CBPeripheral *discoveredPeripheral = [self.peripherals objectAtIndex:0]; - - NSInteger sendDataAmount = authRequest.length - sendDataIndex; - - // - // BLE transfer data limit to 20 byes - // - if (sendDataAmount > 20) - { - sendDataAmount = 20; - } - - // - // Data for for specific amount - // - NSData *chunk = [NSData dataWithBytes:authRequest.bytes+sendDataIndex length:sendDataAmount]; - - // - // Send value to disvered peripheral's characteristic - // - [discoveredPeripheral writeValue:chunk forCharacteristic:characteristic type:CBCharacteristicWriteWithoutResponse]; - - sendDataIndex += sendDataAmount; - - // - // If all data was sent, notify EOM - // - if (sendDataIndex >= authRequest.length) - { - [discoveredPeripheral writeValue:[@"EOM" dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:characteristic type:CBCharacteristicWriteWithoutResponse]; - - // - // Notify delegate - // - [self updateBLEState:MASBLEServiceStateCentralCharacteristicWritten]; - - isSending = NO; - } - } -} - - -- (void)pollAuthorizationCode -{ - - - NSString *pollURL = _provider.pollUrl.absoluteString; - - if ([pollURL isEmpty]) - { - NSError *invalidURLError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEAuthorizationFailed errorDomain:MASFoundationErrorDomainLocal]; - [self notifyErrorForBLEState:invalidURLError]; - - return; - } - - NSString *pollPath = [pollURL stringByReplacingOccurrencesOfString:[MASConfiguration currentConfiguration].gatewayUrl.absoluteString - withString:@""]; - - // - // Instead of making a request through [MAS getFrom:..] public interface, call directly the networking service to bypass validation process - // - [[MASNetworkingService sharedService] getFrom:pollPath - withParameters:nil - andHeaders:nil - requestType:MASRequestResponseTypeWwwFormUrlEncoded - responseType:MASRequestResponseTypeJson - completion:^(NSDictionary *responseInfo, NSError *error) { - // - // Notify that the device is done with authorization - // - [[MASDevice currentDevice] setIsBeingAuthorized:NO]; - - if (error) - { - NSError * pollError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEAuthorizationPollingFailed info:responseInfo errorDomain:MASFoundationErrorDomain]; - [self notifyErrorForBLEState:pollError]; - - // - // Send the notification with authorization code - // - [[NSNotificationCenter defaultCenter] postNotificationName:MASDeviceDidReceiveErrorFromProximityLoginNotification object:pollError]; - } - else { - - // - // Validate PKCE state value - // Only validates state when it is returned from the server for Proximity Login - // - if ([responseInfo objectForKey:MASPKCEStateRequestResponseKey]) - { - NSString *responseState = [responseInfo objectForKey:MASPKCEStateRequestResponseKey]; - NSString *requestState = [[MASAccessService sharedService].currentAccessObj retrievePKCEState]; - - NSError *pkceError = nil; - - // - // If response or request state is nil, invalid request and/or response - // - if (responseState == nil || requestState == nil) - { - pkceError = [NSError errorInvalidAuthorization]; - } - // - // verify that the state in the response is the same as the state sent in the request - // - else if (![[responseInfo objectForKey:MASPKCEStateRequestResponseKey] isEqualToString:[[MASAccessService sharedService].currentAccessObj retrievePKCEState]]) - { - pkceError = [NSError errorInvalidAuthorization]; - } - - // - // If the validation fail, notify - // - if (pkceError) - { - - // - // If MASDevice's BLE delegate is set, and method is implemented, notify the delegate - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(didReceiveProximityLoginError:)]) - { - [[MASDevice proximityLoginDelegate] didReceiveProximityLoginError:pkceError]; - } - - // - // Send the notification with authorization code - // - [[NSNotificationCenter defaultCenter] postNotificationName:MASDeviceDidReceiveErrorFromProximityLoginNotification object:pkceError]; - - return; - } - } - - // - // Retrieve authorization code - // - NSString *code = [responseInfo[MASResponseInfoBodyInfoKey] valueForKey:@"code"]; - - // - // If the delegate is set, send the authorization code to delegation method - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(didReceiveAuthorizationCode:)]) - { - [[MASDevice proximityLoginDelegate] didReceiveAuthorizationCode:code]; - } - - // - // Send the notification with authoriation code - // - [[NSNotificationCenter defaultCenter] postNotificationName:MASDeviceDidReceiveAuthorizationCodeFromProximityLoginNotification object:@{@"code" : code}]; - - } - }]; -} - - -# pragma mark - Creating a new peripheral - -- (id)init -{ - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"init is not a valid initializer, please use a factory method" - userInfo:nil]; - return nil; -} - - -- (id)initWithServiceUUID:(NSString *)serviceUUID characteristicUUID:(NSString *)characteristicUUID -{ - self = [super init]; - if(self) - { - - _serviceUUID = serviceUUID; - _characteristicUUID = characteristicUUID; - - _peripherals = [NSMutableArray new]; - - _lock = [[NSRecursiveLock alloc] init]; - } - - return self; -} - - -- (NSString *)debugDescription -{ - return [NSString stringWithFormat:@"(%@) central manager state is: %@\n\n known peripheral count: %ld", - [self class], [self.centralManager centralManagerStateAsString], (unsigned long)self.peripherals.count]; -} - - -# pragma mark - Starting and Stopping - -/** - * Start the central scanning for peripherals. - */ -- (void)startScanning -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - - __block MASBluetoothCentral *blockSelf = self; - - MASVoidCodeBlock initializeCodeBlock = ^{ - - // - // If the central manager exists, and is not scanning - // - if (blockSelf.centralManager && ![blockSelf.centralManager isScanning]) - { - // - // If the central manager is not powered on and/or is in a state it can't search - // - if (![blockSelf.centralManager isPoweredOn]) - { - NSError *bleError = [blockSelf.centralManager centralManagerStateToMASFoundationError]; - - // - // Notify delegate - // - [blockSelf notifyErrorForBLEState:bleError]; - } - else { - @try { - // - // Start central scanning for peripherals - // - [blockSelf.centralManager scanForPeripheralsWithServices:@[ - [ - CBUUID UUIDWithString:_serviceUUID] - ] - options:@ - { - CBCentralManagerScanOptionAllowDuplicatesKey : @NO - }]; - - [blockSelf updateBLEState:MASBLEServiceStateCentralStarted]; - } - @catch (NSException *exception) { - - // - // Catech an exception - // - NSDictionary *exceptionInfo = @{@"reason" : exception.reason , @"name" : exception.name}; - - // - // Conver the exception with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheral info:exceptionInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [blockSelf notifyErrorForBLEState:masError]; - } - } - } - - blockSelf.initializeCodeBlock = nil; - }; - - // - // If there is no central manager instantiated, so initialize the central manager - // - if (!_centralManager) - { - //DLog(@"\n\nError: no central manager detected!!\n\n"); - _centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; - _centralManager.delegate = self; - _initializeCodeBlock = initializeCodeBlock; - } - else { - - initializeCodeBlock(); - } -} - - -- (void)startScanningWithAuthenticationProvider:(MASAuthenticationProvider *)provider -{ - - // - // If no auth provider is set, notify delegate - // Authentication provider should have both auth url and poll url - // - if (!provider && !provider.authenticationUrl && !provider.pollUrl) - { - NSError *invalidAuthError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEInvalidAuthenticationProvider errorDomain:MASFoundationErrorDomainLocal]; - [self notifyErrorForBLEState:invalidAuthError]; - - return; - } - - _provider = provider; - - [self startScanning]; -} - - -/** - * Stop the central from scanning for peripherals. - */ -- (void)stopScanning -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - - // - // If there is no central manager instantiated stop here - // - if(!self.centralManager) - { - //DLog(@"\n\nError: no central manager detected!!\n\n"); - - return; - } - - // - // For connected peripherals, search for characteristics that are currently subscribing - // - for (CBPeripheral *peripheral in self.peripherals) - { - // - // Loop through services - // - for (CBService *service in peripheral.services) - { - // - // Loop through characteristics - // - for (CBCharacteristic *characteristic in service.characteristics) - { - // - // If characteristics UUID matches with our UUID and it is currently notifying, stop - // - if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:_characteristicUUID]] && characteristic.isNotifying) - { - // - // Unsubscribe characteristics - // - [peripheral setNotifyValue:NO forCharacteristic:characteristic]; - } - } - } - - // - // Cancel peripheral connection - // - [self.centralManager cancelPeripheralConnection:peripheral]; - } - - // - // set being authroized status to false - // - [[MASDevice currentDevice] setIsBeingAuthorized:NO]; - - // - // Stop central scanning for peripherals - // - [self.centralManager stopScan]; - - // - // Notify delegate - // - [self updateBLEState:MASBLEServiceStateCentralDeviceDisconnected]; -} - - -# pragma mark - CBCentralManagerDelegate - -- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI -{ - //DLog(@"\n\ndiscovered peripheral: %@ for central:\n\n%@\n\n", peripheral.name, [self debugDescription]); - - // - // If RSSI is not in reasonable range defined in msso_config.json, reject it - // - if (RSSI.integerValue < [[MASConfiguration currentConfiguration] bluetoothRssi]) - { - NSError *error = [NSError errorForFoundationCode:MASFoundationErrorCodeBLERSSINotInRange errorDomain:MASFoundationErrorDomainLocal]; - [self notifyErrorForBLEState:error]; - - return; - } - - // - // Detect a duplicate and ignore if found - // - if([self.peripherals containsObject:peripheral]) - { - //DLog(@"\n\nDetected duplicate peripheral: %@\n\n", peripheral.name); - - // - // Search only for services that match our UUID - // - [peripheral discoverServices:@[[CBUUID UUIDWithString: _serviceUUID]]]; - - return; - } - - // - // Stop scanning once peripheral discovered - // - [self.centralManager stopScan]; - - // - // Device detected - // - [self updateBLEState:MASBLEServiceStateCentralDeviceDetected]; - - // - // Stop scanning - // - [self updateBLEState:MASBLEServiceStateCentralStopped]; - - // - // Add the discovered peripheral - // - [peripheral setDelegate:self]; - [self.peripherals addObject:peripheral]; - - // - // Connect the peripheral - // - [central connectPeripheral:peripheral options:nil]; -} - - -- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral -{ - //DLog(@"\n\nconnected to peripheral: %@ for central:\n\n%@\n\n", peripheral.name, [self debugDescription]); - - [self updateBLEState:MASBLEServiceStateCentralDeviceConnected]; - - // - // Search only for services that match our UUID - // - [peripheral discoverServices:@[[CBUUID UUIDWithString: _serviceUUID]]]; -} - - -- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error -{ - //DLog(@"\n\nfailed to connect to peripheral: %@ for central:\n\n%@ with error:\n\n%@\n\n", peripheral.name, [self debugDescription], [error localizedDescription]); - - if (error) - { - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheral info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - } - - // - // Remove the peripheral - // - [self.peripherals removeObject:peripheral]; -} - - -- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error -{ - //DLog(@"\n\ndisconnected from peripheral: %@ for central:\n\n%@\n\n with error:\n\n%@\n\n", peripheral.name, [self debugDescription], [error localizedDescription]); - - if (error) - { - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheral info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - } - - // - // Remove the peripheral - // - [self.peripherals removeObject:peripheral]; - - // - // Notify delegate - // - [self updateBLEState:MASBLEServiceStateCentralDeviceDisconnected]; -} - - -- (void)centralManagerDidUpdateState:(CBCentralManager *)central -{ -// DLog(@"\n%@\n\n", [self debugDescription]); - if (_initializeCodeBlock) - { - _initializeCodeBlock(); - } -} - - -- (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary *)stateInfo -{ - //DLog(@"\n\ncalled with restored state: %@\n\n", stateInfo); -} - - -# pragma mark - CBPeripheralDelegate -/* -- (void)peripheralDidUpdateName:(CBPeripheral *)peripheral -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); -} -*/ - -# pragma mark - CBPeripheralDelegate (Services) - -- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error -{ - //DLog(@"\n\ncalled with peripheral: %@, services: %@ with error:\n\n%@\n\n", peripheral.name, peripheral.services, [error localizedDescription]); - - // - // Error - // - if(error) - { - //DLog(@"\n\nError discovering services:\n\n%@\n\n", [error localizedDescription]); - - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLECentral info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - - return; - } - - // - // Iterate the newly filled peripheral.services array, just in case there's more than one. - // - for (CBService *service in peripheral.services) - { - //DLog(@"\n\n found service: %@\n\n", [service debugDescription]); - - [self updateBLEState:MASBLEServiceStateCentralServiceDiscovered]; - - [peripheral discoverCharacteristics:@[[CBUUID UUIDWithString:_characteristicUUID]] forService:service]; - } -} - - -- (void)peripheral:(CBPeripheral *)peripheral didDiscoverIncludedServicesForService:(CBService *)service error:(NSError *)error -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - - if (error) - { - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheralServices info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - } -} - -/* -- (void)peripheral:(CBPeripheral *)peripheral didModifyServices:(NSArray *)invalidatedServices -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); -} -*/ - -# pragma mark - CBPeripheralDelegate (Characteristics) - -- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error -{ - //DLog(@"called with peripheral: %@\n\n%@\n\n with error:\n\n%@\n\n", peripheral.name, [self debugDescription], [error localizedDescription]); - - // - // Error - // - if(error) - { - //DLog(@"\n\nError when discovering service from peripheral: %@ characteristics:\n\n%@\n\n", service.peripheral.name, [error localizedDescription]); - - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheralCharacteristics info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - - return; - } - - // - // Lock the thread for one request at a given time - // - [_lock lock]; - - // - // Again, we loop through the array, just in case. - // - for (CBCharacteristic *characteristic in service.characteristics) - { - // - // Detect the one we are looking for - // - if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:_characteristicUUID]]) - { - [peripheral setNotifyValue:YES forCharacteristic:characteristic]; - - // - // Notify - // - [self updateBLEState:MASBLEServiceStateCentralCharacteristicDiscovered]; - - // - // Call method to send data to peripheral with given auth provider and characteristic if authentication provider is provided - // - if (_provider) - { - [self sendAuthURLWithAuthenticationProvider:_provider characteristic:characteristic]; - } - } - } - - // - // Unlock the thread after it's done - // - [_lock unlock]; -} - - -- (void)peripheral:(CBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - - if (error) - { - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheralCharacteristics info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - } -} - - -- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - if (error) - { - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheralCharacteristics info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - } -} - - -- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForDescriptor:(CBDescriptor *)descriptor error:(NSError *)error -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - - if (error) - { - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheralCharacteristics info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - } -} - - -- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - - // - // Error - // - if(error) - { - NSError *errorDetail = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheralCharacteristics info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:errorDetail]; - - return; - } - - NSString *stringFromData = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding]; - - if ([stringFromData isEqualToString:@"0"]) - { - [self updateBLEState:MASBLEServiceStateCentralAuthorizationSucceeded]; - - // - // Pull URL, if authentication provider is provided - // - if (_provider) - { - [self pollAuthorizationCode]; - } - } - else { - [self updateBLEState:MASBLEServiceStateCentralAuthorizationFailed]; - } - - // - // Stop - // - [self stopScanning]; -} - - -- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - - if (error) - { - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheralCharacteristics info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - } -} - - -@end diff --git a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothPeripheral.h b/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothPeripheral.h deleted file mode 100644 index 0f1ce2b6..00000000 --- a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothPeripheral.h +++ /dev/null @@ -1,52 +0,0 @@ -// -// MASBluetoothPeripheral.h -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import - - -@interface MASBluetoothPeripheral : MASObject - - - -///-------------------------------------- -/// @name Lifecycle -///-------------------------------------- - -# pragma mark - Lifecycle - -/** - * Create a bluetooth peripheral. - * - * @param serviceUUID The peripheral's service UUID. - @ @param characteristicUUI The peripheral's characteristic UUID. - * @return Returns the newly initialized 'MASBluetoothPeripheral'. - */ -+ (id)peripheralWithServiceUUID:(NSString *)serviceUUID characteristicUUID:(NSString *)characteristicUUID; - - - -///-------------------------------------- -/// @name Starting & Stopping -///-------------------------------------- - -# pragma mark - Starting and Stopping - -/** - * Start the peripheral advertising it's presence. - */ -- (void)startAdvertising; - - -/** - * Stop the peripheral advertising it's presence. - */ -- (void)stopAdvertising; - -@end diff --git a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothPeripheral.m b/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothPeripheral.m deleted file mode 100644 index 643b36d5..00000000 --- a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothPeripheral.m +++ /dev/null @@ -1,539 +0,0 @@ -// -// MASBluetoothPeripheral.m -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "MASBluetoothPeripheral.h" - -#import -#import "MASConstantsPrivate.h" - - -@interface MASBluetoothPeripheral () - - -# pragma mark - Properties - -@property (nonatomic, strong, readonly) CBPeripheralManager *peripheralManager; -@property (nonatomic, strong, readwrite) CBMutableCharacteristic *transferCharacteristic; - -@property (nonatomic, copy, readonly) NSString *serviceUUID; -@property (nonatomic, copy, readonly) NSString *characteristicUUID; -@property (nonatomic, copy, readonly) NSMutableData *sessionURLData; - -@property (nonatomic, strong) MASVoidCodeBlock initializeCodeBlock; - -@property (assign) BOOL isSubscribed; - -@end - - -@implementation MASBluetoothPeripheral - - -# pragma mark - Current Peripheral - -+ (id)peripheralWithServiceUUID:(NSString *)serviceUUID characteristicUUID:(NSString *)characteristicUUID; -{ - // - // These are required - // - NSParameterAssert(serviceUUID); - NSParameterAssert(characteristicUUID); - - // todo: validate the UUIDs??? - - MASBluetoothPeripheral *peripheral = [[MASBluetoothPeripheral alloc] initWithServiceUUID:serviceUUID characteristicUUID:characteristicUUID]; - - return peripheral; -} - - -# pragma mark - Private - -- (void)updateBLEState:(MASBLEServiceState)state -{ - // - // If MASDevice's BLE delegate is set, and method is implemented, notify the delegate - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(didReceiveBLEProximityLoginStateUpdate:)]) - { - [[MASDevice proximityLoginDelegate] didReceiveBLEProximityLoginStateUpdate:state]; - } -} - - -- (void)notifyErrorForBLEState:(NSError *)error -{ - // - // If MASDevice's BLE delegate is set, and method is implemented, notify the delegate - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(didReceiveProximityLoginError:)]) - { - [[MASDevice proximityLoginDelegate] didReceiveProximityLoginError:error]; - } -} - - -- (void)requestUserPermissionOnBLEForDeviceName:(NSString *)deviceName completion:(MASCompletionErrorBlock)completion -{ - // - // If MASDevice's BLE delegate is set, and method is implemented, notify the delegate - // - if ([MASDevice proximityLoginDelegate] && [[MASDevice proximityLoginDelegate] respondsToSelector:@selector(handleBLEProximityLoginUserConsent:deviceName:)]) - { - [[MASDevice proximityLoginDelegate] handleBLEProximityLoginUserConsent:completion deviceName:deviceName]; - } - // - // Otherwise, return an error for delegate undefine - // - else { - completion(NO, [NSError errorForFoundationCode:MASFoundationErrorCodeBLEDelegateNotDefined errorDomain:MASFoundationErrorDomainLocal]); - } -} - - -# pragma mark - Creating a new peripheral - -- (id)init -{ - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"init is not a valid initializer, please use a factory method" - userInfo:nil]; - return nil; -} - - -- (id)initWithServiceUUID:(NSString *)serviceUUID characteristicUUID:(NSString *)characteristicUUID -{ - self = [super init]; - if(self) - { - - _serviceUUID = serviceUUID; - _characteristicUUID = characteristicUUID; - _sessionURLData = [[NSMutableData alloc] init]; - } - - return self; -} - - -- (NSString *)debugDescription -{ - return [NSString stringWithFormat:@"(%@) peripheral manager state is: %@ and is advertising: %@\n\n" - " background authorization status: %@\n serviceUUID: %@\n characteristicUUID: %@", - [self class], [self.peripheralManager peripheralManagerStateAsString], ([self.peripheralManager isAdvertising] ? @"Yes" : @"No"), - [CBPeripheralManager peripheralManagerAuthorizationStatusAsString], - self.serviceUUID, self.characteristicUUID]; -} - - -# pragma mark - Starting and Stopping - -- (void)startAdvertising -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - - __block MASBluetoothPeripheral *blockSelf = self; - - MASVoidCodeBlock initializeCodeBlock = ^{ - - // - // If the peripheral manager exists, and is not advertising - // - if (blockSelf.peripheralManager && ![blockSelf.peripheralManager isAdvertising]) - { - // - // Check BLE state, and return proper error if the state is invalid. - // - if (![blockSelf.peripheralManager isPoweredOn]) - { - NSError *bleError = [blockSelf.peripheralManager peripheralManagerStateToMASFoundationError]; - - // - // Notify delegate - // - [blockSelf notifyErrorForBLEState:bleError]; - } - else { - - // - // Notify delegatepo - // - [blockSelf updateBLEState:MASBLEServiceStatePeripheralStarted]; - - // - // If characteristic service is not created - // - if (!blockSelf.transferCharacteristic) - { - @try { - - // - // Create characteristic - // - blockSelf.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:_characteristicUUID] - properties:CBCharacteristicPropertyWriteWithoutResponse + CBCharacteristicPropertyNotify - value:nil - permissions:CBAttributePermissionsReadable|CBAttributePermissionsWriteable]; - - // - // Create service - // - CBMutableService *transferService = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:_serviceUUID] - primary:YES]; - transferService.characteristics = @[blockSelf.transferCharacteristic]; - - // - // Add service - // - [blockSelf.peripheralManager addService:transferService]; - - // - // Start peripheral advertising - // - [blockSelf.peripheralManager startAdvertising:@ - { - CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:_serviceUUID]] - }]; - } - @catch (NSException *exception) { - - // - // Nullify the transferCharacteristic, otherwise on the second attempt to startPeripheral it will throw an uncaught exception. - // - blockSelf.transferCharacteristic = nil; - - NSDictionary *exceptionInfo = @{@"reason" : exception.reason , @"name" : exception.name}; - - // - // Conver the exception with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheral info:exceptionInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [blockSelf notifyErrorForBLEState:masError]; - } - } - else { - - // - // Start peripheral advertising - // - [blockSelf.peripheralManager startAdvertising:@ - { - CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:_serviceUUID]] - }]; - } - } - } - - blockSelf.initializeCodeBlock = nil; - }; - - // - // If there is no peripheral manager instantiated stop here - // - if (!_peripheralManager) - { - //DLog(@"\n\nError: no peripheral manager detected!!\n\n"); - _peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil]; - _peripheralManager.delegate = self; - _initializeCodeBlock = initializeCodeBlock; - } - else { - - initializeCodeBlock(); - } -} - - -- (void)stopAdvertising -{ - //DLog(@"\n\n%@\n\n", [self debugDescription]); - - // - // If there is no peripheral manager instantiated stop here - // - if(!self.peripheralManager) - { - //DLog(@"\n\nError: no peripheral manager detected!!\n\n"); - - return; - } - - // - // If it is already NOT advertising stop here - // - if(![self.peripheralManager isAdvertising]) - { - //DLog(@"\n\nThe peripheral is already NOT advertising:\n%@\n\n", [self debugDescription]); - - return; - } - - // - // Stop peripheral advertising - // - [self.peripheralManager stopAdvertising]; - - // - // Notify delegate - // - [self updateBLEState:MASBLEServiceStatePeripheralStopped]; -} - - -# pragma mark - CBPeripheralManagerDelegate - -- (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didSubscribeToCharacteristic:(CBCharacteristic *)characteristic -{ - //DLog(@"\n\ncalled with characteristic: %@\n\n", [characteristic debugDescription]); - - _isSubscribed = YES; - - // - // Notify delegate - // - [self updateBLEState:MASBLEServiceStatePeripheralSubscribed]; -} - - -- (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didUnsubscribeFromCharacteristic:(CBCharacteristic *)characteristic -{ - //DLog(@"\ncalled with characteristic: %@\n\n", [characteristic debugDescription]); - - _isSubscribed = NO; - - // - // Notify delegate - // - [self updateBLEState:MASBLEServiceStatePeripheralUnsubscribed]; -} - - -- (void)peripheralManagerIsReadyToUpdateSubscribers:(CBPeripheralManager *)peripheral -{ - //DLog(@"\n%@\n\n", [self debugDescription]); -} - -/* -- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveReadRequest:(CBATTRequest *)request -{ - //DLog(@"\n\ncalled with request: %@\n\n", [request debugDescription]); -} -*/ - -- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests -{ - //DLog(@"\n\ncalled with requests: %@\n\n", [requests debugDescription]); - - if([requests count] > 0) - { - CBATTRequest *request = requests[0]; - NSString *sessionURLFragment = [[NSString alloc] initWithData:request.value encoding:NSUTF8StringEncoding]; - - //DLog(@"\n\nsessionURLFragment: %@\n\n", sessionURLFragment); - - // - // We rely on EOM to signal the end of the message - // - if([sessionURLFragment isEqualToString:@"EOM"]) - { - //DLog(@"\n\nreceived EOM indicating the end of the authorization request\n\n"); - - NSError *error = nil; - NSDictionary *authorizationRequest = [NSJSONSerialization JSONObjectWithData:self.sessionURLData - options:kNilOptions - error:&error]; - if(error != nil) - { - //DLog(@"\n\nFailed to load authorization request with error: %@\n\n", error); - - NSError *authorizationError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEAuthorizationFailed - info:error.userInfo - errorDomain:MASFoundationErrorDomainLocal]; - [self notifyErrorForBLEState:authorizationError]; - - return; - } - - //DLog(@"\n\nsessionURL: %@\n\n", authorizationRequest); - - // - // Reset the sessionData - // - _sessionURLData = [[NSMutableData alloc] init]; - - [self requestUserPermissionOnBLEForDeviceName:[authorizationRequest objectForKey:@"device_name"] completion:^(BOOL completed, NSError *error) { - - // - // If error was returned, notify delegate and stop processing - // - if (error) - { - [self notifyErrorForBLEState:error]; - - return; - } - else { - - // - // If user accepts the consent - // - if (completed) - { - NSString *providerURL = [authorizationRequest objectForKey:@"provider_url"]; - - if ([providerURL isEmpty]) - { - NSError *invalidURLError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEAuthorizationFailed errorDomain:MASFoundationErrorDomainLocal]; - [self notifyErrorForBLEState:invalidURLError]; - - return; - } - - // - // Retrieve the absolute URL of the authorizing device's gateway URL - // Due to TLS Caching issue, if the authenticating device is on iOS 8, the auth url may come with trailing dot. - // Make sure to handle both of them. - // - NSString *absoluteURL = [NSString stringWithFormat:@"https://%@:%@",[MASConfiguration currentConfiguration].gatewayHostName, [MASConfiguration currentConfiguration].gatewayPort]; - NSString *absoluteURLWithTrailingDot = [NSString stringWithFormat:@"https://%@.:%@",[MASConfiguration currentConfiguration].gatewayHostName, [MASConfiguration currentConfiguration].gatewayPort]; - - if ([MASConfiguration currentConfiguration].gatewayPrefix) - { - absoluteURL = [NSString stringWithFormat:@"%@/%@", absoluteURL, [MASConfiguration currentConfiguration].gatewayPrefix]; - absoluteURLWithTrailingDot = [NSString stringWithFormat:@"%@/%@", absoluteURLWithTrailingDot, [MASConfiguration currentConfiguration].gatewayPrefix]; - } - - NSString *authPath = @""; - - if ([providerURL rangeOfString:absoluteURL].location != NSNotFound || [providerURL rangeOfString:absoluteURLWithTrailingDot].location != NSNotFound) - { - // - // Extract the path of the authorization URL - // - authPath = [providerURL stringByReplacingOccurrencesOfString:absoluteURL withString:@""]; - authPath = [authPath stringByReplacingOccurrencesOfString:absoluteURLWithTrailingDot withString:@""]; - } - else { - - [self notifyErrorForBLEState:[NSError errorProximityLoginInvalidAuthroizeURL]]; - return; - } - - @try { - - [MAS postTo:authPath - withParameters:nil - andHeaders:nil - requestType:MASRequestResponseTypeWwwFormUrlEncoded - responseType:MASRequestResponseTypeTextPlain - completion:^(NSDictionary *responseInfo, NSError *error) { - - if (error) - { - - NSError * invalidURLError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEAuthorizationFailed info:responseInfo errorDomain:MASFoundationErrorDomain]; - [self notifyErrorForBLEState:invalidURLError]; - - NSString *statusCode = @"1"; - [self.peripheralManager updateValue:[statusCode dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil]; - - return; - } - else { - - [self updateBLEState:MASBLEServiceStatePeripheralSessionAuthorized]; - - if (!_isSubscribed) - { - NSError *noSubscribedDeviceError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLECentralDeviceNotFound errorDomain:MASFoundationErrorDomainLocal]; - [self notifyErrorForBLEState:noSubscribedDeviceError]; - - return; - } - - - NSString *statusCode = @"0"; - [self.peripheralManager updateValue:[statusCode dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil]; - - [self updateBLEState:MASBLEServiceStatePeripheralSessionNotified]; - } - }]; - } - @catch(NSException* exception) - { - NSError *invalidURLError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEAuthorizationFailed errorDomain:MASFoundationErrorDomainLocal]; - [self notifyErrorForBLEState:invalidURLError]; - - return; - } - } - // - // If user does not authroize - // - else { - - NSString *statusCode = @"2"; - [self.peripheralManager updateValue:[statusCode dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil]; - } - } - }]; - } - - // - // Append the data to what we already have - // - else - { - [self.sessionURLData appendData:request.value]; - } - } -} - - -- (void)peripheralManagerDidStartAdvertising:(CBPeripheralManager *)peripheral error:(NSError *)error -{ - //DLog(@"\n%@\n error: %@\n\n", [self debugDescription], [error localizedDescription]); - - if (error) - { - // - // Re-create an error with proper framework error domain and error code. - // - NSError *masError = [NSError errorForFoundationCode:MASFoundationErrorCodeBLEPeripheral info:error.userInfo errorDomain:MASFoundationErrorDomainLocal]; - - // - // Notify delegate - // - [self notifyErrorForBLEState:masError]; - } -} - - -- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral -{ - //DLog(@"\n%@\n\n", [self debugDescription]); - if (_initializeCodeBlock) - { - _initializeCodeBlock(); - } -} - - -- (void)peripheralManager:(CBPeripheralManager *)peripheral willRestoreState:(NSDictionary *)stateInfo -{ - //DLog(@"\n\ncalled with restored state: %@\n\n", stateInfo); -} - -@end diff --git a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothService.h b/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothService.h deleted file mode 100644 index 2fd7803d..00000000 --- a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothService.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// MASBluetoothService.h -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "MASService.h" - -#import "MASConstantsPrivate.h" - - -@class MASBluetoothCentral; -@class MASBluetoothPeripheral; - - -@interface MASBluetoothService : MASService - - - -///-------------------------------------- -/// @name Properties -///-------------------------------------- - -# pragma mark - Properties - -/** - * The BLE central. - */ -@property (nonatomic, strong, readonly) MASBluetoothCentral *central; - - -/** - * The BLE peripheral. - */ -@property (nonatomic, strong, readonly) MASBluetoothPeripheral *peripheral; - -@end diff --git a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothService.m b/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothService.m deleted file mode 100644 index c4e098b7..00000000 --- a/MASFoundation/Classes/_private_/services/bluetooth/MASBluetoothService.m +++ /dev/null @@ -1,135 +0,0 @@ -// -// MASBluetoothService.m -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "MASBluetoothService.h" - -#import -#import "MASBluetoothCentral.h" -#import "MASBluetoothPeripheral.h" - - -@implementation MASBluetoothService - - -# pragma mark - Shared Service - -+ (instancetype)sharedService -{ - static id sharedInstance = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^ - { - sharedInstance = [[MASBluetoothService alloc] initProtected]; - }); - - return sharedInstance; -} - - -# pragma mark - Lifecycle - -+ (void)load -{ - [MASService registerSubclass:[self class] serviceUUID:MASBluetoothServiceUUID]; -} - - -+ (NSString *)serviceUUID -{ - return MASBluetoothServiceUUID; -} - - -- (void)serviceDidLoad -{ - - [super serviceDidLoad]; -} - - -- (void)serviceWillStart -{ - // - // Retrieve the configuation for UUID values - // - MASConfiguration *configuration = [MASConfiguration currentConfiguration]; - - // - // Create the central - // - _central = [MASBluetoothCentral centralWithServiceUUID:configuration.bluetoothServiceUuid - characteristicUUID:configuration.bluetoothCharacteristicUuid]; - - // - // Create the peripheral - // - _peripheral = [MASBluetoothPeripheral peripheralWithServiceUUID:configuration.bluetoothServiceUuid - characteristicUUID:configuration.bluetoothCharacteristicUuid]; - - [super serviceWillStart]; -} - - -- (void)serviceWillStop -{ - // - // If the central exists - // - if(self.central) - { - [self.central stopScanning]; - } - - // - // If the peripheral exists - // - if(self.peripheral) - { - [self.peripheral stopAdvertising]; - } - - [super serviceWillStop]; -} - - -- (void)serviceDidReset -{ - // - // If the central exists - // - if(self.central) - { - [self.central stopScanning]; - _central = nil; - } - - // - // If the peripheral exists - // - if(self.peripheral) - { - [self.peripheral stopAdvertising]; - _peripheral = nil; - } - - [super serviceDidReset]; -} - - -# pragma mark - Public - -- (NSString *)debugDescription -{ - return [NSString stringWithFormat:@"%@\n\n central: %@\n\n peripheral: %@", - [super debugDescription], - [self.central debugDescription], [self.peripheral debugDescription]]; -} - -@end diff --git a/MASFoundation/Classes/models/MASAuthenticationProviders.h b/MASFoundation/Classes/models/MASAuthenticationProviders.h index c3855dc7..9e04f5d3 100644 --- a/MASFoundation/Classes/models/MASAuthenticationProviders.h +++ b/MASFoundation/Classes/models/MASAuthenticationProviders.h @@ -38,6 +38,11 @@ @property (nonatomic, copy, readonly, nullable) NSString *idp; +/** + * PKCE state value being used for current authentication providers + */ +@property (nonatomic, copy, readonly, nullable) NSString *PKCEstate; + ///-------------------------------------- /// @name Authentication Providers diff --git a/MASFoundation/Classes/models/MASAuthenticationProviders.m b/MASFoundation/Classes/models/MASAuthenticationProviders.m index cd913794..becbe85a 100644 --- a/MASFoundation/Classes/models/MASAuthenticationProviders.m +++ b/MASFoundation/Classes/models/MASAuthenticationProviders.m @@ -10,6 +10,7 @@ #import "MASAuthenticationProviders.h" +#import "MASAccessService.h" #import "MASConstantsPrivate.h" #import "MASModelService.h" @@ -20,6 +21,7 @@ @implementation MASAuthenticationProviders +@synthesize PKCEstate = _PKCEstate; - (id)init { @@ -58,6 +60,13 @@ - (NSString *)debugDescription } +# pragma mark - Properties + +- (NSString *)PKCEstate +{ + return [[MASAccessService sharedService].currentAccessObj retrievePKCEState]; +} + # pragma mark - Authentication Providers + (MASAuthenticationProviders *)currentProviders diff --git a/MASFoundation/Classes/models/MASDevice.h b/MASFoundation/Classes/models/MASDevice.h index bea9d2cb..39601d7a 100644 --- a/MASFoundation/Classes/models/MASDevice.h +++ b/MASFoundation/Classes/models/MASDevice.h @@ -11,11 +11,6 @@ #import "MASObject.h" -@class MASAuthenticationProvider; - -@protocol MASProximityLoginDelegate; - - /** * The `MASDevice` class is a local representation of device data. */ @@ -59,18 +54,6 @@ @property (assign) BOOL isBeingAuthorized; -/** - * The MASProximityLoginDelegate static property getter - */ -+ (id _Nullable)proximityLoginDelegate; - - -/** - * The MASProximityLoginDelegate static property setter - */ -+ (void)setProximityLoginDelegate:(id _Nonnull)delegate; - - ///-------------------------------------- /// @name Current Device ///-------------------------------------- @@ -144,55 +127,6 @@ -///-------------------------------------- -/// @name Bluetooth Peripheral -///-------------------------------------- - -# pragma mark - Bluetooth Peripheral - -/** - * Start the device acting as a bluetooth peripheral. - */ -- (void)startAsBluetoothPeripheral; - - - -/** - * Stop the device acting as a bluetooth peripheral. - */ -- (void)stopAsBluetoothPeripheral; - - - -///-------------------------------------- -/// @name Bluetooth Central -///-------------------------------------- - -# pragma mark - Bluetooth Central - -/** - * Start the device acting as a bluetooth central. - */ -- (void)startAsBluetoothCentral; - - - -/** - * Start the device acting as a bluetooth central with given authentication provider. - * - * @param provider MASAuthenticationProvider to pass authentication information to other devices - */ -- (void)startAsBluetoothCentralWithAuthenticationProvider:(MASAuthenticationProvider *_Nonnull)provider; - - - -/** - * Stop the device acting as a bluetooth central. - */ -- (void)stopAsBluetoothCentral; - - - ///-------------------------------------- /// @name Device Metadata ///-------------------------------------- diff --git a/MASFoundation/Classes/models/MASDevice.m b/MASFoundation/Classes/models/MASDevice.m index 553cb7df..03426a2a 100644 --- a/MASFoundation/Classes/models/MASDevice.m +++ b/MASFoundation/Classes/models/MASDevice.m @@ -11,9 +11,6 @@ #import "MASDevice.h" #import "MASAccessService.h" -#import "MASBluetoothCentral.h" -#import "MASBluetoothPeripheral.h" -#import "MASBluetoothService.h" #import "MASConstantsPrivate.h" #import "MASModelService.h" #import "MASSecurityService.h" @@ -29,22 +26,6 @@ @implementation MASDevice @synthesize isRegistered = _isRegistered; -static id _proximityLoginDelegate_; - - -# pragma mark - Property - -+ (id)proximityLoginDelegate -{ - return _proximityLoginDelegate_; -} - - -+ (void)setProximityLoginDelegate:(id)delegate -{ - _proximityLoginDelegate_ = delegate; -} - # pragma mark - Properties @@ -166,40 +147,6 @@ - (NSString *)debugDescription } -# pragma mark - Bluetooth Peripheral - -- (void)startAsBluetoothPeripheral -{ - [[MASBluetoothService sharedService].peripheral startAdvertising]; -} - - -- (void)stopAsBluetoothPeripheral -{ - [[MASBluetoothService sharedService].peripheral stopAdvertising]; -} - - -# pragma mark - Bluetooth Central - -- (void)startAsBluetoothCentral -{ - [[MASBluetoothService sharedService].central startScanning]; -} - - -- (void)startAsBluetoothCentralWithAuthenticationProvider:(MASAuthenticationProvider *)provider -{ - [[MASBluetoothService sharedService].central startScanningWithAuthenticationProvider:provider]; -} - - -- (void)stopAsBluetoothCentral -{ - [[MASBluetoothService sharedService].central stopScanning]; -} - - # pragma mark - Device Metadata - (void)addAttribute:(NSString *_Nonnull)name value:(NSString *)value completion:(MASObjectResponseErrorBlock)completion diff --git a/MASFoundation/Classes/models/MASProximityLogin.h b/MASFoundation/Classes/models/MASProximityLogin.h deleted file mode 100644 index dcfed259..00000000 --- a/MASFoundation/Classes/models/MASProximityLogin.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// MASProximityLogin.h -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "MASObject.h" - -@interface MASProximityLogin : MASObject - -@end diff --git a/MASFoundation/Classes/models/MASProximityLogin.m b/MASFoundation/Classes/models/MASProximityLogin.m deleted file mode 100644 index 5df24bc9..00000000 --- a/MASFoundation/Classes/models/MASProximityLogin.m +++ /dev/null @@ -1,29 +0,0 @@ -// -// MASProximityLogin.m -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "MASProximityLogin.h" - -@implementation MASProximityLogin - -- (void)start -{ - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"not a valid method, please use a factory method" - userInfo:nil]; -} - -- (void)stop -{ - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"not a valid method, please use a factory method" - userInfo:nil]; -} - -@end diff --git a/MASFoundation/Classes/models/MASProximityLoginQRCode.h b/MASFoundation/Classes/models/MASProximityLoginQRCode.h deleted file mode 100644 index 73930283..00000000 --- a/MASFoundation/Classes/models/MASProximityLoginQRCode.h +++ /dev/null @@ -1,128 +0,0 @@ -// -// MASProximityLoginQRCode.h -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import -#import "MASProximityLogin.h" - -@class MASAuthenticationProvider; - -/** - * The `MASProximityLoginQRCode` class is a local representation of QR Code authentication provider data and handle necessary logic. - */ -@interface MASProximityLoginQRCode : MASProximityLogin - -///-------------------------------------- -/// @name Properties -///-------------------------------------- - -# pragma mark - Properties - -/** - * Polling interval in seconds for QR Code proximity login - */ -@property (nonatomic, assign, readonly, nonnull) NSNumber *pollingInterval; - - -/** - * Initial delay in seconds to make polling request for QR Code authorization - */ -@property (nonatomic, assign, readonly, nonnull) NSNumber *pollingDelay; - - -/** - * Limit for number of polling requests for QR Code authorization - */ -@property (nonatomic, assign, readonly, nonnull) NSNumber *pollingLimit; - - -/** - * Counter for current number of polling reuqests made. - */ -@property (nonatomic, assign, readonly) int currentPollingCounter; - - -/** - * Boolean indicator of polling request is in progress or not. - */ -@property (nonatomic, assign, readonly) BOOL isPolling; - - -/** - * NSString of authentication URL - */ -@property (nonatomic, copy, readonly, nonnull) NSString *authenticationUrl; - - -/** - * NSString of polling URL - */ -@property (nonatomic, copy, readonly, nonnull) NSString *pollUrl; - - -# pragma mark - Lifecycle - -/** - * Init the object with given values. - * Property values cannot be changed once it is initialized. - * - * @param provider MASAuthenticationProvider object with authenticationUrl and pollUrl for QR Code. - * @param initDelay NSNumber of initial delay in seconds to start making a request to poll for authorization. - * @param pollingInterval NSNumber of interval for polling requests. - * @param pollingLimit NSNumber of limit counter for number of polling requests. - * - * @return MASProximityLoginQRCode object - */ -- (instancetype _Nullable)initWithAuthenticationProvider:(MASAuthenticationProvider *_Nonnull)provider initialDelay:(NSNumber *_Nonnull)initDelay pollingInterval:(NSNumber *_Nonnull)pollingInterval pollingLimit:(NSNumber *_Nonnull)pollingLimit; - - -/** - * Init the object with authentication provider and default values for polling configurations - * Default values for the objects are - * - * pollingDelay : 10 seconds - * pollingInterval : 5 seconds - * pollingLimit : 6 times - * - * @param provider MASAuthenticationProvider object with authenticationUrl and pollUrl for QR Code. - * - * @return MASProximityLoginQRCode object - */ -- (instancetype _Nullable)initWithAuthenticationProvider:(MASAuthenticationProvider *_Nonnull)provider; - - -# pragma mark - Start/Stop displaying QR Code image - -/** - * Generates QR Code image for proximity login based on provided authentication provider and starts polling request for authorization. - * Upon successful start display, NSNotification with notification name, MASProximityLoginQRCodeDidStartDisplayingQRCodeImage, will be sent. - * - * @return UIImage of QR Code. - */ -- (UIImage *_Nullable)startDisplayingQRCodeImageForProximityLogin; - - -/** - * Stops displaying QR Code image for proximity login based on provided polling configuration. - * Upon successful stop display, NSNotification with notification name, MASProxityLoginQRCodeDidStopDisplayingQRCodeImage, will be sent. - */ -- (void)stopDisplayingQRCodeImageForProximityLogin; - - -# pragma mark - Authorize authenticateUrl for proximity login - -/** - * Authorize given authenticateUrl with gateway. Method will validate authenticateUrl, and send it over to gateway to authorize. - * - * @param authenticateUrl NSString of authenticateUrl. - * @param completion MASCompletionErrorBlock to notify caller for the result. - */ -+ (void)authorizeAuthenticateUrl:(NSString *_Nonnull)authenticateUrl completion:(MASCompletionErrorBlock _Nullable)completion; - -@end diff --git a/MASFoundation/Classes/models/MASProximityLoginQRCode.m b/MASFoundation/Classes/models/MASProximityLoginQRCode.m deleted file mode 100644 index 74e8bb62..00000000 --- a/MASFoundation/Classes/models/MASProximityLoginQRCode.m +++ /dev/null @@ -1,225 +0,0 @@ -// -// MASProximityLoginQRCode.m -// MASFoundation -// -// Copyright (c) 2016 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "MASProximityLoginQRCode.h" - -#import "MASProximityLoginQRCode+MASPrivate.h" -#import "NSString+MASPrivate.h" -#import "NSError+MASPrivate.h" - -# pragma mark - Property Constants - -static NSString *const kMASProximityLoginQRCodeAuthenticationUrlKey = @"authenticationUrl"; // string -static NSString *const kMASProximityLoginQRCodePollUrlKey = @"pollUrl"; // string -static NSString *const kMASProximityLoginQRCodePollingDelayKey = @"pollingDelay"; // string -static NSString *const kMASProximityLoginQRCodePollingIntervalKey = @"pollingInterval"; // string -static NSString *const kMASProximityLoginQRCodePollingLimitKey = @"pollingLimit"; // string -static NSString *const kMASProximityLoginQRCodeCurrentPollingCounterKey = @"currentPollingCounter"; // string -static NSString *const kMASProximityLoginQRCodeIsPollingKey = @"isPolling"; // string - -@interface MASProximityLoginQRCode () - -@property (nonatomic, strong) UIImage *qrCodeImage; - -@property (assign) BOOL isStop; - -@property (assign) int pollCount; - -@end - -@implementation MASProximityLoginQRCode - -# pragma mark - Lifecycle - -- (id)init -{ - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"init is not a valid initializer, please use a factory method" - userInfo:nil]; - return nil; -} - - -- (instancetype)initWithAuthenticationProvider:(MASAuthenticationProvider *)provider initialDelay:(NSNumber *)initDelay pollingInterval:(NSNumber *)pollingInterval pollingLimit:(NSNumber *)pollingLimit -{ - NSParameterAssert(provider); - NSParameterAssert(provider.authenticationUrl); - NSParameterAssert(provider.pollUrl); - NSParameterAssert([initDelay intValue] > 0); - NSParameterAssert([pollingInterval intValue] > 0); - NSParameterAssert([pollingLimit intValue] > 0); - - return [self initPrivateWithAuthenticationUrl:provider.authenticationUrl.absoluteString pollingUrl:provider.pollUrl.absoluteString initialDelay:initDelay pollingInterval:pollingInterval pollingLimit:pollingLimit]; -} - - -- (instancetype)initWithAuthenticationProvider:(MASAuthenticationProvider *)provider -{ - return [self initWithAuthenticationProvider:provider initialDelay:[NSNumber numberWithInt:10] pollingInterval:[NSNumber numberWithInt:5] pollingLimit:[NSNumber numberWithInt:6]]; -} - - -# pragma mark - Start/Stop displaying QR Code image - -- (UIImage *)startDisplayingQRCodeImageForProximityLogin -{ - // - // Generate image only once - // - if (_qrCodeImage == nil) - { - _qrCodeImage = [self startPrivateDisplayingQRCodeImageForProximityLogin]; - } - - return _qrCodeImage; -} - - -- (void)stopDisplayingQRCodeImageForProximityLogin -{ - [self stopPrivateDisplayingQRCodeImageForProximityLogin]; -} - - - -# pragma mark - Authorize authenticateUrl for proximity login - -+ (void)authorizeAuthenticateUrl:(NSString *)authenticateUrl completion:(MASCompletionErrorBlock)completion -{ - NSError *invalidURLError = nil; - - // - // If url is empty - // - if ([authenticateUrl isEmpty]) - { - invalidURLError = [NSError errorForFoundationCode:MASFoundationErrorCodeProximityLoginInvalidAuthenticationURL errorDomain:MASFoundationErrorDomainLocal]; - } - - if (invalidURLError) - { - if (completion) - { - completion(NO, invalidURLError); - } - - return; - } - - - // - // Retrieve the absolute URL of the authorizing device's gateway URL - // Due to TLS Caching issue, if the authenticating device is on iOS 8, the auth url may come with trailing dot. - // Make sure to handle both of them. - // - NSString *absoluteURL = [NSString stringWithFormat:@"https://%@:%@",[MASConfiguration currentConfiguration].gatewayHostName, [MASConfiguration currentConfiguration].gatewayPort]; - NSString *absoluteURLWithTrailingDot = [NSString stringWithFormat:@"https://%@.:%@",[MASConfiguration currentConfiguration].gatewayHostName, [MASConfiguration currentConfiguration].gatewayPort]; - - if ([MASConfiguration currentConfiguration].gatewayPrefix) - { - absoluteURL = [NSString stringWithFormat:@"%@/%@", absoluteURL, [MASConfiguration currentConfiguration].gatewayPrefix]; - absoluteURLWithTrailingDot = [NSString stringWithFormat:@"%@/%@", absoluteURLWithTrailingDot, [MASConfiguration currentConfiguration].gatewayPrefix]; - } - - NSString *authPath = @""; - - if ([authenticateUrl rangeOfString:absoluteURL].location != NSNotFound || [authenticateUrl rangeOfString:absoluteURLWithTrailingDot].location != NSNotFound) - { - // - // Extract the path of the authorization URL - // - authPath = [authenticateUrl stringByReplacingOccurrencesOfString:absoluteURL withString:@""]; - authPath = [authPath stringByReplacingOccurrencesOfString:absoluteURLWithTrailingDot withString:@""]; - } - else { - - if (completion) - { - completion(NO, [NSError errorProximityLoginInvalidAuthroizeURL]); - } - - return; - } - - - [MAS postTo:authPath withParameters:nil andHeaders:nil requestType:MASRequestResponseTypeWwwFormUrlEncoded responseType:MASRequestResponseTypeTextPlain completion:^(NSDictionary *responseInfo, NSError *error) { - - if (error) - { - if (completion) - { - completion(NO, error); - } - } - else { - if (completion) - { - completion(YES, nil); - } - } - }]; -} - - -#pragma mark - Debug methods - -- (NSString *)debugDescription -{ - return [NSString stringWithFormat:@"(%@)\n\n" - " objectId: %@\n auth url: %@\n poll url: %@\n polling delay: %@\n polling interval: %@\n polling limit: %@\n", - [self class], [self objectId], [self authenticationUrl], [self pollUrl], [self pollingDelay], [self pollingInterval], [self pollingLimit]]; -} - -#pragma mark - NSCopying - -- (id)copyWithZone:(NSZone *)zone -{ - MASProximityLoginQRCode *qrCode = [super copyWithZone:zone]; - - [qrCode setValue:self.authenticationUrl forKey:@"authenticationUrl"]; - [qrCode setValue:self.pollUrl forKey:@"pollUrl"]; - [qrCode setValue:self.pollingDelay forKey:@"pollingDelay"]; - [qrCode setValue:self.pollingInterval forKey:@"pollingInterval"]; - [qrCode setValue:self.pollingLimit forKey:@"pollingLimit"]; - - return qrCode; -} - - -# pragma mark - NSCoding - -- (void)encodeWithCoder:(NSCoder *)aCoder -{ - [super encodeWithCoder:aCoder]; //ObjectID is encoded in the super class MASObject - - if (self.authenticationUrl) [aCoder encodeObject:self.authenticationUrl forKey:kMASProximityLoginQRCodeAuthenticationUrlKey]; - if (self.pollUrl) [aCoder encodeObject:self.pollUrl forKey:kMASProximityLoginQRCodePollUrlKey]; - if (self.pollingDelay) [aCoder encodeObject:self.pollingDelay forKey:kMASProximityLoginQRCodePollingDelayKey]; - if (self.pollingInterval) [aCoder encodeObject:self.pollingInterval forKey:kMASProximityLoginQRCodePollingIntervalKey]; - if (self.pollingLimit) [aCoder encodeObject:self.pollingLimit forKey:kMASProximityLoginQRCodePollingLimitKey]; -} - - -- (id)initWithCoder:(NSCoder *)aDecoder -{ - if(self = [super initWithCoder:aDecoder]) //ObjectID is decoded in the super class MASObject - { - [self setValue:[aDecoder decodeObjectForKey:kMASProximityLoginQRCodeAuthenticationUrlKey] forKey:@"authenticationUrl"]; - [self setValue:[aDecoder decodeObjectForKey:kMASProximityLoginQRCodePollUrlKey] forKey:@"pollUrl"]; - [self setValue:[aDecoder decodeObjectForKey:kMASProximityLoginQRCodePollingDelayKey] forKey:@"pollingDelay"]; - [self setValue:[aDecoder decodeObjectForKey:kMASProximityLoginQRCodePollingIntervalKey] forKey:@"pollingInterval"]; - [self setValue:[aDecoder decodeObjectForKey:kMASProximityLoginQRCodePollingLimitKey] forKey:@"pollingLimit"]; - } - - return self; -} - - -@end diff --git a/MASFoundation/MASFoundation.h b/MASFoundation/MASFoundation.h index 5fcf1e1a..9cd5edca 100644 --- a/MASFoundation/MASFoundation.h +++ b/MASFoundation/MASFoundation.h @@ -23,7 +23,6 @@ FOUNDATION_EXPORT const unsigned char MASFoundationVersionString[]; // #import #import -#import #import #import #import @@ -49,8 +48,6 @@ FOUNDATION_EXPORT const unsigned char MASFoundationVersionString[]; #import #import #import -#import -#import #import #import #import From 69dcf2c900b3687fa60cffd31a6bab358c2ce50b Mon Sep 17 00:00:00 2001 From: James Go Date: Mon, 22 Apr 2019 15:26:52 -0700 Subject: [PATCH 02/40] US584914 : iOS - Decoupling the BLE into separate module - correcting the signing profile, and removing podspec --- MASFoundation.podspec | 27 ------------------------- MASFoundation.xcodeproj/project.pbxproj | 7 ++++++- 2 files changed, 6 insertions(+), 28 deletions(-) delete mode 100644 MASFoundation.podspec diff --git a/MASFoundation.podspec b/MASFoundation.podspec deleted file mode 100644 index d6461b2c..00000000 --- a/MASFoundation.podspec +++ /dev/null @@ -1,27 +0,0 @@ -Pod::Spec.new do |s| - - s.version = '1.2.02' - s.summary = 'The MASFoundation framework is the core iOS framework upon which Mobile App Service is built.' - s.homepage = "http://mas.ca.com" - s.authors = {'Luis Sanches' => 'luis.sanches@ca.com'} - s.license = {:type => 'MIT', :file => 'LICENSE'} - s.platform = :ios, '8.0' - s.requires_arc = true - s.source = { :git => 'https://github.com/CAAPIM/iOS-MAS-Foundation.git', :tag => s.version.to_s } - - s.subspec 'Classes' do |classes| - classes.public_header_files = 'MASFoundation/Classes/**/*.h' - classes.source_files = 'MASFoundation/Classes/**/*' - end - - s.subspec 'Vendor' do |vendor| - vendor.subspec 'OpenSSL' do |openssl| - openssl.public_header_files = 'MASFoundation/Vendor/**/*.h' - openssl.source_files = 'MASFoundation/Vendor/**/*' - openssl.preserve_paths = 'MASFoundation/Vendor/OpenSSL/include/openssl/*.h' - openssl.vendored_libraries = 'MASFoundation/Vendor/OpenSSL/include/lib/libcrypto_iOS.a', 'MASFoundation/Vendor/OpenSSL/include/lib/libssl_iOS.a' - openssl.libraries = 'ssl_iOS', 'crypto_iOS' - openssl.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/MASFoundation/Vendor/OpenSSL/include/**" } - end - end -end diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index d65b015c..418edc6a 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -1758,7 +1758,7 @@ TargetAttributes = { 1059D36F1B61AA3700223267 = { CreatedOnToolsVersion = 6.4; - ProvisioningStyle = Automatic; + ProvisioningStyle = Manual; }; 1059D37A1B61AA3800223267 = { CreatedOnToolsVersion = 6.4; @@ -1774,6 +1774,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 1059D3661B61AA3700223267; @@ -2116,6 +2117,7 @@ buildSettings = { CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1.9.10; DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; @@ -2151,6 +2153,7 @@ ONLY_ACTIVE_ARCH = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.ca.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = ""; }; @@ -2161,6 +2164,7 @@ buildSettings = { CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1.9.10; DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; @@ -2196,6 +2200,7 @@ ONLY_ACTIVE_ARCH = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.ca.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = ""; }; From 35dbd52145ec7d18b9cdc4ac90e9e5b89b641b56 Mon Sep 17 00:00:00 2001 From: James Go Date: Thu, 25 Apr 2019 14:54:56 -0700 Subject: [PATCH 03/40] US584914 : iOS - Decoupling the BLE into separate module - Updating README.md and CHANGELOG.md --- CHANGELOG.md | 7 ++++++- README.md | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0b51af1..871ff128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# Version 1.9.20 + +### New features +- Proximity Login feature (BLE and QR Code) is now moved to [MASProximity][MASProximity] framework. No code change is required, and no functionality change was made. In order to use Proxmity Login feature, please include [MASProximity][MASProximity] framework into a project. [US584914] + # Version 1.9.10 ### Bug fixes @@ -228,7 +233,7 @@ None. - . - + [MASProximity]: https://github.com/CAAPIM/iOS-MAS-Proximity [mag]: https://docops.ca.com/mag [mas.ca.com]: http://mas.ca.com/ [docs]: http://mas.ca.com/docs/ diff --git a/README.md b/README.md index 81fc427a..54891da4 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ The MASFoundation framework has the following features: - Authentication + OAuth + OIDC - OpenID Connect - + BLE + + BLE (in [MASProximity][MASProximity] SDK) + Dynamic Client ID & Client Secret - + QR Code + + QR Code (in [MASProximity][MASProximity] SDK) + Social Login + Single Sign On + OTP - One Time Password @@ -144,6 +144,7 @@ Copyright (c) 2016 CA. All rights reserved. This software may be modified and distributed under the terms of the MIT license. See the [LICENSE][license-link] file for details. + [MASProximity]: https://github.com/CAAPIM/iOS-MAS-Proximity [mag]: https://docops.ca.com/mag [mas.ca.com]: http://mas.ca.com/ [get-started]: http://mas.ca.com/get-started/ From 65a87b725a956aa78e8cd2194992f42301acbd60 Mon Sep 17 00:00:00 2001 From: Robert Weber Date: Wed, 8 May 2019 14:17:22 -0700 Subject: [PATCH 04/40] Update version numbers to 1.9.20 --- MASFoundation.xcodeproj/project.pbxproj | 4 ++-- MASFoundation/Info.plist | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 418edc6a..1bb90265 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -2118,7 +2118,7 @@ CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 1.9.10; + CURRENT_PROJECT_VERSION = 1.9.20; DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; @@ -2165,7 +2165,7 @@ CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 1.9.10; + CURRENT_PROJECT_VERSION = 1.9.20; DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; diff --git a/MASFoundation/Info.plist b/MASFoundation/Info.plist index a6cb2047..d27f5019 100644 --- a/MASFoundation/Info.plist +++ b/MASFoundation/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.9.10 + 1.9.20 CFBundleSignature ???? CFBundleVersion From 34041b3d165679e6322de816d16bb3fd787a940b Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Wed, 15 May 2019 15:48:46 +0530 Subject: [PATCH 05/40] Implementation of the intermediate certificate pinning feature. Added a new enum to take the mode of SSL pinning. Modified the logic of evaluating security configuration to include the SSL pinning mode. --- .../MASSecurityConfiguration+MASPrivate.h | 1 - .../MASSecurityConfiguration+MASPrivate.m | 1 + .../network/internal/MASSecurityPolicy.m | 108 +++++++++++++++--- .../Classes/models/MASSecurityConfiguration.h | 27 +++++ .../Classes/models/MASSecurityConfiguration.m | 27 +++++ 5 files changed, 147 insertions(+), 17 deletions(-) diff --git a/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.h b/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.h index f2acfdb0..27a27150 100644 --- a/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.h +++ b/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.h @@ -18,7 +18,6 @@ - (NSArray *)convertCertificatesToData; - /** Converts MASSecurityConfiguration's array of certificate array into array of SecCertificateRef diff --git a/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.m b/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.m index a7a49e2f..0e60c424 100644 --- a/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.m +++ b/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.m @@ -47,6 +47,7 @@ - (NSArray *)convertCertificatesToData } + - (NSArray *)convertCertificatesToSecCertificateRef { NSMutableArray *certAsData = [[self convertCertificatesToData] mutableCopy]; diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index cb64f6c6..d3a1cc85 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -77,7 +77,7 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo // // If trustPublicPKI is set to NO, and there is no pinning information defined, reject connection // - else if (!securityConfiguration.trustPublicPKI && ((([securityConfiguration.certificates isKindOfClass:[NSArray class]] && [securityConfiguration.certificates count] == 0) || securityConfiguration.certificates == nil) && (([securityConfiguration.publicKeyHashes isKindOfClass:[NSArray class]] && [securityConfiguration.publicKeyHashes count] == 0) || securityConfiguration.publicKeyHashes == nil))) + else if (!securityConfiguration.trustPublicPKI && (((([securityConfiguration.certificates isKindOfClass:[NSArray class]] && [securityConfiguration.certificates count] == 0) || securityConfiguration.certificates == nil) && (([securityConfiguration.publicKeyHashes isKindOfClass:[NSArray class]] && [securityConfiguration.publicKeyHashes count] == 0) || securityConfiguration.publicKeyHashes == nil)))) { return NO; } @@ -88,30 +88,43 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo BOOL isPinningVerified = YES; NSArray *certificateChain = [self extractCertificateDataFromServerTrust:serverTrust]; + switch (securityConfiguration.pinningMode) { + case MASSecuritySSLPinningModeCertificate: + { + isPinningVerified = [self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]; + } + break; + case MASSecuritySSLPinningModeIntermediateCertifcate: + { + isPinningVerified = [self validateIntermediateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]; + } + break; + case MASSecuritySSLPinningModePublicKeyHash: + { + isPinningVerified = [self validatePublicKeyHash:serverTrust configuration:securityConfiguration]; + } + break; + + } + + return isPinningVerified; +} + + +- (BOOL)validateCertPinning:(SecTrustRef)serverTrust configuration:(MASSecurityConfiguration *)securityConfiguration certChain:(NSArray *)certificateChain +{ // // pinning with certificates // if (securityConfiguration.certificates != nil && [securityConfiguration.certificates isKindOfClass:[NSArray class]] && [securityConfiguration.certificates count] > 0) { - // - // Set anchor cert with pinned certificates - // - NSMutableArray *pinnedCertificates = [NSMutableArray array]; NSMutableArray *pinnedCertificatesData = [[securityConfiguration convertCertificatesToData] mutableCopy]; - for (NSData *certificateData in pinnedCertificatesData) - { - [pinnedCertificates addObject:(__bridge_transfer id)SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificateData)]; - } - SecTrustSetAnchorCertificates(serverTrust, (__bridge CFArrayRef)pinnedCertificates); - - // - // Stop proceeding if validation of server trust against anchor (pinned) certificates - // - if (![self validateServerTrust:serverTrust]) + if(![self validateAnchorTrust:serverTrust pinnedCerts:pinnedCertificatesData]) { return NO; } + // // As of this point, if the configuration forces to validate the entire chain, validate entire chain of certificates // @@ -137,6 +150,67 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo } } + return YES; +} + + +//Validate the intermediate certificate pinning + +- (BOOL)validateIntermediateCertPinning:(SecTrustRef)serverTrust configuration:(MASSecurityConfiguration *)securityConfiguration certChain:(NSArray *)certificateChain +{ + if (securityConfiguration.certificates != nil && [securityConfiguration.certificates isKindOfClass:[NSArray class]] && [securityConfiguration.certificates count] > 0) + { + NSMutableArray *pinnedCertificatesData = [[securityConfiguration convertCertificatesToData] mutableCopy]; + if(![self validateAnchorTrust:serverTrust pinnedCerts:pinnedCertificatesData]) + { + return NO; + } + + // + // Since this part is only pinning intermediate certificates no need to validate the entire chain. Only make sure if the intermediate certs are part of the CertificateChain that server presented + // + for (NSData *pinnedCertData in pinnedCertificatesData) + { + if (![certificateChain containsObject:pinnedCertData]) + { + return NO; + } + } + + } + + return YES; +} + + +//Validate server anchor trust based on the certificates that are pinned +- (BOOL)validateAnchorTrust:(SecTrustRef)serverTrust pinnedCerts:(NSArray *)pinnedCertificatesData +{ + // + // Set anchor cert with pinned certificates + // + NSMutableArray *pinnedCertificates = [NSMutableArray array]; + + for (NSData *certificateData in pinnedCertificatesData) + { + [pinnedCertificates addObject:(__bridge_transfer id)SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificateData)]; + } + SecTrustSetAnchorCertificates(serverTrust, (__bridge CFArrayRef)pinnedCertificates); + + // + // Stop proceeding if validation of server trust against anchor (pinned) certificates + // + if (![self validateServerTrust:serverTrust]) + { + return NO; + } + + return YES; +} + +//Pinning based on public key hash +- (BOOL)validatePublicKeyHash:(SecTrustRef)serverTrust configuration:(MASSecurityConfiguration *)securityConfiguration +{ // // pinning with public key hashes // @@ -201,8 +275,10 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo } } - return isPinningVerified; + return YES; } + + - (BOOL)validateServerTrust:(SecTrustRef)serverTrust diff --git a/MASFoundation/Classes/models/MASSecurityConfiguration.h b/MASFoundation/Classes/models/MASSecurityConfiguration.h index 5c7455f4..cd90c7cf 100644 --- a/MASFoundation/Classes/models/MASSecurityConfiguration.h +++ b/MASFoundation/Classes/models/MASSecurityConfiguration.h @@ -21,6 +21,27 @@ @interface MASSecurityConfiguration : MASObject +/** + * Different SSL pinning modes that can be opted. + */ +typedef NS_ENUM(NSUInteger, MASSecuritySSLPinningMode) { + /** + * SSL pinning based on Public Key Hash. + */ + MASSecuritySSLPinningModePublicKeyHash, + + /** + * SSL pinning based on Leaf Certificate. + */ + MASSecuritySSLPinningModeCertificate, + + /** + * SSL pinning based on Intermediate Certificate. + */ + MASSecuritySSLPinningModeIntermediateCertifcate, +}; + + ///-------------------------------------- /// @name Properties ///-------------------------------------- @@ -45,6 +66,12 @@ */ @property (assign) BOOL trustPublicPKI; +/** + enum value that determines the SSL pinning mode. The Certifcates array needs to be set accordingly with the certificates that needs to be pinned. If MASSecuritySSLPinningModeIntermediateCertifcate is chosen, then the certificates array should contain intermediate certificate. + @see certificates + */ +@property (assign) MASSecuritySSLPinningMode pinningMode; + /** NSArray value of pinned certificates. Certificates must be in PEM encoded CRT; each line should be an item of the certificate array. diff --git a/MASFoundation/Classes/models/MASSecurityConfiguration.m b/MASFoundation/Classes/models/MASSecurityConfiguration.m index f59f7d11..0b6db956 100644 --- a/MASFoundation/Classes/models/MASSecurityConfiguration.m +++ b/MASFoundation/Classes/models/MASSecurityConfiguration.m @@ -40,6 +40,7 @@ - (instancetype)initWithURL:(NSURL *)url self.trustPublicPKI = NO; self.validateCertificateChain = NO; self.validateDomainName = YES; + self.pinningMode = MASSecuritySSLPinningModeCertificate; } return self; @@ -99,6 +100,11 @@ - (void)setValuesWithConfiguration:(NSDictionary *)configuration self.trustPublicPKI = [[configuration objectForKey:@"trustPublicPKI"] boolValue]; } + if ([configuration.allKeys containsObject:@"pinningMode"]) + { + self.pinningMode = [MASSecurityConfiguration praseStringToPinningMode:[configuration objectForKey:@"pinningMode"]]; + } + if ([configuration.allKeys containsObject:@"certificates"] && [[configuration objectForKey:@"certificates"] isKindOfClass:[NSArray class]]) { self.certificates = [configuration objectForKey:@"certificates"]; @@ -111,6 +117,27 @@ - (void)setValuesWithConfiguration:(NSDictionary *)configuration } ++ (MASSecuritySSLPinningMode)praseStringToPinningMode:(NSString *)pinningMode +{ + MASSecuritySSLPinningMode pinningModeValue = MASSecuritySSLPinningModeCertificate; + + if ([pinningMode isEqualToString:MASSecurityConfigurationPinningModeCertificate]) + { + pinningModeValue = MASSecuritySSLPinningModeCertificate; + } +// else if ([pinningMode isEqualToString:MASSecurityConfigurationPinningModePublicKey]) +// { +// pinningModeValue = MASSecuritySSLPinningModePublicKey; +// } + else if ([pinningMode isEqualToString:MASSecurityConfigurationPinningModePublicKeyHash]) + { + pinningModeValue = MASSecuritySSLPinningModePublicKeyHash; + } + + return pinningModeValue; +} + + - (NSString *)debugDescription { return [NSString stringWithFormat:@"(%@) for %@\n\nisPublic: %@\nvalidateDomainName: %@\ntrustPublicPKI: %@\ncertificates: %@\npublicKeyHashes: %@\n", [self class], [[self host] absoluteString], self.isPublic ? @"YES":@"NO", self.validateDomainName ? @"YES":@"NO", self.trustPublicPKI ? @"YES":@"NO", self.certificates, self.publicKeyHashes]; From 8bfb76786ee95707104cd24e726944731114d69e Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 8 Jul 2019 14:49:21 +0530 Subject: [PATCH 06/40] fixing a bug in the default behaviour --- .../_private_/services/network/internal/MASSecurityPolicy.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index d3a1cc85..0318cd0f 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -128,7 +128,8 @@ - (BOOL)validateCertPinning:(SecTrustRef)serverTrust configuration:(MASSecurityC // // As of this point, if the configuration forces to validate the entire chain, validate entire chain of certificates // - if ([securityConfiguration validateCertificateChain]) + + if (![securityConfiguration validateCertificateChain]) { int matchingCertificatesCount = 0; From e891ec5b2813d8fe2616fea7292bfe335f32437d Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 23 Jul 2019 11:57:39 +0530 Subject: [PATCH 07/40] Fixed a bug in the way certificates are converted to data and a nil data object was causing a crash. --- .../_private_/models/MASSecurityConfiguration+MASPrivate.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.m b/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.m index 0e60c424..f73bccae 100644 --- a/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.m +++ b/MASFoundation/Classes/_private_/models/MASSecurityConfiguration+MASPrivate.m @@ -23,7 +23,7 @@ - (NSArray *)convertCertificatesToData { NSData *certificateAsData = [NSData pemDataFromCertificateArray:certificate]; - if (certificateAsData) + if (certificateAsData && [certificateAsData length]) { [certsAsData addObject:certificateAsData]; } @@ -32,12 +32,12 @@ - (NSArray *)convertCertificatesToData { NSData *certificateAsData = [NSData dataFromPEMBase64String:certificate]; - if (certificateAsData) + if (certificateAsData && [certificateAsData length]) { [certsAsData addObject:certificateAsData]; } } - else if ([certificate isKindOfClass:[NSData class]]) + else if ([certificate isKindOfClass:[NSData class]] && [certificate length]) { [certsAsData addObject:certificate]; } From 6a2a8f79b53df9a9f4ef87deceec814e5a367c07 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Thu, 25 Jul 2019 12:46:29 +0530 Subject: [PATCH 08/40] added backward compatibility support for public key hash pinning --- .../services/network/internal/MASSecurityPolicy.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index 0318cd0f..6b1ac2f0 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -91,7 +91,18 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo switch (securityConfiguration.pinningMode) { case MASSecuritySSLPinningModeCertificate: { - isPinningVerified = [self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]; + BOOL isPublicKeyHashVerified = NO; + + if (securityConfiguration.publicKeyHashes != nil && [securityConfiguration.publicKeyHashes isKindOfClass:[NSArray class]] && [securityConfiguration.publicKeyHashes count] > 0) + { + isPublicKeyHashVerified = [self validatePublicKeyHash:serverTrust configuration:securityConfiguration]; + } + else + { + isPublicKeyHashVerified = YES; + } + + isPinningVerified = ([self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]) && isPublicKeyHashVerified; } break; case MASSecuritySSLPinningModeIntermediateCertifcate: From a62ab4dd1ce393132c6849c6770dfe0c5481a2a7 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Thu, 25 Jul 2019 15:02:54 +0530 Subject: [PATCH 09/40] some more changes related to backwards compatibility --- .../services/network/internal/MASSecurityPolicy.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index 6b1ac2f0..4a7abe4f 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -102,9 +102,10 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo isPublicKeyHashVerified = YES; } - isPinningVerified = ([self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]) && isPublicKeyHashVerified; + isPinningVerified = ([self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]) || isPublicKeyHashVerified; } break; + case MASSecuritySSLPinningModeIntermediateCertifcate: { isPinningVerified = [self validateIntermediateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]; @@ -162,7 +163,7 @@ - (BOOL)validateCertPinning:(SecTrustRef)serverTrust configuration:(MASSecurityC } } - return YES; + return NO; } @@ -191,7 +192,7 @@ - (BOOL)validateIntermediateCertPinning:(SecTrustRef)serverTrust configuration:( } - return YES; + return NO; } @@ -287,7 +288,7 @@ - (BOOL)validatePublicKeyHash:(SecTrustRef)serverTrust configuration:(MASSecurit } } - return YES; + return NO; } From b176e9bf1a9cad65be25011659e90c2cd0fed104 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 5 Aug 2019 11:02:39 +0530 Subject: [PATCH 10/40] initial code and changes related to file upload --- MASFoundation.xcodeproj/project.pbxproj | 36 +++++ MASFoundation/Classes/MAS.h | 5 + MASFoundation/Classes/MAS.m | 51 +++++++ MASFoundation/Classes/MASConstants.h | 16 ++ .../NSMutableURLRequest+MASPrivate.h | 1 + .../NSMutableURLRequest+MASPrivate.m | 4 + .../services/network/MASNetworkingService.h | 6 + .../services/network/MASNetworkingService.m | 91 +++++++++++ .../network/internal/MASSecurityPolicy.m | 24 ++- .../internal/MASSessionDataTaskOperation.h | 2 + .../internal/MASSessionDataTaskOperation.m | 33 +++- .../internal/MASSessionTaskOperation.m | 6 + .../network/internal/MASURLSessionManager.h | 2 + .../network/internal/MASURLSessionManager.m | 19 +++ .../network/requests/MASPostFormURLRequest.h | 20 +++ .../network/requests/MASPostFormURLRequest.m | 67 ++++++++ .../network/requests/MASPostURLRequest.m | 5 +- .../services/network/requests/MASURLRequest.m | 1 + .../Classes/models/Network/MASFileRequest.h | 19 +++ .../Classes/models/Network/MASFileRequest.m | 13 ++ .../models/Network/MASFileRequestBuilder.h | 32 ++++ .../models/Network/MASFileRequestBuilder.m | 13 ++ .../models/Network/MASMultiPartFormData.h | 63 ++++++++ .../Network/MASMultiPartRequestSerializer.h | 23 +++ .../Network/MASMultiPartRequestSerializer.m | 144 ++++++++++++++++++ .../MASIURLResponseSerialization.m | 1 + 26 files changed, 689 insertions(+), 8 deletions(-) create mode 100644 MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h create mode 100644 MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m create mode 100644 MASFoundation/Classes/models/Network/MASFileRequest.h create mode 100644 MASFoundation/Classes/models/Network/MASFileRequest.m create mode 100644 MASFoundation/Classes/models/Network/MASFileRequestBuilder.h create mode 100644 MASFoundation/Classes/models/Network/MASFileRequestBuilder.m create mode 100644 MASFoundation/Classes/models/Network/MASMultiPartFormData.h create mode 100644 MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h create mode 100644 MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 1bb90265..eb19eb0d 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -185,6 +185,15 @@ C81CC3CD1FC2EA190058718E /* MASBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */; }; C81CC3D01FC2EFBB0058718E /* UIAlertController+MAS.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */; }; C81CC3D11FC2EFBB0058718E /* UIAlertController+MAS.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */; }; + C850970C22D48E7E002182A0 /* MASFileRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = C850970A22D48E7E002182A0 /* MASFileRequest.h */; }; + C850970D22D48E7E002182A0 /* MASFileRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C850970B22D48E7E002182A0 /* MASFileRequest.m */; }; + C8C32B0D22D706B900D64DF0 /* MASMultiPartFormData.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */; settings = {ATTRIBUTES = (Public, ); }; }; + C8C32B1022D7163100D64DF0 /* MASMultiPartRequestSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */; }; + C8C32B1122D7163100D64DF0 /* MASMultiPartRequestSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */; }; + C8C32B1822D88BF100D64DF0 /* MASPostFormURLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */; }; + C8C32B1922D88BF100D64DF0 /* MASPostFormURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */; }; + C8CEAFD222D48D32000B6C8A /* MASFileRequestBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */; }; + C8CEAFD322D48D32000B6C8A /* MASFileRequestBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */; }; CB0B58591E258C2A00BC0163 /* MASAuthorizationResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; CB0B585A1E258C2A00BC0163 /* MASAuthorizationResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */; }; CB1907EF1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */; }; @@ -560,6 +569,15 @@ C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASBrowserBasedAuthentication.m; sourceTree = ""; }; C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertController+MAS.h"; sourceTree = ""; }; C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertController+MAS.m"; sourceTree = ""; }; + C850970A22D48E7E002182A0 /* MASFileRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASFileRequest.h; sourceTree = ""; }; + C850970B22D48E7E002182A0 /* MASFileRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASFileRequest.m; sourceTree = ""; }; + C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartFormData.h; sourceTree = ""; }; + C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartRequestSerializer.h; sourceTree = ""; }; + C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASMultiPartRequestSerializer.m; sourceTree = ""; }; + C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASPostFormURLRequest.h; sourceTree = ""; }; + C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASPostFormURLRequest.m; sourceTree = ""; }; + C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASFileRequestBuilder.h; sourceTree = ""; }; + C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASFileRequestBuilder.m; sourceTree = ""; }; CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASAuthorizationResponse.h; sourceTree = ""; }; CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASAuthorizationResponse.m; sourceTree = ""; }; CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASIKeyChainStore+MASPrivate.h"; sourceTree = ""; }; @@ -897,6 +915,8 @@ CB5E4C671C1D21FB001B3B8A /* MASPostURLRequest.m */, CB5E4C6E1C1D250D001B3B8A /* MASPutURLRequest.h */, CB5E4C6F1C1D250D001B3B8A /* MASPutURLRequest.m */, + C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */, + C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */, ); path = requests; sourceTree = ""; @@ -1227,6 +1247,13 @@ 699C17901F9585BC008C1B11 /* MASRequest.m */, 699C17921F9585BC008C1B11 /* MASRequestBuilder.h */, 699C17931F9585BD008C1B11 /* MASRequestBuilder.m */, + C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */, + C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */, + C850970A22D48E7E002182A0 /* MASFileRequest.h */, + C850970B22D48E7E002182A0 /* MASFileRequest.m */, + C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */, + C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */, + C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */, ); path = Network; sourceTree = ""; @@ -1530,6 +1557,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + C8C32B0D22D706B900D64DF0 /* MASMultiPartFormData.h in Headers */, CB2A4048209A341A00F988AA /* MASMultiFactorHandler.h in Headers */, CB1FD14B1FB23701000AFA25 /* MASSharedStorage.h in Headers */, 69B7DF6A1F9675600056DD3A /* MASRequestBuilder.h in Headers */, @@ -1550,6 +1578,7 @@ CBD25B0C1E78C47C00DFB47F /* JWTBase64Coder.h in Headers */, A419B3A11C176259008DC88C /* NSData+MAS.h in Headers */, A488CE751C0B97FD00B8B961 /* MASService.h in Headers */, + C8CEAFD222D48D32000B6C8A /* MASFileRequestBuilder.h in Headers */, CB6491FB1FE9DAF300281288 /* MQTTSSLSecurityPolicy.h in Headers */, CBD25B0B1E78C47C00DFB47F /* JWT.h in Headers */, CBD25B091E78C47C00DFB47F /* JWTCoding.h in Headers */, @@ -1624,6 +1653,7 @@ CB3173E01F1FFF2C00C85E47 /* MASNetworkMonitor.h in Headers */, A4150EE71BF16E5B00037E27 /* MASFileService.h in Headers */, A46F49C41C2F5FC500A4C370 /* MASIHTTPRequestOperation.h in Headers */, + C8C32B1822D88BF100D64DF0 /* MASPostFormURLRequest.h in Headers */, A46F49E51C2F5FC500A4C370 /* UIProgressView+MASINetworking.h in Headers */, A4150E711BF1643900037E27 /* NSMutableURLRequest+MASPrivate.h in Headers */, A46F49BC1C2F5FC500A4C370 /* fmemopen.h in Headers */, @@ -1675,6 +1705,7 @@ A47F126C1C1D6B4B0008E3F2 /* MASURLRequest.h in Headers */, CB9B1211210949E1008A2075 /* MASASN1Decoder.h in Headers */, 10D2D49E1C1686ED00DF8AC4 /* MASGroup+MASPrivate.h in Headers */, + C8C32B1022D7163100D64DF0 /* MASMultiPartRequestSerializer.h in Headers */, CB5E4C681C1D21FB001B3B8A /* MASPostURLRequest.h in Headers */, A4150ED41BF16D9A00037E27 /* MASNetworkingService.h in Headers */, CB2357961F0EFDEA00D4C420 /* MASSessionTaskOperation.h in Headers */, @@ -1694,6 +1725,7 @@ 10E027A61F72B10100EAB103 /* RNEncryptor.h in Headers */, CB6491E01FE9DAF300281288 /* MQTTCFSocketEncoder.h in Headers */, CBD25AFB1E78C47C00DFB47F /* JWTClaimsSet.h in Headers */, + C850970C22D48E7E002182A0 /* MASFileRequest.h in Headers */, CB6491F11FE9DAF300281288 /* MQTTProperties.h in Headers */, 69B7DF6C1F96756B0056DD3A /* MASRequest+MASPrivate.h in Headers */, A417BA511BF033C300EC9BCB /* CLLocation+MASPrivate.h in Headers */, @@ -1851,6 +1883,7 @@ CB99754F1EDF5837006CEBB1 /* MASAuthCredentialsAuthorizationCode.m in Sources */, A488CE761C0B97FD00B8B961 /* MASService.m in Sources */, A42A86A11BBDA27F00AE98AC /* NSError+MASPrivate.m in Sources */, + C8CEAFD322D48D32000B6C8A /* MASFileRequestBuilder.m in Sources */, A450BC0C1BE1570C0030491F /* NSNotificationCenter+MASPrivate.m in Sources */, A46F49F41C2F5FC500A4C370 /* MASIOrderedDictionary.m in Sources */, CB1907F01C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.m in Sources */, @@ -1905,6 +1938,7 @@ 107389F81C7118F800B7E87E /* MASMQTTClient.m in Sources */, 10E027A31F72B10100EAB103 /* RNCryptorEngine.m in Sources */, CBD25AFC1E78C47C00DFB47F /* JWTClaimsSet.m in Sources */, + C8C32B1122D7163100D64DF0 /* MASMultiPartRequestSerializer.m in Sources */, CBD25AF11E78C47C00DFB47F /* JWTAlgorithmRSBase.m in Sources */, CBD25AEF1E78C47C00DFB47F /* JWTAlgorithmHSBase.m in Sources */, CBD25AF81E78C47C00DFB47F /* JWTCryptoSecurity.m in Sources */, @@ -1949,6 +1983,7 @@ A4831AB21BD1A551007B4AE6 /* MASFile.m in Sources */, CB0B585A1E258C2A00BC0163 /* MASAuthorizationResponse.m in Sources */, CB5E4C651C1D1B56001B3B8A /* MASGetURLRequest.m in Sources */, + C8C32B1922D88BF100D64DF0 /* MASPostFormURLRequest.m in Sources */, CB6491FA1FE9DAF300281288 /* MQTTSessionSynchron.m in Sources */, A4831AB01BD1A551007B4AE6 /* MASDevice.m in Sources */, CBD25B001E78C47C00DFB47F /* JWTClaimsSetVerifier.m in Sources */, @@ -1990,6 +2025,7 @@ A46F49D61C2F5FC500A4C370 /* MASIURLResponseSerialization.m in Sources */, CB1907F91C17950700A5EF16 /* MASAccessService.m in Sources */, CBD25B0A1E78C47C00DFB47F /* JWTCoding.m in Sources */, + C850970D22D48E7E002182A0 /* MASFileRequest.m in Sources */, CBD25B101E78C47C00DFB47F /* JWTErrorDescription.m in Sources */, CB5E4C6D1C1D2467001B3B8A /* MASDeleteURLRequest.m in Sources */, A46F49CE1C2F5FC500A4C370 /* MASINetworkReachabilityManager.m in Sources */, diff --git a/MASFoundation/Classes/MAS.h b/MASFoundation/Classes/MAS.h index cf7c56b0..8719ae97 100644 --- a/MASFoundation/Classes/MAS.h +++ b/MASFoundation/Classes/MAS.h @@ -14,6 +14,7 @@ #import "MASClaims.h" #import "MASRequest.h" #import "MASMultiFactorAuthenticator.h" +#import "MASMultiPartFormData.h" /** * The top level MAS object represents the Mobile App Services SDK in it's entirety. It @@ -1059,6 +1060,10 @@ withParameters:(NSDictionary *_Nullable)parameterInfo +# pragma mark - FILE Requests + ++ (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion; + ///-------------------------------------- /// @name JWT Signing ///-------------------------------------- diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index 3cdaa1a4..caa5ffe7 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -1128,8 +1128,59 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj } ++ (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion +{ + [MAS checkAndValidateRequestScope:request.endPoint headerInfo:request.header isPublic:request.isPublic completion:^(BOOL completed, NSError *error) { + + if(!completed){ + completion(nil,nil,error); + return; + } + + [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic constructingBodyBlock:formDatablock progress:progressBlock completion:completion]; + + }]; +} + + # pragma mark - Private ++ (void)checkAndValidateRequestScope:(NSString*)endPoint headerInfo:(NSDictionary *)headerInfo isPublic:(BOOL)isPublic completion:(MASCompletionErrorBlock)completion +{ + // + // Check for endpoint + // + if (!endPoint) + { + if (completion) + { + completion(NO, [NSError errorInvalidEndpoint]); + + return; + } + } + + // + // Check if MAS has been started. + // + if ([MAS MASState] != MASStateDidStart) + { + if (completion) + { + completion(NO, [NSError errorMASIsNotStarted]); + + return; + } + } + + // + // Validate if new scope has been requested in header + // Validation will be ignored if the request is being made as public + // + [MAS validateScopeForRequest:headerInfo isPublic:isPublic completion:completion]; + +} + + (void)httpMethod:(NSString *)httpMethod endPoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo diff --git a/MASFoundation/Classes/MASConstants.h b/MASFoundation/Classes/MASConstants.h index 92b994ed..1dcec58f 100644 --- a/MASFoundation/Classes/MASConstants.h +++ b/MASFoundation/Classes/MASConstants.h @@ -13,6 +13,7 @@ @class CLLocation; @class MASAuthCredentials; @class MASUser; +@protocol MASMultiPartFormData; /** @@ -113,6 +114,16 @@ typedef void (^MASResponseObjectErrorBlock)(NSHTTPURLResponse *_Nullable respons */ typedef void (^MASUserResponseErrorBlock)(MASUser *_Nullable user, NSError *_Nullable error); +/** + * Progress block for File requests + */ +typedef void (^MASFileRequestProgressBlock) (NSProgress* _Nullable progress); + + +/** + * Multi Part body data that needs to be supplied + */ +typedef void (^MASMultiPartFormDataBlock)(id _Nonnull formData); /** * The MASAuthCredentialsBlcok to provide auth credentials for device registration and/or user authentication. @@ -240,6 +251,11 @@ typedef NS_ENUM(NSInteger, MASRequestResponseType) */ MASRequestResponseTypeXml, + /** + * Standard Multi-part form data + */ + MASRequestResponseTypeFormData, + /** * The total number of supported types. */ diff --git a/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.h b/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.h index 043e0991..20af507a 100644 --- a/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.h +++ b/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.h @@ -17,6 +17,7 @@ extern NSString * const MASRequestResponseTypeScimJsonValue; extern NSString * const MASRequestResponseTypeTextPlainValue; extern NSString * const MASRequestResponseTypeWwwFormUrlEncodedValue; extern NSString * const MASRequestResponseTypeXmlValue; +extern NSString * const MASRequestResponseTypeFormDataValue; @interface NSMutableURLRequest (MASPrivate) diff --git a/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.m b/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.m index 468212b9..c1f646f1 100644 --- a/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.m +++ b/MASFoundation/Classes/_private_/categories/NSMutableURLRequest+MASPrivate.m @@ -69,6 +69,8 @@ - (NSString *)requestResponseTypeAsMimeTypeString:(MASRequestResponseType)type // XML // case MASRequestResponseTypeXml: return MASRequestResponseTypeXmlValue; + + case MASRequestResponseTypeFormData : return MASRequestResponseTypeFormDataValue; // // Default @@ -100,6 +102,8 @@ - (MASRequestResponseType)requestResponseTypeFromMimeTypeString:(NSString *)mime // else if([mimeType isEqualToString:MASRequestResponseTypeXmlValue]) return MASRequestResponseTypeXml; + + else if([mimeType isEqualToString:MASRequestResponseTypeFormDataValue]) return MASRequestResponseTypeFormData; // // Default to text/plain // diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h index c9da95d5..bc6e40fd 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h @@ -667,5 +667,11 @@ withParameters:(NSDictionary *)parameterInfo isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion; + + +# pragma mark - HTTP File Requests + +- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion; + @end diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m index e25f0ae5..ab07bcde 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m @@ -29,6 +29,7 @@ #import "MASSecurityPolicy.h" #import "MASNetworkReachability.h" #import "MASMultiFactorHandler+MASPrivate.h" +#import "MASMultiPartRequestSerializer.h" # pragma mark - Configuration Constants @@ -1388,6 +1389,96 @@ - (void)httpPutTo:(NSString *)endPoint } +- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion +{ + // + // endPoint cannot be nil + // + if (!endPoint) + { + // + // Notify + // + if(completion) completion(nil, nil,[NSError errorInvalidEndpoint]); + + return; + } + + [self httpFileUploadRequest:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic constructingBodyBlock:formDataBlock progress:progress completion:completion]; +} + + +- (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion +{ + NSMutableDictionary *mutableHeaderInfo = [headerInfo mutableCopy]; + + MASURLRequest *request = nil; + + // + // if location was successfully retrieved + // + if ([MASLocationService sharedService].lastKnownLocation != nil) + { + mutableHeaderInfo[MASGeoLocationRequestResponseKey] = [[MASLocationService sharedService].lastKnownLocation locationAsGeoCoordinates]; + } + + request = [MASPostFormURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic constructingBodyBlock:formDataBlock]; + + // + // Construct MASSessionDataTaskOperation with request, and completion block to handle any responsive re-authentication or re-registration. + // + if(self.httpRedirectionBlock) + { + [_sessionManager setSessionDidReceiveHTTPRedirectBlock:self.httpRedirectionBlock]; + } + + MASSessionDataTaskOperation *operation = [self.sessionManager fileUploadOperation:request progress:progress completionHandler:[self sessionDataTaskCompletionBlockWithEndPoint:endPoint parameters:parameterInfo headers:headerInfo httpMethod:request.HTTPMethod requestType:requestType responseType:responseType isPublic:isPublic completionBlock:^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { + if (completion) + { + completion([responseInfo objectForKey:MASNSHTTPURLResponseObjectKey], [responseInfo objectForKey:MASResponseInfoBodyInfoKey], error); + } + }]]; + + if (![self isMAGEndpoint:endPoint]) + { + // + // if the request is being made to system endpoint, and is not a public request which requires user credentials (tokens) + // then, add dependency on shared validation operation which will validate current session + // sharedOperation will only exist one at any given time as long as sharedOperation is being executed + // + if (!isPublic) + { + // + // add dependency + // + [operation addDependency:self.sharedOperation]; + + // + // to make sure SDK to not enqueue sharedOperation that is already enqueue and being executed + // + if (!self.sharedOperation.isFinished && !self.sharedOperation.isExecuting && ![_sessionManager.internalOperationQueue.operations containsObject:self.sharedOperation]) + { + // + // add sharedOperation into internal operation queue + // + [_sessionManager.internalOperationQueue addOperation:self.sharedOperation]; + } + } + + // + // add current request into normal operation queue + // + [_sessionManager.operationQueue addOperation:operation]; + } + else { + // + // if the request is being made to any one of system endpoints (registration, and/or authentication), then, add the operation into internal operation queue + // + [_sessionManager.internalOperationQueue addOperation:operation]; + } +} + + - (void)httpRequest:(NSString *)httpMethod endPoint:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { // diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index d3a1cc85..7e1d8537 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -51,7 +51,8 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo // if (securityConfiguration == nil) { - return NO; + //return NO; + return YES; } NSMutableArray *policies = [NSMutableArray array]; @@ -91,7 +92,18 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo switch (securityConfiguration.pinningMode) { case MASSecuritySSLPinningModeCertificate: { - isPinningVerified = [self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]; + BOOL isPublicKeyHashVerified = NO; + + if (securityConfiguration.publicKeyHashes != nil && [securityConfiguration.publicKeyHashes isKindOfClass:[NSArray class]] && [securityConfiguration.publicKeyHashes count] > 0) + { + isPublicKeyHashVerified = [self validatePublicKeyHash:serverTrust configuration:securityConfiguration]; + } + else + { + isPublicKeyHashVerified = YES; + } + + isPinningVerified = ([self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]) || isPublicKeyHashVerified; } break; case MASSecuritySSLPinningModeIntermediateCertifcate: @@ -150,7 +162,7 @@ - (BOOL)validateCertPinning:(SecTrustRef)serverTrust configuration:(MASSecurityC } } - return YES; + return NO; } @@ -179,7 +191,7 @@ - (BOOL)validateIntermediateCertPinning:(SecTrustRef)serverTrust configuration:( } - return YES; + return NO; } @@ -273,9 +285,11 @@ - (BOOL)validatePublicKeyHash:(SecTrustRef)serverTrust configuration:(MASSecurit { return NO; } + + return YES; } - return YES; + return NO; } diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.h b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.h index e5268bdd..37b832fc 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.h +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.h @@ -23,4 +23,6 @@ @property (nonatomic, copy) MASNetworkDataTaskWillCacheResponseBlock willCacheResponseBlock; @property (nonatomic, copy) MASNetworkDataTaskDidReceiveResponseBlock didReceiveResponseBlock; +- (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *)request progress:(MASFileRequestProgressBlock)progress; + @end diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m index 0329c917..550969bc 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m @@ -21,7 +21,7 @@ @interface MASSessionDataTaskOperation () @property (nonatomic, strong) NSMutableData *responseData; @property (nonatomic, strong) NSError *error; -@property (nonatomic) long long totalBytesExpected; +@property (nonatomic) long long didSendBodyDataBlock; @property (nonatomic) long long bytesReceived; @property (nonatomic, readwrite, getter = isFinished) BOOL finished; @@ -30,6 +30,8 @@ @interface MASSessionDataTaskOperation () @property (nonatomic, readwrite, strong) MASURLRequest *request; @property (nonatomic, readwrite, strong) NSURLSession *session; +@property (nonatomic)MASFileRequestProgressBlock fileProgressblock; + @end @@ -41,6 +43,7 @@ @implementation MASSessionDataTaskOperation - (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *)request { + self = [super initWithSession:session request:request]; if (self) { @@ -51,6 +54,20 @@ - (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *) return self; } +- (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *)request progress:(MASFileRequestProgressBlock)progress +{ + self = [super initWithSession:session request:request]; + if(self) + { + self.request = (MASURLRequest *)request; + [self setResponseType:self.request.responseType]; + self.fileProgressblock = progress; + } + + return self; + +} + # pragma mark - Public - (void)updateSession:(NSURLSession *)session @@ -193,6 +210,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler { + NSLog(@"did receive content disposition"); NSURLSessionResponseDisposition disposition = NSURLSessionResponseAllow; if (self.didReceiveResponseBlock) @@ -279,4 +297,17 @@ - (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session } + +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend +{ + + NSLog(@"total bytes sent - %lld total bytes expected %lld",totalBytesSent,totalBytesExpectedToSend); + if(self.fileProgressblock){ + //NSProgress* progress = [NSProgress progressWithTotalUnitCount:totalBytesExpectedToSend]; + //[progress set] + self.fileProgressblock(task.progress); + } + + [super URLSession:session task:task didSendBodyData:bytesSent totalBytesSent:totalBytesSent totalBytesExpectedToSend:totalBytesExpectedToSend]; +} @end diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m b/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m index 9b488a77..42839239 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m @@ -54,6 +54,8 @@ - (instancetype)initWithSession:(NSURLSession *)session request:(NSURLRequest *) } + + # pragma mark - Public - (void)updateSession:(NSURLSession *)session @@ -218,6 +220,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSend self.didSendBodyDataBlock(session, task, bytesSent, totalBytesSent, totalBytesExpectedToSend); }); } + } @@ -232,4 +235,7 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp } } + +//- (void)URLSe + @end diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.h b/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.h index aee49747..317f6fce 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.h +++ b/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.h @@ -14,6 +14,7 @@ #import "MASSecurityPolicy.h" #import "MASSessionDataTaskOperation.h" #import "MASURLRequest.h" +#import "MASPostFormURLRequest.h" // // NSURLSessionDelegate @@ -81,6 +82,7 @@ typedef void (^MASNetworkSessionDidFinishEventsForBackgroundURLSessionBlock)(NSU - (MASSessionDataTaskOperation *)dataOperationWithRequest:(MASURLRequest *)request completionHandler:(MASSessionDataTaskCompletionBlock)completionHandler; +-(MASSessionDataTaskOperation *)fileUploadOperation:(MASURLRequest *)request progress:(MASFileRequestProgressBlock)progress completionHandler:(MASSessionDataTaskCompletionBlock)completionHandler; ///-------------------------------------- /// @name Public diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.m b/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.m index e96ff1dc..e3181367 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASURLSessionManager.m @@ -12,6 +12,8 @@ #import "MASSecurityService.h" +#import "MASPostFormURLRequest.h" + @interface MASURLSessionManager () @property (readwrite, nonatomic, strong) NSURLSession *session; @@ -168,6 +170,23 @@ - (MASSessionDataTaskOperation *)dataOperationWithRequest:(MASURLRequest *)reque return dataTask; } +-(MASSessionDataTaskOperation *)fileUploadOperation:(MASURLRequest *)request progress:(MASFileRequestProgressBlock)progress completionHandler:(MASSessionDataTaskCompletionBlock)completionHandler +{ + MASSessionDataTaskOperation *dataTask = [[MASSessionDataTaskOperation alloc] initWithSession:_session request:request progress:progress]; + + [self.operations addObject:dataTask]; + + dataTask.didCompleteWithDataErrorBlock = ^(NSURLSession *session, NSURLSessionTask *task, NSData *data, NSError *error) { + + if (completionHandler) + { + completionHandler(task.response, data, error); + } + }; + + return dataTask; +} + # pragma mark - NSOperationQueue diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h new file mode 100644 index 00000000..0fb6a343 --- /dev/null +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h @@ -0,0 +1,20 @@ +// +// MASPostFormURLRequest.h +// MASFoundation +// +// Created by nimma01 on 12/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASURLRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MASPostFormURLRequest : MASURLRequest + + ++ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock; + +@end + +NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m new file mode 100644 index 00000000..da724f1b --- /dev/null +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m @@ -0,0 +1,67 @@ +// +// MASPostFormURLRequest.m +// MASFoundation +// +// Created by nimma01 on 12/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASPostFormURLRequest.h" +#import "MASMultiPartRequestSerializer.h" + + +#define kMASHTTPPostRequestMethod @"POST" + +@implementation MASPostFormURLRequest + + ++ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock +{ + // + // Adding prefix to the endpoint path + // + if ([MASConfiguration currentConfiguration].gatewayPrefix && ![endPoint hasPrefix:@"http://"] && ![endPoint hasPrefix:@"https://"]) + { + endPoint = [NSString stringWithFormat:@"%@%@",[MASConfiguration currentConfiguration].gatewayPrefix, endPoint]; + } + + // + // Full URL path (no query parameters go here) + // + NSURL *url = [NSURL URLWithString:endPoint relativeToURL:[MASConfiguration currentConfiguration].gatewayUrl]; + + NSAssert(url, @"URL cannot be nil"); + + // + // Create the request + // + MASPostFormURLRequest *request = [MASPostFormURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:240]; + + // + // Method + // + [request setHTTPMethod:kMASHTTPPostRequestMethod]; + + [request setHeaderInfo:headerInfo forRequestType:requestType andResponseType:responseType]; + + // + // capture request + // + request.isPublic = isPublic; + request.requestType = requestType; + request.responseType = responseType; + request.headerInfo = headerInfo; + request.parameterInfo = parameterInfo; + request.endPoint = endPoint; + + __block MASMultiPartRequestSerializer* formData = [[MASMultiPartRequestSerializer alloc] initWithURLRequest:request]; + + if(formDataBlock){ + formDataBlock(formData); + } + + return [formData requestByFinalizingMultipartFormData]; + + +} +@end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m index 06f16d11..c8304053 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m @@ -70,14 +70,15 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // Body ... format the parameter dictionary to data for the request type if there is anything // to format. It's possible there isn't. // - NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; + // THIS PART Is not needed. Confirm from testing + /* NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; if(data) { // // Set the body with the data // [request setHTTPBody:data]; - } + }*/ return request; } diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.m index cb982295..745234da 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.m @@ -15,6 +15,7 @@ NSString * const MASRequestResponseTypeTextPlainValue = @"text/plain"; NSString * const MASRequestResponseTypeWwwFormUrlEncodedValue = @"application/x-www-form-urlencoded"; NSString * const MASRequestResponseTypeXmlValue = @"application/xml"; +NSString * const MASRequestResponseTypeFormDataValue = @"multipart/form-data"; @implementation MASURLRequest diff --git a/MASFoundation/Classes/models/Network/MASFileRequest.h b/MASFoundation/Classes/models/Network/MASFileRequest.h new file mode 100644 index 00000000..629a1e37 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASFileRequest.h @@ -0,0 +1,19 @@ +// +// MASFileRequest.h +// MASFoundation +// +// Created by nimma01 on 09/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface MASFileRequest : MASRequest + +@property(nonatomic) NSString* boundary; + +@end + +NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASFileRequest.m b/MASFoundation/Classes/models/Network/MASFileRequest.m new file mode 100644 index 00000000..31a9c7ed --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASFileRequest.m @@ -0,0 +1,13 @@ +// +// MASFileRequest.m +// MASFoundation +// +// Created by nimma01 on 09/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASFileRequest.h" + +@implementation MASFileRequest + +@end diff --git a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h new file mode 100644 index 00000000..c4cb3c02 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h @@ -0,0 +1,32 @@ +// +// MASFileRequestBuilder.h +// MASFoundation +// +// Created by nimma01 on 09/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import +#import "MASFileRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MASFileRequestBuilder : MASRequestBuilder + + +@property (nonatomic) NSString* boundary; + +//@property (nonatomic) +/** + Create a MASFileRequest object using the parameters from MASRequestBuider + + @return MASFileRequest object + */ +- (MASFileRequest *_Nullable)build; + + + + +@end + +NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m new file mode 100644 index 00000000..cc0f2a78 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m @@ -0,0 +1,13 @@ +// +// MASFileRequestBuilder.m +// MASFoundation +// +// Created by nimma01 on 09/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASFileRequestBuilder.h" + +@implementation MASFileRequestBuilder + +@end diff --git a/MASFoundation/Classes/models/Network/MASMultiPartFormData.h b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h new file mode 100644 index 00000000..950f002b --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h @@ -0,0 +1,63 @@ +// +// MASMultiPartFormData.h +// MASFoundation +// +// Created by nimma01 on 11/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#ifndef MASMultiPartFormData_h +#define MASMultiPartFormData_h + +@protocol MASMultiPartFormData + + +/** + Appends the HTTP header `Content-Disposition: file; filename=#{generated filename}; name=#{name}"` and `Content-Type: #{generated mimeType}`, followed by the encoded file data and the multipart form boundary. + + The filename and MIME type for this data in the form will be automatically generated, using the last path component of the `fileURL` and system associated MIME type for the `fileURL` extension, respectively. + + @param fileURL The URL corresponding to the file whose content will be appended to the form. This parameter must not be `nil`. + @param name The name to be associated with the specified data. This parameter must not be `nil`. + @param error If an error occurs, upon return contains an `NSError` object that describes the problem. + + @return `YES` if the file data was successfully appended, otherwise `NO`. + */ +- (BOOL)appendPartWithFileURL:(NSURL * __nonnull)fileURL name:(NSString * __nonnull)name error:(NSError *_Nullable* _Nullable)error; + + +/** + Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary. + + @param fileURL The URL corresponding to the file whose content will be appended to the form. This parameter must not be `nil`. + @param name The name to be associated with the specified data. This parameter must not be `nil`. + @param fileName The file name to be used in the `Content-Disposition` header. This parameter must not be `nil`. + @param mimeType The declared MIME type of the file data. This parameter must not be `nil`. + @param error If an error occurs, upon return contains an `NSError` object that describes the problem. + + @return `YES` if the file data was successfully appended otherwise `NO`. + */ +- (BOOL)appendPartWithFileURL:(NSURL * __nonnull)fileURL name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType error:(NSError *_Nullable* _Nullable)error; + + +/** + Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary. + + @param data The data to be encoded and appended to the form data. + @param name The name to be associated with the specified data. This parameter must not be `nil`. + @param fileName The filename to be associated with the specified data. This parameter must not be `nil`. + @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`. + */ +- (void)appendPartWithFileData:(NSData * __nonnull)data name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType; + +/** + Appends the HTTP headers `Content-Disposition: form-data; name=#{name}"`, followed by the encoded data and the multipart form boundary. + + @param data The data to be encoded and appended to the form data. + @param name The name to be associated with the specified data. This parameter must not be `nil`. + */ + +- (void)appendPartWithFormData:(NSData * __nonnull)data name:(NSString * __nonnull)name; + +@end +#endif /* MASMultiPartFormData_h */ diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h new file mode 100644 index 00000000..3c68e440 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h @@ -0,0 +1,23 @@ +// +// MASMultiPartRequestSerializer.h +// MASFoundation +// +// Created by nimma01 on 11/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import +#import "MASMultiPartFormData.h" +#import "MASPostFormURLRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MASMultiPartRequestSerializer : NSObject + +- (id)initWithURLRequest:(MASPostFormURLRequest *)request; + +- (MASPostFormURLRequest *)requestByFinalizingMultipartFormData; + +@end + +NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m new file mode 100644 index 00000000..cde4bc0e --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m @@ -0,0 +1,144 @@ +// +// MASMultiPartRequestSerializer.m +// MASFoundation +// +// Created by nimma01 on 11/07/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASMultiPartRequestSerializer.h" +#import + +@interface MASMultiPartRequestSerializer() +{ + +} + +@property(nonatomic) NSString* boundary; +@property(nonatomic) NSMutableData* body; +@property(nonatomic) MASURLRequest* request; + +@end + +static NSString * MASCreateMultipartFormBoundary() { + return [NSString stringWithFormat:@"Boundary+%08X%08X", arc4random(), arc4random()]; +} + + +static inline NSString * MASMultipartFormEncapsulationBoundary(NSString *boundary) { + return [NSString stringWithFormat:@"%@--%@%@", @"\r\n", boundary, @"\r\n"]; +} + + +static inline NSString * MASMultipartFormFinalBoundary(NSString *boundary) { + return [NSString stringWithFormat:@"%@--%@--%@", @"\r\n", boundary, @"\r\n"]; +} + +static inline NSString * MASContentTypeForPathExtension(NSString *extension) { +#ifdef __UTTYPE__ + NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL); + NSString *contentType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType); + if (!contentType) { + return @"application/octet-stream"; + } else { + return contentType; + } +#else +#pragma unused (extension) + return @"application/octet-stream"; +#endif +} + +@implementation MASMultiPartRequestSerializer + + +- (id)initWithURLRequest:(MASPostFormURLRequest *)request +{ + if(self = [super init]) + { + self.request = request; + self.boundary = MASCreateMultipartFormBoundary(); + self.body = [NSMutableData data]; + [self setInitialHeadersforRequest]; + [self setBodyParameters]; + + } + + return self; +} + +-(void)setInitialHeadersforRequest +{ + NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", self.boundary]; + [self.request addValue:contentType forHTTPHeaderField:@"Content-Type"]; +} + + +-(void)setBodyParameters +{ + [self.request.parameterInfo enumerateKeysAndObjectsUsingBlock:^(NSString *parameterKey, NSString *parameterValue, BOOL *stop) { + [self.body appendData:[[NSString stringWithFormat:@"%@", self.boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", parameterKey] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"%@\r\n", parameterValue] dataUsingEncoding:NSUTF8StringEncoding]]; + }]; +} + + +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError *__autoreleasing _Nullable *)error +{ + return [self appendPartWithFileURL:fileURL name:name fileName:name mimeType:MASContentTypeForPathExtension([fileURL pathExtension]) error:error]; +} + +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType error:(NSError *__autoreleasing _Nullable *)error +{ + if(!fileURL || !name) + { + return NO; + } + + [self.body appendData:[[NSString stringWithFormat:@"%@", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, fileName] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", mimeType] dataUsingEncoding:NSUTF8StringEncoding]]; + NSData* data = [NSData dataWithContentsOfURL:fileURL]; + [self.body appendData:data]; + [self.body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; + + + return YES; +} + + +- (void)appendPartWithFormData:(NSData *)data name:(NSString *)name +{ + [self.body appendData:[[NSString stringWithFormat:@"%@", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"", name] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:data]; +} + + +-(void)appendPartWithFileData:(NSData *)data name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType +{ + [self.body appendData:[[NSString stringWithFormat:@"--%@\r\n", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, fileName] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", mimeType] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:data]; + [self.body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; +} + + +- (MASURLRequest *)requestByFinalizingMultipartFormData { + if (!self.body) { + return self.request; + } + + [self.body appendData:[[NSString stringWithFormat:@"%@", MASMultipartFormFinalBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; + + [self.request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", self.boundary] forHTTPHeaderField:@"Content-Type"]; + [self.request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[self.body length]] forHTTPHeaderField:@"Content-Length"]; + // Reset the initial and final boundaries to ensure correct Content-Length + [self.request setHTTPBody:self.body]; + + return self.request; +} + +@end diff --git a/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m b/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m index 4e28e867..1e43938e 100755 --- a/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m +++ b/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m @@ -111,6 +111,7 @@ - (BOOL)validateResponse:(NSHTTPURLResponse *)response NSError *validationError = nil; if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) { + NSLog(@"response mime type is %@",[response MIMEType]); if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]]) { if ([data length] > 0 && [response URL]) { NSMutableDictionary *mutableUserInfo = [@{ From 0bd088240af405069f77a827bc77b6b636663416 Mon Sep 17 00:00:00 2001 From: Syed Yusuf Date: Mon, 5 Aug 2019 18:57:30 +0530 Subject: [PATCH 11/40] US604884 : iOS - iOS 13 Close gaps - Fix for ASN.1 decoder parser missing MASASN1TagBitStr --- .../services/security/ASN1CertificateParse/MASASN1Decoder.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MASFoundation/Classes/_private_/services/security/ASN1CertificateParse/MASASN1Decoder.m b/MASFoundation/Classes/_private_/services/security/ASN1CertificateParse/MASASN1Decoder.m index 6cf1c60d..9a5c3134 100644 --- a/MASFoundation/Classes/_private_/services/security/ASN1CertificateParse/MASASN1Decoder.m +++ b/MASFoundation/Classes/_private_/services/security/ASN1CertificateParse/MASASN1Decoder.m @@ -194,7 +194,11 @@ - (NSMutableArray *)parseWithRange:(NSRange)range } case MASASN1TagBitStr: { - NSData *dataWithoutUnusedBit = [subContentData subdataWithRange:NSMakeRange(1, [subContentData length]-1)]; + NSData *dataWithoutUnusedBit = [NSData data]; + if (subContentData && [subContentData length]) { + + dataWithoutUnusedBit = [subContentData subdataWithRange:NSMakeRange(1, [subContentData length]-1)]; + } thisObject.value = dataWithoutUnusedBit; break; } From 2d326b51b7174eff3376314943f0e4115f895b53 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Wed, 7 Aug 2019 14:54:11 +0530 Subject: [PATCH 12/40] fixed a bug in not setting mag identifier --- .../services/network/requests/MASPostFormURLRequest.m | 9 +++++++++ .../services/network/requests/MASPostURLRequest.m | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m index da724f1b..078833c9 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m @@ -64,4 +64,13 @@ + (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameter } + +- (MASURLRequest *)rebuildRequest +{ + [self setHeaderInfo:self.headerInfo forRequestType:self.requestType andResponseType:self.responseType]; + + return self; +} + + @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m index c8304053..daf0f7b8 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m @@ -71,14 +71,14 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // to format. It's possible there isn't. // // THIS PART Is not needed. Confirm from testing - /* NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; + NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; if(data) { // // Set the body with the data // [request setHTTPBody:data]; - }*/ + } return request; } From 5601b5d68f628d3b2c5f3cc8f64a8024d0f483bf Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Thu, 8 Aug 2019 09:54:10 +0530 Subject: [PATCH 13/40] fixed a bug found in dev testing --- .../services/network/internal/MASSecurityPolicy.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index 4a7abe4f..78b0e5ff 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -102,7 +102,7 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo isPublicKeyHashVerified = YES; } - isPinningVerified = ([self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]) || isPublicKeyHashVerified; + isPinningVerified = ([self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]) && isPublicKeyHashVerified; } break; @@ -160,6 +160,8 @@ - (BOOL)validateCertPinning:(SecTrustRef)serverTrust configuration:(MASSecurityC { return NO; } + + return YES; } } @@ -190,6 +192,8 @@ - (BOOL)validateIntermediateCertPinning:(SecTrustRef)serverTrust configuration:( } } + return YES; + } return NO; @@ -286,6 +290,8 @@ - (BOOL)validatePublicKeyHash:(SecTrustRef)serverTrust configuration:(MASSecurit { return NO; } + + return YES; } return NO; From 34952fa0dcf4af83d9270cd60de95bde420fd8b7 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Thu, 8 Aug 2019 09:58:18 +0530 Subject: [PATCH 14/40] updated version number to 2.0.00 --- MASFoundation/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MASFoundation/Info.plist b/MASFoundation/Info.plist index d27f5019..b6725b18 100644 --- a/MASFoundation/Info.plist +++ b/MASFoundation/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.9.20 + 2.0.00 CFBundleSignature ???? CFBundleVersion From 42c1dca9584c073925f22e9102f85c3dc2e3ecfd Mon Sep 17 00:00:00 2001 From: Syed Yusuf Date: Tue, 13 Aug 2019 18:22:25 +0530 Subject: [PATCH 15/40] US604884 : iOS - Using the new SecTrustEvaluateWithError for iOS 13 intead of deprecated SecTrustEvaluate --- .../services/network/internal/MASSecurityPolicy.m | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index 78b0e5ff..62a4cbd6 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -304,13 +304,20 @@ - (BOOL)validateServerTrust:(SecTrustRef)serverTrust { BOOL isValid = YES; SecTrustResultType result = 0; + CFErrorRef trustErrorRef = NULL; - if (SecTrustEvaluate(serverTrust, &result) != errSecSuccess) - { - isValid = NO; + if ([NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){13,0,0}]) { + + isValid = SecTrustEvaluateWithError(serverTrust, &trustErrorRef); } else { - isValid = (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed); + if (SecTrustEvaluate(serverTrust, &result) != errSecSuccess) + { + isValid = NO; + } + else { + isValid = (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed); + } } return isValid; From f97c6061bfe79436f00339ef3427ab2d0889273f Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 19 Aug 2019 15:29:40 +0530 Subject: [PATCH 16/40] fixed an issue where multi-part body boundary was missing from the headers --- .../network/requests/MASPostFormURLRequest.m | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m index 078833c9..fe2d6a04 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m @@ -73,4 +73,66 @@ - (MASURLRequest *)rebuildRequest } +//overriding the behavior for this class as the super class does not know about boundary string + +- (void)setHeaderInfo:(NSDictionary *)headerInfo forRequestType:(MASRequestResponseType)requestType andResponseType:(MASRequestResponseType)responseType +{ + + //don't set the request type as we don't want to disturb the boundary string + + // + // Accept based on MASRequestResponseType + // + [self setValue:[self requestResponseTypeAsMimeTypeString:responseType] forHTTPHeaderField:MASAcceptRequestResponseKey]; + + NSString *lowerKey; + NSString *value; + for(NSString *key in [headerInfo allKeys]) + { + lowerKey = [key lowercaseString]; + value = [headerInfo objectForKey:key]; + [self setValue:value forHTTPHeaderField:key]; + } +} + +//overriding the behavior for this class as the super class does not know about boundary string +- (NSString *)requestResponseTypeAsMimeTypeString:(MASRequestResponseType)type +{ + // + // Detect type and respond approriately + // + switch(type) + { + // + // JSON + // + case MASRequestResponseTypeJson: return MASRequestResponseTypeJsonValue; + + // + // SCIM variant JSON + // + case MASRequestResponseTypeScimJson: return MASRequestResponseTypeScimJsonValue; + + // + // Form URL Encoded + // + case MASRequestResponseTypeWwwFormUrlEncoded: return MASRequestResponseTypeWwwFormUrlEncodedValue; + + // + // XML + // + case MASRequestResponseTypeXml: return MASRequestResponseTypeXmlValue; + + case MASRequestResponseTypeFormData : return MASRequestResponseTypeFormDataValue; + + // + // Default + // + default: return MASRequestResponseTypeTextPlainValue; + } +} + + + + @end From aef4d9a21c47937c3d74fb7aa0ca125f68897314 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 20 Aug 2019 15:59:29 +0530 Subject: [PATCH 17/40] removed unnecessary files from the project --- MASFoundation.xcodeproj/project.pbxproj | 16 ---------- .../Classes/models/Network/MASFileRequest.h | 19 ----------- .../Classes/models/Network/MASFileRequest.m | 13 -------- .../models/Network/MASFileRequestBuilder.h | 32 ------------------- .../models/Network/MASFileRequestBuilder.m | 13 -------- 5 files changed, 93 deletions(-) delete mode 100644 MASFoundation/Classes/models/Network/MASFileRequest.h delete mode 100644 MASFoundation/Classes/models/Network/MASFileRequest.m delete mode 100644 MASFoundation/Classes/models/Network/MASFileRequestBuilder.h delete mode 100644 MASFoundation/Classes/models/Network/MASFileRequestBuilder.m diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index eb19eb0d..511a184e 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -185,15 +185,11 @@ C81CC3CD1FC2EA190058718E /* MASBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */; }; C81CC3D01FC2EFBB0058718E /* UIAlertController+MAS.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */; }; C81CC3D11FC2EFBB0058718E /* UIAlertController+MAS.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */; }; - C850970C22D48E7E002182A0 /* MASFileRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = C850970A22D48E7E002182A0 /* MASFileRequest.h */; }; - C850970D22D48E7E002182A0 /* MASFileRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C850970B22D48E7E002182A0 /* MASFileRequest.m */; }; C8C32B0D22D706B900D64DF0 /* MASMultiPartFormData.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */; settings = {ATTRIBUTES = (Public, ); }; }; C8C32B1022D7163100D64DF0 /* MASMultiPartRequestSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */; }; C8C32B1122D7163100D64DF0 /* MASMultiPartRequestSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */; }; C8C32B1822D88BF100D64DF0 /* MASPostFormURLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */; }; C8C32B1922D88BF100D64DF0 /* MASPostFormURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */; }; - C8CEAFD222D48D32000B6C8A /* MASFileRequestBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */; }; - C8CEAFD322D48D32000B6C8A /* MASFileRequestBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */; }; CB0B58591E258C2A00BC0163 /* MASAuthorizationResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; CB0B585A1E258C2A00BC0163 /* MASAuthorizationResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */; }; CB1907EF1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */; }; @@ -569,15 +565,11 @@ C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASBrowserBasedAuthentication.m; sourceTree = ""; }; C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertController+MAS.h"; sourceTree = ""; }; C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertController+MAS.m"; sourceTree = ""; }; - C850970A22D48E7E002182A0 /* MASFileRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASFileRequest.h; sourceTree = ""; }; - C850970B22D48E7E002182A0 /* MASFileRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASFileRequest.m; sourceTree = ""; }; C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartFormData.h; sourceTree = ""; }; C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASMultiPartRequestSerializer.h; sourceTree = ""; }; C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASMultiPartRequestSerializer.m; sourceTree = ""; }; C8C32B1622D88BF100D64DF0 /* MASPostFormURLRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASPostFormURLRequest.h; sourceTree = ""; }; C8C32B1722D88BF100D64DF0 /* MASPostFormURLRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASPostFormURLRequest.m; sourceTree = ""; }; - C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASFileRequestBuilder.h; sourceTree = ""; }; - C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASFileRequestBuilder.m; sourceTree = ""; }; CB0B58571E258C2A00BC0163 /* MASAuthorizationResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASAuthorizationResponse.h; sourceTree = ""; }; CB0B58581E258C2A00BC0163 /* MASAuthorizationResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASAuthorizationResponse.m; sourceTree = ""; }; CB1907ED1C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASIKeyChainStore+MASPrivate.h"; sourceTree = ""; }; @@ -1247,10 +1239,6 @@ 699C17901F9585BC008C1B11 /* MASRequest.m */, 699C17921F9585BC008C1B11 /* MASRequestBuilder.h */, 699C17931F9585BD008C1B11 /* MASRequestBuilder.m */, - C8CEAFD022D48D32000B6C8A /* MASFileRequestBuilder.h */, - C8CEAFD122D48D32000B6C8A /* MASFileRequestBuilder.m */, - C850970A22D48E7E002182A0 /* MASFileRequest.h */, - C850970B22D48E7E002182A0 /* MASFileRequest.m */, C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */, C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */, C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */, @@ -1578,7 +1566,6 @@ CBD25B0C1E78C47C00DFB47F /* JWTBase64Coder.h in Headers */, A419B3A11C176259008DC88C /* NSData+MAS.h in Headers */, A488CE751C0B97FD00B8B961 /* MASService.h in Headers */, - C8CEAFD222D48D32000B6C8A /* MASFileRequestBuilder.h in Headers */, CB6491FB1FE9DAF300281288 /* MQTTSSLSecurityPolicy.h in Headers */, CBD25B0B1E78C47C00DFB47F /* JWT.h in Headers */, CBD25B091E78C47C00DFB47F /* JWTCoding.h in Headers */, @@ -1725,7 +1712,6 @@ 10E027A61F72B10100EAB103 /* RNEncryptor.h in Headers */, CB6491E01FE9DAF300281288 /* MQTTCFSocketEncoder.h in Headers */, CBD25AFB1E78C47C00DFB47F /* JWTClaimsSet.h in Headers */, - C850970C22D48E7E002182A0 /* MASFileRequest.h in Headers */, CB6491F11FE9DAF300281288 /* MQTTProperties.h in Headers */, 69B7DF6C1F96756B0056DD3A /* MASRequest+MASPrivate.h in Headers */, A417BA511BF033C300EC9BCB /* CLLocation+MASPrivate.h in Headers */, @@ -1883,7 +1869,6 @@ CB99754F1EDF5837006CEBB1 /* MASAuthCredentialsAuthorizationCode.m in Sources */, A488CE761C0B97FD00B8B961 /* MASService.m in Sources */, A42A86A11BBDA27F00AE98AC /* NSError+MASPrivate.m in Sources */, - C8CEAFD322D48D32000B6C8A /* MASFileRequestBuilder.m in Sources */, A450BC0C1BE1570C0030491F /* NSNotificationCenter+MASPrivate.m in Sources */, A46F49F41C2F5FC500A4C370 /* MASIOrderedDictionary.m in Sources */, CB1907F01C1794F400A5EF16 /* MASIKeyChainStore+MASPrivate.m in Sources */, @@ -2025,7 +2010,6 @@ A46F49D61C2F5FC500A4C370 /* MASIURLResponseSerialization.m in Sources */, CB1907F91C17950700A5EF16 /* MASAccessService.m in Sources */, CBD25B0A1E78C47C00DFB47F /* JWTCoding.m in Sources */, - C850970D22D48E7E002182A0 /* MASFileRequest.m in Sources */, CBD25B101E78C47C00DFB47F /* JWTErrorDescription.m in Sources */, CB5E4C6D1C1D2467001B3B8A /* MASDeleteURLRequest.m in Sources */, A46F49CE1C2F5FC500A4C370 /* MASINetworkReachabilityManager.m in Sources */, diff --git a/MASFoundation/Classes/models/Network/MASFileRequest.h b/MASFoundation/Classes/models/Network/MASFileRequest.h deleted file mode 100644 index 629a1e37..00000000 --- a/MASFoundation/Classes/models/Network/MASFileRequest.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// MASFileRequest.h -// MASFoundation -// -// Created by nimma01 on 09/07/19. -// Copyright © 2019 CA Technologies. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface MASFileRequest : MASRequest - -@property(nonatomic) NSString* boundary; - -@end - -NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASFileRequest.m b/MASFoundation/Classes/models/Network/MASFileRequest.m deleted file mode 100644 index 31a9c7ed..00000000 --- a/MASFoundation/Classes/models/Network/MASFileRequest.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// MASFileRequest.m -// MASFoundation -// -// Created by nimma01 on 09/07/19. -// Copyright © 2019 CA Technologies. All rights reserved. -// - -#import "MASFileRequest.h" - -@implementation MASFileRequest - -@end diff --git a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h deleted file mode 100644 index c4cb3c02..00000000 --- a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// MASFileRequestBuilder.h -// MASFoundation -// -// Created by nimma01 on 09/07/19. -// Copyright © 2019 CA Technologies. All rights reserved. -// - -#import -#import "MASFileRequest.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface MASFileRequestBuilder : MASRequestBuilder - - -@property (nonatomic) NSString* boundary; - -//@property (nonatomic) -/** - Create a MASFileRequest object using the parameters from MASRequestBuider - - @return MASFileRequest object - */ -- (MASFileRequest *_Nullable)build; - - - - -@end - -NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m b/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m deleted file mode 100644 index cc0f2a78..00000000 --- a/MASFoundation/Classes/models/Network/MASFileRequestBuilder.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// MASFileRequestBuilder.m -// MASFoundation -// -// Created by nimma01 on 09/07/19. -// Copyright © 2019 CA Technologies. All rights reserved. -// - -#import "MASFileRequestBuilder.h" - -@implementation MASFileRequestBuilder - -@end From 4dc7d1479494eb4cbb70478f103b1ec387986c05 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 20 Aug 2019 16:02:48 +0530 Subject: [PATCH 18/40] rectified unwanted change in security policy --- .../_private_/services/network/internal/MASSecurityPolicy.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index 2dad57f1..78b0e5ff 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -51,8 +51,7 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo // if (securityConfiguration == nil) { - //return NO; - return YES; + return NO; } NSMutableArray *policies = [NSMutableArray array]; From a93d3c83121d25b215e1564e6f4a358bbf694de6 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 20 Aug 2019 16:06:48 +0530 Subject: [PATCH 19/40] removed unnecessary params --- .../services/network/internal/MASSessionDataTaskOperation.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m index 550969bc..7889c12a 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionDataTaskOperation.m @@ -21,7 +21,7 @@ @interface MASSessionDataTaskOperation () @property (nonatomic, strong) NSMutableData *responseData; @property (nonatomic, strong) NSError *error; -@property (nonatomic) long long didSendBodyDataBlock; +@property (nonatomic) long long totalBytesExpected; @property (nonatomic) long long bytesReceived; @property (nonatomic, readwrite, getter = isFinished) BOOL finished; @@ -210,7 +210,6 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler { - NSLog(@"did receive content disposition"); NSURLSessionResponseDisposition disposition = NSURLSessionResponseAllow; if (self.didReceiveResponseBlock) From c597904cef6c07bf48ea3756cfcd55564e6783ce Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 20 Aug 2019 16:09:24 +0530 Subject: [PATCH 20/40] undid few changes --- .../services/network/internal/MASSessionTaskOperation.m | 2 -- .../_private_/services/network/requests/MASPostURLRequest.m | 1 - .../Vendor/MASINetworking/MASIURLResponseSerialization.m | 1 - 3 files changed, 4 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m b/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m index 42839239..db685612 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSessionTaskOperation.m @@ -236,6 +236,4 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp } -//- (void)URLSe - @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m index daf0f7b8..06f16d11 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m @@ -70,7 +70,6 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // Body ... format the parameter dictionary to data for the request type if there is anything // to format. It's possible there isn't. // - // THIS PART Is not needed. Confirm from testing NSData *data = [self dataForBodyFromParameterInfo:parameterInfo forRequestType:requestType]; if(data) { diff --git a/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m b/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m index 1e43938e..4e28e867 100755 --- a/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m +++ b/MASFoundation/Vendor/MASINetworking/MASIURLResponseSerialization.m @@ -111,7 +111,6 @@ - (BOOL)validateResponse:(NSHTTPURLResponse *)response NSError *validationError = nil; if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) { - NSLog(@"response mime type is %@",[response MIMEType]); if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]]) { if ([data length] > 0 && [response URL]) { NSMutableDictionary *mutableUserInfo = [@{ From 784c680da0c164534bfd60db96e5a52aa0dc7fa1 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Wed, 21 Aug 2019 16:31:28 +0530 Subject: [PATCH 21/40] throwing an error form the API if the request is not in the proper format for multi-part file upload --- MASFoundation/Classes/MAS.m | 7 +++++++ MASFoundation/Classes/MASError.h | 6 ++++++ .../Classes/_private_/categories/NSError+MASPrivate.h | 9 +++++++++ .../Classes/_private_/categories/NSError+MASPrivate.m | 11 +++++++++++ 4 files changed, 33 insertions(+) diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index caa5ffe7..dce1cdee 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -1130,6 +1130,13 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj + (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion { + if(![request.httpMethod isEqualToString:@"POST"] || request.requestType != MASRequestResponseTypeFormData) + { + NSError* error = [NSError errorInvalidRequestForFileUpload]; + completion(nil,nil,error); + return; + } + [MAS checkAndValidateRequestScope:request.endPoint headerInfo:request.header isPublic:request.isPublic completion:^(BOOL completed, NSError *error) { if(!completed){ diff --git a/MASFoundation/Classes/MASError.h b/MASFoundation/Classes/MASError.h index 2b26156d..8a12dbe4 100644 --- a/MASFoundation/Classes/MASError.h +++ b/MASFoundation/Classes/MASError.h @@ -99,6 +99,7 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode) MASFoundationErrorCodeResponseSerializationFailedToParseResponse = 100407, MASFoundationErrorCodeNetworkSSLAuthenticationChallengeFailure = 100408, + // // Application // @@ -198,6 +199,11 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode) MASFoundationErrorCodeMultiFactorAuthenticationCancelled = 180002, MASFoundationErrorCodeMultiFactorAuthenticationInvalidRequest = 180003, + // + // File Request Errors + // + MASFoundationErrorCodeInvalidRequestForFileUpload = 180100, + MASFoundationErrorCodeCount = -999999 }; diff --git a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h index 91029b35..dc59163f 100644 --- a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h +++ b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.h @@ -647,4 +647,13 @@ */ + (NSError *)errorBrowserBasedAuthenticaionNotEnabled; + +/** + * Create MASFoundationErrorDomainLocal NSError for MASFoundationErrorCodeInvalidRequestForFileUpload. + * + * @return Returns an NSError instance with the domain MASFoundationErrorDomainLocal and + * error MASFoundationErrorCodeInvalidRequestForFileUpload + */ ++ (NSError *)errorInvalidRequestForFileUpload; + @end diff --git a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m index 3219ff6d..f77e5b88 100644 --- a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m +++ b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m @@ -833,6 +833,11 @@ + (NSError *)errorBrowserBasedAuthenticaionNotEnabled return [self errorForFoundationCode:MASFoundationErrorCodeBBANotEnabled errorDomain:MASFoundationErrorDomainLocal]; } ++ (NSError *)errorInvalidRequestForFileUpload +{ + return [self errorForFoundationCode:MASFoundationErrorCodeInvalidRequestForFileUpload errorDomain:MASFoundationErrorDomainLocal]; +} + # pragma mark - Foundation Errors Private @@ -1098,6 +1103,12 @@ + (NSString *)descriptionForFoundationErrorCode:(MASFoundationErrorCode)errorCod case MASFoundationErrorCodeMultiFactorAuthenticationCancelled : return @"Multi factor authentication process has been cancelled."; case MASFoundationErrorCodeMultiFactorAuthenticationInvalidRequest : return @"Invalid request for multi factor authentication."; + // + // File Request Errors + // + + case MASFoundationErrorCodeInvalidRequestForFileUpload : return @"the MASRequest is not valid for multi-part file upload. Please check if the request is of method POST and the request type is MASRequestResponseTypeFormData."; + // // Default // From 1341edda4ba914af9c4af0ad922d8181433cd695 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 26 Aug 2019 15:51:12 +0530 Subject: [PATCH 22/40] changed license part in headers --- .../network/requests/MASPostFormURLRequest.h | 5 +++- .../models/Network/MASMultiPartFormData.h | 23 +++---------------- .../Network/MASMultiPartRequestSerializer.h | 4 +++- .../Network/MASMultiPartRequestSerializer.m | 4 +++- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h index 0fb6a343..880a8439 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h @@ -2,9 +2,12 @@ // MASPostFormURLRequest.h // MASFoundation // -// Created by nimma01 on 12/07/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + #import "MASURLRequest.h" diff --git a/MASFoundation/Classes/models/Network/MASMultiPartFormData.h b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h index 950f002b..ff81528c 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartFormData.h +++ b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h @@ -2,9 +2,11 @@ // MASMultiPartFormData.h // MASFoundation // -// Created by nimma01 on 11/07/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// #ifndef MASMultiPartFormData_h #define MASMultiPartFormData_h @@ -40,24 +42,5 @@ - (BOOL)appendPartWithFileURL:(NSURL * __nonnull)fileURL name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType error:(NSError *_Nullable* _Nullable)error; -/** - Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary. - - @param data The data to be encoded and appended to the form data. - @param name The name to be associated with the specified data. This parameter must not be `nil`. - @param fileName The filename to be associated with the specified data. This parameter must not be `nil`. - @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`. - */ -- (void)appendPartWithFileData:(NSData * __nonnull)data name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType; - -/** - Appends the HTTP headers `Content-Disposition: form-data; name=#{name}"`, followed by the encoded data and the multipart form boundary. - - @param data The data to be encoded and appended to the form data. - @param name The name to be associated with the specified data. This parameter must not be `nil`. - */ - -- (void)appendPartWithFormData:(NSData * __nonnull)data name:(NSString * __nonnull)name; - @end #endif /* MASMultiPartFormData_h */ diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h index 3c68e440..939b30e5 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.h @@ -2,9 +2,11 @@ // MASMultiPartRequestSerializer.h // MASFoundation // -// Created by nimma01 on 11/07/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// #import #import "MASMultiPartFormData.h" diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m index cde4bc0e..224a1a72 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m @@ -2,9 +2,11 @@ // MASMultiPartRequestSerializer.m // MASFoundation // -// Created by nimma01 on 11/07/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// #import "MASMultiPartRequestSerializer.h" #import From 3d62b7e4c36bcc19a6a29c3738a61932b68796aa Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 27 Aug 2019 11:11:48 +0530 Subject: [PATCH 23/40] changed public API name to postMultiPartForm --- MASFoundation/Classes/MAS.h | 26 +++++++++++++++++++++++++- MASFoundation/Classes/MAS.m | 4 ++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/MASFoundation/Classes/MAS.h b/MASFoundation/Classes/MAS.h index 8719ae97..1c4e6e3c 100644 --- a/MASFoundation/Classes/MAS.h +++ b/MASFoundation/Classes/MAS.h @@ -1062,7 +1062,31 @@ withParameters:(NSDictionary *_Nullable)parameterInfo # pragma mark - FILE Requests -+ (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion; +/** + * Post a multi-part form with the parameters defined in the MASRequest object + * + * If endPointPath is full URL format (including port number and http protocol), SDK will validate the server from the client side through SSL pinning (authentication challenge) with + * provided subjectKeyHash (also known as public key hash) in configuration in mag.mobile_sdk.trusted_cert_pinned_public_key_hashes and mag.mobile_sdk.enable_public_key_pinning. + * ALL of servers' public key hashes in certificate chain must be defined in the list. This means when it is configured to use public key hash pinning for SSL pinning, + * subjectKeyHash (public key hash) of the gateway must be also present within the list. The list can contain multiple hash values in array for multiple servers. + * + * When SDK fails to validate SSL with certificate or subjectKeyHash pinning for communication to HTTPs, SDK will cancel the request. + * + * If endPointPath is full URL format, upon successful SSL pinning validation, SDK will also validate the user session against primary gateway regardless the request is being made + * to the primary gateway or not. To ensure bypass the user session validation for public API, use [MAS deleteFrom:withParameters:requestType:responseType:isPublic:completion:] method + * with isPublic being YES. + * + * The API appends the file data and any other parameters to the body and follows the standards defined for Content-Type = multipart/form-data + * + * @param request MASRequest An object containing all parameters to call the endpoint + * When the value is set to true, all automatically injected credentials in SDK will be excluded in the request. + * @param formDataBlock This is a block that gets called while constructing the body of the multi-part form request. Typically files can be added to the body by calling various APIs available in MASMultiPartFormData + * @see MASMultiPartFormData + * @param progressBlock Block which gives back the NSProgress of the task that is going on. Different values can be read from the progress object to present a meaningful progress updates in the UI. Recommend to use progress.fractioncompleted for progress bar updates. + * @param completion An MASResponseObjectErrorBlock (NSHTTPURLResponse *response, id responseObject, NSError *error) that will + * receive the NSHTTPURLResponse object, response object which needs to perform type casting based on the object type, and NSError object when error occurs. + */ ++ (void)postMultiPartForm:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion; ///-------------------------------------- /// @name JWT Signing diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index dce1cdee..90197f61 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -1128,7 +1128,7 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj } -+ (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDatablock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion ++ (void)postMultiPartForm:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:( MASFileRequestProgressBlock _Nullable )progressBlock completion:(nullable MASResponseObjectErrorBlock)completion { if(![request.httpMethod isEqualToString:@"POST"] || request.requestType != MASRequestResponseTypeFormData) { @@ -1144,7 +1144,7 @@ + (void)upload:(nonnull MASRequest *)request constructingBodyWithBlock:(nonnull return; } - [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic constructingBodyBlock:formDatablock progress:progressBlock completion:completion]; + [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic constructingBodyBlock:formDataBlock progress:progressBlock completion:completion]; }]; } From b59373bc1d43bbbdcca3088a5ce998800ff843a0 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Fri, 6 Sep 2019 12:33:13 +0530 Subject: [PATCH 24/40] added a new method in MASMultiPartFormData which enables file data to be added directly to the form body --- .../Classes/models/Network/MASMultiPartFormData.h | 9 +++++++++ .../models/Network/MASMultiPartRequestSerializer.m | 12 +++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/MASFoundation/Classes/models/Network/MASMultiPartFormData.h b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h index ff81528c..8aa3f79b 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartFormData.h +++ b/MASFoundation/Classes/models/Network/MASMultiPartFormData.h @@ -41,6 +41,15 @@ */ - (BOOL)appendPartWithFileURL:(NSURL * __nonnull)fileURL name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType error:(NSError *_Nullable* _Nullable)error; +/** + Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary. + + @param data The data to be encoded and appended to the form data. + @param name The name to be associated with the specified data. This parameter must not be `nil`. + @param fileName The filename to be associated with the specified data. This parameter must not be `nil`. + @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`. + */ +-(BOOL)appendPartWithFileData:(NSData * __nonnull)data name:(NSString * __nonnull)name fileName:(NSString * __nonnull)fileName mimeType:(NSString * __nonnull)mimeType; @end #endif /* MASMultiPartFormData_h */ diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m index 224a1a72..fd4e7c9e 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m @@ -110,21 +110,15 @@ - (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name fileName:(N } -- (void)appendPartWithFormData:(NSData *)data name:(NSString *)name +-(BOOL)appendPartWithFileData:(NSData *)data name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType { [self.body appendData:[[NSString stringWithFormat:@"%@", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; - [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"", name] dataUsingEncoding:NSUTF8StringEncoding]]; - [self.body appendData:data]; -} - - --(void)appendPartWithFileData:(NSData *)data name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType -{ - [self.body appendData:[[NSString stringWithFormat:@"--%@\r\n", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, fileName] dataUsingEncoding:NSUTF8StringEncoding]]; [self.body appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", mimeType] dataUsingEncoding:NSUTF8StringEncoding]]; [self.body appendData:data]; [self.body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; + + return YES; } From d0d06e54d83446098eb332a73db9ac8255a16607 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Fri, 6 Sep 2019 14:07:22 +0530 Subject: [PATCH 25/40] modified response info to carry the entire response from server --- .../Classes/_private_/services/network/MASNetworkingService.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m index ab07bcde..6307cd42 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m @@ -1435,7 +1435,7 @@ - (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)pa MASSessionDataTaskOperation *operation = [self.sessionManager fileUploadOperation:request progress:progress completionHandler:[self sessionDataTaskCompletionBlockWithEndPoint:endPoint parameters:parameterInfo headers:headerInfo httpMethod:request.HTTPMethod requestType:requestType responseType:responseType isPublic:isPublic completionBlock:^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { if (completion) { - completion([responseInfo objectForKey:MASNSHTTPURLResponseObjectKey], [responseInfo objectForKey:MASResponseInfoBodyInfoKey], error); + completion([responseInfo objectForKey:MASNSHTTPURLResponseObjectKey], responseInfo, error); } }]]; From 09b7ce34f99b194daafb1179a9775fb980f08b02 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 9 Sep 2019 14:23:23 +0530 Subject: [PATCH 26/40] fixed a bug in adding boundary and sending success response --- .../Classes/_private_/services/network/MASNetworkingService.m | 2 +- .../Classes/models/Network/MASMultiPartRequestSerializer.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m index 6307cd42..179a31c8 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m @@ -1435,7 +1435,7 @@ - (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)pa MASSessionDataTaskOperation *operation = [self.sessionManager fileUploadOperation:request progress:progress completionHandler:[self sessionDataTaskCompletionBlockWithEndPoint:endPoint parameters:parameterInfo headers:headerInfo httpMethod:request.HTTPMethod requestType:requestType responseType:responseType isPublic:isPublic completionBlock:^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { if (completion) { - completion([responseInfo objectForKey:MASNSHTTPURLResponseObjectKey], responseInfo, error); + completion([responseInfo objectForKey:MASNSHTTPURLResponseObjectKey], responseInfo[MASResponseInfoBodyInfoKey], error); } }]]; diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m index fd4e7c9e..1e48f9e6 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m @@ -79,7 +79,7 @@ -(void)setInitialHeadersforRequest -(void)setBodyParameters { [self.request.parameterInfo enumerateKeysAndObjectsUsingBlock:^(NSString *parameterKey, NSString *parameterValue, BOOL *stop) { - [self.body appendData:[[NSString stringWithFormat:@"%@", self.boundary] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"%@", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", parameterKey] dataUsingEncoding:NSUTF8StringEncoding]]; [self.body appendData:[[NSString stringWithFormat:@"%@\r\n", parameterValue] dataUsingEncoding:NSUTF8StringEncoding]]; }]; From c43880e04272ecaa5d5877b0f0808011adf32866 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 9 Sep 2019 14:29:00 +0530 Subject: [PATCH 27/40] changed script to remove distribution cert --- MASFoundation.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 511a184e..2ed9aec9 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -1837,7 +1837,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "set -e\n\n#---------------\n#Framework Name\n#---------------\n\nFRAMEWORK_NAME=MASFoundation\n\n\n#---------------\n#SDK Directory\n#---------------\n\nSDK_DIR=../iOS_SDK\n\n\n#-----------------------\n#CleanUp Build Cache\n#-----------------------\n\nxcodebuild -project $PROJECT_NAME.xcodeproj -configuration Debug -alltargets clean\nxcodebuild -project $PROJECT_NAME.xcodeproj -configuration Release -alltargets clean\n\n\n#-----------------------\n#CleanUp Previous Builds\n#-----------------------\n\n# Remove the framework from the Project Folder\nrm -Rf \"${PROJECT_DIR}/${FRAMEWORK_NAME}.framework\"\n\n# Remove Build folder from DerivedData\nrm -Rf \"${BUILD_DIR}\"\n\n\n#-----------------------\n#Creating New Builds\n#-----------------------\n\n# define output folder environment variable\nUNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal\nARCHIVE_OUTPUTFOLDER=${OBJROOT}/ArchiveIntermediates/$PROJECT_NAME/IntermediateBuildFilesPath/UninstalledProducts/iphoneos\n\n# Archive framework for iPhoneOS with BitCode enabled\n#xcodebuild -scheme $PROJECT_NAME -configuration Release archive\n\nxcodebuild OTHER_CFLAGS=\"-fembed-bitcode\" -scheme $PROJECT_NAME -configuration Release archive CODE_SIGN_IDENTITY=\"iPhone Distribution: CA, Inc (RAKRWMN9VH)\" -archivePath \"${BUILD_DIR}\"\n\n# Build framework for iPhoneOS\n#xcodebuild -target ${FRAMEWORK_NAME} ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" CODE_SIGN_IDENTITY=\"iPhone Distribution: CA, Inc (RAKRWMN9VH)\"\n\n# Build framework for iPhoneSimulator\nxcodebuild -target ${FRAMEWORK_NAME} -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" CODE_SIGN_IDENTITY=\"iPhone Distribution: CA, Inc (RAKRWMN9VH)\"\n\n\n#-----------------------\n#Creating Universal Framework\n#-----------------------\n\nmkdir -p \"${UNIVERSAL_OUTPUTFOLDER}\"\nmkdir -p \"${SDK_DIR}\"\n\n\n# Build the universal library\nlipo -create -output \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}\" \"${ARCHIVE_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}\" \"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}\"\n\n# Copy the .framework folder of iphoneos\ncp -R \"${ARCHIVE_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework\" \"${UNIVERSAL_OUTPUTFOLDER}/\"\n\n# Delete the library for iphoneos\nrm \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}\"\n\n# Move the Universal Library into our framework\nmv \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}\" \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/\"\n\n# Remove the _CodeSignature from the UniversalFramework\nrm -Rf \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/_CodeSignature\"\n\n# Copy the framework\ncp -R \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework\" \"${SDK_DIR}\"\n\n#-----------------------\n#Deleting Build Folder\n#-----------------------\n\n# Remove build folder from the Project Folder\nrm -Rf \"${PROJECT_DIR}/build\"\n\n"; + shellScript = "set -e\n\n#---------------\n#Framework Name\n#---------------\n\nFRAMEWORK_NAME=MASFoundation\n\n\n#---------------\n#SDK Directory\n#---------------\n\nSDK_DIR=../iOS_SDK\n\n\n#-----------------------\n#CleanUp Build Cache\n#-----------------------\n\nxcodebuild -project $PROJECT_NAME.xcodeproj -configuration Debug -alltargets clean\nxcodebuild -project $PROJECT_NAME.xcodeproj -configuration Release -alltargets clean\n\n\n#-----------------------\n#CleanUp Previous Builds\n#-----------------------\n\n# Remove the framework from the Project Folder\nrm -Rf \"${PROJECT_DIR}/${FRAMEWORK_NAME}.framework\"\n\n# Remove Build folder from DerivedData\nrm -Rf \"${BUILD_DIR}\"\n\n\n#-----------------------\n#Creating New Builds\n#-----------------------\n\n# define output folder environment variable\nUNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal\nARCHIVE_OUTPUTFOLDER=${OBJROOT}/ArchiveIntermediates/$PROJECT_NAME/IntermediateBuildFilesPath/UninstalledProducts/iphoneos\n\n# Archive framework for iPhoneOS with BitCode enabled\n#xcodebuild -scheme $PROJECT_NAME -configuration Release archive\n\nxcodebuild OTHER_CFLAGS=\"-fembed-bitcode\" -scheme $PROJECT_NAME -configuration Release archive CODE_SIGN_IDENTITY=\"iPhone Distribution: CA, Inc\" -archivePath \"${BUILD_DIR}\"\n\n# Build framework for iPhoneOS\n#xcodebuild -target ${FRAMEWORK_NAME} ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" CODE_SIGN_IDENTITY=\"iPhone Distribution: CA, Inc (RAKRWMN9VH)\"\n\n# Build framework for iPhoneSimulator\nxcodebuild -target ${FRAMEWORK_NAME} -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" CODE_SIGN_IDENTITY=\"iPhone Distribution: CA, Inc (RAKRWMN9VH)\"\n\n\n#-----------------------\n#Creating Universal Framework\n#-----------------------\n\nmkdir -p \"${UNIVERSAL_OUTPUTFOLDER}\"\nmkdir -p \"${SDK_DIR}\"\n\n\n# Build the universal library\nlipo -create -output \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}\" \"${ARCHIVE_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}\" \"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}\"\n\n# Copy the .framework folder of iphoneos\ncp -R \"${ARCHIVE_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework\" \"${UNIVERSAL_OUTPUTFOLDER}/\"\n\n# Delete the library for iphoneos\nrm \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}\"\n\n# Move the Universal Library into our framework\nmv \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}\" \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/\"\n\n# Remove the _CodeSignature from the UniversalFramework\nrm -Rf \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework/_CodeSignature\"\n\n# Copy the framework\ncp -R \"${UNIVERSAL_OUTPUTFOLDER}/${FRAMEWORK_NAME}.framework\" \"${SDK_DIR}\"\n\n#-----------------------\n#Deleting Build Folder\n#-----------------------\n\n# Remove build folder from the Project Folder\nrm -Rf \"${PROJECT_DIR}/build\"\n\n"; }; 69DE19DB1F8E8A2300F4C7FE /* Log Build Settings */ = { isa = PBXShellScriptBuildPhase; From 16087d5105285cc5204234900c212220455fb6f4 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 9 Sep 2019 14:59:19 +0530 Subject: [PATCH 28/40] fixed an extra \r\n bug --- .../Classes/models/Network/MASMultiPartRequestSerializer.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m index 1e48f9e6..9ecb4204 100644 --- a/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m +++ b/MASFoundation/Classes/models/Network/MASMultiPartRequestSerializer.m @@ -81,7 +81,7 @@ -(void)setBodyParameters [self.request.parameterInfo enumerateKeysAndObjectsUsingBlock:^(NSString *parameterKey, NSString *parameterValue, BOOL *stop) { [self.body appendData:[[NSString stringWithFormat:@"%@", MASMultipartFormEncapsulationBoundary(self.boundary)] dataUsingEncoding:NSUTF8StringEncoding]]; [self.body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", parameterKey] dataUsingEncoding:NSUTF8StringEncoding]]; - [self.body appendData:[[NSString stringWithFormat:@"%@\r\n", parameterValue] dataUsingEncoding:NSUTF8StringEncoding]]; + [self.body appendData:[[NSString stringWithFormat:@"%@", parameterValue] dataUsingEncoding:NSUTF8StringEncoding]]; }]; } From 27a083ea0d57574ede50e771b664747f3ed415c3 Mon Sep 17 00:00:00 2001 From: Syed Yusuf Date: Tue, 10 Sep 2019 14:57:36 +0530 Subject: [PATCH 29/40] [US609984] Adding MASNetworkConfiguration to configure Timeout and MASRequest to have Timeout configuration for per request configuration. --- MASFoundation.xcodeproj/project.pbxproj | 8 + MASFoundation/Classes/MAS.m | 58 ++++++- MASFoundation/Classes/MASError.h | 4 + .../Classes/_private_/MASConstantsPrivate.h | 3 + .../_private_/categories/NSError+MASPrivate.m | 5 + .../models/Network/MASRequest+MASPrivate.m | 2 + .../configuration/MASConfigurationService.h | 42 +++++ .../configuration/MASConfigurationService.m | 47 ++++- .../_private_/services/jwt/MASJWTService.m | 2 + .../services/network/MASNetworkingService.h | 49 +++++- .../services/network/MASNetworkingService.m | 161 ++++++++++++++++-- .../network/requests/MASDeleteURLRequest.h | 3 +- .../network/requests/MASDeleteURLRequest.m | 3 +- .../network/requests/MASGetURLRequest.h | 3 +- .../network/requests/MASGetURLRequest.m | 3 +- .../network/requests/MASPatchURLRequest.h | 3 +- .../network/requests/MASPatchURLRequest.m | 3 +- .../network/requests/MASPostFormURLRequest.h | 2 +- .../network/requests/MASPostFormURLRequest.m | 4 +- .../network/requests/MASPostURLRequest.h | 3 +- .../network/requests/MASPostURLRequest.m | 3 +- .../network/requests/MASPutURLRequest.h | 3 +- .../network/requests/MASPutURLRequest.m | 3 +- .../services/network/requests/MASURLRequest.h | 1 + .../Classes/models/MASConfiguration.h | 41 +++++ .../Classes/models/MASConfiguration.m | 43 +++++ .../models/Network/MASNetworkConfiguration.h | 52 ++++++ .../models/Network/MASNetworkConfiguration.m | 38 +++++ .../Classes/models/Network/MASRequest.h | 6 + .../Classes/models/Network/MASRequest.m | 1 + .../models/Network/MASRequestBuilder.h | 6 + .../models/Network/MASRequestBuilder.m | 3 + MASFoundation/MASFoundation.h | 1 + 33 files changed, 572 insertions(+), 37 deletions(-) create mode 100644 MASFoundation/Classes/models/Network/MASNetworkConfiguration.h create mode 100644 MASFoundation/Classes/models/Network/MASNetworkConfiguration.m diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 2ed9aec9..ca7a6e34 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -175,6 +175,8 @@ A4F671331BAFC345000E2223 /* NSString+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A4F671311BAFC345000E2223 /* NSString+MASPrivate.m */; }; A858C6651D0978A6001FB9AD /* MASOTPService.h in Headers */ = {isa = PBXBuildFile; fileRef = A858C6631D0978A6001FB9AD /* MASOTPService.h */; }; A858C6661D0978A6001FB9AD /* MASOTPService.m in Sources */ = {isa = PBXBuildFile; fileRef = A858C6641D0978A6001FB9AD /* MASOTPService.m */; }; + A888437E2327858D0005F502 /* MASNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = A888437C2327858C0005F502 /* MASNetworkConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A888437F2327858D0005F502 /* MASNetworkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = A888437D2327858C0005F502 /* MASNetworkConfiguration.m */; }; A898EF632182D30A00CF291B /* MASJWTService.m in Sources */ = {isa = PBXBuildFile; fileRef = A898EF612182D30900CF291B /* MASJWTService.m */; }; A898EF642182D30A00CF291B /* MASJWTService.h in Headers */ = {isa = PBXBuildFile; fileRef = A898EF622182D30900CF291B /* MASJWTService.h */; }; A898EF672182D35700CF291B /* MASJWKSet.h in Headers */ = {isa = PBXBuildFile; fileRef = A898EF652182D35700CF291B /* MASJWKSet.h */; }; @@ -555,6 +557,8 @@ A4F671311BAFC345000E2223 /* NSString+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MASPrivate.m"; sourceTree = ""; }; A858C6631D0978A6001FB9AD /* MASOTPService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASOTPService.h; sourceTree = ""; }; A858C6641D0978A6001FB9AD /* MASOTPService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASOTPService.m; sourceTree = ""; }; + A888437C2327858C0005F502 /* MASNetworkConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASNetworkConfiguration.h; sourceTree = ""; }; + A888437D2327858C0005F502 /* MASNetworkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASNetworkConfiguration.m; sourceTree = ""; }; A898EF612182D30900CF291B /* MASJWTService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASJWTService.m; sourceTree = ""; }; A898EF622182D30900CF291B /* MASJWTService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASJWTService.h; sourceTree = ""; }; A898EF652182D35700CF291B /* MASJWKSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASJWKSet.h; sourceTree = ""; }; @@ -1242,6 +1246,8 @@ C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */, C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */, C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */, + A888437C2327858C0005F502 /* MASNetworkConfiguration.h */, + A888437D2327858C0005F502 /* MASNetworkConfiguration.m */, ); path = Network; sourceTree = ""; @@ -1681,6 +1687,7 @@ A4831AEC1BD1A87C007B4AE6 /* MASApplication+MASPrivate.h in Headers */, CB5E4C741C1D26BA001B3B8A /* MASPatchURLRequest.h in Headers */, A42157261BF864590034BDC9 /* MASConfigurationService.h in Headers */, + A888437E2327858D0005F502 /* MASNetworkConfiguration.h in Headers */, CB5E4C701C1D250D001B3B8A /* MASPutURLRequest.h in Headers */, CB6491DE1FE9DAF300281288 /* MQTTCFSocketDecoder.h in Headers */, CB9975461EDF5799006CEBB1 /* MASAuthCredentials+MASPrivate.h in Headers */, @@ -2011,6 +2018,7 @@ CB1907F91C17950700A5EF16 /* MASAccessService.m in Sources */, CBD25B0A1E78C47C00DFB47F /* JWTCoding.m in Sources */, CBD25B101E78C47C00DFB47F /* JWTErrorDescription.m in Sources */, + A888437F2327858D0005F502 /* MASNetworkConfiguration.m in Sources */, CB5E4C6D1C1D2467001B3B8A /* MASDeleteURLRequest.m in Sources */, A46F49CE1C2F5FC500A4C370 /* MASINetworkReachabilityManager.m in Sources */, A4831AEF1BD1A87C007B4AE6 /* MASAuthenticationProvider+MASPrivate.m in Sources */, diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index 90197f61..0521c675 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -641,7 +641,7 @@ + (void)startWithURL:(NSURL *)url completion:(MASCompletionErrorBlock)completion withParameters:urlParameters andHeaders:nil requestType:MASRequestResponseTypeJson - responseType:MASRequestResponseTypeJson isPublic:YES]; + responseType:MASRequestResponseTypeJson isPublic:YES timeoutInterval:MASDefaultNetworkTimeoutConfiguration]; MASSessionDataTaskOperation *dataTaskOperation = [urlSessionManager dataOperationWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nonnull responseObject, NSError * _Nonnull error) { if (error) @@ -926,7 +926,8 @@ + (void)deleteFrom:(NSString *)endPoint isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"DELETE" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"DELETE" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -971,7 +972,8 @@ + (void)getFrom:(NSString *)endPoint isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"GET" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"GET" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -1015,7 +1017,8 @@ + (void)patchTo:(NSString *)endPoint isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"PATCH" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"PATCH" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -1059,7 +1062,8 @@ + (void)postTo:(NSString *)endPoint isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"POST" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"POST" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -1103,7 +1107,8 @@ + (void)putTo:(nonnull NSString *)endPoint isPublic:(BOOL)isPublic completion:(nullable MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"PUT" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"PUT" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -1111,6 +1116,11 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj { __block MASResponseObjectErrorBlock blockCompletion = completion; + // If default timeoutInterval override to NetworkConfiguration timeoutInterval. + NSTimeInterval timeoutInterval = + (request.timeoutInterval == MASDefaultNetworkTimeoutConfiguration) ? + [self timeoutIntervalForEndpoint:request.endPoint] : request.timeoutInterval; + [MAS httpMethod:request.httpMethod endPoint:request.endPoint withParameters:request.body @@ -1118,6 +1128,7 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj requestType:request.requestType responseType:request.responseType isPublic:request.isPublic + timeoutInterval:request.timeoutInterval completion:^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { if (blockCompletion) @@ -1144,7 +1155,12 @@ + (void)postMultiPartForm:(nonnull MASRequest *)request constructingBodyWithBloc return; } - [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic constructingBodyBlock:formDataBlock progress:progressBlock completion:completion]; + // If default timeoutInterval override to NetworkConfiguration timeoutInterval. + NSTimeInterval timeoutInterval = + (request.timeoutInterval == MASDefaultNetworkTimeoutConfiguration) ? + [self timeoutIntervalForEndpoint:request.endPoint] : request.timeoutInterval; + + [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic timeoutInterval:timeoutInterval constructingBodyBlock:formDataBlock progress:progressBlock completion:completion]; }]; } @@ -1195,6 +1211,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1231,6 +1248,7 @@ + (void)httpMethod:(NSString *)httpMethod __block MASRequestResponseType blockRequestType = requestType; __block MASRequestResponseType blockResponseType = responseType; __block BOOL blockIsPublic = isPublic; + __block NSTimeInterval blockTimeoutInterval = timeoutInterval; // // Validate if new scope has been requested in header @@ -1249,6 +1267,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } else if ([blockHttpMethod isEqualToString:@"GET"]) @@ -1259,6 +1278,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } else if ([blockHttpMethod isEqualToString:@"PATCH"]) @@ -1269,6 +1289,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } else if ([blockHttpMethod isEqualToString:@"POST"]) @@ -1279,6 +1300,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } else if ([blockHttpMethod isEqualToString:@"PUT"]) @@ -1289,6 +1311,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } }]; @@ -1461,6 +1484,27 @@ + (BOOL)isPublicForEndpoint:(NSString *)endPoint } ++ (NSTimeInterval)timeoutIntervalForEndpoint:(NSString *)endPoint +{ + NSTimeInterval timeoutInterval = MASDefaultNetworkTimeoutConfiguration; + + NSURL *endpointURL = [NSURL URLWithString:endPoint]; + if (endpointURL.scheme && endpointURL.host) + { + MASNetworkConfiguration *networkConfiguration = [MASConfiguration networkConfigurationForDomain:[NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", endpointURL.scheme, endpointURL.host, endpointURL.port]]]; + timeoutInterval = networkConfiguration.timeoutInterval; + } + else if ([MASConfiguration currentConfiguration]) + { + NSURL *gatewayURL = [MASConfiguration currentConfiguration].gatewayUrl; + MASNetworkConfiguration *networkConfiguration = [MASConfiguration networkConfigurationForDomain:[NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", gatewayURL.scheme, gatewayURL.host, gatewayURL.port]]]; + timeoutInterval = networkConfiguration.timeoutInterval; + } + + return timeoutInterval; +} + + # pragma mark - JWT Signing + (NSString * _Nullable)signWithClaims:(MASClaims *_Nonnull)claims error:(NSError *__nullable __autoreleasing *__nullable)error diff --git a/MASFoundation/Classes/MASError.h b/MASFoundation/Classes/MASError.h index 8a12dbe4..ea6bfe60 100644 --- a/MASFoundation/Classes/MASError.h +++ b/MASFoundation/Classes/MASError.h @@ -99,6 +99,10 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode) MASFoundationErrorCodeResponseSerializationFailedToParseResponse = 100407, MASFoundationErrorCodeNetworkSSLAuthenticationChallengeFailure = 100408, + // + // Network Configuration + // + MASFoundationErrorCodeConfigurationInvalidHostForNetworkConfiguration = 100501, // // Application diff --git a/MASFoundation/Classes/_private_/MASConstantsPrivate.h b/MASFoundation/Classes/_private_/MASConstantsPrivate.h index f2c10ce0..931bbb17 100644 --- a/MASFoundation/Classes/_private_/MASConstantsPrivate.h +++ b/MASFoundation/Classes/_private_/MASConstantsPrivate.h @@ -204,6 +204,9 @@ static NSString *_Nonnull const MASUserPhoneRequestResponseKey = @"phone_number" static NSString *_Nonnull const MASUserPictureRequestResponseKey = @"picture"; // string static NSString *_Nonnull const MASUserRefreshTokenRequestResponseKey = @"refresh_token"; // string +// Default network timeout configuration. +static int const MASDefaultNetworkTimeoutConfiguration = 60; + # pragma mark - GrantType Constants diff --git a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m index f77e5b88..59d37e2d 100644 --- a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m +++ b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m @@ -994,6 +994,11 @@ + (NSString *)descriptionForFoundationErrorCode:(MASFoundationErrorCode)errorCod case MASFoundationErrorCodeConfigurationInvalidHostForSecurityConfiguration: return @"Invalid host information for security configuration. NSURL host or port cannot be nil."; case MASFoundationErrorCodeConfigurationInvalidPinningInfoForSecurityConfiguration: return @"Invalid pinning information for security configuration. At least one pinning information should be provided or public PKI should be trusted."; + // + // Security Configuration + // + case MASFoundationErrorCodeConfigurationInvalidHostForNetworkConfiguration: return @"Invalid host information for network configuration. NSURL host or port cannot be nil."; + // // Device // diff --git a/MASFoundation/Classes/_private_/models/Network/MASRequest+MASPrivate.m b/MASFoundation/Classes/_private_/models/Network/MASRequest+MASPrivate.m index 746cadce..80289881 100644 --- a/MASFoundation/Classes/_private_/models/Network/MASRequest+MASPrivate.m +++ b/MASFoundation/Classes/_private_/models/Network/MASRequest+MASPrivate.m @@ -23,6 +23,7 @@ @interface MASRequest () @property (assign, readwrite) BOOL sign; @property (assign, readwrite) MASRequestResponseType requestType; @property (assign, readwrite) MASRequestResponseType responseType; +@property (assign, readwrite) NSTimeInterval timeoutInterval; @end @@ -48,6 +49,7 @@ - (instancetype)initWithBuilder:(MASRequestBuilder *)builder self.header = builder.header; self.body = builder.body; self.query = builder.query; + self.timeoutInterval = builder.timeoutInterval; // diff --git a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h index 31e42df9..d8ff2c94 100644 --- a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h +++ b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h @@ -17,6 +17,48 @@ @interface MASConfigurationService : MASService + +///-------------------------------------- +/// @name Network Configuration +///-------------------------------------- + +# pragma mark - Network Configuration + +/** + */ ++ (void)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration; + + + + +/** + Removes network configuration object based on the domain. + + @param domain NSURL of the domain to delete network configuration. + */ ++ (void)removeNetworkConfigurationForDomain:(NSURL *)domain; + + + +/** + Returns an array of MASNetworkConfiguration objects for each host. + + @return Returns an array of currently active MASNetworkConfigurations. + */ ++ (NSArray *)networkConfigurations; + + + +/** + Returns MASNetworkConfiguration object for a specific domain. + + @param domain NSURL of the domain for the MASNetworkConfiguration object. + @return Returns a MASNetworkConfiguration object for the domain. + */ ++ (MASNetworkConfiguration *)networkConfigurationForDomain:(NSURL *)domain; + + + ///-------------------------------------- /// @name Security Configuration ///-------------------------------------- diff --git a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.m b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.m index 42a67cf9..0f0aa643 100644 --- a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.m +++ b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.m @@ -18,6 +18,7 @@ @implementation MASConfigurationService static NSString *_configurationFileType_ = @"json"; static NSDictionary *_newConfigurationObject_ = nil; static BOOL _newConfigurationDetected_ = NO; +static NSMutableDictionary *_networkConfigurations_; static NSMutableDictionary *_securityConfigurations_; static BOOL _enableIdTokenValidation_ = YES; @@ -80,6 +81,42 @@ + (NSDictionary *)getDefaultConfigurationAsDictionary } +# pragma mark - Network Configuration + ++ (void)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration +{ + if (!_networkConfigurations_) + { + _networkConfigurations_ = [NSMutableDictionary dictionary]; + } + + if ([networkConfiguration.host absoluteString]) + { + [_networkConfigurations_ setObject:networkConfiguration forKey:[networkConfiguration.host absoluteString]]; + } +} + + ++ (void)removeNetworkConfigurationForDomain:(NSURL *)domain +{ + NSURL *thisDomain = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", domain.scheme, domain.host, domain.port]]; + [_networkConfigurations_ removeObjectForKey:[thisDomain absoluteString]]; +} + + ++ (NSArray *)networkConfigurations +{ + return _networkConfigurations_ ? [_networkConfigurations_ allValues] : nil; +} + + ++ (MASNetworkConfiguration *)networkConfigurationForDomain:(NSURL *)domain +{ + NSURL *thisDomain = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", domain.scheme, domain.host, domain.port]]; + return thisDomain ? [_networkConfigurations_ objectForKey:[thisDomain absoluteString]] : nil; +} + + # pragma mark - Security Configuration + (void)setSecurityConfiguration:(MASSecurityConfiguration *)securityConfiguration @@ -281,10 +318,18 @@ - (void)serviceWillStart } } + + NSURL *currentURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", _currentConfiguration.gatewayUrl.scheme, _currentConfiguration.gatewayHostName, _currentConfiguration.gatewayPort]]; + + // + // Construct and set MASNetworkConfiguration for the primary gateway + // + MASNetworkConfiguration *defaultNetworkConfiguration = [[MASNetworkConfiguration alloc] initWithURL:currentURL]; + [MASConfiguration setNetworkConfiguration:defaultNetworkConfiguration error:nil]; + // // Construct and set MASSecurityConfiguration for the primary gateway // - NSURL *currentURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", _currentConfiguration.gatewayUrl.scheme, _currentConfiguration.gatewayHostName, _currentConfiguration.gatewayPort]]; MASSecurityConfiguration *defaultSecurityConfiguration = [[MASSecurityConfiguration alloc] initWithURL:currentURL]; defaultSecurityConfiguration.trustPublicPKI = _currentConfiguration.enabledTrustedPublicPKI; defaultSecurityConfiguration.publicKeyHashes = _currentConfiguration.trustedCertPinnedPublicKeyHashes; diff --git a/MASFoundation/Classes/_private_/services/jwt/MASJWTService.m b/MASFoundation/Classes/_private_/services/jwt/MASJWTService.m index 32e66603..c4769655 100644 --- a/MASFoundation/Classes/_private_/services/jwt/MASJWTService.m +++ b/MASFoundation/Classes/_private_/services/jwt/MASJWTService.m @@ -167,6 +167,7 @@ - (void)loadJWKSAsynchronously:(BOOL)async completion:(MASCompletionErrorBlock)c requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:YES + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion: ^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { @@ -191,6 +192,7 @@ - (void)loadJWKSAsynchronously:(BOOL)async completion:(MASCompletionErrorBlock)c requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:YES + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion: ^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h index bc6e40fd..8d1bbbb0 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h @@ -276,6 +276,15 @@ typedef NSURLRequest* (^MASSessionDataTaskHTTPRedirectBlock)(NSURLSession *sessi completion:(MASResponseInfoErrorBlock)completion; +- (void)deleteFrom:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + /** * Request method for an HTTP GET call from the Gateway. This type of HTTP Method type * places it's parameters within the NSURL itself as an HTTP query extension as so: @@ -369,6 +378,16 @@ typedef NSURLRequest* (^MASSessionDataTaskHTTPRedirectBlock)(NSURLSession *sessi completion:(MASResponseInfoErrorBlock)completion; +- (void)getFrom:(NSString *)endPoint + withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + + /** * Request method for an HTTP PATCH call to the Gateway. This type of HTTP Method type * places it's parameters within the HTTP body in www-form-urlencoded format: @@ -468,6 +487,15 @@ typedef NSURLRequest* (^MASSessionDataTaskHTTPRedirectBlock)(NSURLSession *sessi completion:(MASResponseInfoErrorBlock)completion; +- (void)patchTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + /** * Request method for an HTTP POST call to the Gateway. This type of HTTP Method type * places it's parameters within the HTTP body in www-form-urlencoded format: @@ -569,6 +597,15 @@ withParameters:(NSDictionary *)parameterInfo completion:(MASResponseInfoErrorBlock)completion; +- (void)postTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + /** * Request method for an HTTP PUT call to the Gateway. This type of HTTP Method type * places it's parameters within the HTTP body in www-form-urlencoded format: @@ -668,10 +705,20 @@ withParameters:(NSDictionary *)parameterInfo completion:(MASResponseInfoErrorBlock)completion; +- (void)putTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + + # pragma mark - HTTP File Requests -- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion; +- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion; @end diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m index 179a31c8..d3e6ffc8 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m @@ -976,6 +976,7 @@ - (void)deleteFrom:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -996,6 +997,7 @@ - (void)deleteFrom:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1017,6 +1019,30 @@ - (void)deleteFrom:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} + + +- (void)deleteFrom:(NSString *)endPoint + withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion +{ + // + // Just passthrough + // + [self httpDeleteFrom:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1027,6 +1053,7 @@ - (void)httpDeleteFrom:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { //DLog(@"called"); @@ -1044,7 +1071,7 @@ - (void)httpDeleteFrom:(NSString *)endPoint return; } - [self httpRequest:@"DELETE" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"DELETE" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } @@ -1062,6 +1089,7 @@ - (void)getFrom:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1082,9 +1110,30 @@ - (void)getFrom:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } +- (void)getFrom:(NSString *)endPoint + withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic + completion:(MASResponseInfoErrorBlock)completion +{ + // + // Just passthrough + // + [self getFrom:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} - (void)getFrom:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo @@ -1092,6 +1141,7 @@ - (void)getFrom:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1103,6 +1153,7 @@ - (void)getFrom:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1113,6 +1164,7 @@ - (void)httpGetFrom:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { //DLog(@"called"); @@ -1130,7 +1182,7 @@ - (void)httpGetFrom:(NSString *)endPoint return; } - [self httpRequest:@"GET" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"GET" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } @@ -1148,6 +1200,7 @@ - (void)patchTo:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1168,6 +1221,7 @@ - (void)patchTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1189,6 +1243,29 @@ - (void)patchTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} + +- (void)patchTo:(NSString *)endPoint + withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion +{ + // + // Just passthrough + // + [self httpPatchTo:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1199,6 +1276,7 @@ - (void)httpPatchTo:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1214,7 +1292,7 @@ - (void)httpPatchTo:(NSString *)endPoint return; } - [self httpRequest:@"PATCH" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"PATCH" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } @@ -1232,6 +1310,7 @@ - (void)postTo:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1252,6 +1331,7 @@ - (void)postTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1263,6 +1343,29 @@ - (void)postTo:(NSString *)endPoint responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion +{ + //DLog(@"called"); + // + // Just passthrough + // + [self postTo:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} + +- (void)postTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion { //DLog(@"called"); // @@ -1274,6 +1377,7 @@ - (void)postTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1284,6 +1388,7 @@ - (void)httpPostTo:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { //DLog(@"called"); @@ -1301,7 +1406,7 @@ - (void)httpPostTo:(NSString *)endPoint return; } - [self httpRequest:@"POST" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"POST" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } @@ -1319,6 +1424,7 @@ - (void)putTo:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO +timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1339,9 +1445,30 @@ - (void)putTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO +timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } +- (void)putTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic + completion:(MASResponseInfoErrorBlock)completion +{ + // + // Just passthrough + // + [self putTo:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} - (void)putTo:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo @@ -1349,6 +1476,7 @@ - (void)putTo:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1360,6 +1488,7 @@ - (void)putTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1370,6 +1499,7 @@ - (void)httpPutTo:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1385,11 +1515,11 @@ - (void)httpPutTo:(NSString *)endPoint return; } - [self httpRequest:@"PUT" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"PUT" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } -- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion +- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion { // // endPoint cannot be nil @@ -1404,11 +1534,11 @@ - (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)par return; } - [self httpFileUploadRequest:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic constructingBodyBlock:formDataBlock progress:progress completion:completion]; + [self httpFileUploadRequest:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval constructingBodyBlock:formDataBlock progress:progress completion:completion]; } -- (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion +- (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion { NSMutableDictionary *mutableHeaderInfo = [headerInfo mutableCopy]; @@ -1422,7 +1552,7 @@ - (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)pa mutableHeaderInfo[MASGeoLocationRequestResponseKey] = [[MASLocationService sharedService].lastKnownLocation locationAsGeoCoordinates]; } - request = [MASPostFormURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic constructingBodyBlock:formDataBlock]; + request = [MASPostFormURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval constructingBodyBlock:formDataBlock]; // // Construct MASSessionDataTaskOperation with request, and completion block to handle any responsive re-authentication or re-registration. @@ -1479,7 +1609,8 @@ - (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)pa } -- (void)httpRequest:(NSString *)httpMethod endPoint:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion +- (void)httpRequest:(NSString *)httpMethod endPoint:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // // Update the header @@ -1501,23 +1632,23 @@ - (void)httpRequest:(NSString *)httpMethod endPoint:(NSString *)endPoint paramet // if ([httpMethod isEqualToString:@"DELETE"]) { - request = [MASDeleteURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASDeleteURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } else if ([httpMethod isEqualToString:@"GET"]) { - request = [MASGetURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASGetURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } else if ([httpMethod isEqualToString:@"PATCH"]) { - request = [MASPatchURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASPatchURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } else if ([httpMethod isEqualToString:@"POST"]) { - request = [MASPostURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASPostURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } else if ([httpMethod isEqualToString:@"PUT"]) { - request = [MASPutURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASPutURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } // diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h index 96f9ef4c..d8722b32 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h @@ -40,6 +40,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m index 3e91aa41..97b7ad72 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m @@ -26,6 +26,7 @@ + (MASDeleteURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -50,7 +51,7 @@ + (MASDeleteURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASDeleteURLRequest *request = [MASDeleteURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASDeleteURLRequest *request = [MASDeleteURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h index 62ce7a0e..fabc5066 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h @@ -40,6 +40,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m index 74b1d3fb..75cbe0b1 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m @@ -26,6 +26,7 @@ + (MASGetURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -50,7 +51,7 @@ + (MASGetURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASGetURLRequest *request = [MASGetURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASGetURLRequest *request = [MASGetURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h index 00370698..d8b7d4ff 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h @@ -40,6 +40,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m index 3ab2d9ff..43b3fe7c 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m @@ -26,6 +26,7 @@ + (MASPatchURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -45,7 +46,7 @@ + (MASPatchURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASPatchURLRequest *request = [MASPatchURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASPatchURLRequest *request = [MASPatchURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h index 880a8439..c9f2d8b7 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MASPostFormURLRequest : MASURLRequest -+ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock; ++ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m index fe2d6a04..38768cb9 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m @@ -15,7 +15,7 @@ @implementation MASPostFormURLRequest -+ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock ++ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock { // // Adding prefix to the endpoint path @@ -35,7 +35,7 @@ + (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameter // // Create the request // - MASPostFormURLRequest *request = [MASPostFormURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:240]; + MASPostFormURLRequest *request = [MASPostFormURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h index ec4a129e..876e54e9 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h @@ -40,6 +40,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m index 06f16d11..31116911 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m @@ -26,6 +26,7 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -45,7 +46,7 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASPostURLRequest *request = [MASPostURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASPostURLRequest *request = [MASPostURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h index abc7f459..f0b5db8f 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h @@ -40,6 +40,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m index f3ebba17..c042dc75 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m @@ -26,6 +26,7 @@ + (MASPutURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -45,7 +46,7 @@ + (MASPutURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASPutURLRequest *request = [MASPutURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASPutURLRequest *request = [MASPutURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.h index 79407d8a..3297d7a3 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.h @@ -27,6 +27,7 @@ @property (assign) BOOL isPublic; @property (assign) MASRequestResponseType requestType; @property (assign) MASRequestResponseType responseType; +@property (assign) NSTimeInterval timeoutInterval; @property (nonatomic, strong) NSString *endPoint; @property (nonatomic, strong) NSDictionary *parameterInfo; @property (nonatomic, strong) NSDictionary *headerInfo; diff --git a/MASFoundation/Classes/models/MASConfiguration.h b/MASFoundation/Classes/models/MASConfiguration.h index 84c07c32..db5b09dd 100644 --- a/MASFoundation/Classes/models/MASConfiguration.h +++ b/MASFoundation/Classes/models/MASConfiguration.h @@ -9,6 +9,7 @@ // @import Foundation; +@class MASNetworkConfiguration; @class MASSecurityConfiguration; /** @@ -173,6 +174,46 @@ +///-------------------------------------- +/// @name Security Configuration +///-------------------------------------- + +# pragma mark - Network Configuration + +/** + */ ++ (BOOL)setNetworkConfiguration:(MASNetworkConfiguration *_Nonnull)networkConfiguration error:(NSError *__nullable __autoreleasing *__nullable)error; + + + +/** + Removes network configuration object based on the domain (host, and port number). + + @param domain NSURL object of domain to delete MASNetworkConfiguration. + */ ++ (void)removeNetworkConfigurationForDomain:(NSURL *_Nonnull)domain; + + + +/** + Returns an array of MASNetworkConfiguration objects for each host. + + @return Returns an array of currently active MASNetworkConfigurations. + */ ++ (NSArray *_Nullable)networkConfigurations; + + + +/** + Returns MASSecurityConfiguration object for a specific domain. + + @param domain NSURL of the domain for the MASSecurityConfiguration object. + @return Returns a MASSecurityConfiguration object for the domain. + */ ++ (MASNetworkConfiguration *_Nullable)networkConfigurationForDomain:(NSURL *_Nonnull)domain; + + + ///-------------------------------------- /// @name Security Configuration ///-------------------------------------- diff --git a/MASFoundation/Classes/models/MASConfiguration.m b/MASFoundation/Classes/models/MASConfiguration.m index 4c245d35..52bb0d33 100644 --- a/MASFoundation/Classes/models/MASConfiguration.m +++ b/MASFoundation/Classes/models/MASConfiguration.m @@ -419,6 +419,49 @@ - (id)initWithCoder:(NSCoder *)aDecoder } +# pragma mark - Network Configuration + ++ (BOOL)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration error:(NSError **)error +{ + // + // Validate the NSURL host for security configuration. + // + if (!networkConfiguration.host || !networkConfiguration.host.port) + { + if (error) + { + *error = [NSError errorForFoundationCode:MASFoundationErrorCodeConfigurationInvalidHostForNetworkConfiguration errorDomain:MASFoundationErrorDomainLocal]; + } + + return NO; + } + + [MASConfigurationService setNetworkConfiguration:networkConfiguration]; + + return YES; +} + + ++ (void)removeNetworkConfigurationForDomain:(NSURL *)domain +{ + [MASConfigurationService removeNetworkConfigurationForDomain:domain]; +} + + ++ (NSArray *)networkConfigurations +{ + return [MASConfigurationService networkConfigurations]; +} + + ++ (MASNetworkConfiguration *)networkConfigurationForDomain:(NSURL *)domain +{ + return [MASConfigurationService networkConfigurationForDomain:domain]; +} + + +# pragma mark - Security Configuration + + (BOOL)setSecurityConfiguration:(MASSecurityConfiguration *)securityConfiguration error:(NSError **)error { // diff --git a/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h new file mode 100644 index 00000000..03da9a8b --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h @@ -0,0 +1,52 @@ +// +// MASNetworkConfiguration.h +// MASFoundation +// +// Created by yussy01 on 05/09/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASObject.h" + + +@interface MASNetworkConfiguration : MASObject + + + +///-------------------------------------- +/// @name Properties +///-------------------------------------- + +# pragma mark - Properties + + +/** +The NSTimeInterval value that specifies the global timeInterval of all the requests. +*/ +@property (assign) NSTimeInterval timeoutInterval; + + + +/** + NSURL value of the target host. + */ +@property (nonatomic, strong, readonly, nonnull) NSURL *host; + + + +///-------------------------------------- +/// @name Lifecycle +///-------------------------------------- + +# pragma mark - Lifecycle + +/** + Designated initializer for MASNetworkConfiguration. + + @discussion default values for designated initializer are: timeoutInterval : 60. + @param url NSURL of the target domain + @return MASNetworkConfiguration object + */ +- (instancetype _Nonnull)initWithURL:(NSURL * _Nonnull)url NS_DESIGNATED_INITIALIZER; + +@end diff --git a/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m new file mode 100644 index 00000000..e5f5c31d --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m @@ -0,0 +1,38 @@ +// +// MASNetworkConfiguration.m +// MASFoundation +// +// Created by yussy01 on 05/09/19. +// Copyright © 2019 CA Technologies. All rights reserved. +// + +#import "MASNetworkConfiguration.h" + +#import "MASConstantsPrivate.h" + + +@interface MASNetworkConfiguration () + +@property (nonatomic, strong, readwrite) NSURL *host; + +@end + + +@implementation MASNetworkConfiguration + + +# pragma mark - Lifecycle + +- (instancetype)initWithURL:(NSURL *)url +{ + self = [super init]; + + if (self) { + self.host = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", url.scheme, url.host, url.port]]; + self.timeoutInterval = MASDefaultNetworkTimeoutConfiguration; + } + + return self; +} + +@end diff --git a/MASFoundation/Classes/models/Network/MASRequest.h b/MASFoundation/Classes/models/Network/MASRequest.h index 5b493627..67d17225 100644 --- a/MASFoundation/Classes/models/Network/MASRequest.h +++ b/MASFoundation/Classes/models/Network/MASRequest.h @@ -84,6 +84,12 @@ @property (assign, readonly) MASRequestResponseType responseType; +/** +The NSTimeInterval value that specifies the timeInterval of the request. +*/ +@property (assign, readonly) NSTimeInterval timeoutInterval; + + # pragma mark - Public diff --git a/MASFoundation/Classes/models/Network/MASRequest.m b/MASFoundation/Classes/models/Network/MASRequest.m index c63179d8..57f1f108 100644 --- a/MASFoundation/Classes/models/Network/MASRequest.m +++ b/MASFoundation/Classes/models/Network/MASRequest.m @@ -22,6 +22,7 @@ @interface MASRequest () @property (assign, readwrite) BOOL sign; @property (assign, readwrite) MASRequestResponseType requestType; @property (assign, readwrite) MASRequestResponseType responseType; +@property (assign, readwrite) NSTimeInterval timeoutInterval; @end diff --git a/MASFoundation/Classes/models/Network/MASRequestBuilder.h b/MASFoundation/Classes/models/Network/MASRequestBuilder.h index 1bdbb6cd..2ecabfbe 100644 --- a/MASFoundation/Classes/models/Network/MASRequestBuilder.h +++ b/MASFoundation/Classes/models/Network/MASRequestBuilder.h @@ -98,6 +98,12 @@ @property (assign) MASRequestResponseType responseType; +/** +The NSTimeInterval value that specifies the timeInterval of the request. +*/ +@property (assign) NSTimeInterval timeoutInterval; + + ///-------------------------------------- /// @name Lifecycle ///-------------------------------------- diff --git a/MASFoundation/Classes/models/Network/MASRequestBuilder.m b/MASFoundation/Classes/models/Network/MASRequestBuilder.m index b04d6944..34bf0117 100644 --- a/MASFoundation/Classes/models/Network/MASRequestBuilder.m +++ b/MASFoundation/Classes/models/Network/MASRequestBuilder.m @@ -10,8 +10,10 @@ #import "MASRequestBuilder.h" +#import "MASConstantsPrivate.h" #import "MASRequest+MASPrivate.h" + @interface MASRequestBuilder () @property (nonatomic, strong, readwrite) NSString *httpMethod; @@ -36,6 +38,7 @@ - (instancetype)initWithHTTPMethod:(NSString *)method self.sign = NO; self.requestType = MASRequestResponseTypeJson; self.responseType = MASRequestResponseTypeJson; + self.timeoutInterval = MASDefaultNetworkTimeoutConfiguration; // default to 60 seconds. } return self; diff --git a/MASFoundation/MASFoundation.h b/MASFoundation/MASFoundation.h index 9cd5edca..7f36d17b 100644 --- a/MASFoundation/MASFoundation.h +++ b/MASFoundation/MASFoundation.h @@ -24,6 +24,7 @@ FOUNDATION_EXPORT const unsigned char MASFoundationVersionString[]; #import #import #import +#import #import #import #import From 6d6940b1bfb03262d095e3236cc9ca47be7f5796 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Mon, 16 Sep 2019 11:44:47 +0530 Subject: [PATCH 30/40] fixing a bug in the default behaviour --- .../services/network/internal/MASSecurityPolicy.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m index 62a4cbd6..d64e879b 100644 --- a/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m +++ b/MASFoundation/Classes/_private_/services/network/internal/MASSecurityPolicy.m @@ -89,6 +89,7 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo NSArray *certificateChain = [self extractCertificateDataFromServerTrust:serverTrust]; switch (securityConfiguration.pinningMode) { + //Tricky case where the default behaviour is still the same as older release. If certificate is set check it or check if atleast public key hash is set, if yes verify public key hash. Not setting both would have errored out in the code above case MASSecuritySSLPinningModeCertificate: { BOOL isPublicKeyHashVerified = NO; @@ -102,7 +103,11 @@ - (BOOL)evaluateSecurityConfigurationsForServerTrust:(SecTrustRef)serverTrust fo isPublicKeyHashVerified = YES; } - isPinningVerified = ([self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]) && isPublicKeyHashVerified; + if(securityConfiguration.certificates != nil && [securityConfiguration.certificates isKindOfClass:[NSArray class]] && [securityConfiguration.certificates count] > 0) + { + isPinningVerified = ([self validateCertPinning:serverTrust configuration:securityConfiguration certChain:certificateChain]) && isPublicKeyHashVerified; + } + } break; From e0e3463f90eed5e33b0c9828e492a4f6c936c889 Mon Sep 17 00:00:00 2001 From: Syed Yusuf Date: Mon, 16 Sep 2019 15:32:38 +0530 Subject: [PATCH 31/40] US609984-RequestTimeout comments added for reference docs and add license header --- .../_private_/categories/NSError+MASPrivate.m | 2 +- .../configuration/MASConfigurationService.h | 7 +- .../services/network/MASNetworkingService.h | 131 ++++++++++++++++++ .../network/requests/MASDeleteURLRequest.h | 1 + .../network/requests/MASDeleteURLRequest.m | 1 + .../network/requests/MASGetURLRequest.h | 1 + .../network/requests/MASGetURLRequest.m | 1 + .../network/requests/MASPatchURLRequest.h | 1 + .../network/requests/MASPatchURLRequest.m | 1 + .../network/requests/MASPostFormURLRequest.m | 1 + .../network/requests/MASPostURLRequest.h | 1 + .../network/requests/MASPostURLRequest.m | 1 + .../network/requests/MASPutURLRequest.h | 1 + .../network/requests/MASPutURLRequest.m | 1 + .../Classes/models/MASConfiguration.h | 8 +- .../Classes/models/MASConfiguration.m | 2 +- .../models/Network/MASNetworkConfiguration.h | 4 +- .../models/Network/MASNetworkConfiguration.m | 4 +- .../models/Network/MASRequestBuilder.h | 1 + 19 files changed, 162 insertions(+), 8 deletions(-) diff --git a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m index 59d37e2d..173bdbcc 100644 --- a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m +++ b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m @@ -995,7 +995,7 @@ + (NSString *)descriptionForFoundationErrorCode:(MASFoundationErrorCode)errorCod case MASFoundationErrorCodeConfigurationInvalidPinningInfoForSecurityConfiguration: return @"Invalid pinning information for security configuration. At least one pinning information should be provided or public PKI should be trusted."; // - // Security Configuration + // Network Configuration // case MASFoundationErrorCodeConfigurationInvalidHostForNetworkConfiguration: return @"Invalid host information for network configuration. NSURL host or port cannot be nil."; diff --git a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h index d8ff2c94..a6156105 100644 --- a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h +++ b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h @@ -25,9 +25,12 @@ # pragma mark - Network Configuration /** - */ -+ (void)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration; +Sets network timeout for specified host in MASNetworkConfiguration object +@warning Upon SDK initialization, [MASConfiguration currentConfiguration].gatewayUrl's MASNetworkConfiguration object will be overwritten. If primary gateway's network configuration has to be modified, ensure to set network configuration after SDK initialization. +@param networkConfiguration MASNetworkConfiguration object with host, and network configuration values. +*/ ++ (void)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration; diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h index 8d1bbbb0..ecca1591 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h @@ -276,6 +276,31 @@ typedef NSURLRequest* (^MASSessionDataTaskHTTPRedirectBlock)(NSURLSession *sessi completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP DELETE call from the Gateway. This type of HTTP Method type +* places it's parameters within the NSURL itself as an HTTP query extension as so: +* +* https://:/ +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ - (void)deleteFrom:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo @@ -378,6 +403,31 @@ timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP GET call from the Gateway. This type of HTTP Method type +* places it's parameters within the NSURL itself as an HTTP query extension as so: +* +* https://:/ +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ - (void)getFrom:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo @@ -487,6 +537,33 @@ timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP PATCH call to the Gateway. This type of HTTP Method type +* places it's parameters within the HTTP body in www-form-urlencoded format: +* +* +* +* +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ - (void)patchTo:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo @@ -597,6 +674,33 @@ withParameters:(NSDictionary *)parameterInfo completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP POST call to the Gateway. This type of HTTP Method type +* places it's parameters within the HTTP body in www-form-urlencoded format: +* +* +* +* +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ - (void)postTo:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo @@ -705,6 +809,33 @@ withParameters:(NSDictionary *)parameterInfo completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP PUT call to the Gateway. This type of HTTP Method type +* places it's parameters within the HTTP body in www-form-urlencoded format: +* +* +* +* +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ - (void)putTo:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h index d8722b32..1ee38b57 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASDeleteURLRequest which could be used to create NSURLSessionDataTask. */ + (MASDeleteURLRequest *)requestForEndpoint:(NSString *)endPoint diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m index 97b7ad72..eace3350 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m @@ -67,6 +67,7 @@ + (MASDeleteURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h index fabc5066..c72260c7 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASGetURLRequest which could be used to create NSURLSessionDataTask. */ + (MASGetURLRequest *)requestForEndpoint:(NSString *)endPoint diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m index 75cbe0b1..f262bcb6 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m @@ -67,6 +67,7 @@ + (MASGetURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h index d8b7d4ff..3c03b416 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASPatchURLRequest which could be used to create NSURLSessionDataTask. */ + (MASPatchURLRequest *)requestForEndpoint:(NSString *)endPoint diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m index 43b3fe7c..134ba8f4 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m @@ -62,6 +62,7 @@ + (MASPatchURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m index 38768cb9..c35596cf 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m @@ -48,6 +48,7 @@ + (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameter // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h index 876e54e9..acefeeb4 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASPostURLRequest which could be used to create NSURLSessionDataTask. */ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m index 31116911..e96cb087 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m @@ -61,6 +61,7 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h index f0b5db8f..f73d1a86 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASPutURLRequest which could be used to create NSURLSessionDataTask. */ + (MASPutURLRequest *)requestForEndpoint:(NSString *)endPoint diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m index c042dc75..85766203 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m @@ -62,6 +62,7 @@ + (MASPutURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/models/MASConfiguration.h b/MASFoundation/Classes/models/MASConfiguration.h index db5b09dd..5f694ead 100644 --- a/MASFoundation/Classes/models/MASConfiguration.h +++ b/MASFoundation/Classes/models/MASConfiguration.h @@ -175,13 +175,17 @@ ///-------------------------------------- -/// @name Security Configuration +/// @name Network Configuration ///-------------------------------------- # pragma mark - Network Configuration /** - */ +Sets network timeout for specified host in MASNetworkConfiguration object + +@warning Upon SDK initialization, [MASConfiguration currentConfiguration].gatewayUrl's MASNetworkConfiguration object will be overwritten. If primary gateway's network configuration has to be modified, ensure to set network configuration after SDK initialization. +@param networkConfiguration MASNetworkConfiguration object with host, and network configuration values. +*/ + (BOOL)setNetworkConfiguration:(MASNetworkConfiguration *_Nonnull)networkConfiguration error:(NSError *__nullable __autoreleasing *__nullable)error; diff --git a/MASFoundation/Classes/models/MASConfiguration.m b/MASFoundation/Classes/models/MASConfiguration.m index 52bb0d33..34226dba 100644 --- a/MASFoundation/Classes/models/MASConfiguration.m +++ b/MASFoundation/Classes/models/MASConfiguration.m @@ -424,7 +424,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder + (BOOL)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration error:(NSError **)error { // - // Validate the NSURL host for security configuration. + // Validate the NSURL host for network configuration. // if (!networkConfiguration.host || !networkConfiguration.host.port) { diff --git a/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h index 03da9a8b..c99d9c16 100644 --- a/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h +++ b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h @@ -2,9 +2,11 @@ // MASNetworkConfiguration.h // MASFoundation // -// Created by yussy01 on 05/09/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// #import "MASObject.h" diff --git a/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m index e5f5c31d..da2b71f2 100644 --- a/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m +++ b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m @@ -2,9 +2,11 @@ // MASNetworkConfiguration.m // MASFoundation // -// Created by yussy01 on 05/09/19. // Copyright © 2019 CA Technologies. All rights reserved. // +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// #import "MASNetworkConfiguration.h" diff --git a/MASFoundation/Classes/models/Network/MASRequestBuilder.h b/MASFoundation/Classes/models/Network/MASRequestBuilder.h index 2ecabfbe..2d12f0cf 100644 --- a/MASFoundation/Classes/models/Network/MASRequestBuilder.h +++ b/MASFoundation/Classes/models/Network/MASRequestBuilder.h @@ -18,6 +18,7 @@ Default configuration value for designated initializer, [[MASRequestBuilder alloc] initWithHTTPMethod:], would be: isPublic: NO, + timeoutInterval: 60, sign: NO, requestType:MASRequestResponseTypeJson, responseType:MASRequestResponseTypeJson. From cfe540bb3477ff29fc350c98374384a39ee8201d Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 17 Sep 2019 11:13:48 +0530 Subject: [PATCH 32/40] Updated License to contain Broadcom licensing details --- CONTRIBUTING.md | 8 ++++---- GUIDELINES.md | 2 +- LICENSE | 3 ++- LICENSE.md | 3 ++- README.md | 3 ++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3b8d6f13..ec6d3f68 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,8 +26,8 @@ To accept pull requests, submit a CLA. (Submitting a single CLA lets you work on Complete your CLA here: ## Bugs -We work hard to avoid them, but they still happen. If you're a CA customer, open an issue in our [Support Page][casupport], otherwise use GitHub issues. -To share ideas or ask product-related questions go to [CA Communities][community]. +We work hard to avoid them, but they still happen. If you're a Broadcom customer, open an issue in our [Support Page][casupport], otherwise use GitHub issues. +To share ideas or ask product-related questions go to [Broadcom Communities][community]. ### Known Issues We also use GitHub issues for updates to known issues, including alerts when fixes are in progress. @@ -48,8 +48,8 @@ By contributing to iOS Mobile SDK, you agree that your contributions will be lic [guidelines]: /GUIDELINES.md -[community]: https://communities.ca.com/community/ca-api-management-community/content?filterID=contentstatus%5Bpublished%5D~category%5Bca-mobile-api-gateway%5D +[community]: https://community.broadcom.com/enterprisesoftware/communities/communityhomeblogs?CommunityKey=0f580f5f-30a4-41de-a75c-e5f433325a18 [license-link]: /LICENSE [cla]: https://www.clahub.com/agreements/CAAPIM/iOS-MAS-Foundation -[casupport]: https://support.ca.com/irj/portal/implsvcnewcase +[casupport]: https://casupport.broadcom.com diff --git a/GUIDELINES.md b/GUIDELINES.md index 28972890..b7b08bb8 100644 --- a/GUIDELINES.md +++ b/GUIDELINES.md @@ -1,4 +1,4 @@ -# CA Technologies Objective-C Style Guide +# Broadcom Objective-C Style Guide This document describes the Objective-C coding style of the iOS Mobile SDK team. This guideline is recommended to comply with all Objective-C implementations of our products. diff --git a/LICENSE b/LICENSE index 56dbc620..a0a95c1a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) -Copyright (c) 2016 CA. All rights reserved. +Copyright (c) 2019 Broadcom. All Rights Reserved. +The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/LICENSE.md b/LICENSE.md index a54c3d26..d49a6b40 100755 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,8 @@ The MIT License (MIT) ===================== -Copyright (c) 2016 CA. All rights reserved. +Copyright (c) 2019 Broadcom. All Rights Reserved. +The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/README.md b/README.md index 54891da4..0e8a0c98 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,8 @@ For more documentation and API references, go to our [main website][docs] ## License -Copyright (c) 2016 CA. All rights reserved. +Copyright (c) 2019 Broadcom. All Rights Reserved. +The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. This software may be modified and distributed under the terms of the MIT license. See the [LICENSE][license-link] file for details. From f070f887ef8595a675fa713184332e5b066b0b24 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 17 Sep 2019 11:26:54 +0530 Subject: [PATCH 33/40] Replaced CA with Broadcom --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ec6d3f68..1951d855 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,7 +21,7 @@ Follow these steps for pull requests: 6. If you haven't already, complete the [Contributor License Agreement ("CLA")][cla]. ### Contributor License Agreement ("CLA") -To accept pull requests, submit a CLA. (Submitting a single CLA lets you work on any open source projects from CA, Inc.) +To accept pull requests, submit a CLA. (Submitting a single CLA lets you work on any open source projects from Broadcom, Inc.) Complete your CLA here: From f056e4122837c8cdb67491d38584314d1e49e7f8 Mon Sep 17 00:00:00 2001 From: Syed Yusuf Date: Tue, 17 Sep 2019 12:32:20 +0530 Subject: [PATCH 34/40] [2.0.00Release] Updating the XCode11 project setting addition of Support Mac Catalyst to NO --- MASFoundation.xcodeproj/project.pbxproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index ca7a6e34..00a5556b 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -2183,6 +2183,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_BRIDGING_HEADER = ""; }; name = Debug; @@ -2230,6 +2231,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_BRIDGING_HEADER = ""; }; name = Release; @@ -2253,6 +2255,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.ca.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = NO; }; name = Debug; }; @@ -2271,6 +2274,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.ca.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = NO; }; name = Release; }; @@ -2282,6 +2286,7 @@ ENABLE_BITCODE = YES; MACH_O_TYPE = staticlib; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = NO; }; name = Debug; }; @@ -2293,6 +2298,7 @@ ENABLE_BITCODE = YES; MACH_O_TYPE = staticlib; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = NO; }; name = Release; }; From 62d14ca121872aaa22c959eb99816be5a1d531c2 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Tue, 24 Sep 2019 12:17:54 +0530 Subject: [PATCH 35/40] updated change log to update proper user story --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 871ff128..0ca15c3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,13 @@ -# Version 1.9.20 +# Version 2.0.00 ### New features - Proximity Login feature (BLE and QR Code) is now moved to [MASProximity][MASProximity] framework. No code change is required, and no functionality change was made. In order to use Proxmity Login feature, please include [MASProximity][MASProximity] framework into a project. [US584914] +# Version 1.9.20 + +### Bug fixes +- ASN.1 Bit String Null Range Handled. [US604884] + # Version 1.9.10 ### Bug fixes From d9108e9335a33e2adff159ed48bddc586e293fc5 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Wed, 25 Sep 2019 12:44:07 +0530 Subject: [PATCH 36/40] updated changelog file with new features --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ca15c3a..ae690fe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,19 @@ # Version 2.0.00 +### Bug fixes +- None + ### New features - Proximity Login feature (BLE and QR Code) is now moved to [MASProximity][MASProximity] framework. No code change is required, and no functionality change was made. In order to use Proxmity Login feature, please include [MASProximity][MASProximity] framework into a project. [US584914] +- Intermediate Certificate Pinning-Implementation Cordova-iOS [US579432] +- Multipart Form data support (Usage: File Upload) [US605851] +- Ability to specify Timeout parameter for HTTP(S) Requests [US609984] + +### Deprecated methods +- None + +### Removed methods +- None # Version 1.9.20 From 78ea6a5c4001d4e238ad2a4e9ba819a3134e21ca Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Wed, 25 Sep 2019 12:45:36 +0530 Subject: [PATCH 37/40] updated build version --- MASFoundation.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 00a5556b..f77cc0e4 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -2146,7 +2146,7 @@ CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 1.9.20; + CURRENT_PROJECT_VERSION = 2.0.00; DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; @@ -2194,7 +2194,7 @@ CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 1.9.20; + CURRENT_PROJECT_VERSION = 2.0.00; DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; From 01f716f208560f8a61555bec53fbbbbdeb2114a5 Mon Sep 17 00:00:00 2001 From: MANU TRIPATHI <32505656+manutripathi82@users.noreply.github.com> Date: Thu, 26 Sep 2019 20:41:05 +0530 Subject: [PATCH 38/40] Update landing page link --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0e8a0c98..7e671671 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ For manual install, you add the Mobile SDK to your Xcode project. Note that you ## Set Up Project and Start the SDK -To start your project, see [developer site](https://mas.ca.com/docs) +To start your project, see [developer site](http://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/layer7-api-management/mobile-sdk-for-ca-mobile-api-gateway/2-0.html) After your project is properly configured, you must start the SDK to establish a secure connection with the backend services. The startup process includes: initialize necessary services for library (such as geo-location, BLE, and network services), and load configuration. @@ -149,7 +149,7 @@ of the MIT license. See the [LICENSE][license-link] file for details. [mag]: https://docops.ca.com/mag [mas.ca.com]: http://mas.ca.com/ [get-started]: http://mas.ca.com/get-started/ - [docs]: http://mas.ca.com/docs/ + [docs]: http://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/layer7-api-management/mobile-sdk-for-ca-mobile-api-gateway/2-0.html [blog]: http://mas.ca.com/blog/ [videos]: https://www.ca.com/us/developers/mas/videos.html [StackOverflow]: http://stackoverflow.com/questions/tagged/massdk From 84944223ce4532cdb52bf3b88229f9f5d23599f5 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Fri, 27 Sep 2019 14:41:35 +0530 Subject: [PATCH 39/40] Update README.md further updates for landing page --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7e671671..3df2c3e9 100644 --- a/README.md +++ b/README.md @@ -147,11 +147,9 @@ of the MIT license. See the [LICENSE][license-link] file for details. [MASProximity]: https://github.com/CAAPIM/iOS-MAS-Proximity [mag]: https://docops.ca.com/mag - [mas.ca.com]: http://mas.ca.com/ - [get-started]: http://mas.ca.com/get-started/ + [techdocs.broadcom.com]: http://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/layer7-api-management/mobile-sdk-for-ca-mobile-api-gateway/2-0.html + [get-started]: http://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/layer7-api-management/mobile-sdk-for-ca-mobile-api-gateway/2-0.html [docs]: http://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/layer7-api-management/mobile-sdk-for-ca-mobile-api-gateway/2-0.html - [blog]: http://mas.ca.com/blog/ - [videos]: https://www.ca.com/us/developers/mas/videos.html [StackOverflow]: http://stackoverflow.com/questions/tagged/massdk [download]: https://github.com/CAAPIM/iOS-MAS-Foundation/archive/master.zip [contributing]: https://github.com/CAAPIM/iOS-MAS-Foundation/blob/develop/CONTRIBUTING.md From fbb296f5dbf9e2f7d3dc9c908cfd3c9ddc58c9f6 Mon Sep 17 00:00:00 2001 From: Mahendra Nimishakavi Date: Fri, 27 Sep 2019 14:43:21 +0530 Subject: [PATCH 40/40] Update CHANGELOG.md --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae690fe1..fe592cb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -252,9 +252,8 @@ None. [MASProximity]: https://github.com/CAAPIM/iOS-MAS-Proximity [mag]: https://docops.ca.com/mag - [mas.ca.com]: http://mas.ca.com/ - [docs]: http://mas.ca.com/docs/ - [blog]: http://mas.ca.com/blog/ + [techdocs.broadcom.com]: http://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/layer7-api-management/mobile-sdk-for-ca-mobile-api-gateway/2-0.html + [docs]: http://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/layer7-api-management/mobile-sdk-for-ca-mobile-api-gateway/2-0.html [releases]: ../../releases [contributing]: /CONTRIBUTING.md