Oracle® Fusion Middleware Oracle WebLogic Serverセキュリティ・プロバイダの開発 12c 12c (12.2.1.3.0) E90323-01 |
|
前 |
次 |
WebLogicセキュリティ・サービスは、着信双方向SSL、発信SSL、アプリケーション・コード、およびWebLogic Webサービスについて、X509証明書チェーンを検索および検証するフレームワークを提供します。証明書の検索と検証(CLV)フレームワークは、証明書チェーンを検索および検証する新しいセキュリティ・プラグイン・フレームワークです。このフレームワークは、JDK証明書パス機能を拡張および完了し、カスタム証明書パス・プロバイダを作成できるようにします。
この章の内容は次のとおりです。
証明書パスは、メモリー内に証明書チェーンを格納するJDKクラスです。「証明書パス」という用語は、証明書チェーンを検索および検証するためのJDKアーキテクチャおよびフレームワークを指す場合にも使われます。
証明書パス・プロバイダには、証明書パス検証プロバイダと証明書パス・ビルダーの2種類があります。
証明書検証プロバイダは、提示された証明書チェーンが有効で信頼できるものかどうかの判別を目的とします。証明書パス検証プロバイダを作成する場合は、証明書チェーンを検証する方法を決定し、信頼性のあるCAを使用する必要があるかどうかを決めます。
証明書ビルダーは、証明書パスを検索するための選択基準を保持するセレクタを使用しての証明書チェーンの検索を目的とします。多くの場合、証明書ビルダーは証明書チェーンの検証も行います。証明書パス・ビルダーを作成する場合は、4種類のセレクタのうちどれをサポートするか、および証明書チェーンの検証も行うかどうかを判別します。また、証明書チェーンをどの程度指定するか、および信頼性のあるCAを使用する必要があるかどうかを決めます。
WebLogic証明書パス・プロバイダは、JDKとWebLogic証明書パスSPIの両方を使用して作成します。
証明書パス・プロバイダはいくつかの方法で実装できます。
作成と検証を行う証明書パス・ビルダーを実装できます。この場合は、以下の操作を行います。
検証プロバイダSPIを実装します。
ビルダーSPIを実装します。
ビルダーSPIの一部として作成する証明書チェーンを検証する必要があります。プロバイダは一度だけ呼び出されます。検証用に改めて呼び出す必要はありません。
検証アルゴリズムとして何を使用するか、どのセレクタをサポートするか、および信頼性のあるCAを使用するかどうかを指定します。
検証のみを行う証明書パス検証プロバイダを実装できます。この場合は、以下の操作を行います。
検証プロバイダSPIを実装します。
検証アルゴリズムとして何を使用するか、および信頼性のあるCAを使用するかどうかを指定します。
作成のみを行う証明書パス・ビルダーを実装できます。この場合は、以下の操作を行います。
ビルダーSPIを実装します。
作成した証明書チェーンを検証するかどうかを指定します。
どのセレクタをサポートするか、および信頼性のあるCAを使用するかどうかを指定します。
WebLogic Serverには、以下の2種類の証明書パス・プロバイダSPI MBeanがあります。いずれもCertPathProviderMBeanの拡張です。
CertPathBuilderMBeanは、プロバイダが証明書チェーンを検索できることを示します。追加の属性またはメソッドはありません。CertPathBuilderプロバイダは、このMBeanを拡張するカスタムMBeanを実装する必要があります。
CertPathValidatorMBeanは、プロバイダが証明書チェーンを検証できることを示します。追加の属性またはメソッドはありません。CertPathValidatorプロバイダは、このMBeanを拡張するカスタムMBeanを実装する必要があります。
証明書パス・プロバイダは、その種類によって、MBeanのいずれか1つまたは両方を拡張する必要があります。作成と検証の両方をサポートするセキュリティ・プロバイダは、例15-1で示すように、両方のMBeanを拡張するMBeanを作成する必要があります。
例15-1 サンプル証明書パスMBean MDF
<?xml version="1.0" ?> <!DOCTYPE MBeanType SYSTEM "commo.dtd"> <MBeanType Name = "MyCertPathProvider" DisplayName = "MyCertPathProvider" Package = "com.acme" Extends = "weblogic.management.security.pk.CertPathBuilder" Implements = "weblogic.management.security.pk.CertPathValidator" PersistPolicy = "OnUpdate" > <MBeanAttribute Name = "ProviderClassName" Type = "java.lang.String" Writeable = "false" Default = ""com.acme.MyCertPathProviderRuntimeImpl"" /> <MBeanAttribute Name = "Description" Type = "java.lang.String" Writeable = "false" Default = ""My CertPath Provider"" /> <MBeanAttribute Name = "Version" Type = "java.lang.String" Writeable = "false" Default = ""1.0"" /> <!-- add custom attributes for the configuration data needed by this provider --> <MBeanAttribute Name = "CustomConfigData" Type = "java.lang.String" />
WebLogic証明書パス検証プロバイダSSPIは、以下の4つの部分で構成されています。
「証明書パス・プロバイダSPI MBean」で説明されているMBean SSPI
「JDK CertPathBuilderSpiインタフェース、CertPathValidatorSpiインタフェースのいずれか、または両方の実装」で説明されているJDK CertPathValidatorSPI
インタフェース
「証明書パス・プロバイダSSPIの実装」
で説明されているWebLogic Server CertPathProvider SSPIインタフェース
「JDKセキュリティ・プロバイダSPIの実装」で説明されている、JDKにCertPathValidatorSPI
実装を登録するJDKセキュリティprovider
WebLogic証明書パス・ビルダーSSPIは、以下の4つの部分で構成されています。
「証明書パス・プロバイダSPI MBean」で説明されているMBean SSPI
「JDK CertPathBuilderSpiインタフェース、CertPathValidatorSpiインタフェースのいずれか、または両方の実装」で説明されているJDK CertPathBuilder
SPIインタフェース
「証明書パス・プロバイダSSPIの実装」
で説明されているWebLogic Server CertPathProvider SSPIインタフェース
「JDKセキュリティ・プロバイダSPIの実装」
で説明されている、JDKにCertPathBuilder
SPIを登録するJDKセキュリティprovider
WebLogicセキュリティ・フレームワーク・プロバイダとは異なり、証明書パス・プロバイダの現在の実装は、WebLogicインタフェースおよびJDKインタフェースの緊密な統合に依存します。この統合は、証明書パス・プロバイダを作成する際に最も明らかになります。
証明書パス検証プロバイダを作成する場合は、次のタスクを実行する必要があります。
「WebLogic MBeanMakerを使用してMBeanタイプを生成する」の説明に従って、CertPathProviderMBeanを拡張するCertPathValidatorMBeanを作成します
「JDK CertPathBuilderSpiインタフェース、CertPathValidatorSpiインタフェースのいずれか、または両方の実装」
の説明に従って、JDK java.security.cert.CertPathValidatorSpiを実装します
JDK実装には、WebLogic CertPathValidatorParametersSpi
にキャストできるJDK CertPathParameters
オブジェクトが渡されます。これにより、信頼性のあるCAおよびContextHandlerを取得するWebLogicメソッドにアクセスできるようになります。また、このオブジェクトを使用すると、WebLogic証明書パス・プロバイダ・オブジェクトにもアクセスできます。
信頼性のあるCA、ContextHandler、MBeanで提供されるカスタム構成データへのアクセスを許可する証明書パス・プロバイダSSPI実装など、証明書チェーンの検証に必要なデータを指定するには、「CertPathValidatorSpi実装でCertPathValidatorParametersSpi SSPIの使用」
で説明されているようにCertPathValidatorParametersSpiを使用します
CertPathValidatorSpi
実装からMBeanのカスタム構成データを直接取得する方法はないので、WebLogic証明書パス・プロバイダは重要な役割を果たします。WebLogic証明書パス・プロバイダは、カスタムMBeanデータをJDK実装で使用可能にするための固有のメカニズムを提供できます。
「証明書パス・プロバイダSSPIの実装」の説明に従って、WebLogic証明書パスSSPIを実装します特に、MBeanへのフックを実行し、そのカスタム構成データをCertPathValidatorSpi
実装で使用できるようにするには、例15-2で示すように、証明書パス・プロバイダSSPIのinitialize
メソッドを使用します。
「JDKセキュリティ・プロバイダSPIの実装」で説明されている、CertPathValidatorSpi実装を登録するJDKセキュリティprovider
を実装しますこのコーディングは直感的には理解しにくいこともあるので、「例15-5で実例を示します。
証明書パス・ビルダーを作成する場合は、次のタスクを実行する必要があります。
「WebLogic MBeanMakerを使用してMBeanタイプを生成する」の説明に従って、CertPathProviderMBeanを拡張するCertPathBuilderMBeanを作成します
「JDK CertPathBuilderSpiインタフェース、CertPathValidatorSpiインタフェースのいずれか、または両方の実装」
の説明に従って、JDK java.security.cert.CertPathBuilderSpiを実装します
JDK実装には、WebLogic CertPathBuilderParametersSpi
にキャストできるJDK CertPathParameters
オブジェクトが渡されます。これにより、信頼性のあるCA、セレクタ、およびContextHandlerを取得するWebLogicメソッドにアクセスできるようになります。また、このオブジェクトを使用すると、WebLogic証明書パス・プロバイダ・オブジェクトにもアクセスできます。
信頼性のあるCA、ContextHandler、MBeanで提供されるカスタム構成データへのアクセスを許可する証明書パス・プロバイダSSPI実装など、証明書チェーンの検証に必要なデータを指定するには、「CertPathBuilderSpi実装でCertPathBuilderParametersSpi SSPIの使用」
で説明されているようにCertPathBuilderParametersSpiを使用します
CertPathBuilderSpi
実装からMBeanのカスタム構成データを直接取得する方法はないので、WebLogic証明書パス・プロバイダは重要な役割を果たします。WebLogic証明書パス・プロバイダは、カスタムMBeanデータをJDK実装で使用可能にするための固有のメカニズムを提供できます。
「証明書パス・プロバイダSSPIの実装」の説明に従って、WebLogic証明書パスSSPIを実装します特に、MBeanへのフックを実行し、そのカスタム構成データをCertPathBuilderSpi
実装で使用できるようにするには、例15-2で示すように、証明書パス・プロバイダSSPIのinitialize
メソッドを使用します。
「JDKセキュリティ・プロバイダSPIの実装」で説明されている、CertPathBuilderSpi実装を登録するJDKセキュリティprovider
を実装しますこのコーディングは直感的には理解しにくいこともあるので、「例15-5で実例を示します。
WebLogic Serverには、証明書パス・プロバイダと証明書レジストリがあります。
WebLogic Server証明書パス・プロバイダは、証明書パス・ビルダーと証明書パス検証プロバイダの両方です。証明書パス・プロバイダは、証明書のパスを完了させ、特定のWebLogic Serverインスタンスのために構成された、信頼性のあるCAを使用して、証明書を検証します。証明書パス・プロバイダは、自己署名型のチェーンまたは自己署名型の認証局によって発行されたチェーンのみを作成できます。認証局は、サーバーの信頼性のあるCAにリストされている必要があります。未完成の証明書チェーンの場合は、無効です。プロバイダは、EndCertificateSelector
セレクタのみを使用します。
また、WebLogic Server証明書パス・プロバイダは、チェーン内の署名をチェックして、チェーンが期限切れでないことを確認し、チェーン内のいずれかの証明書が、サーバー用に構成された信頼性のあるCAによって発行されたものであることを確認します。いずれかのチェックが失敗した場合、そのチェーンは有効ではありません。最後に、プロバイダは、各証明書の基本的な制約(証明書が他の証明書を発行できるかどうか)をチェックし、証明書がチェーン内の適切な場所にあることを確認します。
WebLogic Server証明書パス・プロバイダは、セキュリティ・レルム内の証明書パス・ビルダーおよび証明書パス検証プロバイダとして使用できます。
WebLogic Server証明書レジストリは、初期状態の証明書パス・プロバイダです。管理者は、信頼性のある目的の証明書のリストをWebLogic Server管理コンソールから構成できます。証明書レジストリはビルダー/検証プロバイダです。選択条件は、EndCertificateSelector
、SubjectDNSelector
、IssuerDNSerialNumberSelector
、SubjectKeyIdentifier
のいずれかです。返される証明書チェーンには、目的の証明書のみがあります。プロバイダでは、チェーンを検証する際に目的の証明書が登録されていることのみを確認し、それ以上のチェックは行いません。
証明書パス・プロバイダと証明書レジストリの両方を構成できます。これは、信頼性のあるCAによって署名された場合にのみ証明書チェーンが有効であり、目的の証明書がレジストリにあることを確認するために行うことができます。
WebLogic Server証明書パス・プロバイダが開発者のニーズを満たさない場合、カスタム証明書パス・プロバイダを開発することができます。
WebLogic証明書パス・プロバイダまたは証明書レジストリが開発者のニーズを満たさない場合、次の手順でカスタム証明書パス・プロバイダを開発することができます。
ランタイム・クラスを作成する前に、以下の作業が必要です。
この情報を理解し、設計に関する判断を下したら、次の項で説明されている手順を実行して、カスタム証明書パス・プロバイダのランタイム・クラスを作成します。
java.security.cert.CertPathBuilderSpi
インタフェースは、CertPathBuilder
クラスのサービス・プロバイダ・インタフェース(SPI)です。すべてのCertPathBuilder
実装は、このインタフェース(CertPathBuilderSpi
)を実装するクラスを含む必要があります。
java.security.cert.CertPathValidatorSpi
インタフェースは、CertPathValidator
クラスのサービス・プロバイダ・インタフェース(SPI)です。すべてのCertPathValidator
実装は、このインタフェース(CertPathValidatorSpi
)を実装するクラスを含む必要があります。
例15-6では、CertPathBuilderSpi
インタフェースとCertPathValidatorSpi
インタフェースの実装例を示します。
CertPathProvider
SSPIインタフェースは、JDK CertPathValidator
SPIおよびCertPathBuilder
SPIによって提供されるサービスを公開し、プロバイダの操作(初期化、開始、停止など)を可能にします。
特に、MBeanへのフックを実行し、そのカスタム構成データをCertPathBuilderSpi
実装またはCertPathValidatorSpi
実装で使用できるようにするには、例15-2で示すように、証明書パス・プロバイダSSPIのinitialize
メソッドを使用します。
より詳細な例については、例15-6に示します。
例15-2 コード(抜粋) : MBeanからのカスタム構成データの取得
public class MyCertPathProviderRuntimeImpl implements CertPathProvider { : : public void initialize(ProviderMBean mBean, SecurityServices securityServices) { MyCertPathProviderMBean myMBean = (MyCertPathProviderMBean)mBean; description = myMBean.getDescription(); customConfigData = myMBean.getCustomConfigData(); : } : // make my config data available to my JDK CertPathBuilderSpi and // CertPathValidatorSpi impls private String getCustomConfigData() { return customConfigData; } } : static public class MyJDKCertPathBuilder extends CertPathBuilderSpi { : //get my runtime implementation instance which holds the configuration //data needed to build and validate the cert path MyCertPathProviderRuntimeImpl runtime = (MyCertPathProviderRuntimeImpl)params.getCertPathProvider(); String myCustomConfigData = runtime.getCustomConfigData();
例15-5では、使用するJDK実装をJDKに登録する方法を示します。
CertPathProvider
SSPIを実装するには、Provider SSPIの目的についてで説明されているメソッドおよび次のメソッドの実装を提供する必要があります。
getCertPathBuilder
public CertPathBuilder getCertPathBuilder()
例15-3
で示すように、JDK CertPathBuilderSpi実装を呼び出す証明書パス・プロバイダのJDK CertPathBuilderを取得します。CertPathBuilderは、証明書チェーンを検索し、必要に応じて検証します。
例15-3 コード(抜粋) : getCertPathBuilder
public void initialize(ProviderMBean mBean, SecurityServices securityServices) { : // get my JDK cert path impls try { certPathBuilder = CertPathBuilder.getInstance(BUILDER_ALGORITHM); } catch (NoSuchAlgorithmException e) { throw new AssertionError("..."); }
getCertPathValidator
public CertPathValidator getCertPathValidator()
例15-4
で示すように、JDK CertPathValidatorSpi実装を呼び出す証明書パス・プロバイダのJDK CertPathValidatorを取得します。CertPathValidatorは、証明書チェーンを検証します。
例15-4 コード(抜粋) : getCertPathValidator
public void initialize(ProviderMBean mBean, SecurityServices securityServices) { : // get my JDK cert path impls try { certPathValidator = CertPathValidator.getInstance(VALIDATOR_ALGORITHM); } catch (NoSuchAlgorithmException e) { throw new AssertionError("..."); } }
JDKセキュリティprovider
SPIを実装し、そのSPIを使用してCertPathBuilderSpi
実装またはCertPathValidatorSpi
実装をJDKに登録します。その実装を使用して、JDK実装をプロバイダのinitialize
メソッドに登録します。
例15-6に、サンプル証明書パス・プロバイダのランタイム・クラスの作成例を示します。例15-5では、JDKセキュリティprovider
を実装するサンプル・コードの一部を示します。
例15-5 JDKセキュリティ・プロバイダの実装
public class MyCertPathProviderRuntimeImpl implements CertPathProvider { private static final String MY_JDK_SECURITY_PROVIDER_NAME = "MyCertPathProvider"; private static final String BUILDER_ALGORITHM = MY_JDK_SECURITY_PROVIDER_NAME + "CertPathBuilder"; private static final String VALIDATOR_ALGORITHM = MY_JDK_SECURITY_PROVIDER_NAME + "CertPathValidator"; : : public void initialize(ProviderMBean mBean, SecurityServices securityServices) { MyCertPathProviderMBean myMBean = (MyCertPathProviderMBean)mBean; description = myMBean.getDescription(); customConfigData = myMBean.getCustomConfigData(); // register my cert path impls with the JDK // so that the CLV framework may invoke them via // the JDK cert path apis. if (Security.getProvider(MY_JDK_SECURITY_PROVIDER_NAME) == null) { AccessController.doPrivileged( new PrivilegedAction() { public Object run() { Security.addProvider(new MyJDKSecurityProvider()); return null; } } ); } : // This class implements the JDK security provider that registers // this provider's cert path builder and cert path validator implementations // with the JDK. private class MyJDKSecurityProvider extends Provider { private MyJDKSecurityProvider() { super(MY_JDK_SECURITY_PROVIDER_NAME, 1.0, "MyCertPathProvider JDK CertPath provider"); put("CertPathBuilder." + BUILDER_ALGORITHM, "com.acme.MyPathProviderRuntimeImpl$MyJDKCertPathBuilder"); put("CertPathValidator." + VALIDATOR_ALGORITHM, "com.acme.MyCertPathProviderRuntimeImpl$MyJDKCertPathValidator"); } } }
JDK実装には、WebLogic CertPathBuilderParametersSpi
にキャストできるJDK CertPathParameters
オブジェクトが渡されます。これにより、信頼性のあるCA、セレクタ、およびContextHandlerを取得するWebLogicメソッドにアクセスできるようになります。また、このオブジェクトを使用すると、WebLogic証明書パス・プロバイダ・オブジェクトにもアクセスできます。以下のメソッドを利用できます。
getCertPathProvider
CertPathProvider getCertPathProvider()
証明書パス・プロバイダで提供されているサービスをWebLogicセキュリティ・フレームワークに公開する証明書パス・プロバイダSSPIインタフェースを取得します。特に、MBeanへのフックを実行し、そのカスタム構成データをCertPathBuilderSpi
実装で利用できるようにするには、例15-2
で示すように、証明書パス・プロバイダSSPIのinitializeメソッドを使用します。
getCertPathSelector
CertPathSelector getCertPathSelector()
証明書パスを検索する際の選択条件を保持するCertPathSelector
インタフェースを取得します。
WebLogic Serverでは、サポートされている証明書チェーン検索の種類ごとに1つずつのCertPathSelector
インタフェースを実装するweblogic.security.pk
内の一連のクラスを使用できます。そのため、getCertPathSelector
メソッドは、以下の派生クラスのいずれか1つを返します。
EndCertificateSelector
- 目的の証明書がある証明書チェーンを検索および検証する場合に使用します。
IssuerDNSerialNumberSelector
- 目的の証明書の発行者DNとシリアル番号から証明書チェーンを検索および検証する場合に使用します。
SubjectDNSelector
- 目的の証明書のサブジェクトDNから証明書チェーンを検索および検証する場合に使用します。
SubjectKeyIdentifierSelector
- 目的の証明書のサブジェクト・キー識別子(X509証明書のオプション・フィールド)から証明書チェーンを検索および検証する場合に使用します。
各セレクタ・クラスには、選択データおよびコンストラクタを取得するためのメソッドが1つまたは複数あります。
CertPathBuilderSpi
実装は、どのセレクタをサポートするかを決めます。CertPathBuilderSpi
実装は、CertPathBuilderParametersSpi
SSPIのgetCertPathSelector
メソッドを使用して、証明書パスを検索する際の選択条件を保持するCertPathSelector
を取得する必要があります。その種類のセレクタをサポートしている場合、CertPathBuilderSpi
実装は、そのセレクタを使用して証明書チェーンを作成および検証します。そうでない場合は、呼出し側に伝播されるInvalidAlgorithmParameterExceptionをスローします。
getContext()
ContextHandler getContext()
証明書パスの作成および検証に使用可能な追加パラメータを渡すことができるContextHandlerを取得します。
getTrustedCAs()
X509Certificate[] getTrustedCAs()
証明書チェーンの作成に使用できる、信頼性のある認証局のリストを取得します。信頼性のあるCAでチェーンを作成する必要がある場合、CertPathBuilderSpi
実装は、このリスト内のCAを使用する必要があります。
clone
Object clone()
このインタフェースのクローンは作成できません。
JDK実装には、WebLogic CertPathValidatorParametersSpi
にキャストできるJDK CertPathParameters
オブジェクトが渡されます。これにより、信頼性のあるCAおよびContextHandlerを取得するWebLogicメソッドにアクセスできるようになります。また、このオブジェクトを使用すると、WebLogic証明書パス・プロバイダ・オブジェクトにもアクセスできます。CLVフレームワークは、検証プロバイダSPIに渡された証明書チェーンが適切な順序になっている(目的の証明書から開始される)こと、および各証明書が次の証明書に署名していることを確認します。以下のメソッドを利用できます。
getCertPathProvider
CertPathProvider getCertPathProvider()
証明書パス・プロバイダで提供されているサービスをWebLogicセキュリティ・フレームワークに公開する証明書パス・プロバイダSSPIインタフェースを取得します。特に、MBeanへのフックを実行し、そのカスタム構成データをCertPathValidatorSpi
実装で使用できるようにするには、例15-2で示すように、証明書パス・プロバイダSSPIのinitialize
メソッドを使用します。
getContext()
ContextHandler getContext()
証明書パスの作成および検証に使用可能な追加パラメータを渡すことができるContextHandlerを取得します。
SSLは、1つまたは複数のCertPathValidatorオブジェクトを呼び出して追加検証を実行する前に、一部の組込み検証を実行します。検証プロバイダは、実行済みの検証を検出することで、必要な検証の規模を縮小できます。
たとえば、WebLogic証明書パス・プロバイダは、SSLが実行するものと同じ検証を実行します。SSLによって呼び出された場合でも、その検証を繰り返す必要はありません。そのため、SSLは、検証プロバイダに渡すコンテキストに一部の情報を保存し、どの検証がすでに実行済みかを示します。weblogic.security.SSL.SSLValidationConstants CHAIN_PREVALIDATED_BY_SSL
フィールドは、SSLが証明書チェーンを検証済みかどうかを示すブール値です。アプリケーション・コードは、このフィールドをテストできます。フィールドは、SSLが証明書チェーンを検証済みの場合はtrue、まだ検証していない場合はfalseに設定されます。
getTrustedCAs()
X509Certificate[] getTrustedCAs()
証明書チェーンの検証に使用できる、信頼性のある認証局のリストを取得します。信頼性のあるCAでチェーンを検証する必要がある場合、CertPathBuilderSpi実装は、このリスト内のCAを使用する必要があります。
clone
Object clone()
このインタフェースのクローンは作成できません。
JDK CertPathBuilder実装またはCertPathValidator実装は、java.security.cert.CertPathValidatorResult
インタフェースまたはjava.security.cert.CertPathValidatorResult
インタフェースを実装するオブジェクトを返す必要があります。
ユーザー独自の結果の実装を作成することも、WebLogic Serverコンビニエンス・ルーチンを使用することもできます。
WebLogic Serverには、WLSCertPathBuilderResult
とWLSCertPathValidatorResult
という2つの便利な結果実装クラスがあります。どちらのクラスもweblogic.security.pk
にあり、java.security.cert.CertPathValidatorResult
またはjava.security.cert.CertPathValidatorResult
のインスタンスを返す場合に使用できます。
注意:
返される結果は、WebLogicセキュリティ・フレームワーク内を通りません。
例15-6では、証明書パス・ビルダー/検証プロバイダの例を示します。例には、コード・フローを説明する拡張コメントが記載されています。
例15-6 サンプル証明書パス・プロバイダの作成
package com.acme; import weblogic.management.security.ProviderMBean; import weblogic.security.pk.CertPathSelector; import weblogic.security.pk.SubjectDNSelector; import weblogic.security.pk.WLSCertPathBuilderResult; import weblogic.security.pk.WLSCertPathValidatorResult; import weblogic.security.service.ContextHandler; import weblogic.security.spi.CertPathBuilderParametersSpi; import weblogic.security.spi.CertPathProvider; import weblogic.security.spi.CertPathValidatorParametersSpi; import weblogic.security.spi.SecurityServices; import weblogic.security.SSL.SSLValidationConstants; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.security.AccessController; import java.security.PrivilegedAction; import java.security.Provider; import java.security.Security; import java.security.cert.CertPath; import java.security.cert.CertPathBuilder; import java.security.cert.CertPathBuilderResult; import java.security.cert.CertPathBuilderSpi; import java.security.cert.CertPathBuilderException; import java.security.cert.CertPathParameters; import java.security.cert.CertPathValidator; import java.security.cert.CertPathValidatorResult; import java.security.cert.CertPathValidatorSpi; import java.security.cert.CertPathValidatorException; import java.security.cert.X509Certificate; public class MyCertPathProviderRuntimeImpl implements CertPathProvider { private static final String MY_JDK_SECURITY_PROVIDER_NAME = "MyCertPathProvider"; private static final String BUILDER_ALGORITHM = MY_JDK_SECURITY_PROVIDER_NAME + "CertPathBuilder"; private static final String VALIDATOR_ALGORITHM = MY_JDK_SECURITY_PROVIDER_NAME + "CertPathValidator"; // Used to invoke my JDK cert path builder / validator implementations private CertPathBuilder certPathBuilder; private CertPathValidator certPathValidator; // remember my custom configuration data from my mbean private String customConfigData; private String description; public void initialize(ProviderMBean mBean, SecurityServices securityServices) { MyCertPathProviderMBean myMBean = (MyCertPathProviderMBean)mBean; description = myMBean.getDescription(); customConfigData = myMBean.getCustomConfigData(); // register my cert path impls with the JDK // so that the CLV framework may invoke them via // the JDK cert path apis. if (Security.getProvider(MY_JDK_SECURITY_PROVIDER_NAME) == null) { AccessController.doPrivileged( new PrivilegedAction() { public Object run() { Security.addProvider(new MyJDKSecurityProvider()); return null; } } ); } // get my JDK cert path impls try { certPathBuilder = CertPathBuilder.getInstance(BUILDER_ALGORITHM); } catch (NoSuchAlgorithmException e) { throw new AssertionError("..."); } try { certPathValidator = CertPathValidator.getInstance(VALIDATOR_ALGORITHM); } catch (NoSuchAlgorithmException e) { throw new AssertionError("..."); } } public void shutdown () { } public String getDescription () { return description; } public CertPathBuilder getCertPathBuilder () { return certPathBuilder;} public CertPathValidator getCertPathValidator () { return certPathValidator;} // make my config data available to my JDK CertPathBuilderSpi and // CertPathValidatorSpi impls private String getCustomConfigData() { return customConfigData; } /** * This class contains JDK cert path builder implementation for this provider. */ static public class MyJDKCertPathBuilder extends CertPathBuilderSpi { public CertPathBuilderResult engineBuild(CertPathParameters genericParams) throws CertPathBuilderException, InvalidAlgorithmParameterException { // narrow the CertPathParameters to the WLS ones so we can get the // data needed to build and validate the cert path if (!(genericParams instanceof CertPathBuilderParametersSpi)) { throw new InvalidAlgorithmParameterException("The CertPathParameters must be a weblogic.security.pk.CertPathBuilderParametersSpi instance."); } CertPathBuilderParametersSpi params = (CertPathBuilderParametersSpi)genericParams; // get my runtime implementation instance which holds the configuration // data needed to build and validate the cert path MyCertPathProviderRuntimeImpl runtime = (MyCertPathProviderRuntimeImpl)params.getCertPathProvider(); String myCustomConfigData = runtime.getCustomConfigData(); // get the selector which indicates which cert path the caller wants built. // it can be an EndCertificateSelector, SubjectDNSelector, // IssuerDNSerialNumberSelector // or a SubjectKeyIdentifier. CertPathSelector genericSelector = params.getCertPathSelector(); // decide which kinds of selectors this builder wants to support. if (genericSelector instanceof SubjectDNSelector) { // get the subject dn of the end certificate of the cert path the caller // wants built SubjectDNSelector selector = (SubjectDNSelector)genericSelector; String subjectDN = selector.getSubjectDN(); // if your implementation requires trusted CAs, get them. // otherwise, ignore them. that is, it's a quality of service // issue whether or not you require trusted CAs. X509Certificate[] trustedCAs = params.getTrustedCAs(); // if your implementation requires looks for extra data in // the context handler, get it. otherwise ignore it. ContextHandler context = params.getContext(); if (context != null) { // ... } // use my custom configuration data (ie. myCustomConfigData), // the trusted CAs (if applicable to my implementation), // the context (if applicable to my implementation), // and the subject DN to build and validate the cert path CertPath certpath = ... // or X509Certificate[] chain = ... // if not found, throw an exception: if (...) { throw new CertPathBuilderException("Could not build a cert path for " + subjectDN); } // if not valid, throw an exception: if (...) { throw new CertPathBuilderException("Could not validate the cert path for " + subjectDN); } // if found and valid, return the cert path. // for convenience, use the WLSCertPathBuilderResult class return new WLSCertPathBuilderResult(certpath); // or return new WLSCertPathBuilderResult(chain); } else { // the caller passed in a selector that my implementation does not support throw new InvalidAlgorithmParameterException("MyCertPathProvider only supports weblogoic.security.pk.SubjectDNSelector"); } } } /** * This class contains JDK cert path validator implementation for this provider. */ static public class MyJDKCertPathValidator extends CertPathValidatorSpi { public CertPathValidatorResult engineValidate(CertPath certPath, CertPathParameters genericParams) throws CertPathValidatorException, InvalidAlgorithmParameterException { // narrow the CertPathParameters to the WLS ones so we can get the // data needed to build and validate the cert path if (!(genericParams instanceof CertPathValidatorParametersSpi)) { throw new InvalidAlgorithmParameterException("The CertPathParameters must be a weblogic.security.pk.CertPathValidatorParametersSpi instance."); } CertPathValidatorParametersSpi params = (CertPathValidatorParametersSpi)genericParams; // get my runtime implementation instance which holds the configuration // data needed to build and validate the cert path MyCertPathProviderRuntimeImpl runtime = (MyCertPathProviderRuntimeImpl)params.getCertPathProvider(); String myCustomConfigData = runtime.getCustomConfigData(); // if your implementation requires trusted CAs, get them. // otherwise, ignore them. that is, it's a quality of service // issue whether or not you require trusted CAs. X509Certificate[] trustedCAs = params.getTrustedCAs(); // if your implementation requires looks for extra data in // the context handler, get it. otherwise ignore it. ContextHandler context = params.getContext(); if (context != null) { // ... } // The CLV framework has already done some minimal validation // on the cert path before sending it to your provider: // 1) the cert path is not empty // 2) the cert path starts with the end cert // 3) each certificate in the cert path was issued and // signed by the next certificate in the chain // So, your validator can rely on these checks having // already been performed (vs your validator needing to // do these checks too). // Use my custom configuration data (ie. myCustomConfigData), // the trusted CAs (if applicable to my implementation), // and the context (if applicable to my implementation) // to validate the cert path // if not valid, throw an exception: if (...) { throw new CertPathValidatorException("Could not validate the cerpath " + certPath); } // if valid, return success // For convenience, use the WLSCertPathValidatorResult class return new WLSCertPathValidatorResult(); } } // This class implements the JDK security provider that registers this // provider's // cert path builder and cert path validator implementations with the JDK. private class MyJDKSecurityProvider extends Provider { private MyJDKSecurityProvider() { super(MY_JDK_SECURITY_PROVIDER_NAME, 1.0, "MyCertPathProvider JDK CertPath provider"); put("CertPathBuilder." + BUILDER_ALGORITHM, "com.acme.MyPathProviderRuntimeImpl$MyJDKCertPathBuilder"); put("CertPathValidator." + VALIDATOR_ALGORITHM, "com.acme.MyCertPathProviderRuntimeImpl$MyJDKCertPathValidator"); } } }
カスタム証明書パス・プロバイダを構成するということは、証明書サービスを必要とするアプリケーションがアクセス可能なセキュリティ・レルムにカスタム証明書パス・プロバイダを追加するということです。
カスタム・セキュリティ・プロバイダの構成は管理タスクですが、カスタム・セキュリティ・プロバイダの開発者が行うこともできます。
注意:
WebLogic Server管理コンソールを使用してカスタムのCertPathプロバイダを構成する手順は、Oracle WebLogic Serverセキュリティの管理のWebLogicセキュリティ・プロバイダの構成を参照してください。