| Oracle® Fusion Middleware Oracle Platform Security Servicesによるアプリケーションの保護 12c (12.2.1.3.0) E92000-01 |
|
![]() 前 |
![]() 次 |
この章の内容は次のとおりです。
キーストアは鍵と証明書を安全に格納するために使用し、キーストア・サービスAPIはキーストア・リポジトリのデータへのアクセス、取得およびメンテナンスのために使用します。このリポジトリ・タイプは、ファイル、LDAPまたはDBのいずれかです。
操作には鍵の作成、読取り、更新、削除などがあり、キーストアの構成済プロパティであるキーストア・アーティファクトへのハンドルを取得します。このような操作は、サービスで使用されるファイングレイン・アクセス制御モデルを実装するKeyStoreAccessPermissionクラスによって保護されます。
アプリケーションでキーストア・サービスAPIを使用する前に、次のようにします。
使用するアプリケーション・ストライプとキーストアを特定します。
アプリケーションによるキーストアへのアクセスおよび使用を可能にする必要なポリシーをプロビジョニングします。ポリシーのプロビジョニングの詳細は、「ポリシー・パーミッションの設定」を参照してください。
必ずキーストア・インスタンスをjps-config.xmlファイルに指定します。
ドメインに構成されているキーストア・プロバイダは、サーバーの起動時にインスタンス化されます。ファイル・キーストア・プロバイダにより、その内容はsystem-jazn-data.xmlファイルに指定されます。
鍵はアプリケーション・ストライプ・レベル、キーストア・レベルまたは単一の鍵レベルで保護できます。キーストア・サービスAPIを使用してキーストアにアクセスするには、アプリケーションで実行できる操作を指定するコードソース・パーミッションがアプリケーションに必要です。
このようなパーミッションは特定のアプリケーションおよび鍵に限定することをお薦めします。
次の各項では、いくつかのパーミッションの例を示します。
次の例では、ストライプ内のキーストアに対するアクションをコードソースに付与するポリシーを示します。
<jazn-policy>
<grant>
<grantee>
<principals>...</principals>
<!-- This is the location of the JAR as loaded with the runtime -->
<codesource>
<url>file:${oracle.deployed.app.dir}/<MyApp>${oracle.deployed.app.ext}</url>
</codesource>
</grantee>
<permissions>
<permission>
<class>oracle.security.jps.service.keystore.KeyStoreAccessPermission</class>
<name>stripeName=keystoreapp,keystoreName=ks1,alias=*</name>
<!-- All actions are granted -->
<actions>*</actions>
</permission>
</permissions>
</grant>
</jazn-policy>
説明:
stripeNameは、パーミッションを付与するアプリケーション・ストライプの名前です。
keystoreNameは、キーストアの名前です。
aliasはキーストア内のキー別名を示します。ワイルドカードは、すべての別名に対するパーミッションがアプリケーションに付与されることを意味します。
関連項目:
次の例では、ストライプ内のすべてのキーストアに対する読取り、書込みおよび削除のパーミッションをコードソースに付与するポリシーを示します。
<jazn-policy>
<grant>
<grantee>
<principals>...</principals>
<codesource>
<url>file:${oracle.deployed.app.dir}/<MyApp>${oracle.deployed.app.ext}</url>
</codesource>
</grantee>
<permissions>
<permission>
<class>oracle.security.jps.service.keystore.KeyStoreAccessPermission</class>
<name>stripeName=keystoreapp,keystoreName=*,alias=*</name>
<actions>read,write,update,delete</actions>
</permission>
</permissions>
</grant>
</jazn-policy>
次の例では、ストライプ内の特定のキーストアおよび別名に対する読取りパーミッションをコードソースに付与するポリシーを示します。
<jazn-policy>
<grant>
<grantee>
<principals>...</principals>
<codesource>
<url>file:${oracle.deployed.app.dir}/<MyApp>${oracle.deployed.app.ext}</url>
</codesource>
</grantee>
<permissions>
<permission>
<class>oracle.security.jps.service.keystore.KeyStoreAccessPermission</class>
<name>stripeName=keystoreapp,keystoreName=ks1,alias=orakey</name>
<actions>read</actions>
</permission>
</permissions>
</grant>
</jazn-policy>
Java EEアプリケーションでキーストア・サービスAPIを使用するには、次の手順を実行します。
次の各項では、APIの使用例を示します。
次の例では、一般的なキーストアの操作を示します。
import oracle.security.jps.JpsContext;
import oracle.security.jps.JpsContextFactory;
import oracle.security.jps.JpsException;
import oracle.security.jps.service.keystore.KeyStoreProperties;
import oracle.security.jps.service.keystore.KeyStoreService;
import oracle.security.jps.service.keystore.KeyStoreServiceException;
import java.security.AccessController;
import java.security.PrivilegedAction;
public class KeyStoreTest {
private static KeyStoreService ks = null;
public KeyStoreTest() {
super();
}
/*
* This method performs a non-privileged operation. Either all code
* in the call stack must have KeyStoreAccessPermission
* OR
* the caller must have the KeyStoreAccessPermission only and
* invoke this operation in doPrivileged block
*/
public static void doKeyStoreOperation() {
doOperation();
}
/*
* because this method performs a privileged operation, only current class or
* jar containing this class needs KeyStoreAccessPermission
*/
public static void doPrivilegedKeyStoreOperation() {
AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
doOperation();
return "done";
}
});
}
private static void doOperation() {
try {
ks.deleteKeyStore("keystoreapp", "ks1", null);
} catch(KeyStoreServiceException e) {
e.printStackTrace();
}
public static void main(String args[]) throws Exception {
try {
new JpsStartup().start();
JpsContext ctx = JpsContextFactory.getContextFactory().getContext();
ks = ctx.getServiceInstance(KeyStoreService.class);
// this call is in a doPrivileged block
doPrivilegedKeyStoreOperation();
} catch (JpsException je) {
je.printStackTrace();
}
}
}
関連項目:
Oracle Platform Security ServicesのJava APIリファレンス
次の例では、実行時にキーストア・アーティファクトにアクセスする方法をいくつか示します。
キーストアにアクセスするには、まずアプリケーションで、アプリケーション・ストライプおよびキーストア名を別々のパラメータとして指定するか、アプリケーション・ストライプおよびキーストア名を1つのパラメータとして指定して、キーストア・ハンドルを取得する必要があります。
いずれの方法も、鍵および証明書のフェッチとまったく同じ方法で動作をしますが、唯一の相違はキーストアのロード方法です。1つ目の方法1ではOPSS APIを使用します。2つ目の方法ではJava SE Development Kit (JDK) APIを使用します。
次の例では、アプリケーション・ストライプおよびキーストアを別々のパラメータとして指定し、キーストアへのハンドルを取得する方法を示します。
// First get the KeyStoreService handle from JpsContext
JpsContext ctx = JpsContextFactory.getContextFactory().getContext();
KeyStoreService kss = ctx.getServiceInstance(KeyStoreService.class);
// Now get the keystore handle from KeyStoreService.
// Method 1: Explicitly specify application stripe and keystore name as
// separate parameters. In this example, the last parameter is null because
// we are demonstrating a password-protected keystore.
java.security.KeyStore keyStore = kss.getKeyStore("keystoreapp", "ks1", null);
// If this keystore is password-protected, provide the keystore password as the
// last parameter.
// java.security.KeyStore.ProtectionParameter pwd = new
java.security.KeyStore.PasswordProtection("password".toCharArray());
// java.security.KeyStore keyStore = kss.getKeyStore("keystoreapp", "ks1", pwd);
// Method 2: Specify application stripe and keystore name as one parameter
// using KSS URI. The last parameter is the keystore password, which is
// set to null in this example due to permission protected keystore.
// For password-protected keystore, set it to the keystore password.
Key key = keyStore.getKey("key-alias", null);
// Get the certificate associated with this alias
Certificate cert = keyStore.getCertificate("cert-alias");
注意:
メソッドload、getKey、getCertへのコールをdoPrivilegedブロック内に入れることをお薦めします。
次の例では、JDKキーストアURIを使用してアプリケーション・ストライプおよびキーストアを1つのパラメータとして指定し、キーストアへのハンドルを取得する方法を示します。
// Create an object with parameters indicating the keystore to load
FarmKeyStoreLoadStoreParameter param = new FarmKeyStoreLoadStoreParameter();
param.setAppStripeName("keystoreapp");
param.setKeyStoreName("ks1");
// The password is set to null in this example because it assumes this is a
// permission protected keystore.
param.setProtectionParameter(null);
// If the keystore is password protected, use the following lines instead
// java.security.KeyStore.ProtectionParameter pwd = new java.security.KeyStore.PasswordProtection("password".toCharArray());
// param.setProtectionParameter(pwd);
// Initialize the keystore object by setting keystore type and provider
java.security.KeyStore keyStore = KeyStore.getInstance("KSS", new FarmKeyStoreProvider());
// Load the keystore. There are two ways to do this:
// Method 1: Explicitly specify application stripe and keystore name as
// separate parameters in param object
// keyStore.load(param);
// Method 2: Specify application stripe and keystore name as one parameter
// using KSS URI. because we demonstrate method 2, in this
// example, method 1 is commented out
FarmKeyStoreLoadStoreParameter param = new FarmKeyStoreLoadStoreParameter();
param.setKssUri("kss://keystoreapp/ks1");
param.setProtectionParameter(null);
keyStore.load(param);
// Now you have a handle to JDK KeyStore object. Use this handle to get
// key(s) and/or certificate(s)
// Get the private key associated with this alias
Key key = keyStore.getKey("key-alias", null);
// Get the certificate associated with this alias
Certificate cert = keyStore.getCertificate("cert-alias");
注意:
メソッドload、getKey、getCertへのコールをdoPrivilegedブロック内に入れることをお薦めします。