Skip to content

Commit c1edba4

Browse files
committed
Merge branch 'RM-3029_cdoc_usage_guide_jkusman' into 'master'
RM-3029: CDOC2 usage guide jkusman See merge request cdoc2/cdoc2-java-ref-impl!58
2 parents ec036f1 + 8a73f84 commit c1edba4

File tree

13 files changed

+898
-9
lines changed

13 files changed

+898
-9
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ Other CDOC2 repositories:
157157
- https://github.com/open-eid/cdoc2-capsule-server CDOC2 Capsule Server
158158
- https://github.com/open-eid/cdoc2-gatling-tests Gatling tests for CDOC2 Capsule Server
159159

160+
## Using
161+
162+
Refer [cdoc2-lib/README.md](cdoc2-lib/README.md) and see [cdoc2-example-app](cdoc2-example-app)
163+
160164
## Preconditions for building
161165
* Java 17
162166
* Maven 3.8.x
@@ -169,7 +173,8 @@ https://github.com/open-eid/cdoc2-openapi OpenAPI specifications for client stub
169173
Configure github package repo access
170174
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry#authenticating-with-a-personal-access-token
171175

172-
Example `<profile>` section of `settings.xml` for using cdoc2 dependencies:
176+
Add repository url to `<profile>` section of your PC local file `.m2/settings.xml` for using cdoc2
177+
dependencies:
173178
```xml
174179
<profile>
175180
<id>github</id>
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
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+
![cdoc1-solution.png](cdoc1-solution.png)
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+
![cdoc2-solution.png](cdoc2-solution.png)
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)

cdoc2-example-app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Requirements:
88

99
* Java17
1010

11-
TODO: howto setup mvn repository for getting cdoc2 dependencies (depends: GitHub maven repo)
11+
Configure cdoc2 maven dependencies: https://github.com/open-eid/cdoc2-java-ref-impl/tree/master?tab=readme-ov-file#maven-dependencies
1212

1313
```bash
1414
mvnw install
63 KB
Loading
63.6 KB
Loading

cdoc2-example-app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<dependency>
3636
<groupId>ee.cyber.cdoc2</groupId>
3737
<artifactId>cdoc2-lib</artifactId>
38-
<version>1.2.0</version>
38+
<version>2.0.0</version>
3939
</dependency>
4040
<dependency>
4141
<groupId>org.open-eid.cdoc4j</groupId>

cdoc2-example-app/src/main/java/ee/cyber/cdoc2/converter/util/AutoRemovableDir.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import java.nio.file.Path;
77
import java.util.Objects;
88

9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
912
public class AutoRemovableDir implements AutoCloseable {
1013

1114
private static final Logger log = LoggerFactory.getLogger(AutoRemovableDir.class);

cdoc2-example-app/src/main/java/ee/cyber/cdoc2/converter/util/Util.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import ee.cyber.cdoc2.CDocBuilder;
44
import ee.cyber.cdoc2.CDocException;
5+
import ee.cyber.cdoc2.CDocUserException;
56
import ee.cyber.cdoc2.CDocValidationException;
7+
import ee.cyber.cdoc2.UserErrorCode;
68
import ee.cyber.cdoc2.crypto.keymaterial.EncryptionKeyMaterial;
79

810
import org.openeid.cdoc4j.CDOCDecrypter;
@@ -65,9 +67,9 @@ public static char[] readPasswordInteractively(String prompt) {
6567
if (result == JOptionPane.OK_OPTION) {
6668
return pf.getPassword();
6769
} else if (result == JOptionPane.OK_CANCEL_OPTION) {
68-
throw new CDocUserException("Password entry cancelled by user");
70+
throw new CDocUserException(UserErrorCode.USER_CANCEL, "Password entry cancelled by user");
6971
} else {
70-
throw new CDocUserException("Password not entered");
72+
throw new CDocUserException(UserErrorCode.USER_CANCEL, "Password not entered");
7173
}
7274
}
7375
}

0 commit comments

Comments
 (0)