-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for on-device resident credential management
- Loading branch information
Showing
13 changed files
with
285 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
authenticator/src/main/java/me/henneke/wearauthn/ui/main/ResidentCredentialsList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package me.henneke.wearauthn.ui.main | ||
|
||
import android.app.AlertDialog | ||
import android.os.Bundle | ||
import android.preference.PreferenceCategory | ||
import android.preference.PreferenceFragment | ||
import android.support.wearable.preference.WearableDialogPreference | ||
import android.support.wearable.preference.WearablePreferenceActivity | ||
import android.support.wearable.view.AcceptDenyDialog | ||
import me.henneke.wearauthn.R | ||
import me.henneke.wearauthn.fido.context.AuthenticatorContext | ||
|
||
@ExperimentalUnsignedTypes | ||
class ResidentCredentialsList : WearablePreferenceActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
startPreferenceFragment(ResidentCredentialsPreferenceFragment(), false) | ||
} | ||
} | ||
|
||
@ExperimentalUnsignedTypes | ||
class ResidentCredentialsPreferenceFragment : PreferenceFragment() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
createCredentialList() | ||
} | ||
|
||
private fun createCredentialList() { | ||
preferenceScreen = preferenceManager.createPreferenceScreen(context) | ||
val credentialsPerRp = AuthenticatorContext.getAllResidentCredentials(context) | ||
preferenceScreen.title = | ||
if (credentialsPerRp.isEmpty()) "No single-factor credentials" else "Single-factor credentials" | ||
for ((rpId, credentials) in credentialsPerRp) { | ||
if (credentials.isEmpty()) | ||
continue | ||
val rpCategory = PreferenceCategory(context) | ||
// PreferenceCategory has to be added to the PreferenceScreen before customizing it | ||
// https://stackoverflow.com/a/49108303/297261 | ||
preferenceScreen.addPreference(rpCategory) | ||
rpCategory.apply { | ||
title = rpId | ||
for ((index, credential) in credentials.withIndex()) { | ||
credential.unlockUserInfoIfNecessary() | ||
val credentialTwoLineInfo = credential.getTwoLineInfo(index + 1) | ||
val credentialFormattedInfo = credential.getFormattedInfo() | ||
addPreference(object : WearableDialogPreference(context) { | ||
init { | ||
isIconSpaceReserved = false | ||
title = credentialTwoLineInfo.first | ||
summary = credentialTwoLineInfo.second | ||
} | ||
|
||
override fun onPrepareDialogBuilder(builder: AlertDialog.Builder) { | ||
super.onPrepareDialogBuilder(builder) | ||
val preference = this | ||
builder.apply { | ||
setTitle(rpId) | ||
setMessage(credentialFormattedInfo) | ||
setPositiveButton(R.string.button_delete) { _, _ -> | ||
AcceptDenyDialog(context).run { | ||
setTitle(rpId) | ||
setMessage("Delete credential for\n${credentialTwoLineInfo.first}\n?") | ||
setPositiveButton { _, _ -> | ||
AuthenticatorContext.deleteResidentCredential( | ||
context, | ||
credential | ||
) | ||
rpCategory.removePreference(preference) | ||
if (rpCategory.preferenceCount == 0) | ||
preferenceScreen.removePreference(rpCategory) | ||
} | ||
setNegativeButton { _, _ -> } | ||
show() | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
Based on ic_vpn_key_24px.svg from the Material Design Icons, | ||
modified by Fabian Henneke | ||
Original license: | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FFFFFFFF" | ||
android:pathData="M12.65,10C11.83,7.67 9.61,6 7,6c-3.31,0 -6,2.69 -6,6s2.69,6 6,6c2.61,0 4.83,-1.67 5.65,-4H17v4h4v-4h2v-4H12.65zM7,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"/> | ||
</vector> |
Oops, something went wrong.