Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NextcloudTalk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@
membershipExceptions = (
CurrentUserAbsence.swift,
NCAppBranding.m,
NCAppBrandingExtensions.swift,
NCKeyChainController.m,
NCUserDefaults.m,
NCUtils.swift,
Expand All @@ -704,6 +705,7 @@
membershipExceptions = (
CurrentUserAbsence.swift,
NCAppBranding.m,
NCAppBrandingExtensions.swift,
NCKeyChainController.m,
NCUserDefaults.m,
NCUserStatus.m,
Expand All @@ -717,6 +719,7 @@
membershipExceptions = (
CurrentUserAbsence.swift,
NCAppBranding.m,
NCAppBrandingExtensions.swift,
NCKeyChainController.m,
NCUserStatus.m,
NCUtils.swift,
Expand All @@ -729,6 +732,7 @@
membershipExceptions = (
CurrentUserAbsence.swift,
NCAppBranding.m,
NCAppBrandingExtensions.swift,
NCKeyChainController.m,
NCUserDefaults.m,
NCUserStatus.m,
Expand Down
5 changes: 1 addition & 4 deletions NextcloudTalk/Login/AuthenticationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ - (void)viewDidLoad
[request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];

self->_webView = [[DebounceWebView alloc] initWithFrame:self.view.frame configuration:configuration];
NSString *appDisplayName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
NSString *deviceName = [[UIDevice currentDevice] name];
NSString *userAgent = [NSString stringWithFormat:@"%@ (%@)", deviceName, appDisplayName];
self->_webView.customUserAgent = [[NSString alloc] initWithCString:[userAgent UTF8String] encoding:NSASCIIStringEncoding];
self->_webView.customUserAgent = [NCAppBranding userAgentForLogin];
self->_webView.navigationDelegate = self;
self->_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Expand Down
21 changes: 21 additions & 0 deletions NextcloudTalk/Login/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,25 @@ class LoginViewController: UIViewController, UITextFieldDelegate, CCCertificateD
NCSettingsController.sharedInstance().addNewAccount(forUser: user, withToken: password, inServer: serverURL)
delegate?.loginViewControllerDidFinish()
}

func qrScanner(_ scanner: QRScannerViewController, didScanNextcloudOnetimeLogin serverURL: String, user: String, onetimeToken: String) {
NotificationPresenter.shared().present(text: NSLocalizedString("Trying to login…", comment: "Waiting message when trying to login with QR code"))
NotificationPresenter.shared().displayActivityIndicator(true)

// We received a onetime login token and need to convert it to a permanent one. The token only allows to retrieve a permanent one, no other routes allowed
NCAPIController.sharedInstance().getAppPasswordOnetime(forServer: serverURL, withUsername: user, andOnetimeToken: onetimeToken) { [weak self] permanentAppToken in
NotificationPresenter.shared().dismiss()

guard let permanentAppToken else {
self?.showAlert(
title: NSLocalizedString("Could not login with QR code", comment: ""),
message: NSLocalizedString("The token might be used already or is expired. Please generate a new QR code and retry.", comment: ""))

return
}

NCSettingsController.sharedInstance().addNewAccount(forUser: user, withToken: permanentAppToken, inServer: serverURL)
self?.delegate?.loginViewControllerDidFinish()
}
}
}
13 changes: 11 additions & 2 deletions NextcloudTalk/Login/QRScannerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import VisionKit

@objc protocol QRScannerViewControllerDelegate: AnyObject {
func qrScanner(_ scanner: QRScannerViewController, didScanNextcloudLogin serverURL: String, user: String, password: String)
func qrScanner(_ scanner: QRScannerViewController, didScanNextcloudOnetimeLogin serverURL: String, user: String, onetimeToken: String)
}

@objcMembers
Expand Down Expand Up @@ -137,7 +138,10 @@ class QRScannerViewController: UIViewController, DataScannerViewControllerDelega
guard case let .barcode(barcode) = item,
let value = barcode.payloadStringValue else { return }

if let urlComponents = NSURLComponents(string: value), var path = urlComponents.path, urlComponents.scheme == "nc", urlComponents.host == "login" {
if let urlComponents = NSURLComponents(string: value), var path = urlComponents.path, urlComponents.scheme == "nc" {
let isOnetimeLogin = (urlComponents.host == "onetime-login")
guard urlComponents.host == "login" || isOnetimeLogin else { return }

if path.starts(with: "/") {
path.removeFirst()
}
Expand All @@ -152,7 +156,12 @@ class QRScannerViewController: UIViewController, DataScannerViewControllerDelega

scannerViewController?.stopScanning()
self.dismiss(animated: true)
self.delegate?.qrScanner(self, didScanNextcloudLogin: serverUrl, user: user, password: password)

if isOnetimeLogin {
self.delegate?.qrScanner(self, didScanNextcloudOnetimeLogin: serverUrl, user: user, onetimeToken: password)
} else {
self.delegate?.qrScanner(self, didScanNextcloudLogin: serverUrl, user: user, password: password)
}

return
}
Expand Down
4 changes: 1 addition & 3 deletions NextcloudTalk/Network/NCAPIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ - (void)initImageDownloaders
[SDImageCache sharedImageCache].config.shouldRemoveExpiredDataWhenTerminate = NO;
[SDImageCache sharedImageCache].config.shouldRemoveExpiredDataWhenEnterBackground = NO;

NSString *userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (iOS) Nextcloud-Talk v%@",
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
[[SDWebImageDownloader sharedDownloader] setValue:userAgent forHTTPHeaderField:@"User-Agent"];
[[SDWebImageDownloader sharedDownloader] setValue:[NCAppBranding userAgent] forHTTPHeaderField:@"User-Agent"];
}

- (NSString *)authHeaderForAccount:(TalkAccount *)account
Expand Down
29 changes: 29 additions & 0 deletions NextcloudTalk/Network/NCAPIControllerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1360,4 +1360,33 @@ import NextcloudKit

return NCChatMessage(dictionary: ocsResponse.dataDict, andAccountId: account.accountId)
}

// MARK: - Core

@nonobjc
func getAppPasswordOnetime(forServer server: String, withUsername username: String, andOnetimeToken onetimeToken: String, completionBlock: @escaping (_ permanentAppToken: String?) -> Void) {
let appPasswordRoute = "\(server)/ocs/v2.php/core/getapppassword-onetime"

let credentialsString = "\(username):\(onetimeToken)"
let authHeader = "Basic \(credentialsString.data(using: .utf8)!.base64EncodedString())"

let configuration = URLSessionConfiguration.default
let apiSessionManager = NCAPISessionManager(configuration: configuration)
apiSessionManager.requestSerializer.setValue(authHeader, forHTTPHeaderField: "Authorization")
apiSessionManager.requestSerializer.setValue(NCAppBranding.userAgentForLogin(), forHTTPHeaderField: "User-Agent")

_ = apiSessionManager.get(appPasswordRoute, parameters: nil, progress: nil) { _, result in
if let resultDict = result as? [String: AnyObject],
let ocs = resultDict["ocs"] as? [String: AnyObject],
let data = ocs["data"] as? [String: AnyObject],
let apppassword = data["apppassword"] as? String {

completionBlock(apppassword)
}

completionBlock(nil)
} failure: { _, _ in
completionBlock(nil)
}
}
}
3 changes: 1 addition & 2 deletions NextcloudTalk/Network/NCBaseSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import Foundation

@objcMembers public class NCBaseSessionManager: AFHTTPSessionManager {

public static var baseUserAgent = "Mozilla/5.0 (iOS) Nextcloud-Talk v\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] ?? "Unknown")"
public var userAgent: String = baseUserAgent
public var userAgent: String = NCAppBranding.userAgent()

init(configuration: URLSessionConfiguration, responseSerializer: AFHTTPResponseSerializer, requestSerializer: AFHTTPRequestSerializer) {
super.init(baseURL: nil, sessionConfiguration: configuration)
Expand Down
13 changes: 13 additions & 0 deletions NextcloudTalk/Settings/NCAppBrandingExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@ extension NCAppBranding {
return NCAppBranding.getDynamicColor(lightColor, withDarkMode: darkColor)
}

@objc
static func userAgent() -> String {
return "Mozilla/5.0 (iOS) Nextcloud-Talk v\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] ?? "Unknown")"
}

@objc
static func userAgentForLogin() -> String {
let appDisplayName = Bundle.main.infoDictionary?["CFBundleDisplayName"] ?? "Unknown app"
let deviceName = UIDevice.current.name

return "\(deviceName) (\(appDisplayName)"
}

}
4 changes: 1 addition & 3 deletions NextcloudTalk/WebRTC/NCExternalSignalingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ public enum NCExternalSignalingSendMessageStatus {

NCUtils.log("Connecting to: \(self.serverUrl)")

let userAgent = "Mozilla/5.0 (iOS) Nextcloud-Talk v\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] ?? "Unknown")"

let wsSession = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
var wsRequest = URLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: webSocketTimeoutInterval)
wsRequest.setValue(userAgent, forHTTPHeaderField: "User-Agent")
wsRequest.setValue(NCAppBranding.userAgent(), forHTTPHeaderField: "User-Agent")

if self.resumeId != nil {
let currentTimestamp = Date().timeIntervalSince1970
Expand Down
9 changes: 9 additions & 0 deletions NextcloudTalk/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@
/* No comment provided by engineer. */
"Could not leave conversation" = "Could not leave conversation";

/* No comment provided by engineer. */
"Could not login with QR code" = "Could not login with QR code";

/* No comment provided by engineer. */
"Could not remove participant" = "Could not remove participant";

Expand Down Expand Up @@ -2150,6 +2153,9 @@
/* No comment provided by engineer. */
"The recording might include your voice, video from camera, and screen share. Your consent is required before joining the call." = "The recording might include your voice, video from camera, and screen share. Your consent is required before joining the call.";

/* No comment provided by engineer. */
"The token might be used already or is expired. Please generate a new QR code and retry." = "The token might be used already or is expired. Please generate a new QR code and retry.";

/* No comment provided by engineer. */
"There is no account for user %@ in server %@ configured in this app." = "There is no account for user %1$@ in server %2$@ configured in this app.";

Expand Down Expand Up @@ -2234,6 +2240,9 @@
/* No comment provided by engineer. */
"Translation failed" = "Translation failed";

/* Waiting message when trying to login with QR code */
"Trying to login…" = "Trying to login…";

/* No comment provided by engineer. */
"TURN servers" = "TURN servers";

Expand Down
5 changes: 1 addition & 4 deletions NotificationServiceExtension/NotificationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withConte

NSURL *url = [NSURL URLWithString:urlString];

NSString *userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (iOS) Nextcloud-Talk v%@",
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];

[[SDWebImageDownloader sharedDownloader] setValue:userAgent forHTTPHeaderField:@"User-Agent"];
[[SDWebImageDownloader sharedDownloader] setValue:[NCAppBranding userAgent] forHTTPHeaderField:@"User-Agent"];
[SDWebImageDownloader sharedDownloader].config.downloadTimeout = 25.0;

SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageRefreshCached;
Expand Down
Loading