Bug 1384307 - Set WebAuthn PublicKeyCredential's "id" and "type" fields r=keeler

The Web Authentication PublicKeyCredential object has two fields currently
unpopulated which, to be spec-compliant, must be set. These fields duplicate
available data.

  [PublicKeyCredential.id] must be set to the base64url encoding with omitted
  padding of whatever data is in "rawId".

  [PublicKeyCredential.type] must be the literal "public-key".

MozReview-Commit-ID: L6wPYpZdD8A

--HG--
extra : rebase_source : 3ca83598b70f99f4d60f303d113e875046268669
This commit is contained in:
J.C. Jones 2017-07-25 15:03:59 -07:00
Родитель 4c1f464cff
Коммит 860e263cc7
4 изменённых файлов: 46 добавлений и 0 удалений

Просмотреть файл

@ -46,5 +46,17 @@ Credential::GetType(nsAString& aType) const
aType.Assign(mType);
}
void
Credential::SetId(const nsAString& aId)
{
mId.Assign(aId);
}
void
Credential::SetType(const nsAString& aType)
{
mType.Assign(aType);
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -44,6 +44,12 @@ public:
void
GetType(nsAString& aType) const;
void
SetId(const nsAString& aId);
void
SetType(const nsAString& aType);
private:
nsCOMPtr<nsPIDOMWindowInner> mParent;
nsAutoString mId;

Просмотреть файл

@ -695,6 +695,13 @@ WebAuthnManager::FinishMakeCredential(nsTArray<uint8_t>& aRegBuffer)
}
MOZ_ASSERT(keyHandleBuf.Length() <= 0xFFFF);
nsAutoString keyHandleBase64Url;
rv = keyHandleBuf.ToJwkBase64(keyHandleBase64Url);
if (NS_WARN_IF(NS_FAILED(rv))) {
Cancel(rv);
return;
}
CryptoBuffer clientDataBuf;
if (!clientDataBuf.Assign(mClientData.ref())) {
Cancel(NS_ERROR_OUT_OF_MEMORY);
@ -775,6 +782,8 @@ WebAuthnManager::FinishMakeCredential(nsTArray<uint8_t>& aRegBuffer)
attestation->SetAttestationObject(attObj);
RefPtr<PublicKeyCredential> credential = new PublicKeyCredential(mCurrentParent);
credential->SetId(keyHandleBase64Url);
credential->SetType(NS_LITERAL_STRING("public-key"));
credential->SetRawId(keyHandleBuf);
credential->SetResponse(attestation);
@ -817,6 +826,13 @@ WebAuthnManager::FinishGetAssertion(nsTArray<uint8_t>& aCredentialId,
CryptoBuffer credentialBuf;
if (!credentialBuf.Assign(aCredentialId)) {
Cancel(NS_ERROR_OUT_OF_MEMORY);
return;
}
nsAutoString credentialBase64Url;
rv = credentialBuf.ToJwkBase64(credentialBase64Url);
if (NS_WARN_IF(NS_FAILED(rv))) {
Cancel(rv);
return;
}
@ -834,6 +850,8 @@ WebAuthnManager::FinishGetAssertion(nsTArray<uint8_t>& aCredentialId,
RefPtr<PublicKeyCredential> credential =
new PublicKeyCredential(mCurrentParent);
credential->SetId(credentialBase64Url);
credential->SetType(NS_LITERAL_STRING("public-key"));
credential->SetRawId(credentialBuf);
credential->SetResponse(assertion);

Просмотреть файл

@ -43,13 +43,18 @@ function() {
function decodeCreatedCredential(aCredInfo) {
/* PublicKeyCredential : Credential
- rawId: Key Handle buffer pulled from U2F Register() Response
- id: Key Handle buffer in base64url form, should == rawId
- type: Literal 'public-key'
- response : AuthenticatorAttestationResponse : AuthenticatorResponse
- attestationObject: CBOR object
- clientDataJSON: serialized JSON
- clientExtensionResults: (not yet supported)
*/
is(aCredInfo.type, "public-key", "Credential type must be public-key")
ok(aCredInfo.rawId.length > 0, "Key ID exists");
is(aCredInfo.id, bytesToBase64UrlSafe(aCredInfo.rawId), "Encoded Key ID and Raw Key ID match");
let clientData = JSON.parse(buffer2string(aCredInfo.response.clientDataJSON));
is(clientData.challenge, bytesToBase64UrlSafe(gCredentialChallenge), "Challenge is correct");
@ -68,13 +73,18 @@ function() {
function checkAssertionAndSigValid(aPublicKey, aAssertion) {
/* PublicKeyCredential : Credential
- rawId: ID of Credential from AllowList that succeeded
- id: Key Handle buffer in base64url form, should == rawId
- type: Literal 'public-key'
- response : AuthenticatorAssertionResponse : AuthenticatorResponse
- clientDataJSON: serialized JSON
- authenticatorData: RP ID Hash || U2F Sign() Response
- signature: U2F Sign() Response
*/
is(aAssertion.type, "public-key", "Credential type must be public-key")
ok(aAssertion.rawId.length > 0, "Key ID exists");
is(aAssertion.id, bytesToBase64UrlSafe(aAssertion.rawId), "Encoded Key ID and Raw Key ID match");
ok(aAssertion.response.authenticatorData.length > 0, "Authenticator data exists");
let clientData = JSON.parse(buffer2string(aAssertion.response.clientDataJSON));