Different types of keystore in Java -- DKS

English 简体中文 繁体中文 ภาษาไทย Tiếng Việt
Summary

Domain KeyStore (DKS), introduced in Java 8, functions as a "keystore of keystores," abstracting a collection of individual keystores into a single logical unit. Developers configure DKS by defining domains in a configuration file, specifying each contained keystore with properties such as its URI and type. Loading a DKS instance involves using KeyStore.getInstance("DKS") and passing a DomainLoadStoreParameter object, which includes the configuration URI and a map of passwords for the underlying keystores. DKS also supports loading a single JKS or default-type keystore directly from an InputStream. Once loaded, DKS behaves like any other KeyStore for subsequent cryptographic operations.

Domain KeyStore (DKS) คือ keystore ของ keystore มันเป็นการรวม keystore หลายๆ อันเข้าด้วยกันให้เป็น keystore เดียว แต่ตัวมันเองไม่ได้เป็น keystore จริงๆ รูปแบบ keystore ใหม่นี้ถูกนำมาใช้ใน Java 8 มีคลาสใหม่ DomainLoadStoreParameter ซึ่งเกี่ยวข้องอย่างใกล้ชิดกับ DKS

ในการโหลด keystore ต่างๆ เข้าไปใน keystore เดียว จำเป็นต้องมีการกำหนดค่า นี่คือรูปแบบการกำหนดค่าสำหรับการจัดกลุ่ม keystore ต่างๆ

domain  [ ...] {
         keystore  [ ...] ;
         ...
};

ด้านล่างนี้เป็นตัวอย่างการกำหนดค่าสำหรับโดเมน domain

domain app1 {
     keystore app1-truststore
         keystoreURI="file:///app1/etc/truststore.jks";

     keystore system-truststore
         keystoreURI="${java.home}/lib/security/cacerts";

     keystore app1-keystore
         keystoreType="PKCS12"
         keystoreURI="file:///app1/etc/keystore.p12";
 };

การกำหนดค่านี้กำหนดโดเมน app1 และมี keystore สามอัน มีการระบุ keystoreName สำหรับแต่ละ keystore (app1-truststore, system-truststore, app1-keystore) โปรดทราบว่า keystoreName ต้องไม่ซ้ำกันสำหรับแต่ละรายการ

หลังจาก keystoreName คือชุดของ properties สำหรับ keystore properties เหล่านี้รวมถึง keystoreURI, keystoreType, keystoreProviderName, keystorePasswordEnv, entryNameSeparator ชื่อ properties อธิบายตัวเองได้

เมื่อโหลด keystore DKS วัตถุ DomainLoadStoreParameter จะถูกสร้างขึ้นและส่งไปยัง KeyStore.load() ด้านล่างนี้เป็นตัวอย่างโค้ดสำหรับการโหลด keystore DKS

Map<String, KeyStore.ProtectionParameter> PASSWORDS =
        new HashMap<String, KeyStore.ProtectionParameter>() {{
            put("keystore",
                new KeyStore.PasswordProtection("test123".toCharArray()));
            put("policy_keystore",
                new KeyStore.PasswordProtection(
                    "Alias.password".toCharArray()));
            put("pw_keystore",
                new KeyStore.PasswordProtection("test12".toCharArray()));
            put("eckeystore1",
                new KeyStore.PasswordProtection("password".toCharArray()));
            put("eckeystore2",
                new KeyStore.PasswordProtection("password".toCharArray()));
            put("truststore",
                new KeyStore.PasswordProtection("changeit".toCharArray()));
            put("empty",
                new KeyStore.PasswordProtection("passphrase".toCharArray()));
}};
URI config = new URI(CONFIG + "#system");
KeyStore keystore = KeyStore.getInstance("DKS");
keystore.load(new DomainLoadStoreParameter(config, PASSWORDS));

config คือเส้นทางการกำหนดค่าสำหรับ keystore DKS และ PASSWORDS คือ map ที่มีรหัสผ่านที่ตรงกันสำหรับ keystore ที่กำหนดไว้ในไฟล์กำหนดค่า

DKS ยังรองรับการโหลด InputStream ในกรณีนี้ InputStream ต้องเป็นสตรีม keystore เดียวที่มีชนิด keystore เป็น JKS หรือ KeyStore.getDefaultType() ตัวอย่างเช่น โค้ดสแนปช็อตด้านล่างจะโหลด keystore JKS โดยใช้ DKS

char[] PASSWORD = <PASSWORD>;
KeyStore keyStore = KeyStore.getInstance("DKS");, 
keyStore.load(new FileInputStream("keystore.jks"), PASSWORD);

เมื่อโหลด keystore แล้ว การทำงานอื่นๆ ของ keystore ก็เหมือนกับ keystore ชนิดอื่นๆ เช่น JKS สำหรับการดำเนินการเกี่ยวกับการสร้างคีย์และใบรับรอง โปรดอ่าน Different types of keystore in Java -- JKS

JAVA TUTORIAL KEYSTORE DKS

  RELATED

  COMMENTS

0

No comment for this article.