|
| 1 | +# CDOC encrypted document format |
| 2 | +`.CDOC` is an extension used for distinguishing between encrypted DigiDoc files, which can only |
| 3 | +be accessed by using a secret key associated with ID-card (or other digital document’s) |
| 4 | +authentication certificate for specific recipients. |
| 5 | +The CDOC format relies on a public key infrastructure (PKI), where data encrypted with a public |
| 6 | +key can be decrypted with a private key, and vice versa: data encrypted with a private key can |
| 7 | +be decrypted with a public key. |
| 8 | + |
| 9 | +# CDOC1 usage guide |
| 10 | + |
| 11 | +## Introduction |
| 12 | +Platform provides the solution for document encryption/decryption in CDOC format with |
| 13 | +ID-card authentication certificate. |
| 14 | +CDOC1 is an XML-ENC-based CDOC format. First five chars `"<?xml"` (ignore case). |
| 15 | +CDOC files include an encrypted data file (XML document or another binary file (MS Word, Excel, |
| 16 | +PDF, RTF, etc), the recipient’s certificate, an encrypted key for decrypting the data file |
| 17 | +(so-called transport key) and other optional metadata. The data file is encrypted with the AES |
| 18 | +encryption algorithm using a 128-bit key. Several recipients (potential decrypters) can be added |
| 19 | +to one encrypted file – to this end, the certificates of all recipients and each recipient’s |
| 20 | +transport keys for encrypting the data file are added to the CDOC file. |
| 21 | +CDOC1 encryption is not appropriate for long term file storage. |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +### Decryption with expired certificate: |
| 26 | +* To decrypt documents, need exactly the same document (with the same certificates) as the |
| 27 | + one that the file was encrypted with. For example, can also decrypt files with expired |
| 28 | + certificates, even there is already issued a new document. |
| 29 | +* Files that have been encrypted to earlier/expired document cannot be opened with updated |
| 30 | + certificates and/or a new document. |
| 31 | + |
| 32 | +## Prerequisites |
| 33 | +* Java 1.8 |
| 34 | +* [Unlimited Strength Jurisdiction Policy](https://github.com/open-eid/cdoc4j/wiki/Enabling-Unlimited-Strength-Jurisdiction-Policy) |
| 35 | + |
| 36 | +## Installation |
| 37 | +You can use the library as a dependency from [Maven Central](https://mvnrepository.com/artifact/org.open-eid.cdoc4j/cdoc4j) |
| 38 | +``` |
| 39 | +<dependency> |
| 40 | + <groupId>org.open-eid.cdoc4j</groupId> |
| 41 | + <artifactId>cdoc4j</artifactId> |
| 42 | + <version>1.5</version> |
| 43 | +</dependency> |
| 44 | +``` |
| 45 | + |
| 46 | +See git repository for CDOC lib [cdoc4j](https://github.com/open-eid/cdoc4j). |
| 47 | + |
| 48 | +## Quick start guide |
| 49 | +Usage examples can see in [cdoc4j library](https://github.com/open-eid/cdoc4j/wiki/Examples-of-how-to-use-it). |
| 50 | + |
| 51 | +## Testing and Debugging |
| 52 | +CDOC1 has only unit testing, running at compile time. |
| 53 | + |
| 54 | + |
| 55 | +# CDOC2 usage guide |
| 56 | + |
| 57 | +## Introduction |
| 58 | +Platform provides the solution for document encryption/decryption in CDOC 2.0 file format |
| 59 | +with ID-card, digital ID (such as Smart-ID smart app or SIM-based Mobile-ID ) or user password. |
| 60 | +CDOC2 is binary that start with bytes (hex) `"43 44 4f 43 02"` (`"CDOC."`) |
| 61 | +It is designed to encrypt data in such a way that it is decryptable to a specific user or group of users. |
| 62 | +CDOC2 also allows to re-encrypt existing CDOC2 container but using only user password. |
| 63 | +Encryption with password allows file long term storage. |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +## Prerequisites |
| 68 | +* Java 17 |
| 69 | +* Maven 3.8.x |
| 70 | +* Docker available and running for server scenarios (required for running tests, use |
| 71 | + `-Dmaven.test.skip=true` to skip) |
| 72 | + |
| 73 | +## Command line installation |
| 74 | +* Download the latest version of [cdoc2-cli.jar](https://github.com/open-eid/cdoc2-java-ref-impl/packages/2223169). |
| 75 | +* Configure it using [configuration](https://github.com/open-eid/cdoc2-java-ref-impl/blob/master/cdoc2-cli/config/localhost/localhost.properties). |
| 76 | + Key store and certificates located in [Keys directoriy](https://github.com/open-eid/cdoc2-java-ref-impl/tree/master/cdoc2-cli/keys). |
| 77 | + |
| 78 | +Or follow manual installation instruction. |
| 79 | + |
| 80 | +### Manual installation instruction |
| 81 | +Clone [cdoc2-java-ref-impl](https://github.com/open-eid/cdoc2-java-ref-impl) and build it for creating `cdoc2-cli-<version>.jar` manually. |
| 82 | +Running guide is described in [cdoc2-cli/README.md](https://github.com/open-eid/cdoc2-java-ref-impl/blob/master/cdoc2-cli/README.md). |
| 83 | +This will create `cdoc2-cli/target/cdoc2-cli-<version>.jar`. |
| 84 | + |
| 85 | +## Quick start guide |
| 86 | + |
| 87 | +See [cdoc2-lib/README.md](../cdoc2-lib/README.md) for quick start how to use the `cdoc2-lib`. |
| 88 | + |
| 89 | +For command line usage execute encryption/decryption commands via `cdoc2-cli-<version>.jar` |
| 90 | +as per [cdoc2-cli/README.md](../cdoc2-cli/README.md). |
| 91 | + |
| 92 | +## Server scenarios |
| 93 | +For executing server scenarios you will also need to run the capsule server: |
| 94 | +* [OpenAPI specifications](https://github.com/open-eid/cdoc2-openapi) is required for server stub generation. |
| 95 | + Installing instruction is described in [README.md](https://github.com/open-eid/cdoc2-openapi/blob/master/README.md). |
| 96 | +* [cdoc2-capsule-server](https://github.com/open-eid/cdoc2-capsule-server). Running instruction |
| 97 | + is described in [getting-started.md](https://github.com/open-eid/cdoc2-capsule-server/blob/master/getting-started.md). |
| 98 | + |
| 99 | +Capsule server module has an [admin guide](https://github.com/open-eid/cdoc2-capsule-server/blob/master/admin-guide.md) |
| 100 | +with details for application configuration, keystore creation and monitoring. |
| 101 | + |
| 102 | +### Server maven dependencies installation |
| 103 | +You should configure GitHub package repository access with Personal Access Token for getting |
| 104 | +[Open API](https://gitlab.ext.cyber.ee/cdoc2/cdoc2-java-ref-impl#maven-dependencies) and [Key |
| 105 | +Capsule Server](https://github.com/open-eid/cdoc2-capsule-server/blob/master/README.md#maven-dependencies) |
| 106 | +Maven dependencies. |
| 107 | + |
| 108 | +### Key capsule client configuration |
| 109 | +Server configuration can be sent in command line request via option `--server`. Property keys start |
| 110 | +with `cdoc2.client.server.*`. |
| 111 | +Local configuration example located in [localhost.properties](https://github.com/open-eid/cdoc2-java-ref-impl/blob/master/cdoc2-cli/config/localhost/localhost.properties). |
| 112 | + |
| 113 | +### Server scenario usage example |
| 114 | +Encrypt document with server properties and public key: |
| 115 | + |
| 116 | +`java -jar target/cdoc2-cli-*.jar create --server=config/localhost/localhost.properties -f /tmp/localhost.cdoc -p keys/cdoc2client_pub.key README.md` |
| 117 | + |
| 118 | +Decrypt document with server properties: |
| 119 | + |
| 120 | +`java -jar target/cdoc2-cli-*.jar decrypt --server=config/localhost/localhost.properties -f /tmp/localhost.cdoc -o /tmp/` |
| 121 | + |
| 122 | +`*` must be replaced with the latest version built. Example `1.4.0`. |
| 123 | + |
| 124 | +Configuration properties for testing located in [localhost.properties](https://github.com/open-eid/cdoc2-java-ref-impl/blob/master/cdoc2-cli/config/localhost/localhost.properties). |
| 125 | + |
| 126 | +## Use cases |
| 127 | +All use cases are described in [CDOC2 specification](https://open-eid.github.io/CDOC2/1.1/01_use_case_model/ch03_use_cases/) |
| 128 | + |
| 129 | +## End-user software |
| 130 | +End-user software to create/decrypt CDOC2: https://github.com/open-eid/DigiDoc4-Client |
| 131 | + |
| 132 | +## Testing and Debugging |
| 133 | +Servers debugging is switched off by default. Change [get-server](https://github.com/open-eid/cdoc2-capsule-server/blob/master/get-server/config/application-local.properties#L31) |
| 134 | +and [put-server](https://github.com/open-eid/cdoc2-capsule-server/blob/master/put-server/config/application-local.properties#L18) |
| 135 | +application property `logging.level.root` from `info` to `debug` to see servers logs. |
| 136 | + |
| 137 | +_CDOC2 has few testing tools:_ |
| 138 | +* General unit tests |
| 139 | +* PKCS11 unit tests |
| 140 | +* Bats tests |
| 141 | +* Gatling load tests |
| 142 | + |
| 143 | +### General unit tests |
| 144 | +Tests are run within compile time. |
| 145 | + |
| 146 | +### PKCS11 unit tests |
| 147 | +Besides general unit tests both `cdoc2-capsule-server` and `cdoc2-java-ref-impl` have PKCS11 |
| 148 | +unit tests with tag `pkcs11`, which are disabled at compile time and can be run separately only |
| 149 | +with PKCS11 hardware device (smart card, usb token). The device and its details can be |
| 150 | +configured using a property file [pkcs11-test-idcard.properties](https://github.com/open-eid/cdoc2-java-ref-impl/blob/master/cdoc2-lib/src/test/resources/pkcs11-test-idcard.properties). |
| 151 | + |
| 152 | +### Bats tests |
| 153 | +Tests can be run manually from `cdoc2-java-ref-impl` module. For running follow instruction in |
| 154 | +[README.md](https://github.com/open-eid/cdoc2-java-ref-impl/blob/master/test/README.md). |
| 155 | +Bats tests have test vectors with already generated CDOC2 documents samples and testing their |
| 156 | +successful decryption. It is required to ensure that new changes won't brake previously |
| 157 | +encrypted documents and still can decrypt them. At the same time there are tests which create new |
| 158 | +encrypted CDOC2 documents and also test their successful decryption. |
| 159 | + |
| 160 | +### Gatling load tests |
| 161 | +Load tests are located in [cdoc2-gatling-tests](https://github.com/open-eid/cdoc2-gatling-tests) |
| 162 | +module. |
| 163 | +Get/Put servers must be running for load tests execution. Follow description in [README.md](https://github.com/open-eid/cdoc2-gatling-tests/blob/master/README.md). |
| 164 | +Gatling tests are running at CI pipeline. |
| 165 | + |
| 166 | +### Establish versioning |
| 167 | +Each module/submodule has its own independent semantic versioning `MAJOR.MINOR.PATCH`. |
| 168 | +* MAJOR version when you make incompatible API changes |
| 169 | +* MINOR version when you add functionality in a backward compatible manner |
| 170 | +* PATCH version when you make backward compatible bug fixes |
| 171 | + |
| 172 | +Additional label `-SNAPSHOT` is added for pre-release and build metadata as an extension to the |
| 173 | +`MAJOR.MINOR.PATCH` format. |
| 174 | +More details in [VERSIONING.md](https://github.com/open-eid/cdoc2-java-ref-impl/blob/master/VERSIONING.md). |
| 175 | + |
| 176 | +### Monitoring |
| 177 | +`cdoc2-capsule-server` has a monitoring tool Spring-boot actuator. It has several endpoints for |
| 178 | +monitoring metrics, such as application info, health, startup timeline and prometheus. |
| 179 | +Monitoring endpoints are described in [cdoc2-server/admin-guide.md](https://github.com/open-eid/cdoc2-capsule-server/blob/master/admin-guide.md) |
0 commit comments