@@ -6,7 +6,8 @@ CDOC stands for 'Crypto Digidoc', encrypted file transmission format used in the
66
77* CDOC1 - Unofficial term for all (XML-ENC based) CDOC formats preceding CDOC2.
88* [ CDOC2] ( https://open-eid.github.io/CDOC2 ) is a new version of CDOC, featuring additional security
9- measures with optional server backend and support for long term cryptography.
9+ measures with optional server backend and support for long term cryptography and Smart-ID/Mobile-ID
10+ (auth based encryption)
1011
1112CDOC1 and CDOC2 version are not compatible.
1213
@@ -120,6 +121,7 @@ public KeyCapsuleClientFactory initKeyCapsuleClientFactory(String keyServerPrope
120121}
121122```
122123
124+
123125Alternatively:
124126
125127``` java
136138``` java
137139import ee.cyber.cdoc2.services.Cdoc2Services ;
138140
139- Properties p = new Properties (). setProperty(" key-capsule.properties" , " classpath:localhost.properties" );
141+ Properties p = new Properties ();
142+ p. setProperty(" key-capsule.properties" , " classpath:localhost.properties" );
140143Services services = Cdoc2Services . initFromProperties(p);
141144KeyCapsuleClientFactory capsuleClientFactory = services. get(KeyCapsuleClientFactory . class);
142145```
@@ -324,22 +327,29 @@ was used, see source code for [cdoc2-cli info](https://github.com/open-eid/cdoc2
324327
325328To create CDOC2 document with server scenario, [ cdoc2-capsule-server] ( https://github.com/open-eid/cdoc2-capsule-server ) client needs to be configured.
326329Easiest is to use one of existing properties files from [ cdoc2-cli/config] ( https://github.com/open-eid/cdoc2-java-ref-impl/tree/master/cdoc2-cli/config/ )
327- directory and ` .withServerProperties ` method:
330+ directory and ` .withKeyCapsuleClient ` method (or ` .withServices ` where ` Services ` object ` .hasService(KeyCapsuleClient.class) ` ) :
328331
329332``` java
330- File cdoc2FileToCreate = Paths . get(" /tmp/second.cdoc2" ). toFile();
331- String identificationCode = " 3..." ; // your id-code
332- String keyServerPropertiesFile = " /path/to/cdoc2-cli/conf/id.properties" ;
333- Properties p = new Properties (). load(
334- Resources . getResourceAsStream(keyServerPropertiesFile));
333+ import ee.cyber.cdoc2.client.KeyCapsuleClient ;
334+ import ee.cyber.cdoc2.client.KeyCapsuleClientImpl ;
335+ import ee.cyber.cdoc2.config.KeyCapsuleClientConfiguration ;
336+ import ee.cyber.cdoc2.config.PropertiesLoader ;
335337
336- List<EncryptionKeyMaterial > recipients =
337- EncryptionKeyMaterial . collectionBuilder(). fromEId(new String []{identificationCode});
338+ File cdoc2FileToCreate = Paths . get(" /tmp/second.cdoc2" ). toFile();
339+ String identificationCode = " 3..." ; // your id-code
340+ String keyServerPropertiesFile = " /path/to/cdoc2-cli/conf/id.properties" ;
341+ Properties p = PropertiesLoader . loadProperties(keyServerPropertiesFile);
342+ KeyCapsuleClient capsuleClient = KeyCapsuleClientImpl . create(KeyCapsuleClientConfiguration . load(p), false );
338343
339- CDocBuilder builder = new CDocBuilder ()
340- .withServerProperties(p)
341- .withPayloadFiles(Arrays . asList(payloadFiles))
342- .withRecipients(recipients);
344+ // download certificates from SK LDAP and creates EncryptionKeyMaterial from them
345+ // works for Estonian ID code only, implement similar class for other national ID codes or different LDAP
346+ List<EncryptionKeyMaterial > recipients =
347+ EstEncKeyMaterialBuilder . fromCertDirectory(new String []{identificationCode}). build();
348+
349+ CDocBuilder builder = new CDocBuilder ()
350+ .withKeyCapsuleClient(capsuleClient) // will use server scenario
351+ .withPayloadFiles(Arrays . asList(payloadFiles))
352+ .withRecipients(recipients);
343353
344354 builder. buildToFile(cdoc2FileToCreate);
345355```
@@ -370,7 +380,7 @@ key parts
370380 File [] payloadFiles = new File []{};// add some files
371381
372382 // normally initialized through -D option to java process
373- System . setProperty(" key-capsule.properties" ," classpath:localhost.properties" ); // from classpath
383+ System . setProperty(" key-capsule-post .properties" ," classpath:localhost.properties" ); // from classpath
374384 System . setProperty(" key-shares.properties" ," config/key_shares-test.properties" ); // from file system
375385
376386 // alternatively use Cdoc2Services.initFromProperties(Properties)
0 commit comments