Skip to content

Commit fe4a45a

Browse files
authored
Update Public 5.2.1 (#262)
Fixes for new Penn Auth system (#260)
1 parent b64d300 commit fe4a45a

3 files changed

Lines changed: 31 additions & 45 deletions

File tree

PennMobile.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,14 +1949,14 @@
19491949
CODE_SIGN_ENTITLEMENTS = PennMobile/PennMobile.entitlements;
19501950
CODE_SIGN_IDENTITY = "iPhone Developer";
19511951
CODE_SIGN_STYLE = Automatic;
1952-
CURRENT_PROJECT_VERSION = 5211;
1952+
CURRENT_PROJECT_VERSION = 5220;
19531953
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
19541954
DEVELOPMENT_TEAM = VU59R57FGM;
19551955
GCC_PREFIX_HEADER = PennMobile/Supporting_Files/PrefixHeader.pch;
19561956
INFOPLIST_FILE = PennMobile/Supporting_Files/Info.plist;
19571957
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
19581958
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1959-
MARKETING_VERSION = 5.2.1;
1959+
MARKETING_VERSION = 5.2.2;
19601960
PRODUCT_BUNDLE_IDENTIFIER = org.pennlabs.PennMobile;
19611961
PRODUCT_NAME = "$(TARGET_NAME)";
19621962
PROVISIONING_PROFILE = "";
@@ -1977,13 +1977,13 @@
19771977
CODE_SIGN_ENTITLEMENTS = PennMobile/PennMobile.entitlements;
19781978
CODE_SIGN_IDENTITY = "iPhone Developer";
19791979
CODE_SIGN_STYLE = Automatic;
1980-
CURRENT_PROJECT_VERSION = 5211;
1980+
CURRENT_PROJECT_VERSION = 5220;
19811981
DEVELOPMENT_TEAM = VU59R57FGM;
19821982
GCC_PREFIX_HEADER = PennMobile/Supporting_Files/PrefixHeader.pch;
19831983
INFOPLIST_FILE = PennMobile/Supporting_Files/Info.plist;
19841984
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
19851985
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1986-
MARKETING_VERSION = 5.2.1;
1986+
MARKETING_VERSION = 5.2.2;
19871987
PRODUCT_BUNDLE_IDENTIFIER = org.pennlabs.PennMobile;
19881988
PRODUCT_NAME = "$(TARGET_NAME)";
19891989
PROVISIONING_PROFILE = "";

PennMobile/General/PennAuthRequestable.swift

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ protocol PennAuthRequestable {}
1212

1313
extension PennAuthRequestable {
1414

15-
private var loginUrl: String {
16-
return "https://weblogin.pennkey.upenn.edu/login"
15+
private var baseUrl: String {
16+
return "https://weblogin.pennkey.upenn.edu"
1717
}
1818

1919
private var authUrl: String {
20-
return "https://idp.pennkey.upenn.edu/idp/Authn"
20+
return "https://weblogin.pennkey.upenn.edu/idp/profile"
2121
}
2222

2323
func makeAuthRequest(targetUrl: String, shibbolethUrl: String, _ completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) {
@@ -51,20 +51,12 @@ extension PennAuthRequestable {
5151
}
5252

5353
private func makeRequestWithAuth(targetUrl: String, shibbolethUrl: String, html: String, _ completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) {
54-
guard let passcode = html.getMatches(for: "name=\"passcode\" value=\"(.*?)\"").first,
55-
let required = html.getMatches(for: "name=\"required\" value=\"(.*?)\"").first,
56-
let appfactor = html.getMatches(for: "name=\"appfactor\" value=\"(.*?)\"").first,
57-
let ref = html.getMatches(for: "name=\"ref\" value=\"(.*?)\"").first,
58-
let service = html.getMatches(for: "name=\"service\" value=\"(.*?)\"").first else {
59-
UserDefaults.standard.setShibbolethAuth(authedIn: false)
60-
completionHandler(nil, nil, NetworkingError.authenticationError)
61-
return
54+
guard let actionUrl = html.getMatches(for: "form action=\"(.*?)\" method=\"POST\" id=\"login-form\"").first else {
55+
UserDefaults.standard.setShibbolethAuth(authedIn: false)
56+
completionHandler(nil, nil, NetworkingError.authenticationError)
57+
return
6258
}
6359

64-
// Check if have two factor trusted browser cookie (may have expired)
65-
// let cookies = HTTPCookieStorage.shared.cookies ?? []
66-
let isTwoFactorTrusted = true //!cookies.filter { $0.name == "twoFactorTrustedBrowser" }.isEmpty
67-
6860
let genericPwdQueryable =
6961
GenericPasswordQueryable(service: "PennWebLogin")
7062
let secureStore =
@@ -84,30 +76,22 @@ extension PennAuthRequestable {
8476
pennkey = nil
8577
}
8678

87-
guard pennkey != nil && password != nil && isTwoFactorTrusted else {
79+
guard pennkey != nil && password != nil else {
8880
UserDefaults.standard.setShibbolethAuth(authedIn: false)
8981
completionHandler(nil, nil, NetworkingError.authenticationError)
9082
return
9183
}
9284

93-
let url = URL(string: loginUrl)!
85+
let url = URL(string: baseUrl + actionUrl)!
9486
var request = URLRequest(url: url)
9587
request.httpMethod = "POST"
9688

97-
var params: [String: String] = [
98-
"password": password,
99-
"submit1": "Log in",
100-
"passcode": passcode,
101-
"required": required,
102-
"appfactor": appfactor,
103-
"ref": ref,
104-
"service": service,
105-
"login": pennkey,
89+
let params: [String: String] = [
90+
"j_username": pennkey,
91+
"j_password": password,
92+
"_eventId_proceed": "",
10693
]
10794

108-
if let reauth = html.getMatches(for: "name=\"reauth\" value=\"(.*?)\"").first {
109-
params["reauth"] = reauth
110-
}
11195
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
11296
let characterSet = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
11397
let parameterArray = params.map { key, value -> String in
@@ -133,7 +117,6 @@ extension PennAuthRequestable {
133117
private func makeRequestWithShibboleth(targetUrl: String, shibbolethUrl: String, html: String, _ completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) {
134118
guard let samlResponse = html.getMatches(for: "<input type=\"hidden\" name=\"SAMLResponse\" value=\"(.*?)\"/>").first,
135119
let relayState = html.getMatches(for: "<input type=\"hidden\" name=\"RelayState\" value=\"(.*?)\"/>").first?.replacingOccurrences(of: "&#x3a;", with: ":") else {
136-
HTTPCookieStorage.shared.removeCookies(since: Date(timeIntervalSince1970: 0))
137120
UserDefaults.standard.setShibbolethAuth(authedIn: false)
138121
completionHandler(nil, nil, NetworkingError.authenticationError)
139122
return

PennMobile/General/PennLoginController.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ class PennLoginController: UIViewController, WKUIDelegate, WKNavigationDelegate
104104
// Webview has redirected to desired site.
105105
self.handleSuccessfulNavigation(webView, decisionHandler: decisionHandler)
106106
} else {
107-
if url.absoluteString == self.loginURL {
108-
webView.evaluateJavaScript("document.getElementById('pennkey').value;") { (result, error) in
107+
if url.absoluteString.contains("password") {
108+
webView.evaluateJavaScript("document.getElementById('pennname').value;") { (result, error) in
109109
if let pennkey = result as? String {
110110
webView.evaluateJavaScript("document.getElementById('password').value;") { (result, error) in
111111
if let password = result as? String {
112-
self.pennkey = pennkey
113-
self.password = password
112+
if(!pennkey.isEmpty && !password.isEmpty) {
113+
self.pennkey = pennkey
114+
self.password = password
115+
}
114116
}
115117
decisionHandler(.allow)
116118
}
@@ -144,29 +146,30 @@ class PennLoginController: UIViewController, WKUIDelegate, WKNavigationDelegate
144146
guard let url = webView.url else {
145147
return
146148
}
147-
148-
if url.absoluteString == loginURL {
149+
150+
if url.absoluteString.contains("twostep") {
149151
guard let pennkey = pennkey, let password = password else { return }
150152
try? secureStore.setValue(pennkey, for: "PennKey")
151153
try? secureStore.setValue(password, for: "PennKey Password")
152-
trustDevice()
153-
return
154-
} else if url.absoluteString.contains(loginURL) {
154+
} else {
155155
self.autofillCredentials()
156+
self.trustDevice()
156157
}
157158
}
158159

159160
func autofillCredentials() {
160161
guard let pennkey = pennkey else { return }
161-
webView.evaluateJavaScript("document.getElementById('pennkey').value = '\(pennkey)'") { (_,_) in
162+
webView.evaluateJavaScript("document.getElementById('pennname').value = '\(pennkey)'") { (_,_) in
162163
}
163164
guard let password = password else { return }
164165
webView.evaluateJavaScript("document.getElementById('password').value = '\(password)'") { (_,_) in
165166
}
166167
}
167168

168169
func trustDevice() {
169-
webView.evaluateJavaScript("document.getElementById('trustUA').value = 'true'") { (_, _) in
170+
webView.evaluateJavaScript("document.getElementById('trustUA').value = 'true'") { (res, err) in
171+
self.webView.evaluateJavaScript("document.documentElement.outerHTML.toString()") { (html, error) in
172+
}
170173
}
171174
}
172175

0 commit comments

Comments
 (0)