# 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 を追加します: 次へ移動します `Branding & Properties` アプリ登録のセクション。ホーム ページ URL フィールドに SCEPman の App Service URL を追加します:

<figure><img src="/files/e040831addcf6b8024e8848b58bf996a7c8ccd1d" alt=""><figcaption></figcaption></figure>

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

{% step %}

### Azure PowerShell が App Registration と対話できるようにする

App Registration で、次へ移動します *Expose an API* そして、クライアント ID を認可するために使用できるカスタム スコープを作成します `1950a258-227b-4e31-a9cf-717495945fc2` (Microsoft Azure PowerShell)

<figure><img src="/files/6943655e2f61637f8725a0f3a739f89334349cfa" alt=""><figcaption><p>カスタム API スコープの情報例</p></figcaption></figure>

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

<figure><img src="/files/b3cd8a80fdd5f72ac3cb1cccc30c424cc261057d" alt=""><figcaption><p>認可された Microsoft Azure PowerShell アプリケーション</p></figcaption></figure>
{% endstep %}

{% step %}

### EST エンドポイントを有効化

{% endstep %}
{% endstepper %}

## アクセス許可

SCEPman には、異なる種類の証明書の登録を許可するさまざまなロールがあります。これらは次の *SCEPman-api* （既定の名前）Enterprise Application:

#### CSR DB Requesters

このロールは、既定では Service Principals（たとえば App Registrations）にのみ割り当て可能で、任意のサブジェクトおよび用途を持つ証明書を要求できます。

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

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

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

* ClientAuth EKU のみ
* ユーザー証明書は、サブジェクトまたは UPN subject alternative name のいずれかで、ユーザーの 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 認証

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

パラメーター スプラッティングを使用すると、実行もより読みやすくなります:

```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* キーストア。

入力された値は、利用可能なすべての証明書のサブジェクトに対して regex 一致が行われます。

```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 Profiles が有効になっている場合、WAF は TLS 接続を終端します。これにより、EST を使用した証明書の更新は機能しなくなります。これは、この手順が認証に mTLS に依存しているためです。この場合、 `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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
