Skip to content

Commit c778919

Browse files
[milestone/11.9] Milestone 11.9 (#93)
- Authentication: new type OCAuthenticationDataID - an ID that's unique for every OCBookmark.authenticationData and changes when the authenticationData is changed - is attached to OCHTTPRequests and OCHTTPResponses, allowing to determine if a request's "Authorization" is based on a different token - OCHTTPRequest / OCHTTPResponse - add authenticationDataID property - added counter to logged "Authorization" header fields that allow to determine if its contents was changed between requests - the counter issues a new number for every new and not previously used header field contents - initial idea was to log the OCAuthenticationDataID, but that could have given hints to its content - OCAuthenticationMethodOAuth2 / OCAuthenticationMethodOIDC: - add support for authenticationDataID - in case of preemptive token renewals, now reloads the secret from keychain and performs another date check before triggering a refresh - used OCAuthenticationDataID to reschedule/resend HTTP requests that were responded to with a 401 status code and that was sent with another (older) token - OCAuthenticationMethodBasicAuth - store authenticationDataID when loading secret - OCBookmark - add .authenticationDataID property that returns the OCAuthenticationDataID for the bookmark's authenticationData - add .user property, storing the last retrieved version of OCConnection.loggedInUser - use .user property to compose WebDAV endpoint path (fixing owncloud/enterprise#4924 ) - OCChecksumAlgorithm: add convenience method to use OCChecksumAlgorithms for checksum calculations on NSData objects - Server Locator: allow locating the actual server for a user via webfinger or lookup table - OCCore+CommandLocalModification: no longer handle failure of -startAccessingSecurityScopedResource as an error, as that may indicate the inputFileURL is not actually security scoped, not that the file can't be accessed. Fixes enterprise#4934.
1 parent 00e01d2 commit c778919

37 files changed

+1019
-83
lines changed

CHANGELOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
## 11.9 version
2+
- Authentication: new type OCAuthenticationDataID
3+
- an ID that's unique for every OCBookmark.authenticationData and changes when the authenticationData is changed
4+
- is attached to OCHTTPRequests and OCHTTPResponses, allowing to determine if a request's "Authorization" is based on a different token
5+
- OCHTTPRequest / OCHTTPResponse
6+
- add authenticationDataID property
7+
- added counter to logged "Authorization" header fields that allow to determine if its contents was changed between requests
8+
- the counter issues a new number for every new and not previously used header field contents
9+
- initial idea was to log the OCAuthenticationDataID, but that could have given hints to its content
10+
- OCAuthenticationMethodOAuth2 / OCAuthenticationMethodOIDC:
11+
- add support for authenticationDataID
12+
- in case of preemptive token renewals, now reloads the secret from keychain and performs another date check before triggering a refresh
13+
- used OCAuthenticationDataID to reschedule/resend HTTP requests that were responded to with a 401 status code and that was sent with another (older) token
14+
- OCAuthenticationMethodBasicAuth
15+
- store authenticationDataID when loading secret
16+
- OCBookmark
17+
- add .authenticationDataID property that returns the OCAuthenticationDataID for the bookmark's authenticationData
18+
- add .user property, storing the last retrieved version of OCConnection.loggedInUser
19+
- use .user property to compose WebDAV endpoint path (fixing https://github.com/owncloud/enterprise/issues/4924 )
20+
- OCChecksumAlgorithm: add convenience method to use OCChecksumAlgorithms for checksum calculations on NSData objects
21+
- Server Locator: allow locating the actual server for a user via webfinger or lookup table
22+
- OCCore+CommandLocalModification: no longer handle failure of -startAccessingSecurityScopedResource as an error, as that may indicate the inputFileURL is not actually security scoped, not that the file can't be accessed. Fixes enterprise#4934.
23+
124
## 11.8.1 version
225
- OCSQL: add collation support via new OCSQLiteCollation class, making it as simple as possible to encapsulate and add collations, avoiding string format conversions (i.e. UTF-8 <-> UTF-16) where possible
326
- OCSQL: add collation OCSQLiteCollationLocalized (OCLOCALIZED) for "Finder-like" sorting

doc/CONFIGURATION.json

+40
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,10 @@
738738
{
739739
"description" : "Redirect any request without cookies to a cookie-setting endpoint, where cookies are set - and then redirect back.",
740740
"value" : "simple-apm"
741+
},
742+
{
743+
"description" : "Responds to all .well-known\/webfinger requests with server-instance responses.",
744+
"value" : "web-finger"
741745
}
742746
],
743747
"status" : "debugOnly",
@@ -1082,6 +1086,42 @@
10821086
"status" : "debugOnly",
10831087
"type" : "bool"
10841088
},
1089+
{
1090+
"autoExpansion" : "none",
1091+
"category" : "Connection",
1092+
"categoryTag" : "connection",
1093+
"classIdentifier" : "server-locator",
1094+
"className" : "OCServerLocator",
1095+
"description" : "Lookup table that maps users to server URLs",
1096+
"flatIdentifier" : "server-locator.lookup-table",
1097+
"key" : "lookup-table",
1098+
"label" : "server-locator.lookup-table",
1099+
"status" : "advanced",
1100+
"type" : "dictionary"
1101+
},
1102+
{
1103+
"autoExpansion" : "none",
1104+
"category" : "Connection",
1105+
"categoryTag" : "connection",
1106+
"classIdentifier" : "server-locator",
1107+
"className" : "OCServerLocator",
1108+
"description" : "Use Server Locator",
1109+
"flatIdentifier" : "server-locator.use",
1110+
"key" : "use",
1111+
"label" : "server-locator.use",
1112+
"possibleValues" : [
1113+
{
1114+
"description" : "Locate server via lookup table. Keys can match against the beginning (f.ex. \"begins:bob@\"), end (f.ex. \"ends:@owncloud.org\") or regular expression (f.ex. \"regexp:\")",
1115+
"value" : "lookup-table"
1116+
},
1117+
{
1118+
"description" : "Locate server via Webfinger service-instance relation (http:\/\/webfinger.owncloud\/rel\/server-instance) using the entered\/provided server URL",
1119+
"value" : "web-finger"
1120+
}
1121+
],
1122+
"status" : "advanced",
1123+
"type" : "string"
1124+
},
10851125
{
10861126
"autoExpansion" : "none",
10871127
"category" : "Security",

ownCloudSDK.xcodeproj/project.pbxproj

+56
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,14 @@
564564
DCD9B8832379783200691929 /* UIDevice+ModelID.m in Sources */ = {isa = PBXBuildFile; fileRef = DCD9B8812379783200691929 /* UIDevice+ModelID.m */; };
565565
DCDA307121412A0100DB61A9 /* OCSyncAction.h in Headers */ = {isa = PBXBuildFile; fileRef = DCDA306F21412A0100DB61A9 /* OCSyncAction.h */; };
566566
DCDA307221412A0100DB61A9 /* OCSyncAction.m in Sources */ = {isa = PBXBuildFile; fileRef = DCDA307021412A0100DB61A9 /* OCSyncAction.m */; };
567+
DCDB76122739D30500EE7A06 /* OCServerLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = DCDB76102739D30500EE7A06 /* OCServerLocator.h */; settings = {ATTRIBUTES = (Public, ); }; };
568+
DCDB76132739D30500EE7A06 /* OCServerLocator.m in Sources */ = {isa = PBXBuildFile; fileRef = DCDB76112739D30500EE7A06 /* OCServerLocator.m */; };
569+
DCDB761E2739D4A300EE7A06 /* OCServerLocatorWebFinger.h in Headers */ = {isa = PBXBuildFile; fileRef = DCDB761C2739D4A300EE7A06 /* OCServerLocatorWebFinger.h */; };
570+
DCDB761F2739D4A300EE7A06 /* OCServerLocatorWebFinger.m in Sources */ = {isa = PBXBuildFile; fileRef = DCDB761D2739D4A300EE7A06 /* OCServerLocatorWebFinger.m */; };
571+
DCDB76242739D51200EE7A06 /* OCServerLocatorLookupTable.h in Headers */ = {isa = PBXBuildFile; fileRef = DCDB76222739D51200EE7A06 /* OCServerLocatorLookupTable.h */; };
572+
DCDB76252739D51200EE7A06 /* OCServerLocatorLookupTable.m in Sources */ = {isa = PBXBuildFile; fileRef = DCDB76232739D51200EE7A06 /* OCServerLocatorLookupTable.m */; };
573+
DCDB76282739EF9A00EE7A06 /* OCExtension+ServerLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = DCDB76262739EF9A00EE7A06 /* OCExtension+ServerLocator.h */; };
574+
DCDB76292739EF9A00EE7A06 /* OCExtension+ServerLocator.m in Sources */ = {isa = PBXBuildFile; fileRef = DCDB76272739EF9A00EE7A06 /* OCExtension+ServerLocator.m */; };
567575
DCDBEE2C2048A6A800189B9A /* OCConnection+Setup.m in Sources */ = {isa = PBXBuildFile; fileRef = DCDBEE2A2048A6A700189B9A /* OCConnection+Setup.m */; };
568576
DCDBEE302048A71200189B9A /* OCConnection+Tools.m in Sources */ = {isa = PBXBuildFile; fileRef = DCDBEE2E2048A71200189B9A /* OCConnection+Tools.m */; };
569577
DCDBEE342048A8BC00189B9A /* OCConnection+Authentication.m in Sources */ = {isa = PBXBuildFile; fileRef = DCDBEE322048A8BC00189B9A /* OCConnection+Authentication.m */; };
@@ -1381,6 +1389,14 @@
13811389
DCD9B8812379783200691929 /* UIDevice+ModelID.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+ModelID.m"; sourceTree = "<group>"; };
13821390
DCDA306F21412A0100DB61A9 /* OCSyncAction.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCSyncAction.h; sourceTree = "<group>"; };
13831391
DCDA307021412A0100DB61A9 /* OCSyncAction.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OCSyncAction.m; sourceTree = "<group>"; };
1392+
DCDB76102739D30500EE7A06 /* OCServerLocator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCServerLocator.h; sourceTree = "<group>"; };
1393+
DCDB76112739D30500EE7A06 /* OCServerLocator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OCServerLocator.m; sourceTree = "<group>"; };
1394+
DCDB761C2739D4A300EE7A06 /* OCServerLocatorWebFinger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCServerLocatorWebFinger.h; sourceTree = "<group>"; };
1395+
DCDB761D2739D4A300EE7A06 /* OCServerLocatorWebFinger.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OCServerLocatorWebFinger.m; sourceTree = "<group>"; };
1396+
DCDB76222739D51200EE7A06 /* OCServerLocatorLookupTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCServerLocatorLookupTable.h; sourceTree = "<group>"; };
1397+
DCDB76232739D51200EE7A06 /* OCServerLocatorLookupTable.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OCServerLocatorLookupTable.m; sourceTree = "<group>"; };
1398+
DCDB76262739EF9A00EE7A06 /* OCExtension+ServerLocator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OCExtension+ServerLocator.h"; sourceTree = "<group>"; };
1399+
DCDB76272739EF9A00EE7A06 /* OCExtension+ServerLocator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OCExtension+ServerLocator.m"; sourceTree = "<group>"; };
13841400
DCDBEE2A2048A6A700189B9A /* OCConnection+Setup.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OCConnection+Setup.m"; sourceTree = "<group>"; };
13851401
DCDBEE2E2048A71200189B9A /* OCConnection+Tools.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OCConnection+Tools.m"; sourceTree = "<group>"; };
13861402
DCDBEE322048A8BC00189B9A /* OCConnection+Authentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OCConnection+Authentication.m"; sourceTree = "<group>"; };
@@ -2529,6 +2545,7 @@
25292545
DCCE49362684BBF5005961D8 /* DAVResponse */,
25302546
DCD63279223BB1930090169E /* Capabilities */,
25312547
DC85570A204FEA5E00189B9A /* Categories */,
2548+
DCDB760F2739D26100EE7A06 /* ServerLocator */,
25322549
);
25332550
path = Connection;
25342551
sourceTree = "<group>";
@@ -3105,6 +3122,37 @@
31053122
path = Capabilities;
31063123
sourceTree = "<group>";
31073124
};
3125+
DCDB760F2739D26100EE7A06 /* ServerLocator */ = {
3126+
isa = PBXGroup;
3127+
children = (
3128+
DCDB76112739D30500EE7A06 /* OCServerLocator.m */,
3129+
DCDB76102739D30500EE7A06 /* OCServerLocator.h */,
3130+
DCDB76272739EF9A00EE7A06 /* OCExtension+ServerLocator.m */,
3131+
DCDB76262739EF9A00EE7A06 /* OCExtension+ServerLocator.h */,
3132+
DCDB76212739D4FD00EE7A06 /* LookupTable */,
3133+
DCDB76202739D4AA00EE7A06 /* WebFinger */,
3134+
);
3135+
path = ServerLocator;
3136+
sourceTree = "<group>";
3137+
};
3138+
DCDB76202739D4AA00EE7A06 /* WebFinger */ = {
3139+
isa = PBXGroup;
3140+
children = (
3141+
DCDB761D2739D4A300EE7A06 /* OCServerLocatorWebFinger.m */,
3142+
DCDB761C2739D4A300EE7A06 /* OCServerLocatorWebFinger.h */,
3143+
);
3144+
path = WebFinger;
3145+
sourceTree = "<group>";
3146+
};
3147+
DCDB76212739D4FD00EE7A06 /* LookupTable */ = {
3148+
isa = PBXGroup;
3149+
children = (
3150+
DCDB76232739D51200EE7A06 /* OCServerLocatorLookupTable.m */,
3151+
DCDB76222739D51200EE7A06 /* OCServerLocatorLookupTable.h */,
3152+
);
3153+
path = LookupTable;
3154+
sourceTree = "<group>";
3155+
};
31083156
DCE227CC22D60CF4000BE0A5 /* ItemPolicies */ = {
31093157
isa = PBXGroup;
31103158
children = (
@@ -3286,6 +3334,7 @@
32863334
DC35969A2240EC0A00C4D6E6 /* OCQueryCondition+Item.h in Headers */,
32873335
DC4B1171220830F20062BCDD /* OCHTTPPipelineBackend.h in Headers */,
32883336
DC19BFD221CA6C15007C20D1 /* OCSyncIssueChoice.h in Headers */,
3337+
DCDB761E2739D4A300EE7A06 /* OCServerLocatorWebFinger.h in Headers */,
32893338
DCEE0B6F25E697AF006534B5 /* OCCoreManager+ItemResolution.h in Headers */,
32903339
DCC8FA21202B218100EB6701 /* OCAppIdentity.h in Headers */,
32913340
DCC3701324D4D134008B0DEB /* OCScanJobActivity.h in Headers */,
@@ -3299,6 +3348,7 @@
32993348
DC1C7AC2253F3CD9002F2B9F /* OCClassSettings+Metadata.h in Headers */,
33003349
DC2AA57922DDD005001D5C39 /* OCSyncActionLocalCopyDelete.h in Headers */,
33013350
DCA35D7624D00B2900DBE2B0 /* OCHTTPPipelineTask+Diagnostic.h in Headers */,
3351+
DCDB76242739D51200EE7A06 /* OCServerLocatorLookupTable.h in Headers */,
33023352
DCC832CE242BB05A00153F8C /* OCCore+MessageResponseHandler.h in Headers */,
33033353
DCC8FA0F2029C6A400EB6701 /* OCQueryChangeSet.h in Headers */,
33043354
DC701484220B090B009D4FD9 /* OCHTTPTypes.h in Headers */,
@@ -3371,6 +3421,7 @@
33713421
DC114A9422A7A87C00CBD597 /* NSData+OCRandom.h in Headers */,
33723422
DC114A9822A7AA2E00CBD597 /* NSString+OCRandom.h in Headers */,
33733423
DC19BFF121CBE28B007C20D1 /* OCWaitCondition.h in Headers */,
3424+
DCDB76282739EF9A00EE7A06 /* OCExtension+ServerLocator.h in Headers */,
33743425
DCA35D5D24CF6BEC00DBE2B0 /* NSArray+OCNullable.h in Headers */,
33753426
DC3CE065242A49E100AB8B88 /* OCMessagePresenter.h in Headers */,
33763427
DC04A4942330290A006285AC /* OCCoreProxy.h in Headers */,
@@ -3398,6 +3449,7 @@
33983449
DCCE49392684BC1B005961D8 /* OCDAVRawResponse.h in Headers */,
33993450
DCC83307242E1B4600153F8C /* OCCore+MessageAutoresolver.h in Headers */,
34003451
DC07C28E21244FC800B815A4 /* OCExtensionManager.h in Headers */,
3452+
DCDB76122739D30500EE7A06 /* OCServerLocator.h in Headers */,
34013453
DCE370942099D18100114981 /* OCDatabaseConsistentOperation.h in Headers */,
34023454
DC47DF762770CEE300989D84 /* NSError+OCErrorTools.h in Headers */,
34033455
DCC8FA0B2029C0BE00EB6701 /* OCQueryFilter.h in Headers */,
@@ -3919,6 +3971,7 @@
39193971
DCE451A62459AD3F0074363F /* OCTUSJob.m in Sources */,
39203972
DC19BFEE21CBACBC007C20D1 /* OCProcessManager.m in Sources */,
39213973
DCC8FA0020285C1500EB6701 /* OCAuthenticationMethodOAuth2.m in Sources */,
3974+
DCDB761F2739D4A300EE7A06 /* OCServerLocatorWebFinger.m in Sources */,
39223975
DCDD9B15222986D50052A001 /* OCShare+OCXMLObjectCreation.m in Sources */,
39233976
DC54396520D50B8A002BF291 /* OCCore+CommandDelete.m in Sources */,
39243977
DCF163F7274BA6C300E0182A /* OCSQLiteCollationLocalized.m in Sources */,
@@ -3963,6 +4016,7 @@
39634016
DCC8F9F7202855A200EB6701 /* OCShare.m in Sources */,
39644017
DC47DF772770CEE300989D84 /* NSError+OCErrorTools.m in Sources */,
39654018
DCA35D7324D00A9800DBE2B0 /* OCHTTPPipeline+Diagnostic.m in Sources */,
4019+
DCDB76292739EF9A00EE7A06 /* OCExtension+ServerLocator.m in Sources */,
39664020
DC73F3C0254BFE9900CE5FA9 /* NSArray+ObjCRuntime.m in Sources */,
39674021
DC39DC472041A03300189B9A /* OCAuthenticationMethodBasicAuth.m in Sources */,
39684022
DCEAA0D125CEB7F90017F99B /* OCLockRequest.m in Sources */,
@@ -4119,6 +4173,7 @@
41194173
DCADC04E2072D54200DB8E83 /* OCSQLiteTableSchema.m in Sources */,
41204174
DC35969B2240EC0A00C4D6E6 /* OCQueryCondition+Item.m in Sources */,
41214175
DC708CE1214135D100FE43CA /* OCSyncActionDelete.m in Sources */,
4176+
DCDB76132739D30500EE7A06 /* OCServerLocator.m in Sources */,
41224177
DC2D646621C3D63000EB26FD /* OCCore+Thumbnails.m in Sources */,
41234178
DC188998218B09CC00CFB3F9 /* OCLogFileSource.m in Sources */,
41244179
DC72E42F2063DBF900189B9A /* OCClassSettingsFlatSourceManagedConfiguration.m in Sources */,
@@ -4127,6 +4182,7 @@
41274182
DC179CD2209475C20018DF7F /* UIImage+OCTools.m in Sources */,
41284183
DC2AA57122DD1339001D5C39 /* OCItemPolicyProcessorAvailableOffline.m in Sources */,
41294184
DC14CC4B21067320006DDA69 /* OCCore+ItemList.m in Sources */,
4185+
DCDB76252739D51200EE7A06 /* OCServerLocatorLookupTable.m in Sources */,
41304186
DC166E9F2428FD9A00347714 /* OCItemPolicyProcessorVersionUpdates.m in Sources */,
41314187
DC4AFAB5206AE61400189B9A /* OCSQLiteQuery.m in Sources */,
41324188
DCD7AA452580E5A5000CD155 /* NSURLSessionTask+Debug.m in Sources */,

ownCloudSDK/Authentication/OCAuthenticationMethod.h

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef NSString* OCAuthenticationMethodIdentifier NS_TYPED_EXTENSIBLE_ENUM; //!
3030
typedef NSString* OCAuthenticationMethodKey NS_TYPED_ENUM; //!< NSString key used in the options dictionary used to generate the authentication data for a bookmark.
3131
typedef NSDictionary<OCAuthenticationMethodKey,id>* OCAuthenticationMethodBookmarkAuthenticationDataGenerationOptions; //!< Dictionary with options used to generate the authentication data for a bookmark. F.ex. passwords or the view controller to attach own UI to.
3232
typedef NSDictionary<OCAuthenticationMethodKey,id>* OCAuthenticationMethodDetectionOptions; //!< Dictionary with options used to detect available authentication methods
33+
typedef NSString* OCAuthenticationDataID; //!< String that's unique for a particular authenticationData. (format not detailed)
3334

3435
NS_ASSUME_NONNULL_BEGIN
3536

@@ -44,6 +45,7 @@ typedef NS_ENUM(NSUInteger, OCAuthenticationMethodType)
4445
@interface OCAuthenticationMethod : NSObject <OCLogTagging, OCClassSettingsSupport>
4546
{
4647
NSDate *_authenticationDataKnownInvalidDate;
48+
OCAuthenticationDataID _cachedAuthenticationDataID;
4749

4850
@private
4951
id _cachedAuthenticationSecret;
@@ -72,6 +74,9 @@ typedef NS_ENUM(NSUInteger, OCAuthenticationMethodType)
7274
+ (nullable NSArray <OCHTTPRequest *> *)detectionRequestsForConnection:(OCConnection *)connection; //!< Provides a list of URLs whose content is needed to determine whether this authentication method is supported
7375
+ (void)detectAuthenticationMethodSupportForConnection:(OCConnection *)connection withServerResponses:(NSDictionary<NSURL *, OCHTTPRequest *> *)serverResponses options:(OCAuthenticationMethodDetectionOptions)options completionHandler:(void(^)(OCAuthenticationMethodIdentifier identifier, BOOL supported))completionHandler; //!< Detects authentication method support using collected responses (for URL provided by -detectionRequestsForConnection:) and then returns result via the completionHandler.
7476

77+
#pragma mark - Authentication Data ID computation
78+
+ (nullable OCAuthenticationDataID)authenticationDataIDForAuthenticationData:(nullable NSData *)data; //!< Returns the OCAuthenticationDataID for the passed authenticationData (usually from OCBookmark).
79+
7580
#pragma mark - Authentication / Deauthentication ("Login / Logout")
7681
- (void)authenticateConnection:(OCConnection *)connection withCompletionHandler:(OCAuthenticationMethodAuthenticationCompletionHandler)completionHandler; //!< Authenticates the connection.
7782
- (void)deauthenticateConnection:(OCConnection *)connection withCompletionHandler:(OCAuthenticationMethodAuthenticationCompletionHandler)completionHandler; //!< Deauthenticates the connection.
@@ -86,6 +91,7 @@ typedef NS_ENUM(NSUInteger, OCAuthenticationMethodType)
8691
#pragma mark - Authentication Secret Caching
8792
- (nullable id)cachedAuthenticationSecretForConnection:(OCConnection *)connection; //!< Method that allows an authentication method to cache a secret in memory. If none is present in memory, -loadCachedAuthenticationSecretForConnection: is called.
8893
- (nullable id)loadCachedAuthenticationSecretForConnection:(OCConnection *)connection; //!< Called by -cachedAuthenticationSecretForConnection: if no authentication secret is stored in memory. Should retrieve and return the authentication secret for the connection.
94+
@property(readonly,strong,nullable) OCAuthenticationDataID cachedAuthenticationDataID; //!< Returns the authentication data ID for the currently cached auth secret
8995
- (void)flushCachedAuthenticationSecret; //!< Flushes the cached authentication secret. Called f.ex. if the device is locked or the user switches to another app.
9096

9197
#pragma mark - Wait for authentication

ownCloudSDK/Authentication/OCAuthenticationMethod.m

+17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
@implementation OCAuthenticationMethod
3131

32+
@synthesize cachedAuthenticationDataID = _cachedAuthenticationDataID;
33+
3234
#pragma mark - Registration
3335
+ (NSMutableSet <Class> *)_registeredAuthenticationMethodClasses
3436
{
@@ -210,6 +212,7 @@ - (OCHTTPRequest *)authorizeRequest:(OCHTTPRequest *)request forConnection:(OCCo
210212

211213
if ((authHeaders = [self authorizationHeadersForConnection:connection error:&error]) != nil)
212214
{
215+
request.authenticationDataID = self.cachedAuthenticationDataID;
213216
[request addHeaderFields:authHeaders];
214217
}
215218

@@ -221,6 +224,19 @@ - (OCHTTPRequest *)authorizeRequest:(OCHTTPRequest *)request forConnection:(OCCo
221224
return (nil);
222225
}
223226

227+
#pragma mark - Authentication Data ID computation
228+
+ (nullable OCAuthenticationDataID)authenticationDataIDForAuthenticationData:(nullable NSData *)authenticationData
229+
{
230+
OCAuthenticationDataID identifier = nil;
231+
232+
if (authenticationData != nil)
233+
{
234+
identifier = [[[authenticationData sha256Hash] sha1Hash] asHexStringWithSeparator:nil];
235+
}
236+
237+
return (identifier);
238+
}
239+
224240
#pragma mark - Generate bookmark authentication data
225241
- (void)generateBookmarkAuthenticationDataWithConnection:(OCConnection *)connection options:(OCAuthenticationMethodBookmarkAuthenticationDataGenerationOptions)options completionHandler:(void(^)(NSError *error, OCAuthenticationMethodIdentifier authenticationMethodIdentifier, NSData *authenticationData))completionHandler
226242
{
@@ -276,6 +292,7 @@ - (void)flushCachedAuthenticationSecret
276292
@synchronized(self)
277293
{
278294
_cachedAuthenticationSecret = nil;
295+
_cachedAuthenticationDataID = nil;
279296
[self willChangeValueForKey:@"authenticationDataKnownInvalidDate"];
280297
_authenticationDataKnownInvalidDate = nil;
281298
[self didChangeValueForKey:@"authenticationDataKnownInvalidDate"];

0 commit comments

Comments
 (0)