-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJBSPasswordViewController.m
More file actions
288 lines (207 loc) · 14.6 KB
/
JBSPasswordViewController.m
File metadata and controls
288 lines (207 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#import "JBSPasswordViewController.h"
#import "JBSLoadingViewController.h"
#import "JBSWelcomeViewController.h"
#import "JBSErrorDelegate.h"
@interface JBSPasswordViewController () <UITextFieldDelegate, JBSErrorDelegate>
@property (nonatomic, strong) UITextField *passwordTextField;
@property (nonatomic, strong) UITextField *verifyTextField;
@property (nonatomic, copy) NSString *errorString;
-(void)showJBSLoadingViewController;
@end
@implementation JBSPasswordViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *topSeparatorView = [[UIView alloc] init];
topSeparatorView.translatesAutoresizingMaskIntoConstraints = NO;
topSeparatorView.backgroundColor = [UIColor colorWithRed:237.0 / 255.0 green:237.0 / 255.0 blue:237.0 / 255.0 alpha:1.0];
[self.contentView addSubview:topSeparatorView];
[topSeparatorView.leadingAnchor constraintEqualToAnchor:self.contentView.readableContentGuide.leadingAnchor].active = YES;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[topSeparatorView.trailingAnchor constraintEqualToAnchor:self.contentView.readableContentGuide.trailingAnchor].active = YES;
} else {
[topSeparatorView.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor].active = YES;
}
[topSeparatorView.topAnchor constraintEqualToAnchor:self.contentView.topAnchor constant:25.0].active = YES;
[topSeparatorView.heightAnchor constraintEqualToConstant:1.0].active = YES;
UILabel *passwordLabel = [[UILabel alloc] init];
passwordLabel.translatesAutoresizingMaskIntoConstraints = NO;
passwordLabel.text = @"Password";
passwordLabel.font = [UIFont systemFontOfSize:17.0 weight:UIFontWeightSemibold];
[self.contentView addSubview:passwordLabel];
[passwordLabel.leadingAnchor constraintEqualToAnchor:topSeparatorView.leadingAnchor].active = YES;
[passwordLabel.topAnchor constraintEqualToAnchor:topSeparatorView.bottomAnchor].active = YES;
[passwordLabel.heightAnchor constraintEqualToConstant:60.0].active = YES;
UIView *bottomSeparatorView = [[UIView alloc] init];
bottomSeparatorView.translatesAutoresizingMaskIntoConstraints = NO;
bottomSeparatorView.backgroundColor = [UIColor colorWithRed:237.0 / 255.0 green:237.0 / 255.0 blue:237.0 / 255.0 alpha:1.0];
[self.contentView addSubview:bottomSeparatorView];
[bottomSeparatorView.leadingAnchor constraintEqualToAnchor:topSeparatorView.leadingAnchor].active = YES;
[bottomSeparatorView.trailingAnchor constraintEqualToAnchor:topSeparatorView.trailingAnchor].active = YES;
[bottomSeparatorView.topAnchor constraintEqualToAnchor:passwordLabel.bottomAnchor].active = YES;
[bottomSeparatorView.heightAnchor constraintEqualToConstant:1.0].active = YES;
self.passwordTextField = [[UITextField alloc] init];
self.passwordTextField.translatesAutoresizingMaskIntoConstraints = NO;
self.passwordTextField.placeholder = @"Required";
self.passwordTextField.font = [UIFont systemFontOfSize:17.0 weight:UIFontWeightRegular];
self.passwordTextField.secureTextEntry = YES;
self.passwordTextField.returnKeyType = UIReturnKeyDone;
[self.contentView addSubview:self.passwordTextField];
[self.passwordTextField.trailingAnchor constraintEqualToAnchor:topSeparatorView.trailingAnchor].active = YES;
[self.passwordTextField.topAnchor constraintEqualToAnchor:passwordLabel.topAnchor].active = YES;
[self.passwordTextField.bottomAnchor constraintEqualToAnchor:passwordLabel.bottomAnchor].active = YES;
UILabel *verifyLabel = [[UILabel alloc] init];
verifyLabel.translatesAutoresizingMaskIntoConstraints = NO;
verifyLabel.text = @"Verify";
verifyLabel.font = [UIFont systemFontOfSize:17.0 weight:UIFontWeightSemibold];
[self.contentView addSubview:verifyLabel];
[verifyLabel.leadingAnchor constraintEqualToAnchor:topSeparatorView.leadingAnchor].active = YES;
[verifyLabel.topAnchor constraintEqualToAnchor:bottomSeparatorView.bottomAnchor].active = YES;
[verifyLabel.heightAnchor constraintEqualToAnchor:passwordLabel.heightAnchor].active = YES;
UIView *bottom1SeparatorView = [[UIView alloc] init];
bottom1SeparatorView.translatesAutoresizingMaskIntoConstraints = NO;
bottom1SeparatorView.backgroundColor = [UIColor colorWithRed:237.0 / 255.0 green:237.0 / 255.0 blue:237.0 / 255.0 alpha:1.0];
[self.contentView addSubview:bottom1SeparatorView];
[bottom1SeparatorView.leadingAnchor constraintEqualToAnchor:topSeparatorView.leadingAnchor].active = YES;
[bottom1SeparatorView.trailingAnchor constraintEqualToAnchor:topSeparatorView.trailingAnchor].active = YES;
[bottom1SeparatorView.topAnchor constraintEqualToAnchor:verifyLabel.bottomAnchor].active = YES;
[bottom1SeparatorView.heightAnchor constraintEqualToConstant:1.0].active = YES;
self.verifyTextField = [[UITextField alloc] init];
self.verifyTextField.translatesAutoresizingMaskIntoConstraints = NO;
self.verifyTextField.placeholder = @"Retype password";
self.verifyTextField.font = [UIFont systemFontOfSize:17.0 weight:UIFontWeightRegular];
self.verifyTextField.secureTextEntry = YES;
self.verifyTextField.returnKeyType = UIReturnKeyDone;
[self.contentView addSubview:self.verifyTextField];
[self.verifyTextField.leadingAnchor constraintEqualToAnchor:self.passwordTextField.leadingAnchor].active = YES;
[self.verifyTextField.trailingAnchor constraintEqualToAnchor:topSeparatorView.trailingAnchor].active = YES;
[self.verifyTextField.topAnchor constraintEqualToAnchor:verifyLabel.topAnchor].active = YES;
[self.verifyTextField.bottomAnchor constraintEqualToAnchor:verifyLabel.bottomAnchor].active = YES;
UIButton *skipButton = [UIButton buttonWithType:UIButtonTypeSystem];
skipButton.translatesAutoresizingMaskIntoConstraints = NO;
[skipButton setTitle:@"Skip this step" forState:UIControlStateNormal];
skipButton.titleLabel.font = [UIFont systemFontOfSize:17.0 weight:UIFontWeightRegular];
[skipButton addTarget:self action:@selector(skipButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:skipButton];
[skipButton.trailingAnchor constraintEqualToAnchor:self.contentView.readableContentGuide.trailingAnchor].active = YES;
[skipButton.topAnchor constraintEqualToAnchor:bottom1SeparatorView.bottomAnchor constant:15.0].active = YES;
[skipButton.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor].active = YES;
UIButton *moreInfoButton = [UIButton buttonWithType:UIButtonTypeSystem];
moreInfoButton.translatesAutoresizingMaskIntoConstraints = NO;
[moreInfoButton setTitle:@"More Info" forState:UIControlStateNormal];
moreInfoButton.titleLabel.font = [UIFont systemFontOfSize:17.0 weight:UIFontWeightRegular];
[moreInfoButton addTarget:self action:@selector(moreInfoButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:moreInfoButton];
[moreInfoButton.leadingAnchor constraintEqualToAnchor:self.contentView.readableContentGuide.leadingAnchor].active = YES;
[moreInfoButton.topAnchor constraintEqualToAnchor:bottom1SeparatorView.bottomAnchor constant:15.0].active = YES;
CGFloat textFieldMargin = fmax(passwordLabel.intrinsicContentSize.width, verifyLabel.intrinsicContentSize.width);
[self.passwordTextField.leadingAnchor constraintEqualToAnchor:topSeparatorView.leadingAnchor constant:textFieldMargin + 30.0].active = YES;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleDone target:self action:@selector(nextButtonTapped:)];
self.navigationItem.rightBarButtonItem.enabled = NO;
self.hideContinueButton = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
self.passwordTextField.delegate = self;
self.verifyTextField.delegate = self;
[self.passwordTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[self.verifyTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.titleLabel.text = [NSString stringWithFormat:@"%@ Password", self.root ? @"Root" : @"Mobile"];
self.descriptionLabel.text = [NSString stringWithFormat:@"Set a new password for the %@ user. \nThis will make your device more secure.", self.root ? @"root" : @"mobile"];
self.navigationItem.hidesBackButton = !self.skippedLastStep;
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (self.errorString) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:self.errorString preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
self.errorString = nil;
}
}
-(void)showJBSLoadingViewController {
JBSLoadingViewController *vc = [[JBSLoadingViewController alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
vc.root = self.root;
vc.password = self.passwordTextField.text;
vc.errorDelegate = self;
[self.navigationController pushViewController:vc animated:YES];
}
-(void)textFieldDidChange:(UITextField *)sender {
self.navigationItem.rightBarButtonItem.enabled = [self.passwordTextField.text isEqualToString:self.verifyTextField.text] && self.passwordTextField.text.length > 4;
}
-(void)nextButtonTapped:(UIBarButtonItem *)sender {
[self.view endEditing:YES];
if ([self.passwordTextField.text isEqualToString:@"alpine"]) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"\"alpine\" is the default password. Do you really want to continue?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *continueAction = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self showJBSLoadingViewController];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:continueAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
} else {
[self showJBSLoadingViewController];
}
}
- (void)keyboardWillShow:(NSNotification*)notification {
CGRect frame = [[notification.userInfo objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat additionalInset = self.view.bounds.size.height - self.scrollView.bounds.size.height;
self.scrollView.contentInset = UIEdgeInsetsMake(0.0, 0.0, frame.size.height - self.continueButton.bounds.size.height - additionalInset, 0.0);
self.scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0.0, 0.0, frame.size.height - self.continueButton.bounds.size.height - additionalInset, 0.0);
}
- (void)keyboardWillHide:(NSNotification*)notification {
self.scrollView.contentInset = UIEdgeInsetsZero;
self.scrollView.scrollIndicatorInsets = UIEdgeInsetsZero;
}
-(void)skipButtonTapped:(UIButton *)sender {
NSString *user = self.root ? @"root" : @"mobile";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Not setting a password for the %@ user will leave your device vulnerable to potential attacks. You can still set the %@ password via the command line later on. Do you really want to skip this step?", user, user] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *skipAction = [UIAlertAction actionWithTitle:@"Skip" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (self.root) {
JBSPasswordViewController *vc = [[JBSPasswordViewController alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
vc.root = NO;
vc.skippedLastStep = YES;
[self.navigationController pushViewController:vc animated:YES];
} else {
JBSWelcomeViewController *vc = [[JBSWelcomeViewController alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
[self.navigationController pushViewController:vc animated:YES];
}
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:skipAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}
-(void)moreInfoButtonTapped:(UIBarButtonItem *)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"What is this?" message:@"Most jailbreaks install a tool that allows you to connect to your device from a computer with a username and password. iOS has a default password set for both the root and mobile user. This password is well known. An attacker could scan for your device in a public WiFi for example and gain full access to your device by using the default password. It is therefore advised to change the root and mobile user password immediately after jailbreaking. It must be at least 5 characters long." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.passwordTextField) {
[self.verifyTextField becomeFirstResponder];
} else {
[textField resignFirstResponder];
}
return YES;
}
-(void)settingPasswordDidFail:(NSString *)reason {
self.errorString = reason;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end