Skip to content

Commit

Permalink
Merge pull request #67 from SUPLA/develop
Browse files Browse the repository at this point in the history
v2.3.2
  • Loading branch information
przemyslawzygmunt authored Nov 2, 2019
2 parents 30c7717 + d5c3acf commit 7c7e3da
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 43 deletions.
18 changes: 14 additions & 4 deletions SUPLA.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
013D73B022DD105400E3515A /* SAChartFilterField.m in Sources */ = {isa = PBXBuildFile; fileRef = 013D73AF22DD105400E3515A /* SAChartFilterField.m */; };
01567446232FCFD700397393 /* SAIncrementalMeterExtendedValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 01567445232FCFD700397393 /* SAIncrementalMeterExtendedValue.m */; };
01567449232FD0A100397393 /* SAImpulseCounterExtendedValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 01567448232FD0A100397393 /* SAImpulseCounterExtendedValue.m */; };
016ABE16236D8363001BF5FB /* SAKeychain.m in Sources */ = {isa = PBXBuildFile; fileRef = 016ABE15236D8363001BF5FB /* SAKeychain.m */; };
016ABE18236DA795001BF5FB /* KeychainTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 016ABE17236DA795001BF5FB /* KeychainTests.m */; };
016EE77423074DDC00FD301C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 016EE77223074DDC00FD301C /* [email protected] */; };
016EE77523074DDC00FD301C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 016EE77323074DDC00FD301C /* [email protected] */; };
0172677D234FAF78000F1CFB /* SADownloadImpulseCounterMeasurements.m in Sources */ = {isa = PBXBuildFile; fileRef = 0172677C234FAF78000F1CFB /* SADownloadImpulseCounterMeasurements.m */; };
Expand Down Expand Up @@ -396,6 +398,9 @@
01567445232FCFD700397393 /* SAIncrementalMeterExtendedValue.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAIncrementalMeterExtendedValue.m; sourceTree = "<group>"; };
01567447232FD0A100397393 /* SAImpulseCounterExtendedValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SAImpulseCounterExtendedValue.h; sourceTree = "<group>"; };
01567448232FD0A100397393 /* SAImpulseCounterExtendedValue.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAImpulseCounterExtendedValue.m; sourceTree = "<group>"; };
016ABE14236D8363001BF5FB /* SAKeychain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SAKeychain.h; sourceTree = "<group>"; };
016ABE15236D8363001BF5FB /* SAKeychain.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAKeychain.m; sourceTree = "<group>"; };
016ABE17236DA795001BF5FB /* KeychainTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KeychainTests.m; sourceTree = "<group>"; };
016EE77223074DDC00FD301C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/Assets/Img/[email protected]"; sourceTree = "<group>"; };
016EE77323074DDC00FD301C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/Assets/Img/[email protected]"; sourceTree = "<group>"; };
0172677B234FAF78000F1CFB /* SADownloadImpulseCounterMeasurements.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SADownloadImpulseCounterMeasurements.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1159,6 +1164,8 @@
404E48F61FC75D0B001F6266 /* SAClassHelper.h */,
013D350223350C48006E3B75 /* SAThermostatScheduleCfg.h */,
013D350323350C48006E3B75 /* SAThermostatScheduleCfg.m */,
016ABE14236D8363001BF5FB /* SAKeychain.h */,
016ABE15236D8363001BF5FB /* SAKeychain.m */,
);
path = SUPLA;
sourceTree = "<group>";
Expand All @@ -1176,6 +1183,7 @@
isa = PBXGroup;
children = (
01EFD94B236CA9AE00893489 /* NSDataEncryptionTest.m */,
016ABE17236DA795001BF5FB /* KeychainTests.m */,
012F722822DF3CF000E5F72E /* ChartFilterFieldTests.m */,
401CA1DB1BA067DB00117AF4 /* SUPLATests.m */,
401CA1D91BA067DB00117AF4 /* Supporting Files */,
Expand Down Expand Up @@ -2090,6 +2098,7 @@
403EB1141FBDF47F00AD6460 /* AddWizardVC.m in Sources */,
013D350423350C48006E3B75 /* SAThermostatScheduleCfg.m in Sources */,
408034C41BC83D1A007666E7 /* MGSwipeButton.m in Sources */,
016ABE16236D8363001BF5FB /* SAKeychain.m in Sources */,
01EE9BB022BA4B050029A142 /* SAChannelExtendedValue+CoreDataProperties.m in Sources */,
01BDAC7522C518DE00915646 /* SARestApiClientTask.m in Sources */,
401CA1BF1BA067DB00117AF4 /* main.m in Sources */,
Expand Down Expand Up @@ -2142,6 +2151,7 @@
buildActionMask = 2147483647;
files = (
401CA1DC1BA067DB00117AF4 /* SUPLATests.m in Sources */,
016ABE18236DA795001BF5FB /* KeychainTests.m in Sources */,
01EFD94C236CA9AE00893489 /* NSDataEncryptionTest.m in Sources */,
012F722C22DF3E2300E5F72E /* ChartFilterFieldTests.m in Sources */,
0130894523395F4C00F46FCD /* ThermostatScheduleCfgTests.m in Sources */,
Expand Down Expand Up @@ -2517,7 +2527,7 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 36;
CURRENT_PROJECT_VERSION = 37;
DEFINES_MODULE = YES;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
INFOPLIST_FILE = SUPLA/Info.plist;
Expand All @@ -2527,7 +2537,7 @@
"$(inherited)",
"$(PROJECT_DIR)/SUPLA/lib",
);
MARKETING_VERSION = 2.3.1;
MARKETING_VERSION = 2.3.2;
PRODUCT_BUNDLE_IDENTIFIER = com.acsoftware.ios.supla;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SUPLA/SUPLA-Bridging-Header.h";
Expand All @@ -2544,7 +2554,7 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 36;
CURRENT_PROJECT_VERSION = 37;
DEFINES_MODULE = YES;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
INFOPLIST_FILE = SUPLA/Info.plist;
Expand All @@ -2554,7 +2564,7 @@
"$(inherited)",
"$(PROJECT_DIR)/SUPLA/lib",
);
MARKETING_VERSION = 2.3.1;
MARKETING_VERSION = 2.3.2;
PRODUCT_BUNDLE_IDENTIFIER = com.acsoftware.ios.supla;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SUPLA/SUPLA-Bridging-Header.h";
Expand Down
1 change: 1 addition & 0 deletions SUPLA/NSData+AES.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (NSData *)aes128DecryptWithPassword:(NSString *)password {
}

- (NSData *)aes128EncryptWithDeviceUniqueId {
// Unfortunately, identifierForVendor is different for AppStore and TestFlight
NSString *pwd = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
return [self aes128EncryptWithPassword:pwd];
}
Expand Down
29 changes: 29 additions & 0 deletions SUPLA/SAKeychain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface SAKeychain : NSObject
+ (BOOL)deleteObjectWithKey:(NSString *)key;
+ (BOOL)addObject:(id)object withKey:(NSString *)key;
+ (id)getObjectWithKey:(NSString *)key;
@end

NS_ASSUME_NONNULL_END
70 changes: 70 additions & 0 deletions SUPLA/SAKeychain.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#import "SAKeychain.h"

@implementation SAKeychain

+ (NSMutableDictionary *)attributesWithKey:(NSString *)key {
return [@{(__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword,
(__bridge id)kSecAttrService : @"SAKeychain",
(__bridge id)kSecAttrAccount : key,
(__bridge id)kSecAttrAccessible : (__bridge id)kSecAttrAccessibleAfterFirstUnlock
} mutableCopy];
}

+ (BOOL)deleteObjectWithKey:(NSString *)key {
NSMutableDictionary *attrs = [self attributesWithKey:key];
return noErr == SecItemDelete((__bridge CFDictionaryRef)attrs);
}

+ (BOOL)addObject:(id)object withKey:(NSString *)key {
NSMutableDictionary *attrs = [self attributesWithKey:key];

[attrs setObject:[NSKeyedArchiver archivedDataWithRootObject:object] forKey:(__bridge id)kSecValueData];
return noErr == SecItemAdd((__bridge CFDictionaryRef)attrs, NULL);
}

+ (id)getObjectWithKey:(NSString *)key {
id result = nil;

NSMutableDictionary *attrs = [self attributesWithKey:key];

[attrs setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];
[attrs setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];

CFDataRef data = NULL;

if (noErr == SecItemCopyMatching((__bridge CFDictionaryRef)attrs, (CFTypeRef *)&data)) {
@try {
result = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge NSData *)data];
}
@catch (NSException *exception) {
NSLog(@"%@", exception);
result = nil;
}
@finally {}
}

if (data) {
CFRelease(data);
}

return result;
}
@end
56 changes: 31 additions & 25 deletions SUPLA/SuplaClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,15 @@ - (void*) client_init {
TSuplaClientCfg scc;
supla_client_cfginit(&scc);

[SAApp getClientGUID:scc.clientGUID];
[SAApp getAuthKey:scc.AuthKey];
if (![SAApp getClientGUID:scc.clientGUID]) {
NSLog(@"Can't get client GUID!");
return NULL;
}

if (![SAApp getAuthKey:scc.AuthKey]) {
NSLog(@"Can't get AuthKey!");
return NULL;
}

scc.user_data = (__bridge void *)self;
scc.host = [self getServerHostName];
Expand Down Expand Up @@ -382,37 +389,36 @@ - (void)main {
_sclient = [self client_init];
}

if ( _sclient != NULL )
@try {

if ( supla_client_connect(_sclient) == 1 ) {

while ( [self isCancelled] == NO
&& supla_client_iterate(_sclient, 100000) == 1) {
if ( _sclient == NULL ) {
NSLog(@"_sclient not initialized!");
usleep(2000000);
} else {
@try {
if ( supla_client_connect(_sclient) == 1 ) {
while ( [self isCancelled] == NO
&& supla_client_iterate(_sclient, 100000) == 1) {
}

if ( [self isCancelled] == NO ) {
usleep(5000000);
}
}

if ( [self isCancelled] == NO ) {
usleep(5000000);
usleep(2000000);
}

}

if ( [self isCancelled] == NO ) {
usleep(2000000);
@catch (NSException *exception) {
NSLog(@"%@", exception);
}

}
@catch (NSException *exception) {
NSLog(@"%@", exception);
}
@finally {
@synchronized(self) {
supla_client_free(_sclient);
_sclient = NULL;
@finally {
@synchronized(self) {
supla_client_free(_sclient);
_sclient = NULL;
}

}

}

}
}

Expand Down
41 changes: 41 additions & 0 deletions SUPLATests/KeychainTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#import <XCTest/XCTest.h>
#import "SAKeychain.h"

@interface KeychainTests : XCTestCase
@end

@implementation KeychainTests

- (void)testKeychainStorage {
NSString *source = @"ABCDEFGH";
[SAKeychain deleteObjectWithKey:@"1"];
XCTAssertFalse([SAKeychain deleteObjectWithKey:@"1"]);
XCTAssertNil([SAKeychain getObjectWithKey:@"1"]);
XCTAssertTrue([SAKeychain addObject:source withKey:@"1"]);
XCTAssertFalse([SAKeychain addObject:@"XYZ" withKey:@"1"]);
XCTAssertNil([SAKeychain getObjectWithKey:@"2"]);
NSString *dest = [SAKeychain getObjectWithKey:@"1"];
XCTAssertNotNil(dest);
XCTAssertTrue([source isEqualToString:dest]);
XCTAssertTrue([SAKeychain deleteObjectWithKey:@"1"]);
}

@end
4 changes: 2 additions & 2 deletions SuplaApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
@interface SAApp : NSObject

+(SAApp*)instance;
+(void) getClientGUID:(char[SUPLA_GUID_SIZE])guid;
+(void) getAuthKey:(char[SUPLA_AUTHKEY_SIZE])auth_key;
+(BOOL) getClientGUID:(char[SUPLA_GUID_SIZE])guid;
+(BOOL) getAuthKey:(char[SUPLA_AUTHKEY_SIZE])auth_key;
+(int) getAccessID;
+(void) setAccessID:(int)aid;
+(NSString*) getAccessIDpwd;
Expand Down
Loading

0 comments on commit 7c7e3da

Please sign in to comment.