Skip to content

MS_Fido2NetLib

nishi_74322014 edited this page Sep 1, 2026 · 1 revision

fido2-net-lib

概要

補足(現在の状況): fido2-net-lib はその後も更新が続いており、
NuGet パッケージ名は Fido2(および Fido2.Models
ASP.NET Core 連携用の Fido2.AspNet)である。
.NET のサーバ側で WebAuthn(Relying Party)を実装する際の
事実上の標準的な選択肢になっている。

詳細

ストア

https://github.com/abergs/fido2-net-lib/blob/master/fido2-net-lib/DevelopmentInMemoryStore.cs

  • DevelopmentInMemoryStore をデモ実装にして、
    本体側は、IUserStore 的な Interface のみにした方が良さそう。
  • 一先ず、WebAuthnStore を実装して、内部を UserStoreType (mem, sql, ora, npg) で Switch。

メンバ

  • storedUsers

    ConcurrentDictionary<string, User> storedUsers = new ConcurrentDictionary<string, User>();
    • User

      - string Name
      - byte[] Id
      - string DisplayName
  • storedCredentials

    List<StoredCredential> storedCredentials = new List<StoredCredential>();
    • StoredCredential

      - byte[] UserId
      - PublicKeyCredentialDescriptor Descriptor
      - byte[] PublicKey
      - byte[] UserHandle
      - uint SignatureCounter
      - string CredType
      - DateTime RegDate
      - Guid AaGuid
    • PublicKeyCredentialDescriptor

      - PublicKeyCredentialType? Type(enum)
      - byte[] Id
      - AuthenticatorTransport[] Transports

補足(SignatureCounterAaGuid: SignatureCounter
認証器が署名するたびに増える値で、
サーバ側が前回値より大きいことを確認することで
認証器のクローン(複製)を検知するために使う。
AaGuid は認証器のモデルを表す識別子で、
メタデータ サービス(MDS)と突き合わせると
「どのメーカーのどの製品か」「認定を受けているか」が分かる。

メソッド

  • User

    - User GetUser
    - User GetOrAddUser(string username, Func<User> addCallback)
    - List<User> GetUsersByCredentialIdAsync(byte[] credentialId)
  • StoredCredential

    - List<StoredCredential> GetCredentialsByUser(User user)
    - List<StoredCredential> GetCredentialsByUserHandleAsync(byte[] userHandle)
    - StoredCredential GetCredentialById(byte[] id)
    - void AddCredentialToUser(User user, StoredCredential credential)
    - void UpdateCounter(byte[] credentialId, uint counter)

サーバ

https://github.com/abergs/fido2-net-lib/blob/master/Fido2Demo/Controller.cs

MakeCredentialOptions

  1. Get from DB by username (ユーザ名で DB から取得)
    • user (in our example, auto create missing users)
      (ユーザ (この例では、見つからないユーザを自動作成))
    • keys (キー)
  2. Create options (MakeCredentialOptions を作成)
  3. Temporarily store options, session/in-memory cache/redis/db
    (session/in-memory cache/redis/db の一時保存オプション)
  4. return options to client
    (クライアントに MakeCredentialOptions を返す)

MakeCredential

  1. get the options we sent the client
    (クライアントに送信した MakeCredentialOptions を取得)
  2. Create callback so that lib can verify credential id is unique to this user
    (信任状 ID がこのユーザに固有であることを lib が検証できるように callback を作成。)
  3. Verify and make the credentials
    (認証情報を確認して作成)
  4. Store the credentials in db
    (資格情報を db に格納)
  5. return "ok" to the client
    (クライアントに "ok" を返す)

移行メモ(誤字): 元ページの「the clientt」は「the client」の誤りである
(引用元のコード コメントに由来する可能性もあるため、
本文では修正のうえここに注記する)。

AssertionOptionsPost

  1. Get from DB (DB から取得)
    • user (ユーザ)
    • registered credentials (登録済み資格情報)
  2. Create options (AssertionOptions を作成)
  3. Temporarily store options, session/in-memory cache/redis/db
    (session/in-memory cache/redis/db の一時保存オプション)
  4. Return options to client
    (クライアントに AssertionOptions を返す)

MakeAssertion

  1. Get the assertion options we sent the client
    (クライアントに送信した AssertionOptions を取得)
  2. Get from database (DB から取得)
    • Registered credential (登録済み資格情報)
    • Credential counter (資格情報カウンタ)
  3. Create callback to check if userhandle owns the credentialId
    (userhandle が credentialId を所有しているかどうかを確認する callback を作成)
  4. Make the assertion
    (アサーションをする)
  5. Store the updated counter
    (更新したカウンタを保存)
  6. return OK to client
    (クライアントに "ok" を返す)

補足(options の一時保存が要になる): 4 つの手順すべてに
「送った options を取り出す」という段が入っている点が要点である。
WebAuthn の検証はサーバが直前に発行した challenge との照合が前提なので、
options をセッション等に保持しておかないと
リプレイ攻撃を防げない。
ステートレスにしたい場合は、challenge を署名付きトークンにして
クライアントに預ける方式を取る。

参考

abergs/fido2-net-lib

GitHub

abergs/fido2-net-lib: FIDO2 .NET library for FIDO2 / WebAuthn Attestation and Assertion using .NET
https://github.com/abergs/fido2-net-lib

FIDO2 .NET lib Demo

Ideas Of Anders Åberg

Latest Posts
http://ideasof.andersaberg.com/

過去ログ

セットアップ

https://twitter.com/openhishopjpo/status/1101432292419895296

分析

現在、分析中。

フィードバック

Open棟梁への実装結果

Library

https://github.com/OpenTouryoProject/MultiPurposeAuthSite/tree/develop/root/programs/CommonLibrary/Extensions/FIDO

  • DataProvider.cs
  • WebAuthnHelper.cs

HTML + WebAPI

移行メモ(表記): 元ページの見出しは「HTPM + WebAPI」だったが、
挙げられているのが Razor ビュー(.cshtml)とコントローラーであることから
「HTML + WebAPI」の誤りと判断して修正した。

Script

本 Wiki 内


Tags: IT国際標準, 認証基盤

NetDevInfraWiki

マイクロソフト系技術情報 Wiki
Open 棟梁 Wiki

(未着手)

開発基盤部会 Wiki

移行管理: DONETODO

Clone this wiki locally