Skip to content

Commit

Permalink
[NEW] Allow authentication without password #559
Browse files Browse the repository at this point in the history
[NEW] Add X-Limit-U and X-Limit-D to HTTP mode headers #560
  • Loading branch information
ckrey committed Dec 16, 2018
1 parent 6b43e9b commit 27881db
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 105 deletions.
8 changes: 4 additions & 4 deletions OwnTracks/OwnTracks/Base.lproj/Launch Screen.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -30,8 +30,8 @@
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="12.0.1" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="wg9-vU-Qvm">
<rect key="frame" x="164" y="469.5" width="47" height="20.5"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="12.0.2" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="wg9-vU-Qvm">
<rect key="frame" x="162.5" y="469.5" width="50" height="20.5"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="xFp-b4-JHU"/>
</constraints>
Expand Down
153 changes: 76 additions & 77 deletions OwnTracks/OwnTracks/Base.lproj/Storyboard.storyboard

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion OwnTracks/OwnTracks/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ enum state {
securityPolicy:(MQTTSSLSecurityPolicy *)securityPolicy
certificates:(NSArray *)certificates;

- (void)connectHTTP:(NSString *)url auth:(BOOL)auth user:(NSString *)user pass:(NSString *)pass;
- (void)connectHTTP:(NSString *)url
auth:(BOOL)auth
user:(NSString *)user
pass:(NSString *)pass
device:(NSString *)device;

- (void)connectToLast;

Expand Down
23 changes: 20 additions & 3 deletions OwnTracks/OwnTracks/Connection.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ @interface Connection() <NSURLSessionDelegate>
@property (nonatomic) NSInteger willQos;
@property (nonatomic) BOOL willRetainFlag;
@property (strong, nonatomic) NSString *clientId;
@property (strong, nonatomic) NSString *device;
@property (strong, nonatomic) MQTTSSLSecurityPolicy *securityPolicy;
@property (strong, nonatomic) NSArray *certificates;

Expand Down Expand Up @@ -336,11 +337,16 @@ - (void)URLSession:(NSURLSession *)session
}


- (void)connectHTTP:(NSString *)url auth:(BOOL)auth user:(NSString *)user pass:(NSString *)pass {
- (void)connectHTTP:(NSString *)url
auth:(BOOL)auth
user:(NSString *)user
pass:(NSString *)pass
device:(NSString *)device {
self.url = url;
self.auth = auth;
self.user = auth ? user : nil;
self.pass = auth ? pass : nil;
self.user = user;
self.pass = pass;
self.device = device;
self.reconnectTime = RECONNECT_TIMER;
self.reconnectFlag = FALSE;
self.state = state_starting;
Expand Down Expand Up @@ -430,6 +436,17 @@ - (void)sendHTTP:(NSString *)topic data:(NSData *)data {
NSString *authValue = [authData base64EncodedStringWithOptions:0];
[request setValue:[NSString stringWithFormat:@"Basic %@", authValue] forHTTPHeaderField:@"Authorization"];
}
NSString *user = @"user";
if (self.user && self.user.length > 0) {
user = self.user;
}
[request setValue:user forHTTPHeaderField:@"X-Limit-U"];

NSString *device = @"device";
if (self.device && self.device.length > 0) {
device = self.device;
}
[request setValue:device forHTTPHeaderField:@"X-Limit-D"];

request.URL = [NSURL URLWithString:self.url];
request.HTTPMethod = @"POST";
Expand Down
2 changes: 2 additions & 0 deletions OwnTracks/OwnTracks/HTTP.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<string>user</string>
<key>pass_preference</key>
<string>pass</string>
<key>usepassword_preference</key>
<true/>
<key>monitoring_preference</key>
<integer>1</integer>
<key>ranging_preference</key>
Expand Down
2 changes: 2 additions & 0 deletions OwnTracks/OwnTracks/MQTT.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<string>user</string>
<key>pass_preference</key>
<string>pass</string>
<key>usepassword_preference</key>
<true/>
<key>keepalive_preference</key>
<integer>60</integer>
<key>clean_preference</key>
Expand Down
4 changes: 2 additions & 2 deletions OwnTracks/OwnTracks/OwnTracks-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>12.0.1</string>
<string>12.0.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -115,7 +115,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>12.0.1</string>
<string>12.0.2</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
Expand Down
10 changes: 8 additions & 2 deletions OwnTracks/OwnTracks/OwnTracksAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1134,14 +1134,20 @@ - (void)sendRegion:(Region *)region {
#pragma internal helpers

- (void)connect {
BOOL usePassword = [Settings theMqttUsePasswordInMOC:CoreData.sharedInstance.mainMOC];
NSString *password = nil;
if (usePassword) {
password = [Settings theMqttPassInMOC:CoreData.sharedInstance.mainMOC];
}
if ([Settings intForKey:@"mode" inMOC:CoreData.sharedInstance.mainMOC] == CONNECTION_MODE_HTTP) {
self.connection.key = [Settings stringForKey:@"secret_preference"
inMOC:CoreData.sharedInstance.mainMOC];
[self.connection connectHTTP:[Settings stringForKey:@"url_preference"
inMOC:CoreData.sharedInstance.mainMOC]
auth:[Settings theMqttAuthInMOC:CoreData.sharedInstance.mainMOC]
user:[Settings theMqttUserInMOC:CoreData.sharedInstance.mainMOC]
pass:[Settings theMqttPassInMOC:CoreData.sharedInstance.mainMOC]];
pass:password
device:[Settings theDeviceIdInMOC:CoreData.sharedInstance.mainMOC]];

} else {
NSURL *directoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory
Expand Down Expand Up @@ -1233,7 +1239,7 @@ - (void)connect {
clean:[Settings intForKey:@"clean_preference" inMOC:CoreData.sharedInstance.mainMOC]
auth:[Settings theMqttAuthInMOC:CoreData.sharedInstance.mainMOC]
user:[Settings theMqttUserInMOC:CoreData.sharedInstance.mainMOC]
pass:[Settings theMqttPassInMOC:CoreData.sharedInstance.mainMOC]
pass:password
willTopic:[Settings theWillTopicInMOC:CoreData.sharedInstance.mainMOC]
will:[self jsonToData:json]
willQos:[Settings intForKey:@"willqos_preference" inMOC:CoreData.sharedInstance.mainMOC]
Expand Down
1 change: 1 addition & 0 deletions OwnTracks/OwnTracks/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ typedef NS_ENUM(int, ConnectionMode) {

+ (NSString *)theMqttUserInMOC:(NSManagedObjectContext *)context;
+ (NSString *)theMqttPassInMOC:(NSManagedObjectContext *)context;
+ (BOOL)theMqttUsePasswordInMOC:(NSManagedObjectContext *)context;
+ (BOOL)theMqttAuthInMOC:(NSManagedObjectContext *)context;

+ (BOOL)validKey:(NSString *)key inMode:(ConnectionMode)mode;
Expand Down
10 changes: 9 additions & 1 deletion OwnTracks/OwnTracks/Settings.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ + (NSError *)fromDictionary:(NSDictionary *)dictionary inMOC:(NSManagedObjectCon

object = dictionary[@"auth"];
if (object) [self setString:object forKey:@"auth_preference" inMOC:context];


object = dictionary[@"usePassword"];
if (object) [self setString:object forKey:@"usepassword_preference" inMOC:context];

object = dictionary[@"cleanSession"];
if (object) [self setString:[NSString stringWithFormat:@"%@", object]
forKey:@"clean_preference"
Expand Down Expand Up @@ -426,6 +429,7 @@ + (NSDictionary *)toDictionaryInMOC:(NSManagedObjectContext *)context {
dict[@"tls"] = @([Settings boolForKey:@"tls_preference" inMOC:context]);
dict[@"ws"] = @([Settings boolForKey:@"ws_preference" inMOC:context]);
dict[@"auth"] = @([Settings boolForKey:@"auth_preference" inMOC:context]);
dict[@"usePassword"] = @([Settings boolForKey:@"usepassword_preference" inMOC:context]);
dict[@"cleanSession"] = @([Settings boolForKey:@"clean_preference" inMOC:context]);
dict[@"willRetain"] = @([Settings boolForKey:@"willretain_preference" inMOC:context]);
dict[@"allowRemoteLocation"] = @([Settings boolForKey:@"allowremotelocation_preference" inMOC:context]);
Expand Down Expand Up @@ -744,6 +748,10 @@ + (NSString *)theMqttPassInMOC:(NSManagedObjectContext *)context {
return [self stringForKey:@"pass_preference" inMOC:context];
}

+ (BOOL)theMqttUsePasswordInMOC:(NSManagedObjectContext *)context {
return [self boolForKey:@"usepassword_preference" inMOC:context];
}

+ (BOOL)theMqttAuthInMOC:(NSManagedObjectContext *)context {
return [self boolForKey:@"auth_preference" inMOC:context];
}
Expand Down
24 changes: 18 additions & 6 deletions OwnTracks/OwnTracks/SettingsTVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ @interface SettingsTVC ()
@property (weak, nonatomic) IBOutlet UITextField *UIHost;
@property (weak, nonatomic) IBOutlet UITextField *UIUserID;
@property (weak, nonatomic) IBOutlet UITextField *UIPassword;
@property (weak, nonatomic) IBOutlet UISwitch *UIUsePassword;
@property (weak, nonatomic) IBOutlet UITextField *UIPort;
@property (weak, nonatomic) IBOutlet UISwitch *UITLS;
@property (weak, nonatomic) IBOutlet UITextField *UIproto;
Expand Down Expand Up @@ -184,6 +185,9 @@ - (void)updateValues {
if (self.UIPassword) [Settings setString:self.UIPassword.text
forKey:@"pass_preference"
inMOC:CoreData.sharedInstance.mainMOC];
if (self.UIUsePassword) [Settings setBool:self.UIUsePassword.on
forKey:@"usepassword_preference"
inMOC:CoreData.sharedInstance.mainMOC];
if (self.UIsecret) [Settings setString:self.UIsecret.text
forKey:@"secret_preference"
inMOC:CoreData.sharedInstance.mainMOC];
Expand Down Expand Up @@ -439,6 +443,11 @@ - (void)updated
inMOC:CoreData.sharedInstance.mainMOC];
self.UIPassword.enabled = !locked;
}
if (self.UIUsePassword) {
self.UIUsePassword.on = [Settings boolForKey:@"usepassword_preference"
inMOC:CoreData.sharedInstance.mainMOC];
self.UIUsePassword.enabled = !locked;
}
if (self.UIsecret) {
self.UIsecret.text = [Settings stringForKey:@"secret_preference"
inMOC:CoreData.sharedInstance.mainMOC];
Expand Down Expand Up @@ -591,8 +600,7 @@ - (void)updated
}
}

NSArray <NSIndexPath *> *privatePaths = @[[NSIndexPath indexPathForRow:4 inSection:0],
[NSIndexPath indexPathForRow:5 inSection:0],
NSArray <NSIndexPath *> *privatePaths = @[[NSIndexPath indexPathForRow:5 inSection:0],
[NSIndexPath indexPathForRow:6 inSection:0],
[NSIndexPath indexPathForRow:7 inSection:0]
];
Expand All @@ -606,14 +614,18 @@ - (void)updated

if (self.UIUserID) {
if (self.UIAuth) {
self.UIUserID.enabled = !locked && self.UIAuth.on;
self.UIUserID.textColor = self.UIAuth.on ? [UIColor blackColor] : [UIColor lightGrayColor];
self.UIUserID.enabled = !locked;
}
}
if (self.UIUsePassword) {
if (self.UIAuth) {
self.UIUsePassword.enabled = !locked && self.UIAuth.on;
}
}
if (self.UIPassword) {
if (self.UIAuth) {
self.UIPassword.enabled = !locked && self.UIAuth.on;
self.UIPassword.textColor = self.UIAuth.on ? [UIColor blackColor] : [UIColor lightGrayColor];
self.UIPassword.enabled = !locked && self.UIAuth.on && self.UIUsePassword.on;
self.UIPassword.textColor = (self.UIAuth.on && self.UIUsePassword.on) ? [UIColor blackColor] : [UIColor lightGrayColor];
}
}

Expand Down
24 changes: 17 additions & 7 deletions OwnTracks/OwnTracks/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,23 @@ - (IBAction)longDoublePress:(UILongPressGestureRecognizer *)sender {

- (void)sendNow {
OwnTracksAppDelegate *delegate = (OwnTracksAppDelegate *)[UIApplication sharedApplication].delegate;
[delegate sendNow];
[delegate.navigationController alert:NSLocalizedString(@"Location",
@"Header of an alert message regarding a location")
message:NSLocalizedString(@"publish queued on user request",
@"content of an alert message regarding user publish")
dismissAfter:1
];

if (![Settings validIdsInMOC:CoreData.sharedInstance.mainMOC]) {
NSString *message = NSLocalizedString(@"To publish your location userID and deviceID must be set",
@"Warning displayed if necessary settings are missing");

[delegate.navigationController alert:@"Settings" message:message];
} else {
[delegate sendNow];
[delegate.navigationController alert:
NSLocalizedString(@"Location",
@"Header of an alert message regarding a location")
message:
NSLocalizedString(@"publish queued on user request",
@"content of an alert message regarding user publish")
dismissAfter:1
];
}
}

- (IBAction)longPress:(UILongPressGestureRecognizer *)sender {
Expand Down
4 changes: 2 additions & 2 deletions OwnTracks/OwnTracksToday/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>12.0.1</string>
<string>12.0.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>12.0.1</string>
<string>12.0.2</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
Expand Down

0 comments on commit 27881db

Please sign in to comment.