HTTP_REQUEST_AUTH_INFO
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 | ||||
|---|---|---|---|---|---|---|---|---|---|
| AuthStatus | HTTP_AUTH_STATUS | 4 | +0 | +0 | リクエストの最終的な認証状態を示す HTTP_AUTH_STATUS 列挙型のメンバーです。 認証状態が HttpAuthStatusSuccess でない場合、アプリケーションは AuthStatus、SecStatus、AuthType を除くこの構造体のメンバーを無視してください。 | ||||
| SecStatus | HRESULT | 4 | +4 | +4 | AuthStatus メンバーが HttpAuthStatusFailure の場合に、セキュリティ上の失敗状態を示す SECURITY_STATUS 値です。 | ||||
| Flags | DWORD | 4 | +8 | +8 | 次の認証属性を示す認証フラグです。
| ||||
| AuthType | HTTP_REQUEST_AUTH_TYPE | 4 | +12 | +12 | リクエストに対して試行された、または確立された認証スキームを示す HTTP_REQUEST_AUTH_TYPE 列挙型のメンバーです。 | ||||
| AccessToken | HANDLE | 8/4 | +16 | +16 | 受信側プロセスが認証済みクライアントを偽装するために使用できる、クライアントトークンのハンドルです。 トークンのハンドルは、不要になった時点で CloseHandle を呼び出して閉じてください。このトークンはリクエストの有効期間中のみ有効です。トークンの有効期限が切れた場合、アプリケーションは最初の 401 チャレンジを再生成して再認証できます。 | ||||
| ContextAttributes | DWORD | 4 | +24 | +20 | アクセストークンのクライアントコンテキスト属性です。 | ||||
| PackedContextLength | DWORD | 4 | +28 | +24 | PackedContext の長さ (バイト単位) です。 | ||||
| PackedContextType | DWORD | 4 | +32 | +28 | PackedContext メンバーに格納されているコンテキストの種類です。 | ||||
| PackedContext | void* | 8/4 | +40 | +32 | 認証の種類に対応するセキュリティコンテキストです。 アプリケーションは、SSPI の QueryContextAttributes API を呼び出して、パックされたコンテキストの属性を照会できます。ただし、指定された AuthType のセキュリティパッケージに対する資格情報ハンドルを取得しておく必要があります。 シリアル化されたコンテキストが不要になった時点で、アプリケーションは SSPI の FreeContextBuffer API を呼び出して解放してください。 | ||||
| MutualAuthDataLength | DWORD | 4 | +48 | +36 | pMutualAuthData メンバーの長さ (バイト単位) です。 | ||||
| pMutualAuthData | LPSTR | 8/4 | +56 | +40 | WWW-Authenticate ヘッダーで使用される、Base64 でエンコードされた相互認証データです。 | ||||
| PackageNameLength | WORD | 2 | +64 | +44 | pPackageNameのバイト長(WORD)である。 | ||||
| pPackageName | LPWSTR | 8/4 | +72 | +48 | 使用された認証パッケージ名を示すワイド文字列ポインターである。 |
公式ドキュメント
HTTP_REQUEST_AUTH_INFO 構造体は、リクエストの認証状態と、受信側プロセスが認証済みクライアントを偽装するために使用できるクライアントトークンのハンドルを格納します。
この構造体は HTTP_REQUEST_INFO 構造体に含まれます。
解説(Remarks)
HTTP バージョン 2.0 以降、HTTP_REQUEST 構造体には HTTP_REQUEST_INFO 構造体が含まれます。リクエスト情報の種類が HttpRequestInfoTypeAuth の場合、HTTP_REQUEST_INFO 構造体の pVoid メンバーは HTTP_REQUEST_AUTH_INFO を指します。
アプリケーションがこの構造体を伴うリクエストを受け取り、そのリクエストがまだ認証されていない場合、HTTP_MULTIPLE_KNOWN_HEADERS 構造体に必要な WWW-Authenticate ヘッダーのセットを設定して、最初の 401 チャレンジを送信できます。HTTP Server API は認証ハンドシェイクを完了すると、HTTP_REQUEST_AUTH_INFO 構造体を設定し、リクエストとともに再度アプリケーションへ渡します。クライアント ID を表すアクセストークンのハンドルは、HTTP Server API によってこの構造体に格納されます。
コンテキスト属性
ContextAttributes メンバーは SSPI ベースのスキーム向けに用意されています。たとえば SSPI アプリケーションは、相互認証されたセッションで ASC_RET_MUTUAL_AUTH が設定されているかどうかを判断できます。
HTTP Server API は、PackedContext メンバーのコンテキストの有効期限を提供しません。アプリケーションによっては、特定の状況で有効期限が必要になることがあります。たとえば、NTLM の資格情報キャッシュが有効で、アプリケーションがキャッシュされたコンテキストの有効期限を照会する場合などです。サーバーアプリケーションがアクセストークンに関連付けられた基になるクライアントコンテキストの有効期限を必要とする場合は、パックされたコンテキストを受け取り、SECPKG_ATTR_LIFESPAN を指定して QueryContextAttributes を呼び出すことができます。
相互認証データ
既定では、HTTP Server API が相互認証データを最終的な 200 応答に追加します。一般に、サーバーアプリケーションが相互認証データを送信する必要はありません。
ただし、アプリケーションが相互認証データを受け取り、最終的な応答とともに送信することもできます。HTTP_SERVER_AUTHENTICATION_INFO 構造体の ReceiveMutualAuth メンバーが true に設定されている場合、アプリケーションは認証済みリクエストとともに相互認証用のサーバー資格情報を受け取ります。
pMutualAuthData メンバーで提供される相互認証データには、ヘッダー名を除いた WWW-Authenticate ヘッダーの値がそのまま格納されます。たとえば、pMutualAuthData は "Negotiate ade02938481eca" を指します。アプリケーションは、提供された pMutualAuthData を応答ヘッダーの値として付加することで、WWW-Authenticate ヘッダーを構築します。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での定義
#include <windows.h>
// HTTP_REQUEST_AUTH_INFO (x64 80 / x86 52 バイト)
typedef struct HTTP_REQUEST_AUTH_INFO {
HTTP_AUTH_STATUS AuthStatus;
HRESULT SecStatus;
DWORD Flags;
HTTP_REQUEST_AUTH_TYPE AuthType;
HANDLE AccessToken;
DWORD ContextAttributes;
DWORD PackedContextLength;
DWORD PackedContextType;
void* PackedContext;
DWORD MutualAuthDataLength;
LPSTR pMutualAuthData;
WORD PackageNameLength;
LPWSTR pPackageName;
} HTTP_REQUEST_AUTH_INFO;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct HTTP_REQUEST_AUTH_INFO
{
public int AuthStatus;
public int SecStatus;
public uint Flags;
public int AuthType;
public IntPtr AccessToken;
public uint ContextAttributes;
public uint PackedContextLength;
public uint PackedContextType;
public IntPtr PackedContext;
public uint MutualAuthDataLength;
public IntPtr pMutualAuthData;
public ushort PackageNameLength;
public IntPtr pPackageName;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure HTTP_REQUEST_AUTH_INFO
Public AuthStatus As Integer
Public SecStatus As Integer
Public Flags As UInteger
Public AuthType As Integer
Public AccessToken As IntPtr
Public ContextAttributes As UInteger
Public PackedContextLength As UInteger
Public PackedContextType As UInteger
Public PackedContext As IntPtr
Public MutualAuthDataLength As UInteger
Public pMutualAuthData As IntPtr
Public PackageNameLength As UShort
Public pPackageName As IntPtr
End Structureimport ctypes
from ctypes import wintypes
class HTTP_REQUEST_AUTH_INFO(ctypes.Structure):
_fields_ = [
("AuthStatus", ctypes.c_int),
("SecStatus", ctypes.c_int),
("Flags", wintypes.DWORD),
("AuthType", ctypes.c_int),
("AccessToken", ctypes.c_void_p),
("ContextAttributes", wintypes.DWORD),
("PackedContextLength", wintypes.DWORD),
("PackedContextType", wintypes.DWORD),
("PackedContext", ctypes.c_void_p),
("MutualAuthDataLength", wintypes.DWORD),
("pMutualAuthData", ctypes.c_void_p),
("PackageNameLength", ctypes.c_ushort),
("pPackageName", ctypes.c_void_p),
]#[repr(C)]
pub struct HTTP_REQUEST_AUTH_INFO {
pub AuthStatus: i32,
pub SecStatus: i32,
pub Flags: u32,
pub AuthType: i32,
pub AccessToken: *mut core::ffi::c_void,
pub ContextAttributes: u32,
pub PackedContextLength: u32,
pub PackedContextType: u32,
pub PackedContext: *mut core::ffi::c_void,
pub MutualAuthDataLength: u32,
pub pMutualAuthData: *mut core::ffi::c_void,
pub PackageNameLength: u16,
pub pPackageName: *mut core::ffi::c_void,
}import "golang.org/x/sys/windows"
type HTTP_REQUEST_AUTH_INFO struct {
AuthStatus int32
SecStatus int32
Flags uint32
AuthType int32
AccessToken uintptr
ContextAttributes uint32
PackedContextLength uint32
PackedContextType uint32
PackedContext uintptr
MutualAuthDataLength uint32
pMutualAuthData uintptr
PackageNameLength uint16
pPackageName uintptr
}type
HTTP_REQUEST_AUTH_INFO = record
AuthStatus: Integer;
SecStatus: Integer;
Flags: DWORD;
AuthType: Integer;
AccessToken: Pointer;
ContextAttributes: DWORD;
PackedContextLength: DWORD;
PackedContextType: DWORD;
PackedContext: Pointer;
MutualAuthDataLength: DWORD;
pMutualAuthData: Pointer;
PackageNameLength: Word;
pPackageName: Pointer;
end;const HTTP_REQUEST_AUTH_INFO = extern struct {
AuthStatus: i32,
SecStatus: i32,
Flags: u32,
AuthType: i32,
AccessToken: ?*anyopaque,
ContextAttributes: u32,
PackedContextLength: u32,
PackedContextType: u32,
PackedContext: ?*anyopaque,
MutualAuthDataLength: u32,
pMutualAuthData: ?*anyopaque,
PackageNameLength: u16,
pPackageName: ?*anyopaque,
};type
HTTP_REQUEST_AUTH_INFO {.bycopy.} = object
AuthStatus: int32
SecStatus: int32
Flags: uint32
AuthType: int32
AccessToken: pointer
ContextAttributes: uint32
PackedContextLength: uint32
PackedContextType: uint32
PackedContext: pointer
MutualAuthDataLength: uint32
pMutualAuthData: pointer
PackageNameLength: uint16
pPackageName: pointerstruct HTTP_REQUEST_AUTH_INFO
{
int AuthStatus;
int SecStatus;
uint Flags;
int AuthType;
void* AccessToken;
uint ContextAttributes;
uint PackedContextLength;
uint PackedContextType;
void* PackedContext;
uint MutualAuthDataLength;
void* pMutualAuthData;
ushort PackageNameLength;
void* pPackageName;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; HTTP_REQUEST_AUTH_INFO サイズ: 52 バイト(x86)
dim st, 13 ; 4byte整数×13(構造体サイズ 52 / 4 切り上げ)
; AuthStatus : HTTP_AUTH_STATUS (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; SecStatus : HRESULT (+4, 4byte) st.1 = 値 / 値 = st.1 (lpoke/lpeek も可)
; Flags : DWORD (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; AuthType : HTTP_REQUEST_AUTH_TYPE (+12, 4byte) st.3 = 値 / 値 = st.3 (lpoke/lpeek も可)
; AccessToken : HANDLE (+16, 4byte) st.4 = 値 / 値 = st.4 (lpoke/lpeek も可)
; ContextAttributes : DWORD (+20, 4byte) st.5 = 値 / 値 = st.5 (lpoke/lpeek も可)
; PackedContextLength : DWORD (+24, 4byte) st.6 = 値 / 値 = st.6 (lpoke/lpeek も可)
; PackedContextType : DWORD (+28, 4byte) st.7 = 値 / 値 = st.7 (lpoke/lpeek も可)
; PackedContext : void* (+32, 4byte) st.8 = 値 / 値 = st.8 (lpoke/lpeek も可)
; MutualAuthDataLength : DWORD (+36, 4byte) st.9 = 値 / 値 = st.9 (lpoke/lpeek も可)
; pMutualAuthData : LPSTR (+40, 4byte) st.10 = 値 / 値 = st.10 (lpoke/lpeek も可)
; PackageNameLength : WORD (+44, 2byte) wpoke st,44,値 / 値 = wpeek(st,44)
; pPackageName : LPWSTR (+48, 4byte) st.12 = 値 / 値 = st.12 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; HTTP_REQUEST_AUTH_INFO サイズ: 80 バイト(x64)
dim st, 20 ; 4byte整数×20(構造体サイズ 80 / 4 切り上げ)
; AuthStatus : HTTP_AUTH_STATUS (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; SecStatus : HRESULT (+4, 4byte) st.1 = 値 / 値 = st.1 (lpoke/lpeek も可)
; Flags : DWORD (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; AuthType : HTTP_REQUEST_AUTH_TYPE (+12, 4byte) st.3 = 値 / 値 = st.3 (lpoke/lpeek も可)
; AccessToken : HANDLE (+16, 8byte) qpoke st,16,値 / qpeek(st,16) ※IronHSPのみ。3.7/3.8は lpoke st,16,下位 : lpoke st,20,上位
; ContextAttributes : DWORD (+24, 4byte) st.6 = 値 / 値 = st.6 (lpoke/lpeek も可)
; PackedContextLength : DWORD (+28, 4byte) st.7 = 値 / 値 = st.7 (lpoke/lpeek も可)
; PackedContextType : DWORD (+32, 4byte) st.8 = 値 / 値 = st.8 (lpoke/lpeek も可)
; PackedContext : void* (+40, 8byte) qpoke st,40,値 / qpeek(st,40) ※IronHSPのみ。3.7/3.8は lpoke st,40,下位 : lpoke st,44,上位
; MutualAuthDataLength : DWORD (+48, 4byte) st.12 = 値 / 値 = st.12 (lpoke/lpeek も可)
; pMutualAuthData : LPSTR (+56, 8byte) qpoke st,56,値 / qpeek(st,56) ※IronHSPのみ。3.7/3.8は lpoke st,56,下位 : lpoke st,60,上位
; PackageNameLength : WORD (+64, 2byte) wpoke st,64,値 / 値 = wpeek(st,64)
; pPackageName : LPWSTR (+72, 8byte) qpoke st,72,値 / qpeek(st,72) ※IronHSPのみ。3.7/3.8は lpoke st,72,下位 : lpoke st,76,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global HTTP_REQUEST_AUTH_INFO
#field int AuthStatus
#field int SecStatus
#field int Flags
#field int AuthType
#field intptr AccessToken
#field int ContextAttributes
#field int PackedContextLength
#field int PackedContextType
#field intptr PackedContext
#field int MutualAuthDataLength
#field intptr pMutualAuthData
#field short PackageNameLength
#field intptr pPackageName
#endstruct
stdim st, HTTP_REQUEST_AUTH_INFO ; NSTRUCT 変数を確保
st->AuthStatus = 100
mes "AuthStatus=" + st->AuthStatus