ホーム › Security.Cryptography › CertAddCTLContextToStore
CertAddCTLContextToStore
関数CTLコンテキストをストアに追加する。
シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CertAddCTLContextToStore(
HCERTSTORE hCertStore, // optional
CTL_CONTEXT* pCtlContext,
DWORD dwAddDisposition,
CTL_CONTEXT** ppStoreContext // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hCertStore | HCERTSTORE | inoptional | 証明書ストアのハンドル。 | ||||||||||||||||
| pCtlContext | CTL_CONTEXT* | in | ストアに追加する CTL_CONTEXT 構造体へのポインター。 | ||||||||||||||||
| dwAddDisposition | DWORD | in | 一致する CTL、または一致する CTL へのリンクがストアに既に存在する場合に実行する処理を指定します。現在定義されている disposition の値とその用途は次のとおりです。
| ||||||||||||||||
| ppStoreContext | CTL_CONTEXT** | outoptional | デコードされた CTL コンテキスト へのポインターへのポインター。この省略可能なパラメーターは NULL にすることができ、その場合は呼び出し元のアプリケーションが、追加された CTL または既存の CTL のコピーを必要としないことを示します。コピーが作成された場合、そのコンテキストは CertFreeCTLContext を使用して解放する必要があります。 |
戻り値の型: BOOL
公式ドキュメント
証明書信頼リスト (CTL) コンテキストを証明書ストアに追加します。
戻り値
関数が成功した場合、戻り値は TRUE です。
関数が失敗した場合、戻り値は FALSE です。呼び出される関数 CertAddEncodedCRLToStore および CertSetCRLContextProperty からのエラーが、この関数に伝播される場合があります。
拡張エラー情報を取得するには、 GetLastError を呼び出します。考えられるエラーコードの一部を以下に示します。
| Return code | Description |
|---|---|
| このエラーは、CERT_STORE_ADD_NEW が設定されていて CTL がストアに存在する場合、または CERT_STORE_ADD_NEWER が設定されていて、追加する CTL の ThisUpdate の日付以上の ThisUpdate の日付を持つ CTL がストアに存在する場合に返されます。 | |
| dwAddDisposition パラメーターに無効な add disposition が指定されました。 |
解説(Remarks)
CTL コンテキストは CertDuplicateCTLContext を使用して複製されるのではありません。代わりに、新しいコピーが作成されてストアに追加されます。エンコードされた CTL に加えて、コンテキストのプロパティもコピーされます。
証明書ストアから CTL コンテキストを削除するには、CertDeleteCTLFromStore 関数を使用します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CertAddCTLContextToStore(
HCERTSTORE hCertStore, // optional
CTL_CONTEXT* pCtlContext,
DWORD dwAddDisposition,
CTL_CONTEXT** ppStoreContext // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CertAddCTLContextToStore(
IntPtr hCertStore, // HCERTSTORE optional
IntPtr pCtlContext, // CTL_CONTEXT*
uint dwAddDisposition, // DWORD
IntPtr ppStoreContext // CTL_CONTEXT** optional, out
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CertAddCTLContextToStore(
hCertStore As IntPtr, ' HCERTSTORE optional
pCtlContext As IntPtr, ' CTL_CONTEXT*
dwAddDisposition As UInteger, ' DWORD
ppStoreContext As IntPtr ' CTL_CONTEXT** optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hCertStore : HCERTSTORE optional
' pCtlContext : CTL_CONTEXT*
' dwAddDisposition : DWORD
' ppStoreContext : CTL_CONTEXT** optional, out
Declare PtrSafe Function CertAddCTLContextToStore Lib "crypt32" ( _
ByVal hCertStore As LongPtr, _
ByVal pCtlContext As LongPtr, _
ByVal dwAddDisposition As Long, _
ByVal ppStoreContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CertAddCTLContextToStore = ctypes.windll.crypt32.CertAddCTLContextToStore
CertAddCTLContextToStore.restype = wintypes.BOOL
CertAddCTLContextToStore.argtypes = [
wintypes.HANDLE, # hCertStore : HCERTSTORE optional
ctypes.c_void_p, # pCtlContext : CTL_CONTEXT*
wintypes.DWORD, # dwAddDisposition : DWORD
ctypes.c_void_p, # ppStoreContext : CTL_CONTEXT** optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CertAddCTLContextToStore = Fiddle::Function.new(
lib['CertAddCTLContextToStore'],
[
Fiddle::TYPE_VOIDP, # hCertStore : HCERTSTORE optional
Fiddle::TYPE_VOIDP, # pCtlContext : CTL_CONTEXT*
-Fiddle::TYPE_INT, # dwAddDisposition : DWORD
Fiddle::TYPE_VOIDP, # ppStoreContext : CTL_CONTEXT** optional, out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CertAddCTLContextToStore(
hCertStore: *mut core::ffi::c_void, // HCERTSTORE optional
pCtlContext: *mut CTL_CONTEXT, // CTL_CONTEXT*
dwAddDisposition: u32, // DWORD
ppStoreContext: *mut *mut CTL_CONTEXT // CTL_CONTEXT** optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern bool CertAddCTLContextToStore(IntPtr hCertStore, IntPtr pCtlContext, uint dwAddDisposition, IntPtr ppStoreContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertAddCTLContextToStore' -Namespace Win32 -PassThru
# $api::CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext)#uselib "CRYPT32.dll"
#func global CertAddCTLContextToStore "CertAddCTLContextToStore" sptr, sptr, sptr, sptr
; CertAddCTLContextToStore hCertStore, varptr(pCtlContext), dwAddDisposition, varptr(ppStoreContext) ; 戻り値は stat
; hCertStore : HCERTSTORE optional -> "sptr"
; pCtlContext : CTL_CONTEXT* -> "sptr"
; dwAddDisposition : DWORD -> "sptr"
; ppStoreContext : CTL_CONTEXT** optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CRYPT32.dll" #cfunc global CertAddCTLContextToStore "CertAddCTLContextToStore" sptr, var, int, var ; res = CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext) ; hCertStore : HCERTSTORE optional -> "sptr" ; pCtlContext : CTL_CONTEXT* -> "var" ; dwAddDisposition : DWORD -> "int" ; ppStoreContext : CTL_CONTEXT** optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CertAddCTLContextToStore "CertAddCTLContextToStore" sptr, sptr, int, sptr ; res = CertAddCTLContextToStore(hCertStore, varptr(pCtlContext), dwAddDisposition, varptr(ppStoreContext)) ; hCertStore : HCERTSTORE optional -> "sptr" ; pCtlContext : CTL_CONTEXT* -> "sptr" ; dwAddDisposition : DWORD -> "int" ; ppStoreContext : CTL_CONTEXT** optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CertAddCTLContextToStore(HCERTSTORE hCertStore, CTL_CONTEXT* pCtlContext, DWORD dwAddDisposition, CTL_CONTEXT** ppStoreContext) #uselib "CRYPT32.dll" #cfunc global CertAddCTLContextToStore "CertAddCTLContextToStore" intptr, var, int, var ; res = CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext) ; hCertStore : HCERTSTORE optional -> "intptr" ; pCtlContext : CTL_CONTEXT* -> "var" ; dwAddDisposition : DWORD -> "int" ; ppStoreContext : CTL_CONTEXT** optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CertAddCTLContextToStore(HCERTSTORE hCertStore, CTL_CONTEXT* pCtlContext, DWORD dwAddDisposition, CTL_CONTEXT** ppStoreContext) #uselib "CRYPT32.dll" #cfunc global CertAddCTLContextToStore "CertAddCTLContextToStore" intptr, intptr, int, intptr ; res = CertAddCTLContextToStore(hCertStore, varptr(pCtlContext), dwAddDisposition, varptr(ppStoreContext)) ; hCertStore : HCERTSTORE optional -> "intptr" ; pCtlContext : CTL_CONTEXT* -> "intptr" ; dwAddDisposition : DWORD -> "int" ; ppStoreContext : CTL_CONTEXT** optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCertAddCTLContextToStore = crypt32.NewProc("CertAddCTLContextToStore")
)
// hCertStore (HCERTSTORE optional), pCtlContext (CTL_CONTEXT*), dwAddDisposition (DWORD), ppStoreContext (CTL_CONTEXT** optional, out)
r1, _, err := procCertAddCTLContextToStore.Call(
uintptr(hCertStore),
uintptr(pCtlContext),
uintptr(dwAddDisposition),
uintptr(ppStoreContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CertAddCTLContextToStore(
hCertStore: THandle; // HCERTSTORE optional
pCtlContext: Pointer; // CTL_CONTEXT*
dwAddDisposition: DWORD; // DWORD
ppStoreContext: Pointer // CTL_CONTEXT** optional, out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CertAddCTLContextToStore';result := DllCall("CRYPT32\CertAddCTLContextToStore"
, "Ptr", hCertStore ; HCERTSTORE optional
, "Ptr", pCtlContext ; CTL_CONTEXT*
, "UInt", dwAddDisposition ; DWORD
, "Ptr", ppStoreContext ; CTL_CONTEXT** optional, out
, "Int") ; return: BOOL●CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext) = DLL("CRYPT32.dll", "bool CertAddCTLContextToStore(void*, void*, dword, void*)")
# 呼び出し: CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext)
# hCertStore : HCERTSTORE optional -> "void*"
# pCtlContext : CTL_CONTEXT* -> "void*"
# dwAddDisposition : DWORD -> "dword"
# ppStoreContext : CTL_CONTEXT** optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CertAddCTLContextToStore(
hCertStore: ?*anyopaque, // HCERTSTORE optional
pCtlContext: [*c]CTL_CONTEXT, // CTL_CONTEXT*
dwAddDisposition: u32, // DWORD
ppStoreContext: [*c][*c]CTL_CONTEXT // CTL_CONTEXT** optional, out
) callconv(std.os.windows.WINAPI) i32;proc CertAddCTLContextToStore(
hCertStore: pointer, # HCERTSTORE optional
pCtlContext: ptr CTL_CONTEXT, # CTL_CONTEXT*
dwAddDisposition: uint32, # DWORD
ppStoreContext: ptr CTL_CONTEXT # CTL_CONTEXT** optional, out
): int32 {.importc: "CertAddCTLContextToStore", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CertAddCTLContextToStore(
void* hCertStore, // HCERTSTORE optional
CTL_CONTEXT* pCtlContext, // CTL_CONTEXT*
uint dwAddDisposition, // DWORD
CTL_CONTEXT** ppStoreContext // CTL_CONTEXT** optional, out
);ccall((:CertAddCTLContextToStore, "CRYPT32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{CTL_CONTEXT}, UInt32, Ptr{CTL_CONTEXT}),
hCertStore, pCtlContext, dwAddDisposition, ppStoreContext)
# hCertStore : HCERTSTORE optional -> Ptr{Cvoid}
# pCtlContext : CTL_CONTEXT* -> Ptr{CTL_CONTEXT}
# dwAddDisposition : DWORD -> UInt32
# ppStoreContext : CTL_CONTEXT** optional, out -> Ptr{CTL_CONTEXT}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CertAddCTLContextToStore(
void* hCertStore,
void* pCtlContext,
uint32_t dwAddDisposition,
void* ppStoreContext);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext)
-- hCertStore : HCERTSTORE optional
-- pCtlContext : CTL_CONTEXT*
-- dwAddDisposition : DWORD
-- ppStoreContext : CTL_CONTEXT** optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CertAddCTLContextToStore = lib.func('__stdcall', 'CertAddCTLContextToStore', 'int32_t', ['void *', 'void *', 'uint32_t', 'void *']);
// CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext)
// hCertStore : HCERTSTORE optional -> 'void *'
// pCtlContext : CTL_CONTEXT* -> 'void *'
// dwAddDisposition : DWORD -> 'uint32_t'
// ppStoreContext : CTL_CONTEXT** optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CertAddCTLContextToStore: { parameters: ["pointer", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext)
// hCertStore : HCERTSTORE optional -> "pointer"
// pCtlContext : CTL_CONTEXT* -> "pointer"
// dwAddDisposition : DWORD -> "u32"
// ppStoreContext : CTL_CONTEXT** optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CertAddCTLContextToStore(
void* hCertStore,
void* pCtlContext,
uint32_t dwAddDisposition,
void* ppStoreContext);
C, "CRYPT32.dll");
// $ffi->CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext);
// hCertStore : HCERTSTORE optional
// pCtlContext : CTL_CONTEXT*
// dwAddDisposition : DWORD
// ppStoreContext : CTL_CONTEXT** optional, out
// 構造体/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);
boolean CertAddCTLContextToStore(
Pointer hCertStore, // HCERTSTORE optional
Pointer pCtlContext, // CTL_CONTEXT*
int dwAddDisposition, // DWORD
Pointer ppStoreContext // CTL_CONTEXT** optional, out
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CertAddCTLContextToStore = CertAddCTLContextToStore(
hCertStore : Void*, # HCERTSTORE optional
pCtlContext : CTL_CONTEXT*, # CTL_CONTEXT*
dwAddDisposition : UInt32, # DWORD
ppStoreContext : CTL_CONTEXT** # CTL_CONTEXT** optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CertAddCTLContextToStoreNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, Pointer<Void>);
typedef CertAddCTLContextToStoreDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>);
final CertAddCTLContextToStore = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CertAddCTLContextToStoreNative, CertAddCTLContextToStoreDart>('CertAddCTLContextToStore');
// hCertStore : HCERTSTORE optional -> Pointer<Void>
// pCtlContext : CTL_CONTEXT* -> Pointer<Void>
// dwAddDisposition : DWORD -> Uint32
// ppStoreContext : CTL_CONTEXT** optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CertAddCTLContextToStore(
hCertStore: THandle; // HCERTSTORE optional
pCtlContext: Pointer; // CTL_CONTEXT*
dwAddDisposition: DWORD; // DWORD
ppStoreContext: Pointer // CTL_CONTEXT** optional, out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CertAddCTLContextToStore';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CertAddCTLContextToStore"
c_CertAddCTLContextToStore :: Ptr () -> Ptr () -> Word32 -> Ptr () -> IO CInt
-- hCertStore : HCERTSTORE optional -> Ptr ()
-- pCtlContext : CTL_CONTEXT* -> Ptr ()
-- dwAddDisposition : DWORD -> Word32
-- ppStoreContext : CTL_CONTEXT** optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let certaddctlcontexttostore =
foreign "CertAddCTLContextToStore"
((ptr void) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hCertStore : HCERTSTORE optional -> (ptr void) *)
(* pCtlContext : CTL_CONTEXT* -> (ptr void) *)
(* dwAddDisposition : DWORD -> uint32_t *)
(* ppStoreContext : CTL_CONTEXT** optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CertAddCTLContextToStore" cert-add-ctlcontext-to-store :convention :stdcall) :int32
(h-cert-store :pointer) ; HCERTSTORE optional
(p-ctl-context :pointer) ; CTL_CONTEXT*
(dw-add-disposition :uint32) ; DWORD
(pp-store-context :pointer)) ; CTL_CONTEXT** optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CertAddCTLContextToStore = Win32::API::More->new('CRYPT32',
'BOOL CertAddCTLContextToStore(HANDLE hCertStore, LPVOID pCtlContext, DWORD dwAddDisposition, LPVOID ppStoreContext)');
# my $ret = $CertAddCTLContextToStore->Call($hCertStore, $pCtlContext, $dwAddDisposition, $ppStoreContext);
# hCertStore : HCERTSTORE optional -> HANDLE
# pCtlContext : CTL_CONTEXT* -> LPVOID
# dwAddDisposition : DWORD -> DWORD
# ppStoreContext : CTL_CONTEXT** optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f CertAddEncodedCTLToStore — エンコードされたCTLをストアに追加する。
- f CertSetCTLContextProperty — CTLコンテキストの指定プロパティを設定する。
使用する型