Skip to content

Commit

Permalink
Ported reset oath to swiftui.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensutbult committed Aug 22, 2024
1 parent e191938 commit b461437
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 180 deletions.
27 changes: 19 additions & 8 deletions Authenticator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
B40F44452B27033A000D5E02 /* TokenRequestYubiOTPViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B40F44442B27033A000D5E02 /* TokenRequestYubiOTPViewController.swift */; };
B411242F29D423A300D58001 /* ListStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B411242E29D423A300D58001 /* ListStatusView.swift */; };
B42A39332B2A03D20039DB26 /* YubiKit in Frameworks */ = {isa = PBXBuildFile; productRef = B42A39322B2A03D20039DB26 /* YubiKit */; };
B44E5E812C74BE67007ABB79 /* OATHResetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B44E5E802C74BE67007ABB79 /* OATHResetView.swift */; };
B44E5E842C74C8CC007ABB79 /* YubiKit in Frameworks */ = {isa = PBXBuildFile; productRef = B44E5E832C74C8CC007ABB79 /* YubiKit */; };
B452EC1F2A1E4F460045E5D9 /* YubiOtpRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B452EC1E2A1E4F460045E5D9 /* YubiOtpRowView.swift */; };
B452EC3D2A264A620045E5D9 /* ToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B452EC3C2A264A620045E5D9 /* ToastView.swift */; };
B452EC442A2A06940045E5D9 /* ToastPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = B452EC432A2A06940045E5D9 /* ToastPresenter.swift */; };
Expand Down Expand Up @@ -227,6 +229,7 @@
B40D61A12AE7F89500467AE9 /* DisableOTPModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisableOTPModel.swift; sourceTree = "<group>"; };
B40F44442B27033A000D5E02 /* TokenRequestYubiOTPViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenRequestYubiOTPViewController.swift; sourceTree = "<group>"; };
B411242E29D423A300D58001 /* ListStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStatusView.swift; sourceTree = "<group>"; };
B44E5E802C74BE67007ABB79 /* OATHResetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OATHResetView.swift; sourceTree = "<group>"; };
B452EC1E2A1E4F460045E5D9 /* YubiOtpRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YubiOtpRowView.swift; sourceTree = "<group>"; };
B452EC3C2A264A620045E5D9 /* ToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastView.swift; sourceTree = "<group>"; };
B452EC432A2A06940045E5D9 /* ToastPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastPresenter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -280,6 +283,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
B44E5E842C74C8CC007ABB79 /* YubiKit in Frameworks */,
B42A39332B2A03D20039DB26 /* YubiKit in Frameworks */,
B9F0FF11F842A39183974083 /* (null) in Frameworks */,
51AFD4DA271D4278008F2630 /* QuartzCore.framework in Frameworks */,
Expand Down Expand Up @@ -315,6 +319,7 @@
515542672654413600B19C59 /* SmartCardConfigurationController.swift */,
81FA3C31231AF289009C22AB /* SetPasswordViewController.swift */,
51AFD4D32716FC78008F2630 /* NFCSettingsController.swift */,
B44E5E802C74BE67007ABB79 /* OATHResetView.swift */,
);
path = YubiKeyConfiguration;
sourceTree = "<group>";
Expand Down Expand Up @@ -604,6 +609,7 @@
name = Authenticator;
packageProductDependencies = (
B42A39322B2A03D20039DB26 /* YubiKit */,
B44E5E832C74C8CC007ABB79 /* YubiKit */,
);
productName = Authenticator;
productReference = 818866B322DFD729006BC0A8 /* Authenticator.app */;
Expand Down Expand Up @@ -666,7 +672,7 @@
);
mainGroup = 818866AA22DFD729006BC0A8;
packageReferences = (
B42A39312B2A03D20039DB26 /* XCLocalSwiftPackageReference "../yubikit-ios" */,
B44E5E822C74C8CC007ABB79 /* XCLocalSwiftPackageReference "../yubikit-ios" */,
);
productRefGroup = 818866B422DFD729006BC0A8 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -735,6 +741,7 @@
A591412123835F4600CCCF67 /* Constants.swift in Sources */,
515542852656A30B00B19C59 /* UIButton+Extensions.swift in Sources */,
51BBE37F273982D700DA47CC /* YKFOATHSession+Extensions.swift in Sources */,
B44E5E812C74BE67007ABB79 /* OATHResetView.swift in Sources */,
B411242F29D423A300D58001 /* ListStatusView.swift in Sources */,
816C684823430F8E00209342 /* SecureStoreQueryable.swift in Sources */,
515542882656F64100B19C59 /* Data+Extensions.swift in Sources */,
Expand Down Expand Up @@ -906,7 +913,7 @@
CURRENT_PROJECT_VERSION = 115;
DEVELOPMENT_TEAM = LQA3CS5MM7;
INFOPLIST_FILE = TokenExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -930,7 +937,7 @@
CURRENT_PROJECT_VERSION = 115;
DEVELOPMENT_TEAM = LQA3CS5MM7;
INFOPLIST_FILE = TokenExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -1077,7 +1084,7 @@
DEVELOPMENT_TEAM = LQA3CS5MM7;
HEADER_SEARCH_PATHS = "../Submodules/YubiKit/**";
INFOPLIST_FILE = Authenticator/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -1106,7 +1113,7 @@
DEVELOPMENT_TEAM = LQA3CS5MM7;
HEADER_SEARCH_PATHS = "../Submodules/YubiKit/**";
INFOPLIST_FILE = Authenticator/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1132,7 +1139,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = LQA3CS5MM7;
INFOPLIST_FILE = AuthenticatorTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1154,7 +1161,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = LQA3CS5MM7;
INFOPLIST_FILE = AuthenticatorTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -1210,7 +1217,7 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
B42A39312B2A03D20039DB26 /* XCLocalSwiftPackageReference "../yubikit-ios" */ = {
B44E5E822C74C8CC007ABB79 /* XCLocalSwiftPackageReference "../yubikit-ios" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = "../yubikit-ios";
};
Expand All @@ -1221,6 +1228,10 @@
isa = XCSwiftPackageProductDependency;
productName = YubiKit;
};
B44E5E832C74C8CC007ABB79 /* YubiKit */ = {
isa = XCSwiftPackageProductDependency;
productName = YubiKit;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 818866AB22DFD729006BC0A8 /* Project object */;
Expand Down
26 changes: 13 additions & 13 deletions Authenticator/Model/ResetOATHViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@

import Foundation

class ResetOATHViewModel {
let connection = Connection()
class ResetOATHViewModel: ObservableObject {

@Published var state: ResetState = .ready

enum ResetResult {
case success(String?);
case failure(String?);
enum ResetState: Equatable {
case ready, success, error(String)
}

func reset(completion: @escaping (_ result: ResetResult) -> Void) {
private let connection = Connection()

func reset() {
connection.startConnection { connection in

connection.oathSession { session, error in
guard let session = session else {
YubiKitManager.shared.stopNFCConnection(withErrorMessage: error!.localizedDescription)
completion(.failure((connection as? YKFAccessoryConnection != nil) ? error!.localizedDescription : nil))
let errorMessage = error?.localizedDescription ?? "Unknown error"
YubiKitManager.shared.stopNFCConnection(withErrorMessage: errorMessage)
self.state = .error(errorMessage)
return
}

session.reset { error in
if let error = error {
YubiKitManager.shared.stopNFCConnection(withErrorMessage: error.localizedDescription)
completion(.failure((connection as? YKFAccessoryConnection != nil) ? error.localizedDescription : nil))
return
self.state = .error(error.localizedDescription)
} else {
let message = String(localized: "OATH accounts deleted and OATH application reset to factory defaults.", comment: "OATH reset confirmation message")
YubiKitManager.shared.stopNFCConnection(withMessage: message)
completion(.success((connection as? YKFAccessoryConnection != nil) ? message: nil))
self.state = .success
}
}
}
Expand Down
Loading

0 comments on commit b461437

Please sign in to comment.