Skip to content

Commit

Permalink
added remove keychain option
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Feb 3, 2023
1 parent b8494ee commit 19032d8
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 73 deletions.
11 changes: 11 additions & 0 deletions XCreds/LoginPasswordWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ class LoginPasswordWindowController: NSWindowController {
@IBOutlet weak var passwordTextField: NSSecureTextField!

var password:String?
var resetKeychain = false
override func windowDidLoad() {
super.windowDidLoad()

// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}


@IBAction func removeKeychainButtonPressed(_ sender: Any) {
if self.window?.isModalPanel==true {
resetKeychain=true
NSApp.stopModal(withCode: .OK)

}


}
@IBAction func updateButtonPressed(_ sender: Any) {
if self.window?.isModalPanel==true {
password=passwordTextField.stringValue
Expand Down
91 changes: 52 additions & 39 deletions XCreds/LoginPasswordWindowController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" frameAutosaveName="" animationBehavior="default" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="y1s-aj-r0T">
<windowStyleMask key="styleMask" titled="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="537" y="504" width="497" height="189"/>
<rect key="screenRect" x="0.0" y="0.0" width="2048" height="833"/>
<rect key="contentRect" x="537" y="504" width="497" height="252"/>
<rect key="screenRect" x="0.0" y="0.0" width="1728" height="1079"/>
<view key="contentView" id="keP-aO-VT7">
<rect key="frame" x="0.0" y="0.0" width="497" height="189"/>
<rect key="frame" x="0.0" y="0.0" width="497" height="252"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GHv-Is-FVt">
<rect key="frame" x="20" y="121" width="68" height="68"/>
<rect key="frame" x="14" y="184" width="68" height="68"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="NSApplicationIcon" id="i1e-r0-Waa"/>
</imageView>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NQJ-DJ-Vk6">
<rect key="frame" x="94" y="118" width="385" height="64"/>
<rect key="frame" x="94" y="184" width="385" height="68"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" selectable="YES" id="Kf4-Rd-r7U">
<font key="font" metaFont="systemBold"/>
Expand All @@ -38,38 +38,8 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="or1-FG-c7l">
<rect key="frame" x="96" y="108" width="215" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="To allow this, enter your login password." id="NBo-xg-6iv">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Vgp-AS-5WP">
<rect key="frame" x="96" y="76" width="66" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Password:" id="gjN-RB-inR">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<secureTextField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uxk-Kc-Ey2">
<rect key="frame" x="168" y="73" width="309" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="C9u-SH-tmE">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<allowedInputSourceLocales>
<string>NSAllRomanInputSourcesLocaleIdentifier</string>
</allowedInputSourceLocales>
</secureTextFieldCell>
</secureTextField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gTn-ws-NVT">
<rect key="frame" x="404" y="13" width="80" height="32"/>
<rect key="frame" x="405" y="13" width="79" height="32"/>
<buttonCell key="cell" type="push" title="Update" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Koa-hU-IdG">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -82,7 +52,7 @@ DQ
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0Wv-NR-a6r">
<rect key="frame" x="329" y="13" width="76" height="32"/>
<rect key="frame" x="192" y="13" width="76" height="32"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="yk2-3t-h59">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -94,18 +64,61 @@ Gw
<action selector="cancelButtonPressed:" target="-2" id="qAB-hi-1zy"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vfc-Lt-21D">
<rect key="frame" x="266" y="13" width="141" height="32"/>
<buttonCell key="cell" type="push" title="Remove Keychain" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="AFi-y5-fTi">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="removeKeychainButtonPressed:" target="-2" id="T0U-p4-KUW"/>
</connections>
</button>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qCR-tF-te2">
<rect key="frame" x="94" y="121" width="383" height="55"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" selectable="YES" id="raI-nS-JM6">
<font key="font" metaFont="system"/>
<string key="title">If you do not remember your login password, select Remove Keychain to use your cloud password to create a new keychain and login. The prior keychain willl be renamed.</string>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Vgp-AS-5WP">
<rect key="frame" x="94" y="79" width="66" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Password:" id="gjN-RB-inR">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<secureTextField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uxk-Kc-Ey2">
<rect key="frame" x="166" y="76" width="309" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="C9u-SH-tmE">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<allowedInputSourceLocales>
<string>NSAllRomanInputSourcesLocaleIdentifier</string>
</allowedInputSourceLocales>
</secureTextFieldCell>
</secureTextField>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="gTn-ws-NVT" secondAttribute="bottom" constant="20" symbolic="YES" id="1PF-dv-8LN"/>
<constraint firstItem="gTn-ws-NVT" firstAttribute="leading" secondItem="vfc-Lt-21D" secondAttribute="trailing" constant="12" symbolic="YES" id="4mX-Iu-kv1"/>
<constraint firstAttribute="trailing" secondItem="gTn-ws-NVT" secondAttribute="trailing" constant="20" symbolic="YES" id="Ca3-N3-wr2"/>
<constraint firstItem="gTn-ws-NVT" firstAttribute="leading" secondItem="0Wv-NR-a6r" secondAttribute="trailing" constant="13" id="cuy-Mu-Sgh"/>
<constraint firstItem="vfc-Lt-21D" firstAttribute="leading" secondItem="0Wv-NR-a6r" secondAttribute="trailing" constant="12" symbolic="YES" id="JmP-Hp-WMC"/>
<constraint firstAttribute="bottom" secondItem="vfc-Lt-21D" secondAttribute="bottom" constant="20" symbolic="YES" id="p0P-ke-j6S"/>
<constraint firstItem="0Wv-NR-a6r" firstAttribute="centerY" secondItem="gTn-ws-NVT" secondAttribute="centerY" id="plG-CO-NAT"/>
</constraints>
</view>
<connections>
<outlet property="delegate" destination="-2" id="WxA-Qo-qaN"/>
</connections>
<point key="canvasLocation" x="122.5" y="341.5"/>
<point key="canvasLocation" x="93.5" y="293"/>
</window>
</objects>
<resources>
Expand Down
6 changes: 3 additions & 3 deletions XCreds/VerifyOIDCPassword.xib
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<windowStyleMask key="styleMask" titled="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="519" y="431" width="497" height="189"/>
<rect key="screenRect" x="0.0" y="0.0" width="2048" height="833"/>
<rect key="screenRect" x="0.0" y="0.0" width="1728" height="1079"/>
<view key="contentView" id="keP-aO-VT7">
<rect key="frame" x="0.0" y="0.0" width="497" height="189"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -69,7 +69,7 @@
</secureTextFieldCell>
</secureTextField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gTn-ws-NVT">
<rect key="frame" x="404" y="13" width="80" height="32"/>
<rect key="frame" x="405" y="13" width="79" height="32"/>
<buttonCell key="cell" type="push" title="Update" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Koa-hU-IdG">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -82,7 +82,7 @@ DQ
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0Wv-NR-a6r">
<rect key="frame" x="289" y="13" width="116" height="32"/>
<rect key="frame" x="291" y="13" width="115" height="32"/>
<buttonCell key="cell" type="push" title="Don't Update" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="yk2-3t-h59">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand Down
62 changes: 37 additions & 25 deletions XCredsLoginPlugIn/LoginWindow/LoginWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,35 +273,47 @@ class LoginWebViewController: WebViewController {
if response == .cancel {
break
}
let localPassword = passwordWindowController.password
guard let localPassword = localPassword else {
continue
}
let isValidPassword = try? PasswordUtils.isLocalPasswordValid(userName: username, userPass: localPassword)

if isValidPassword==true {
let localUser = try? PasswordUtils.getLocalRecord(username)
guard let localUser = localUser else {
TCSLogWithMark("invalid local user")
delegate.denyLogin()
return
}
do {
try localUser.changePassword(localPassword, toPassword: tokens.password)
}
catch {
TCSLogWithMark("Error setting local password to cloud password")
delegate.denyLogin()
return
}
TCSLogWithMark("setting original password to use to unlock keychain later")
delegate.setHint(type: .migratePass, hint: localPassword)
let resetKeychain = passwordWindowController.resetKeychain

if resetKeychain == true {
os_log("Setting password to be overwritten.", log: uiLog, type: .default)
delegate.setHint(type: .passwordOverwrite, hint: true)
os_log("Hint set", log: uiLog, type: .debug)
passwordWindowController.window?.close()
break

}
else{
passwordWindowController.window?.shake(self)
else {
let localPassword = passwordWindowController.password
guard let localPassword = localPassword else {
continue
}
let isValidPassword = try? PasswordUtils.isLocalPasswordValid(userName: username, userPass: localPassword)

if isValidPassword==true {
let localUser = try? PasswordUtils.getLocalRecord(username)
guard let localUser = localUser else {
TCSLogWithMark("invalid local user")
delegate.denyLogin()
return
}
do {
try localUser.changePassword(localPassword, toPassword: tokens.password)
}
catch {
TCSLogWithMark("Error setting local password to cloud password")
delegate.denyLogin()
return
}
TCSLogWithMark("setting original password to use to unlock keychain later")
delegate.setHint(type: .migratePass, hint: localPassword)
passwordWindowController.window?.close()
break

}
else{
passwordWindowController.window?.shake(self)
}
}
}
}
Expand Down

0 comments on commit 19032d8

Please sign in to comment.