-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fido: Supplement missing processing #3031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DaVinci9196
wants to merge
11
commits into
microg:master
Choose a base branch
from
DaVinci9196:fix_fido_passkey_sign_in
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c1e5964
Fido: Supplement missing processing
DaVinci9196 632d7f9
Fix verification key failure
DaVinci9196 9aa4c53
Fixed the issue that the created key cannot be used, and the latest k…
DaVinci9196 3d1cd3d
Implement multiple passkey switching logins.
DaVinci9196 6fa53aa
There is a case where the data is null
DaVinci9196 230dee1
Avoid repeated calls
DaVinci9196 a0aded7
Avoid loop calls
DaVinci9196 b5c4c0a
Merge remote-tracking branch 'origin/fix_fido_passkey_sign_in' into f…
DaVinci9196 e0c29c0
Merge branch 'master' into fix_fido_passkey_sign_in
mar-v-in 73a3732
Merge branch 'master' into fix_fido_passkey_sign_in
mar-v-in 13a41e7
Remove sha-1
DaVinci9196 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ import org.json.JSONArray | |
import org.json.JSONObject | ||
import org.microg.gms.fido.core.RequestOptionsType.REGISTER | ||
import org.microg.gms.fido.core.RequestOptionsType.SIGN | ||
import org.microg.gms.fido.core.transport.Transport | ||
import org.microg.gms.utils.* | ||
import java.net.HttpURLConnection | ||
import java.security.MessageDigest | ||
|
@@ -30,6 +31,7 @@ class RequestHandlingException(val errorCode: ErrorCode, message: String? = null | |
class MissingPinException(message: String? = null): Exception(message) | ||
class WrongPinException(message: String? = null): Exception(message) | ||
|
||
data class CredentialUserInfo(val credential: String, val userJson: String, val transport: Transport) | ||
enum class RequestOptionsType { REGISTER, SIGN } | ||
|
||
val RequestOptions.registerOptions: PublicKeyCredentialCreationOptions | ||
|
@@ -71,6 +73,12 @@ val RequestOptions.rpId: String | |
SIGN -> signOptions.rpId | ||
} | ||
|
||
val RequestOptions.user: String? | ||
get() = when (type) { | ||
REGISTER -> registerOptions.user.toJson() | ||
SIGN -> null | ||
} | ||
|
||
val PublicKeyCredentialCreationOptions.skipAttestation: Boolean | ||
get() = attestationConveyancePreference in setOf(AttestationConveyancePreference.NONE, null) | ||
|
||
|
@@ -155,19 +163,15 @@ private suspend fun isAppIdAllowed(context: Context, appId: String, facetId: Str | |
} | ||
|
||
suspend fun RequestOptions.checkIsValid(context: Context, facetId: String, packageName: String?) { | ||
if (type == SIGN) { | ||
if (signOptions.allowList.isNullOrEmpty()) { | ||
throw RequestHandlingException(NOT_ALLOWED_ERR, "Request doesn't have a valid list of allowed credentials.") | ||
} | ||
} | ||
if (facetId.startsWith("https://")) { | ||
if (topDomainOf(Uri.parse(facetId).host) != topDomainOf(rpId)) { | ||
throw RequestHandlingException(NOT_ALLOWED_ERR, "RP ID $rpId not allowed from facet $facetId") | ||
} | ||
// FIXME: Standard suggests doing additional checks, but this is already sensible enough | ||
} else if (facetId.startsWith("android:apk-key-hash:") && packageName != null) { | ||
val sha256FacetId = getAltFacetId(context, packageName, facetId) ?: | ||
throw RequestHandlingException(NOT_ALLOWED_ERR, "Can't resolve $facetId to SHA-256 Facet") | ||
val sha256FacetId = getAltFacetId(context, packageName, facetId)?.ifEmpty { | ||
getAltFacetId(context, packageName, getApkKeyHashFacetId(context, packageName)) | ||
} ?: throw RequestHandlingException(NOT_ALLOWED_ERR, "Can't resolve $facetId to SHA-256 Facet") | ||
if (!isAssetLinked(context, rpId, sha256FacetId, packageName)) { | ||
throw RequestHandlingException(NOT_ALLOWED_ERR, "RP ID $rpId not allowed from facet $sha256FacetId") | ||
} | ||
|
@@ -213,21 +217,18 @@ fun getApplicationName(context: Context, options: RequestOptions, callingPackage | |
} | ||
|
||
fun getApkKeyHashFacetId(context: Context, packageName: String): String { | ||
val digest = context.packageManager.getFirstSignatureDigest(packageName, "SHA1") | ||
// Default: SHA-256 | ||
val digest = context.packageManager.getFirstSignatureDigest(packageName, "SHA-256") | ||
?: throw RequestHandlingException(NOT_ALLOWED_ERR, "Unknown package $packageName") | ||
return "android:apk-key-hash:${digest.toBase64(HASH_BASE64_FLAGS)}" | ||
} | ||
|
||
fun getAltFacetId(context: Context, packageName: String, facetId: String): String? { | ||
val firstSignature = context.packageManager.getSignatures(packageName).firstOrNull() | ||
?: throw RequestHandlingException(NOT_ALLOWED_ERR, "Unknown package $packageName") | ||
val sha256BASE64 = firstSignature.digest("SHA-256").toBase64(HASH_BASE64_FLAGS) | ||
return when (facetId) { | ||
"android:apk-key-hash:${firstSignature.digest("SHA1").toBase64(HASH_BASE64_FLAGS)}" -> { | ||
"android:apk-key-hash-sha256:${firstSignature.digest("SHA-256").toBase64(HASH_BASE64_FLAGS)}" | ||
} | ||
"android:apk-key-hash-sha256:${firstSignature.digest("SHA-256").toBase64(HASH_BASE64_FLAGS)}" -> { | ||
"android:apk-key-hash:${firstSignature.digest("SHA1").toBase64(HASH_BASE64_FLAGS)}" | ||
} | ||
"android:apk-key-hash:$sha256BASE64" -> "android:apk-key-hash-sha256:$sha256BASE64" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And you need this here, because you wrongly created it above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed sha-1 related. |
||
else -> null | ||
} | ||
} | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong. It should be either
android:apk-key-hash:<sha-1>
orandroid:apk-key-hash-sha256:<sha-256>
, but not a mix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also noticed this, but in the fido specification, the pr server recognizes SHA-256