Win32 API 日本語リファレンス
ホームSecurity.Cryptography › CertGetServerOcspResponseContext

CertGetServerOcspResponseContext

関数
サーバーOCSP応答から応答コンテキストを取得する。
DLLCRYPT32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// CRYPT32.dll
#include <windows.h>

CERT_SERVER_OCSP_RESPONSE_CONTEXT* CertGetServerOcspResponseContext(
    void* hServerOcspResponse,
    DWORD dwFlags,
    void* pvReserved   // optional
);

パラメーター

名前方向説明
hServerOcspResponsevoid*in応答コンテキストを取得する対象の OCSP サーバー応答ハンドルです。このハンドルは CertOpenServerOcspResponse 関数によって返されます。
dwFlagsDWORDinこのパラメーターは将来の使用のために予約されており、0 を指定する必要があります。
pvReservedvoid*optionalこのパラメーターは将来の使用のために予約されており、NULL を指定する必要があります。

戻り値の型: CERT_SERVER_OCSP_RESPONSE_CONTEXT*

公式ドキュメント

指定したハンドルに対する、ノンブロッキングで時刻的に有効な OCSP (online certificate status protocol) 応答コンテキストを取得します。

戻り値

関数が成功した場合、CERT_SERVER_OCSP_RESPONSE_CONTEXT 構造体へのポインターを返します。

応答が時刻的に有効であるためには、この関数呼び出しをホストしているシステムの現在時刻が、証明書失効リスト (CRL) コンテキストの次回更新時刻より前である必要があります。時刻的に有効な OCSP 応答が利用できない場合、この関数は NULL を返し、最終エラーを CRYPT_E_REVOCATION_OFFLINE に設定します。

証明書が OCSP レスポンダーによって認識されていない場合、この関数は NULL を返し、最終エラーを CRYPT_E_REVOCATION_OFFLINE に設定します。

解説(Remarks)

CertGetServerOcspResponseContext 関数を使用して OCSP 応答コンテキストへの複数の参照を作成する場合は、CertAddRefServerOcspResponseContext を呼び出して CERT_SERVER_OCSP_RESPONSE_CONTEXT 構造体の参照カウントをインクリメントする必要があります。構造体の使用が終わったら、CertFreeServerOcspResponseContext 関数を呼び出して解放する必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// CRYPT32.dll
#include <windows.h>

CERT_SERVER_OCSP_RESPONSE_CONTEXT* CertGetServerOcspResponseContext(
    void* hServerOcspResponse,
    DWORD dwFlags,
    void* pvReserved   // optional
);
[DllImport("CRYPT32.dll", ExactSpelling = true)]
static extern IntPtr CertGetServerOcspResponseContext(
    IntPtr hServerOcspResponse,   // void*
    uint dwFlags,   // DWORD
    IntPtr pvReserved   // void* optional
);
<DllImport("CRYPT32.dll", ExactSpelling:=True)>
Public Shared Function CertGetServerOcspResponseContext(
    hServerOcspResponse As IntPtr,   ' void*
    dwFlags As UInteger,   ' DWORD
    pvReserved As IntPtr   ' void* optional
) As IntPtr
End Function
' hServerOcspResponse : void*
' dwFlags : DWORD
' pvReserved : void* optional
Declare PtrSafe Function CertGetServerOcspResponseContext Lib "crypt32" ( _
    ByVal hServerOcspResponse As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal pvReserved As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CertGetServerOcspResponseContext = ctypes.windll.crypt32.CertGetServerOcspResponseContext
CertGetServerOcspResponseContext.restype = ctypes.c_void_p
CertGetServerOcspResponseContext.argtypes = [
    ctypes.POINTER(None),  # hServerOcspResponse : void*
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.POINTER(None),  # pvReserved : void* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CertGetServerOcspResponseContext = Fiddle::Function.new(
  lib['CertGetServerOcspResponseContext'],
  [
    Fiddle::TYPE_VOIDP,  # hServerOcspResponse : void*
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_VOIDP,  # pvReserved : void* optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "crypt32")]
extern "system" {
    fn CertGetServerOcspResponseContext(
        hServerOcspResponse: *mut (),  // void*
        dwFlags: u32,  // DWORD
        pvReserved: *mut ()  // void* optional
    ) -> *mut CERT_SERVER_OCSP_RESPONSE_CONTEXT;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CRYPT32.dll")]
public static extern IntPtr CertGetServerOcspResponseContext(IntPtr hServerOcspResponse, uint dwFlags, IntPtr pvReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertGetServerOcspResponseContext' -Namespace Win32 -PassThru
# $api::CertGetServerOcspResponseContext(hServerOcspResponse, dwFlags, pvReserved)
#uselib "CRYPT32.dll"
#func global CertGetServerOcspResponseContext "CertGetServerOcspResponseContext" sptr, sptr, sptr
; CertGetServerOcspResponseContext hServerOcspResponse, dwFlags, pvReserved   ; 戻り値は stat
; hServerOcspResponse : void* -> "sptr"
; dwFlags : DWORD -> "sptr"
; pvReserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CRYPT32.dll"
#cfunc global CertGetServerOcspResponseContext "CertGetServerOcspResponseContext" sptr, int, sptr
; res = CertGetServerOcspResponseContext(hServerOcspResponse, dwFlags, pvReserved)
; hServerOcspResponse : void* -> "sptr"
; dwFlags : DWORD -> "int"
; pvReserved : void* optional -> "sptr"
; CERT_SERVER_OCSP_RESPONSE_CONTEXT* CertGetServerOcspResponseContext(void* hServerOcspResponse, DWORD dwFlags, void* pvReserved)
#uselib "CRYPT32.dll"
#cfunc global CertGetServerOcspResponseContext "CertGetServerOcspResponseContext" intptr, int, intptr
; res = CertGetServerOcspResponseContext(hServerOcspResponse, dwFlags, pvReserved)
; hServerOcspResponse : void* -> "intptr"
; dwFlags : DWORD -> "int"
; pvReserved : void* optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertGetServerOcspResponseContext = crypt32.NewProc("CertGetServerOcspResponseContext")
)

// hServerOcspResponse (void*), dwFlags (DWORD), pvReserved (void* optional)
r1, _, err := procCertGetServerOcspResponseContext.Call(
	uintptr(hServerOcspResponse),
	uintptr(dwFlags),
	uintptr(pvReserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // CERT_SERVER_OCSP_RESPONSE_CONTEXT*
function CertGetServerOcspResponseContext(
  hServerOcspResponse: Pointer;   // void*
  dwFlags: DWORD;   // DWORD
  pvReserved: Pointer   // void* optional
): Pointer; stdcall;
  external 'CRYPT32.dll' name 'CertGetServerOcspResponseContext';
result := DllCall("CRYPT32\CertGetServerOcspResponseContext"
    , "Ptr", hServerOcspResponse   ; void*
    , "UInt", dwFlags   ; DWORD
    , "Ptr", pvReserved   ; void* optional
    , "Ptr")   ; return: CERT_SERVER_OCSP_RESPONSE_CONTEXT*
●CertGetServerOcspResponseContext(hServerOcspResponse, dwFlags, pvReserved) = DLL("CRYPT32.dll", "void* CertGetServerOcspResponseContext(void*, dword, void*)")
# 呼び出し: CertGetServerOcspResponseContext(hServerOcspResponse, dwFlags, pvReserved)
# hServerOcspResponse : void* -> "void*"
# dwFlags : DWORD -> "dword"
# pvReserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "crypt32" fn CertGetServerOcspResponseContext(
    hServerOcspResponse: ?*anyopaque, // void*
    dwFlags: u32, // DWORD
    pvReserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) [*c]CERT_SERVER_OCSP_RESPONSE_CONTEXT;
proc CertGetServerOcspResponseContext(
    hServerOcspResponse: pointer,  # void*
    dwFlags: uint32,  # DWORD
    pvReserved: pointer  # void* optional
): ptr CERT_SERVER_OCSP_RESPONSE_CONTEXT {.importc: "CertGetServerOcspResponseContext", stdcall, dynlib: "CRYPT32.dll".}
pragma(lib, "crypt32");
extern(Windows)
CERT_SERVER_OCSP_RESPONSE_CONTEXT* CertGetServerOcspResponseContext(
    void* hServerOcspResponse,   // void*
    uint dwFlags,   // DWORD
    void* pvReserved   // void* optional
);
ccall((:CertGetServerOcspResponseContext, "CRYPT32.dll"), stdcall, Ptr{CERT_SERVER_OCSP_RESPONSE_CONTEXT},
      (Ptr{Cvoid}, UInt32, Ptr{Cvoid}),
      hServerOcspResponse, dwFlags, pvReserved)
# hServerOcspResponse : void* -> Ptr{Cvoid}
# dwFlags : DWORD -> UInt32
# pvReserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void* CertGetServerOcspResponseContext(
    void* hServerOcspResponse,
    uint32_t dwFlags,
    void* pvReserved);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CertGetServerOcspResponseContext(hServerOcspResponse, dwFlags, pvReserved)
-- hServerOcspResponse : void*
-- dwFlags : DWORD
-- pvReserved : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CertGetServerOcspResponseContext = lib.func('__stdcall', 'CertGetServerOcspResponseContext', 'void *', ['void *', 'uint32_t', 'void *']);
// CertGetServerOcspResponseContext(hServerOcspResponse, dwFlags, pvReserved)
// hServerOcspResponse : void* -> 'void *'
// dwFlags : DWORD -> 'uint32_t'
// pvReserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CRYPT32.dll", {
  CertGetServerOcspResponseContext: { parameters: ["pointer", "u32", "pointer"], result: "pointer" },
});
// lib.symbols.CertGetServerOcspResponseContext(hServerOcspResponse, dwFlags, pvReserved)
// hServerOcspResponse : void* -> "pointer"
// dwFlags : DWORD -> "u32"
// pvReserved : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* CertGetServerOcspResponseContext(
    void* hServerOcspResponse,
    uint32_t dwFlags,
    void* pvReserved);
C, "CRYPT32.dll");
// $ffi->CertGetServerOcspResponseContext(hServerOcspResponse, dwFlags, pvReserved);
// hServerOcspResponse : void*
// dwFlags : DWORD
// pvReserved : void* optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Crypt32 extends StdCallLibrary {
    Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
    Pointer CertGetServerOcspResponseContext(
        Pointer hServerOcspResponse,   // void*
        int dwFlags,   // DWORD
        Pointer pvReserved   // void* optional
    );
}
@[Link("crypt32")]
lib LibCRYPT32
  fun CertGetServerOcspResponseContext = CertGetServerOcspResponseContext(
    hServerOcspResponse : Void*,   # void*
    dwFlags : UInt32,   # DWORD
    pvReserved : Void*   # void* optional
  ) : CERT_SERVER_OCSP_RESPONSE_CONTEXT*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CertGetServerOcspResponseContextNative = Pointer<Void> Function(Pointer<Void>, Uint32, Pointer<Void>);
typedef CertGetServerOcspResponseContextDart = Pointer<Void> Function(Pointer<Void>, int, Pointer<Void>);
final CertGetServerOcspResponseContext = DynamicLibrary.open('CRYPT32.dll')
    .lookupFunction<CertGetServerOcspResponseContextNative, CertGetServerOcspResponseContextDart>('CertGetServerOcspResponseContext');
// hServerOcspResponse : void* -> Pointer<Void>
// dwFlags : DWORD -> Uint32
// pvReserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CertGetServerOcspResponseContext(
  hServerOcspResponse: Pointer;   // void*
  dwFlags: DWORD;   // DWORD
  pvReserved: Pointer   // void* optional
): Pointer; stdcall;
  external 'CRYPT32.dll' name 'CertGetServerOcspResponseContext';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CertGetServerOcspResponseContext"
  c_CertGetServerOcspResponseContext :: Ptr () -> Word32 -> Ptr () -> IO (Ptr ())
-- hServerOcspResponse : void* -> Ptr ()
-- dwFlags : DWORD -> Word32
-- pvReserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let certgetserverocspresponsecontext =
  foreign "CertGetServerOcspResponseContext"
    ((ptr void) @-> uint32_t @-> (ptr void) @-> returning (ptr void))
(* hServerOcspResponse : void* -> (ptr void) *)
(* dwFlags : DWORD -> uint32_t *)
(* pvReserved : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)

(cffi:defcfun ("CertGetServerOcspResponseContext" cert-get-server-ocsp-response-context :convention :stdcall) :pointer
  (h-server-ocsp-response :pointer)   ; void*
  (dw-flags :uint32)   ; DWORD
  (pv-reserved :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CertGetServerOcspResponseContext = Win32::API::More->new('CRYPT32',
    'LPVOID CertGetServerOcspResponseContext(LPVOID hServerOcspResponse, DWORD dwFlags, LPVOID pvReserved)');
# my $ret = $CertGetServerOcspResponseContext->Call($hServerOcspResponse, $dwFlags, $pvReserved);
# hServerOcspResponse : void* -> LPVOID
# dwFlags : DWORD -> DWORD
# pvReserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型