JDK 25 Security Enhancements

原文はこちら。
The original article was written by Sean Mullan (Java Security Tech Lead, Oracle).
https://seanjmullan.org/blog/2025/09/23/jdk25

JDK 25が2025年9月16日にリリースされました!

JDK 25
https://openjdk.org/projects/jdk/25/

これまでのブログと同様に、今回のリリースで最も興味深く有用なセキュリティ強化点をまとめたリストを作成しました。また、各分野(暗号、TLSなど)で変更点を把握しやすくするため、適切なカテゴリに分類しています。JDK 25リリースノートにも、これらの強化点やその他の詳細が記載されています。

原著者のこれまでのブログエントリ
https://seanjmullan.org/blog/
JDK 25リリースノート
https://jdk.java.net/25/release-notes

今回のリリースの主なハイライトは、鍵導出関数APIの最終版と、暗号オブジェクトをPEM形式でエンコード・デコードするための新しいPreview APIです。

JEP 510: Key Derivation Function API
https://openjdk.org/jeps/510
JEP 470: PEM Encodings of Cryptographic Objects (Preview)
https://openjdk.org/jeps/470

Table of Contents

  1. Crypto
  2. TLS
  3. Performance Improvements
  4. Security Manager
  5. Miscellaneous

Crypto

JEP 470: PEM Encodings of Cryptographic Objects (Preview)

JDK 25では、暗号オブジェクトをPEM形式に変換・復元するための新しいPreview APIが導入され、JEP 470で定義されました。

JEP 470: PEM Encodings of Cryptographic Objects (Preview)
https://openjdk.org/jeps/470

PEMは、証明書、CRL、秘密鍵などのDERエンコードされた暗号データを転送・保存するために広く使用される形式です。これは数年前のJCE surveyで最も要望が多かった機能の一つでした。

このPreviewでは、主に2つのAPIが追加されました。暗号オブジェクトをPEM形式にエンコードするPEMEncoderクラスと、PEMデータを暗号オブジェクトにデコードするPEMDecoderクラスです。

Class PEMEncoder
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/security/PEMEncoder.html
Class PEMDecoder
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/security/PEMDecoder.html

新しいマーカーインターフェース DEREncodable が追加され、X509CertificateX509CRL などの既存クラスは、このインターフェースを実装するよう後付けで変更されました。

Interface DEREncodable
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/security/DEREncodable.html

これにより、これらのオブジェクトをPEM形式でエンコード/デコードすることが簡単になりました。

PEMEncoder は暗号化用に設定することも可能で、これにより1ステップで簡単に秘密鍵の暗号化とエンコードが可能になりました。同様に、PEMDecoderも復号用に設定でき、秘密鍵を1ステップでデコードおよび復号できます。より高度な使用のために、既存のEncryptedPrivateKeyInfoクラスも、秘密鍵の暗号化と復号を容易にするいくつかの新しいメソッドで強化されています。

Class EncryptedPrivateKeyInfo
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/javax/crypto/EncryptedPrivateKeyInfo.html

以下は、KeyStoreから取得したX509CertificateをPEM形式にエンコードする例です。

X509Certificate cert = (X509Certificate)keystore.getCertificate("mycert");
PEMEncoder encoder = PEMEncoder.of();
String pem = encoder.encodeToString(cert); 

この例では、PEMをデコードして、X509Certificateに戻しています。

PEMDecoder decoder = PEMDecoder.of();
X509Certificate cert = decoder.decode(pem, X509Certificate.class); 

パスワードでPrivateKeyを暗号化し、PEM形式にエンコードするサンプルを2個ご紹介します。最初の例は、暗号用にPEMEncoder を構成し、1回のメソッド呼び出しで直接秘密鍵を暗号化、エンコードしています。

PEMEncoder encoder = PEMEncoder.of();
String pem = encoder.withEncryption(password).encodeToString(privateKey); 

上記の例は暗号化時にデフォルトのパラメータを使用しています。この2番目の例では、EncryptedPrivateKeyInfo クラスを使い、パスワードベースの暗号化アルゴリズムなどの追加パラメータで秘密鍵を暗号化し、その後PEM形式にエンコードします。

EncryptedPrivateKeyInfo epki = EncryptedPrivateKeyInfo.encryptKey(
    privateKey, password, "PBEWithHmacSHA256AndAES_256", null, null);
PEMEncoder encoder = PEMEncoder.of();
String pem = encoder.encodeToString(epki);

JEP 510: Key Derivation Function API

キー導出関数(KDF)APIのプレビュー版はJDK 24で提供され、JEP 478で定義されました。本リリースでは変更なしでAPIの最終版を提供します。KDFは鍵素材から鍵を導出するためのAPIであり、JEP 510でより詳細に説明されています。

JEP 478: Key Derivation Function API (Preview)
https://openjdk.org/jeps/478
JEP 510: Key Derivation Function API
https://openjdk.org/jeps/510

また、RFC 5869で定義されているHMACベースの抽出・拡張鍵導出関数(HKDF)の実装も含まれています。

RFC 5869: HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
https://www.rfc-editor.org/rfc/rfc5869.html

KDFは、鍵導出に依存する将来の複数の機能強化において非常に有用なAPIとなるでしょう。これにはTLS 1.3におけるハイブリッド鍵交換(IETFドラフト)やハイブリッド公開鍵暗号(RFC 9180)といったPQCメカニズムが含まれます。

Hybrid key exchange in TLS 1.3
https://datatracker.ietf.org/doc/draft-ietf-tls-hybrid-design/
RFC 9180: Hybrid Public Key Encryption
https://www.rfc-editor.org/rfc/rfc9180.html

また本APIは、Argon2(RFC 9106)のような強力で現代的なパスワードベース・アルゴリズムの使用も想定して設計されています。

RFC 9106: Argon2 Memory-Hard Function for Password Hashing and Proof-of-Work Applications
https://www.rfc-editor.org/rfc/rfc9106.html

主たる新規クラスはjavax.crypto.KDFです。

Class KDF
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/javax/crypto/KDF.html

JEPでは、HKDF-SHA256アルゴリズムを用いて32バイトのAES鍵を導出する例を示しています:

// Create a KDF object for the specified algorithm
KDF hkdf = KDF.getInstance("HKDF-SHA256");

// Create an ExtractExpand parameter specification
AlgorithmParameterSpec params = HKDFParameterSpec.ofExtract()
    .addIKM(initialKeyMaterial)
    .addSalt(salt).thenExpand(info, 32);

// Derive a 32-byte AES key
SecretKey key = hkdf.deriveKey("AES", params);

SHAKE128-256 and SHAKE256-512 MessageDigest Algorithms

SUNプロバイダに2つの新しいMessageDigestアルゴリズムが追加されました。

  • SHAKE128-256
  • SHAKE256-512

これらはNIST FIPS 202で定義された、SHAKE128およびSHAKE256拡張出力関数(XOF)の固定長バージョンです。

[FIPS 202] SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions
https://csrc.nist.gov/pubs/fips/202/final

以下はMessageDigestを使用してSHAKE128-256でバイト列をダイジェストする例です:

byte[] bytes = ... 
MessageDigest md = MessageDigest.getInstance("SHAKE128-256");
byte[] digest = md.digest(bytes);

Issue: [JDK-8354305] SHAKE128 and SHAKE256 MessageDigest algorithms
https://bugs.openjdk.org/browse/JDK-8354305

PKCS#11 Support for the HKDF-SHA256, HKDF-SHA384 and HKDF-SHA512 Key Derivation Function Algorithms

SunPKCS11プロバイダに、

  • HKDF-SHA256
  • HKDF-SHA384
  • HKDF-SHA512

という3個のキー導出関数アルゴリズムのサポートが追加されました。これらのアルゴリズムは、JDK 25の新しいKey Derivation Function APIで使用できます。詳細は以下のURLを参照してください。

SunPKCS11 Provider Supported Algorithms
https://docs.oracle.com/en/java/javase/25/security/pkcs11-reference-guide1.html#GUID-D3EF9023-7DDC-435D-9186-D2FD05674777

Issue: [JDK-8328119] Support HKDF in SunPKCS11
https://bugs.openjdk.org/browse/JDK-8328119

Added TLSv1.3 and CNSA 1.0 Algorithms to Implementation Requirements

Java Security Standard Algorithm Names Specification(Javaセキュリティ標準アルゴリズム名仕様)において、すべてのJava SE実装がサポートすべき暗号要件のリストに新たな要件が追加されました。

Security Algorithm Implementation Requirements
https://docs.oracle.com/en/java/javase/25/docs/specs/security/standard-names.html#security-algorithm-implementation-requirements

TLSv1.3暗号スイートおよび署名メカニズムの実装に必要な、RFC 8446で必須(MUST)または推奨(SHOULD)要件として定義されているすべての暗号アルゴリズムが追加されています。CNSA 1.0で要求されるすべてのアルゴリズムも追加されています。現時点で必須アルゴリズムやプロトコルの削除は行われていません。

RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3
https://www.rfc-editor.org/rfc/rfc8446
CNSA (Commercial National Security Algorithm (CNSA) Suite) 1.0
https://media.defense.gov/2021/Oct/15/2002874275/-1/-1/0/CNSA_WORKSHEET_20211015.PDF

新たな要件は以下の通りです:

  • AlgorithmParameters
    • ChaCha20-Poly1305
    • EC with secp256r1 or secp384r1 curves
    • RSASSA-PSS with MGF1 mask generation function and SHA-256 or SHA-384 hash algorithm
  • Cipher
    • AES/GCM/NoPadding with 256 bit key size
    • ChaCha20-Poly1305
  • KeyAgreement
    • ECDH with secp256r1 or secp384r1 curves
    • X25519
  • KeyFactory
    • EC
    • RSASSA-PSS
    • X25519
  • KeyGenerator
    • AES with 256 bit key size
    • ChaCha20
  • KeyPairGenerator
    • DH with 3072 bit key size
    • EC with secp256r1 or secp384r1 curves
    • RSA with 3072 bit key size
    • RSASSA-PSS with 2048, 3072, 4096 bit key sizes
    • X25519
  • MessageDigest
    • SHA-384
  • Signature
    • RSASSA-PSS with MGF1 mask generation function and SHA-256 or SHA-384 hash algorithm
    • SHA256WithECDSA with secp256r1 curve
    • SHA384WithECDSA with secp384r1 curve
    • SHA384WithRSA
  • SSLContext
    • TLSv1.3

Issue: [JDK-8283795] Add TLSv1.3 and CNSA 1.0 algorithms to implementation requirements
https://bugs.openjdk.org/browse/JDK-8283795

New Key Algorithms Section of the Java Security Standard Algorithm Names Specification

Java Security Standard Algorithm Names Specificationに、新しいKey Algorithmという章が追加されました。

Key Algorithms
https://docs.oracle.com/en/java/javase/25/docs/specs/security/standard-names.html#key-algorithms

この章では、KeyFactorySecretKeyFactoryKeyGenerator、またはKeyPairGenerator APIが生成または作成するキーの標準名を列挙しています。章の2パートで、非対称アルゴリズムと秘密鍵(または対称)アルゴリズムを区別しています。

Issue: [JDK-8346736] Java Security Standard Algorithm Names spec should include key algorithm names
https://bugs.openjdk.org/browse/JDK-8346736

Added PBES2 as a Standard AlgorithmParameters Algorithm

Java Security Standard Algorithm Names SpecificationのAlgorithmParametersの章に、標準アルゴリズムとしてPBES2 (Password-Based Cryptography Specification Version 2.1) が追加されました。

AlgorithmParameters Algorithms
https://docs.oracle.com/en/java/javase/25/docs/specs/security/standard-names.html#algorithmparameters-algorithms

PBES2アルゴリズムはPKCS #5: Password-Based Cryptography Specification Version 2.1で定義されています。

RFC 8018: PKCS #5: Password-Based Cryptography Specification Version 2.1
https://www.rfc-editor.org/rfc/rfc8018

PBES2のAlgorithmParameters実装は、SunJCEプロバイダがサポートしています。

Issue: [JDK-8348405] Add PBES2 as a standard AlgorithmParameters algorithm
https://bugs.openjdk.org/browse/JDK-8348405

TLS

Support for TLS Keying Material Exporters

javax.net.ssl.ExtendedSessionクラスに新たなメソッドが追加され、アプリケーションが接続のネゴシエーション済み TLS キーから、追加のアプリケーションレベルのキーマテリアルを生成できるようになりました。

Class ExtendedSSLSession
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/javax/net/ssl/ExtendedSSLSession.html

これらの新しいAPIは、IANAレジストリのTLS Exporter Labelsの章に記載されているものなど、キーマテリアルに依存する様々なエクスポート機構に有用です。

TLS Exporter Labels
https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#exporter-labels

以下の2つの新メソッドが追加されました。

public SecretKey exportKeyingMaterialKey(String keyAlg, String label, byte[] context, int length) throws SSLKeyException 
public byte[] exportKeyingMaterialData( String label, byte[] context, int length) throws SSLKeyException

最初のメソッドは、キーマテリアルをSecretKeyとしてエクスポートします。2番目のメソッドは、バイト配列としてエクスポートします。SecretKeyメソッドは、キーをハードウェアやトークンに保存する実装に有用です。

Issue: [JDK-8341346] Add support for exporting TLS Keying Material
https://bugs.openjdk.org/browse/JDK-8341346

New Mechanism to Disable Signature Schemes Based on Their TLS Scope

jdk.tls.disabledAlgorithmsセキュリティプロパティが強化され、TLSハンドシェイクや証明書署名においてアルゴリズムを選択的に無効化できるようになりました。この新しい構文により、ハンドシェイク署名のみ、または証明書署名のみに対してアルゴリズムを無効化することが容易になり、様々な要因に応じて望ましい場合があります。

この構文は既存のUsageConstraintを拡張し、新しいUsageTypeコンポーネントを追加します。以下はその例です。

UsageConstraint:
  usage UsageType { UsageType }

UsageType:
  HandshakeSignature | CertificateSignature 

アルゴリズム名として、署名アルゴリズム(例:SHA1withRSA)、アルゴリズム(例:RSA)、またはTLS署名方式(例:rsa_pkcs1_sha1)を利用できます。

Signature Algorithms
https://docs.oracle.com/en/java/javase/25/docs/specs/security/standard-names.html#signature-algorithms
Key Algorithms
https://docs.oracle.com/en/java/javase/25/docs/specs/security/standard-names.html#key-algorithms
Signature Schemes
https://docs.oracle.com/en/java/javase/25/docs/specs/security/standard-names.html#signature-schemes

Issue: [JDK-8349583] Add mechanism to disable signature schemes based on their TLS scope
https://bugs.openjdk.org/browse/JDK-8349583

Disabled SHA-1 in TLS 1.2 and DTLS 1.2 Handshake Signatures

TLS 1.2 および DTLS 1.2 のハンドシェイク署名で、SHA-1はデフォルトで無効化されました。RFC 9155 に規定されている通り、ハンドシェイク署名でのSHA-1使用は非推奨です。

RFC 9325: Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)
https://www.rfc-editor.org/rfc/rfc9325

ユーザーは、設定ファイルjava.security内のセキュリティプロパティjdk.tls.disabledAlgorithmsから、

rsa_pkcs1_sha1 usage HandshakeSignature, ecdsa_sha1 usage HandshakeSignature, dsa_sha1 usage HandshakeSignature

を削除することで、自己責任でハンドシェイク署名でのSHA-1を再度有効化できます。

Issue: [JDK-8353879] Release Note: Disabled SHA-1 in TLS 1.2 and DTLS 1.2 Handshake Signatures
https://bugs.openjdk.org/browse/JDK-8353879

Performance Improvements

暗号およびTLS実装において、パフォーマンスが改善しているものがあります。

Optimize Java Implementation of ML-KEM

ML-KEMのKEM実装の性能が1~2%向上しています。

Issue: [JDK-8347608] Optimize Java implementation of ML-KEM
https://bugs.openjdk.org/browse/JDK-8347608

Optimize Java Implementation of ML-DSA

ML-DSAのSignature実装のパフォーマンスが約10%向上しています。

Issue: [JDK-8347606] Optimize Java implementation of ML-DSA
https://bugs.openjdk.org/browse/JDK-8347606

Change ChaCha20 Intrinsic to use Quarter-Round Parallel Implementation on aarch64

ChaCha20暗号実装のパフォーマンスは、aarch64プロセッサ上で2~4%向上しています。

Issue: [JDK-8349106] Change ChaCha20 intrinsic to use quarter-round parallel implementation on aarch64
https://bugs.openjdk.org/browse/JDK-8349106

Reduce TLS Stateless Session Ticket Size

TLSステートレスチケットのサイズが大幅に小さくなりました。

Issue: [JDK-8357033] Reduce stateless session ticket size
https://bugs.openjdk.org/browse/JDK-8357033

Security Manager

Various Permission Classes Deprecated for Removal

Security ManagerがJDK 24で恒久的に無効化されたため、多くのpermissionクラスは現在では削除に向けて非推奨になっています。

JEP 486: Permanently Disable the Security Manager
https://openjdk.org/jeps/486

以下のクラスは最終的に非推奨とされています。

  • java.security.UnresolvedPermission
  • javax.net.ssl.SSLPermission
  • javax.security.auth.AuthPermission
  • javax.security.auth.PrivateCredentialPermission
  • javax.security.auth.kerberos.DelegationPermission
  • javax.security.auth.kerberos.ServicePermission
  • com.sun.security.jgss.InquireSecContextPermission
  • java.lang.RuntimePermission
  • java.lang.reflect.ReflectPermission
  • java.io.FilePermission
  • java.io.SerializablePermission
  • java.nio.file.LinkPermission
  • java.util.logging.LoggingPermission
  • java.util.PropertyPermission
  • jdk.jfr.FlightRecorderPermission
  • java.net.NetPermission
  • java.net.URLPermission
  • jdk.net.NetworkPermission
  • com.sun.tools.attach.AttachPermission
  • com.sun.jdi.JDIPermission
  • java.lang.management.ManagementPermission
  • javax.management.MBeanPermission
  • javax.management.MBeanTrustPermission
  • javax.management.MBeanServerPermission
  • javax.management.remote.SubjectDelegationPermission

さらに、java.net.URLConnectionおよびそのサブクラスjava.net.HttpURLConnectionで定義されているgetPermissionメソッドも廃止予定で非推奨になっています。

Issue: [JDK-8348967] Deprecate security permission classes for removal
https://bugs.openjdk.org/browse/JDK-8348967

Miscellaneous

Turn on Timestamp and Thread Details by Default for java.security.debug

JDK 23でjava.security.debugシステムプロパティに追加されたthreadおよびtimestampオプションが、デフォルトで有効になりました。各デバッグ出力には、スレッドID、スレッド名、呼び出し元情報(ソースコードと行番号)、日付と時刻が含まれるようになりました。例えば、

-Djava.security.debug=properties

オプション付きで実行したアプリケーションの出力の一例です。

properties[0x1|main|Security.java:161|2024-09-20 09:31:39.929]: java.security
properties[0x1|main|Security.java:122|2024-09-20 09:31:39.931]: Initial security property: jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024, DSA keySize < 1024, SHA1 denyAfter 2019-01-01 
properties[0x1|main|Security.java:122|2024-09-20 09:31:39.931]: Initial security property: security.provider.13=SunPKCS11
properties[0x1|main|Security.java:122|2024-09-20 09:31:39.931]: Initial security property: security.provider.12=Apple 
properties[0x1|main|Security.java:122|2024-09-20 09:31:39.931]: Initial security property: http.auth.digest.disabledAlgorithms=MD5, SHA-1
properties[0x1|main|Security.java:122|2024-09-20 09:31:39.932]: Initial security property: jdk.security.legacyAlgorithms=SHA1, RSA keySize < 2048, DSA keySize < 2048, DES, DESede, MD5, RC2, ARCFOUR
properties[0x1|main|Security.java:122|2024-09-20 09:31:39.932]: Initial security property: securerandom.source=file:/dev/random

Issue: [JDK-8350689] Turn on timestamp and thread metadata by default for java.security.debug
https://bugs.openjdk.org/browse/JDK-8350689

Javadoc for the java.security.debug Property

java.security.debugプロパティが、javadocに記載されるようになりました。

java.security.debug
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/security/doc-files/debug-system-property.html#java.security.debug

これはセキュリティコードのデバッグに非常に有用なプロパティです。

Issue: [JDK-8328914] Document the java.security.debug property in javadoc
https://bugs.openjdk.org/browse/JDK-8328914

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください