> For the complete documentation index, see [llms.txt](https://docs.scepman.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scepman.com/ja/zheng-ming-shu-guan-li/api-certificates/scepmanclient.md).

# SCEPmanClient

SCEPmanClient は、SCEPman の REST API と連携するための PowerShell モジュールです。プラットフォームに依存せず、Windows PowerShell v5 と互換性があるため、このモジュールを使用して、REST API で対応可能なすべてのユースケースの証明書を要求できます。

* サーバー証明書の自動発行
* 管理対象外デバイス用のクライアント証明書
* Linux デバイスへの証明書の登録

## インストール

SCEPmanClient モジュールは PowerShell Gallery で提供されており、次のコマンドでインストールできます。

```powershell
Install-Module -Name SCEPmanClient
```

{% hint style="info" %}
PowerShell をインストールする方法については、Microsoft のガイドを参照してください [Linux](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.5) または [MacOS](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-macos?view=powershell-7.5).
{% endhint %}

## 前提条件

モジュールを想定どおりに機能させるには、SCEPman のデプロイに მცირეの変更を加える必要があります。

{% stepper %}
{% step %}

### ホーム ページ URL を追加する

SCEPman の App Service URL を追加します。次の場所に移動します `ブランディングとプロパティ` アプリ登録のセクション。SCEPman の App Service URL をホーム ページ URL フィールドに追加します。

<figure><img src="https://114237723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LoGejQeUQcw7lqnQ3WX%2Fuploads%2FpvtsVJmycjyIgaQh2sHd%2Fimage.png?alt=media&amp;token=9b9a7a21-4516-4718-9e32-346b39f9775a" alt=""><figcaption></figcaption></figure>

これは、モジュールがアクセストークンの取得に必要なアプリ登録のクライアント ID を自動的に検索できるようにするために必要です。
{% endstep %}

{% step %}

### Azure PowerShell によるアプリ登録との連携を許可する

アプリ登録で、次の場所に移動します *API の公開* 次に、クライアント ID の認可に使用できるカスタム スコープを作成します `1950a258-227b-4e31-a9cf-717495945fc2` (Microsoft Azure PowerShell)

<figure><img src="https://114237723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LoGejQeUQcw7lqnQ3WX%2Fuploads%2F46u0uC5d4K6YAQ3zh7YO%2Fimage.png?alt=media&amp;token=82a318d0-5b3c-442a-887d-a064ff5e19be" alt=""><figcaption><p>カスタム API スコープの情報例</p></figcaption></figure>

API スコープを作成した後、Azure PowerShell アプリケーションを認可できます。

<figure><img src="https://114237723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LoGejQeUQcw7lqnQ3WX%2Fuploads%2Fp3C0zdof95GBMKox19RZ%2Fimage.png?alt=media&amp;token=bc916c87-9233-4f11-82b1-33307e241e08" alt=""><figcaption><p>認可済みの Microsoft Azure PowerShell アプリケーション</p></figcaption></figure>
{% endstep %}

{% step %}

### EST エンドポイントを有効にする

#### 構成

*証明書更新に必要*

SCEPman App Service が mTLS クライアント証明書を受け入れるように構成します。Settings セクションの Configuration ブレードで、Incoming client certificates の Client certificate mode が次に設定されていることを確認します。 ***任意の対話型ユーザー***.

<figure><img src="https://114237723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LoGejQeUQcw7lqnQ3WX%2Fuploads%2F9UeFFxwefnV8Cb7Zz14u%2Fimage.png?alt=media&amp;token=210ea9b7-ecd5-4b2b-9641-22447246e718" alt=""><figcaption></figcaption></figure>

Client certificate mode を Require または Allow に設定しないでください。そうすると、SCEP エンドポイントでの SCEPman の通常の動作が壊れてしまいます。

#### 環境変数

このシナリオを使用するには、SCEPman アプリ サービスに次の環境変数を設定する必要があります。

#### [AppConfig:DbCSRValidation:Enabled](https://docs.scepman.com/advanced-configuration/application-settings/dbcsr-validation#appconfig-dbcsrvalidation-enabled)

*証明書の登録と更新に必要*

この変数を次に設定します ***true*** 証明書署名要求 (CSR) の検証を有効にするには、

#### [AppConfig:DbCSRValidation:AllowRenewals](https://docs.scepman.com/advanced-configuration/application-settings/dbcsr-validation#appconfig-dbcsrvalidation-allowrenewals)

*証明書更新に必要*

この変数を次に設定します ***true*** 証明書の更新を有効にするには、

#### [AppConfig:DbCSRValidation:ReenrollmentAllowedCertificateTypes](https://docs.scepman.com/advanced-configuration/application-settings/dbcsr-validation#appconfig-dbcsrvalidation-reenrollmentallowedcertificatetypes)

*証明書更新に必要*

この変数を、更新を許可する証明書の種類のコンマ区切りリストに設定します。使用可能な証明書の種類の一覧については、リンク先の変数のドキュメントを参照してください。

例: ***Static,IntuneUser,IntuneDevice***
{% endstep %}
{% endstepper %}

## アクセス許可

SCEPman には、異なる種類の証明書を登録できるさまざまなロールがあります。これらは次の場所で割り当てることができます *SCEPman-api* (既定の名前) エンタープライズ アプリケーション:

#### CSR DB Requesters

このロールは既定では Service Principals（例: アプリ登録）にのみ割り当て可能であり、任意のサブジェクトおよび用途で証明書を要求できます。

{% content-ref url="/pages/36cc2f22559c6d88af378786d530d4c19b4503b4" %}
[API による登録](/ja/zheng-ming-shu-guan-li/api-certificates/api-enrollment.md)
{% endcontent-ref %}

#### CSR セルフサービス

このロールはユーザーに割り当てることができ、次の制限付きで証明書を登録できます。

* ClientAuth EKU のみ
* ユーザー証明書では、サブジェクトまたは UPN サブジェクト代替名のいずれかがユーザーの UPN と一致している必要があります
* デバイス証明書には、SCEPman が認証済みユーザーによって所有されているデバイス オブジェクトにマッピングできるサブジェクトまたは SAN が必要です

{% content-ref url="/pages/445d23611bcf69e4026fabba99f0bb392434f719" %}
[セルフサービス登録](/ja/zheng-ming-shu-guan-li/api-certificates/self-service-enrollment.md)
{% endcontent-ref %}

## 使用例

### Azure 認証を使用する

#### 対話型認証

認証メカニズムを指定せずに新しい証明書を要求すると、既定ではユーザーが対話形式で認証されます。次の `-SubjectFromUserContext` パラメーターを使用すると、証明書のサブジェクトと UPN SAN は、ログインしているユーザーのコンテキストに基づいて自動的に設定されます。

```powershell
New-SCEPmanCertificate -Url 'scepman.contoso.com' -SubjectFromUserContext -SaveToStore CurrentUser
```

#### デバイス ログイン

デスクトップ環境がないシステムで新しい証明書を要求する場合は、次の `-DeviceCode` パラメーターを使用して、別のセッションで実際の認証を実行できます。

```powershell
New-SCEPmanCertificate -Url 'scepman.contoso.com' -DeviceCode -SubjectFromUserContext -SaveToFolder /home/user/certificates
```

#### Service Principal 認証

完全自動化シナリオでは、認証にアプリ登録を使用できます。この場合、認証済みコンテキストからサブジェクトを推測することはできません。

パラメーターのスプラッティングにより、実行内容も読みやすくなります。

```powershell
$Parameters = @{
    'Url'              = 'scepman.contoso.com'
    'ClientId'         = '569fbf51-aa63-4b5c-8b26-ebbcfcde2715'
    'TenantId'         = '8aa3123d-e76c-42e2-ba3c-190cabbec531'
    'ClientSecret'     = 'csa8Q~aVaWCLZTzswIBGvhxUiEvhptuqEyJugb70'
    'Subject'          = 'CN=WebServer'
    'DNSName'          = 'Webserver.domain.local'
    'ExtendedKeyUsage' = 'ServerAuth'
    'SaveToStore'      = 'LocalMachine'
}

New-SCEPmanCertificate @Parameters
```

### 証明書を使用して認証する

認証済みコンテキストを使用して証明書が発行されると、以降はコンテキストを再度指定せずにその証明書を更新できます。

#### CertificateBySubject

*キーストアとの連携は Windows でのみ可能です*

次のものを指定する場合 `CertificateBySubject` パラメーターを指定すると、モジュールは次の場所で更新に適した証明書を自動的に検索します *CurrentUser* および *LocalMachine* キーストア。

入力した値は、使用可能なすべての証明書のサブジェクトに対して正規表現で照合されます。

```powershell
New-SCEPmanCertificate -CertificateBySubject 'WebServer' -SaveToStore 'LocalMachine'
```

#### 特定の証明書を指定する

```powershell
$Certificate = Get-ChildItem Cert:\LocalMachine\My | Where-Object Thumbprint -eq '9B08EA68B16773CEF3C49D5D95BE50B784638984'

New-SCEPmanCertificate -Certificate $Certificate -SaveToStore LocalMachine
```

#### CertificateFromFile

Linux システムでは、既存の証明書とその秘密キーのパスを渡すことで、証明書の更新を実行できます。

```powershell
New-SCEPmanCertificate -CertificateFromFile '~/certs/myCert.pem' -KeyFromFile '~/certs/myKey.key' -SaveToFolder '~/certs'
```

暗号化された秘密キーを使用する場合、パスワードの入力を求められます。次のものを使用してキーのパスワードを直接渡すこともできます `PlainTextPassword` パラメーター。

#### Azure Web Application Firewall で SCEPman を使用する

SSL プロファイルが有効な場合、WAF は TLS 接続を終端します。その結果、この手順は認証に mTLS を使用するため、EST を使用した証明書更新が機能しなくなります。この場合、次の `UseSCEPRenewal` パラメーターを使用すると、代わりに SCEP プロトコルに準拠した証明書更新を実行できます。

```powershell
New-SCEPmanCertificate -CertificateBySubject 'WebServer' -SaveToStore 'LocalMachine' -UseSCEPRenewal
```

これには、静的 SCEP エンドポイントに関する追加の SCEPman 構成が必要であることに注意してください。

* AppConfig:StaticValidation:Enabled : true
* AppConfig:StaticValidation:AllowRenewals : true
* AppConfig:StaticValidation:ReenrollmentAllowedCertificateTypes: Static（更新対象の種類に応じて）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.scepman.com/ja/zheng-ming-shu-guan-li/api-certificates/scepmanclient.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
