ダイジェスト認証 <digestAuthentication>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

<digestAuthentication> 要素には、インターネット インフォメーション サービス (IIS) 7.0 のダイジェスト認証モジュールの構成設定が含まれます。この要素を構成して、ダイジェスト認証を有効または無効にしたり、オプションでダイジェスト認証領域を指定することができます。

ダイジェスト認証は基本認証ほど一般的に使用されてはいませんが、基本認証や Windows 認証よりも明らかに優れた利点がいくつかあります。暗号化されていない通信手段に対して基本認証を使用する主な欠点は、クライアントのユーザー名とパスワードが Base 64 エンコード プレーンテキスト メッセージとして送信されるため、悪意のあるユーザーが通信を非常に簡単に傍受してユーザー名とパスワードを取得することができることです。Windows 認証ではこの問題をさまざまなセキュリティ オプションで解決していますが、Windows 認証は通常、インターネット環境では機能しません。

ダイジェスト認証では、次の方法で上記の両認証の制限に対応します。

  • 基本認証で使用されているプレーンテキスト スキームとは異なり、ダイジェスト認証ではクライアントがクライアント情報のハッシュを通信チャネル上で送信するため、クライアントのユーザー名とパスワードがネットワーク上に送信されることはありません。
  • ダイジェスト認証はインターネット上で有効に機能するため、Windows 認証よりもインターネット環境に適しています。

: ダイジェスト認証では、クライアントのユーザー名とパスワードのみが保護されます。HTTP 通信の本文はプレーンテキストのままです。通信の本文をセキュリティで保護するには、SSL (Secure Sockets Layer) を使用してください。

互換性

  IIS 7.0 IIS 6.0
注意 <digestAuthentication> は IIS 7.0 で新たに導入された要素です。

<digestAuthentication> 要素は、IIS 6.0 の AuthType および AuthFlags メタベース プロパティの一部に代わるものです。

セットアップ

IIS 7.0 の既定のインストールには、"ダイジェスト認証" 役割サービスは含まれません。ダイジェスト認証を IIS 7.0 で使用するには、この役割サービスをインストールして、Web サイトまたはアプリケーションで匿名認証を無効にし、代わりにダイジェスト認証を有効にする必要があります。

"ダイジェスト認証" 役割サービスをインストールする手順は次のとおりです。

Windows Server 2008

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [サーバー マネージャー] をクリックします。

  2. [サーバー マネージャー] ウィンドウのツリー表示で、[役割] を展開して [Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールして [役割サービスの追加] をクリックします。

  4. 役割サービスの追加ウィザードの [役割サービスの選択] ページで、[ダイジェスト認証] を選択して、[次へ] をクリックします。

    拡大

  5. [インストール オプションの確認] ページで [インストール] をクリックします。

  6. [結果] ページで [閉じる] をクリックします。

Windows Vista

  1. タスク バーで [スタート] ボタンをクリックし、[コントロール パネル] をクリックします。

  2. コントロール パネルで、[プログラムと機能][Windows の機能の有効化または無効化] の順にクリックします。

  3. [Internet Information Services][World Wide Web サービス][セキュリティ] の順に展開し、[ダイジェスト認証] を選択して [OK] をクリックします。

    拡大

方法

ダイジェスト認証を有効にして匿名認証を無効にする方法

  1. タスク バーで [スタート] ボタンをクリックし、[管理ツール] をポイントして [インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで当該サーバー名を展開して [サイト] を展開し、基本認証を有効にする Web サイト、Web アプリケーション、または Web サービスをクリックします。

  3. [ホーム] ウィンドウで、[セキュリティ] セクションまでスクロールして [認証] をダブルクリックします。

    拡大

  4. [認証] ウィンドウで [ダイジェスト認証] を選択し、[操作] ウィンドウの [有効にする] をクリックします。

  5. [認証] ウィンドウで [匿名認証] を選択し、[操作] ウィンドウの [無効にする] をクリックします。

    拡大

構成

<digestAuthentication> 要素は、サイト、アプリケーション、仮想ディレクトリ、および URL レベルで構成可能です。役割サービスをインストールすると、IIS 7.0 は次の構成設定を ApplicationHost.config ファイルに適用します。

<digestAuthentication enabled='false' />

属性

属性 説明
enabled オプションの Boolean 属性。


ダイジェスト認証を有効にするかどうかを指定します。

既定値は false です。
realm オプションの string 属性。

ダイジェスト認証の領域を指定します。

子要素

なし。

構成サンプル

次の構成サンプルでは、Web サイト、Web アプリケーション、または Web サービスでダイジェスト認証を有効にします。既定では、これらの設定を ApplicationHost.config ファイルに含める必要があり、これらの設定を <location> 要素に含めて、path 属性を使用して認証設定を適用する Web サイトまたはアプリケーションを定義する必要があります。

<security>
   <authentication>
      <anonymousAuthentication enabled="false" />
      <digestAuthentication enabled="true" />
   </authentication>
</security>

サンプル コード

次の例では、Contoso という名前のサイトで匿名認証を無効にしてから、ダイジェスト認証を有効にします。

AppCmd.exe

appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"False" /commit:apphost

appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/digestAuthentication /enabled:"True" /commit:apphost

: AppCmd.exe を使用してこれらの設定を構成する際には、commit パラメーターを APPHOST に設定する必要があります。それにより、ApplicationHost.config ファイル内の該当する location セクションに構成設定が適用されます。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample {

   private static void Main() {

      using(ServerManager serverManager = new ServerManager()) { 
         Configuration config = serverManager.GetApplicationHostConfiguration();

         ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso");
         anonymousAuthenticationSection["enabled"] = false;

         ConfigurationSection digestAuthenticationSection = config.GetSection("system.webServer/security/authentication/digestAuthentication", "Contoso");
         digestAuthenticationSection["enabled"] = true;

        serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample
   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration

      Dim anonymousAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso")
      anonymousAuthenticationSection("enabled") = False

      Dim digestAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/digestAuthentication", "Contoso")
      digestAuthenticationSection("enabled") = True

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
anonymousAuthenticationSection.Properties.Item("enabled").Value = false;

var digestAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/digestAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
digestAuthenticationSection.Properties.Item("enabled").Value = true;

adminManager.CommitChanges();

VBScript

Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
anonymousAuthenticationSection.Properties.Item("enabled").Value = False

Set digestAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/digestAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
digestAuthenticationSection.Properties.Item("enabled").Value = True

adminManager.CommitChanges()