JDK 1.8.0_152での無制限強度暗号ポリシーの変更方法 ※Java9も少し含む
今更だけどJCE policyの解除方法がかわったっぽいので検証。
検証プログラム https://github.com/kuwaccho/Verification/blob/master/src/AesCryptTest.java
- Java8の場合
keyが128bitの場合
PLAIN TEXT: (・ω・`U) ENCRYPTED : cOipgSYWi6/AXsfjTNmysQ== DECRYPTED : (・ω・`U)
何もしないでkeyが256bitの場合
PLAIN TEXT: (・ω・`U) java.security.InvalidKeyException: Illegal key size at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1039) at javax.crypto.Cipher.implInit(Cipher.java:805) at javax.crypto.Cipher.chooseProvider(Cipher.java:864) at javax.crypto.Cipher.init(Cipher.java:1396) at javax.crypto.Cipher.init(Cipher.java:1327) at AesCryptTest.main(AesCryptTest.java:23)
jdk1.8.0_152/jre/lib/security/java.security の826行目にある以下のプロパティのコメントアウトを解除
#crypto.policy=unlimited ↓ crypto.policy=unlimited
結果
PLAIN TEXT: (・ω・`U) ENCRYPTED : 3858uw2xCZPbmpV9xs4/eA== DECRYPTED : (・ω・`U)
ちなみに
jdk1.8.0_152/jre/lib/security/policy ├─limited │ local_policy.jar │ US_export_policy.jar │ └─unlimited local_policy.jar US_export_policy.jar
とあるのでこのあたりを切り分けているんだろうなあ。
あと Java™ SE Development Kit 8, Update 152 Release Notes にこんなこと書かれているので注意。
Because the old JCE jurisdiction files are left in <java-home>/lib/security, they may not meet the latest security JAR signing standards, which were refreshed in 6u131, 7u121, 8u111, and later updates. An exception similar to the following might be seen if the old files are used:
Caused by: java.lang.SecurityException: Jurisdiction policy files are not signed by trusted signers! at javax.crypto.JceSecurity.loadPolicies(JceSecurity.java:593) at javax.crypto.JceSecurity.setupJurisdictionPolicies(JceSecurity.java:524)
- Java9,10の場合
Java9,10の場合はjava.securityの場所がconf以下に変更になっているのと、最初からコメントアウトはされていない(832行目付近参照)ので 何もしないで動く。
The default JCE policy files bundled in this Java Runtime Environment allow for "unlimited" cryptographic strengths.
For convenience, this software also contains the historic "limited" strength policy files which restricts cryptographic strengths. To use the limited strength policy, instead of the default unlimited policy, you must update the "crypto.policy" Security property (in /conf/security/java.security) to point to the appropriate directory. You are advised to consult your export/import control counsel or attorney to determine the exact requirements of your location, and what policy settings should be used.
弁護士とちゃんと相談しろよという一文がなんかひっかかるが。
AESの暗号鍵列長のポリシーが変更になった理由は何なのかは気になる。 アメリカ政府の方針変換なのか、そもそも年数がたちすぎているからかセキュリティの問題か......。