Skip to content

Commit 5e08474

Browse files
committed
v0.5.1
1 parent 64b0254 commit 5e08474

File tree

8 files changed

+760
-235
lines changed

8 files changed

+760
-235
lines changed

README.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,37 @@
44
The library provides a Java friendly API to the Cosmian Ubiquitous Encryption platform:
55

66
- perform [Confidential Data Access](#confidential-data-access) advanced encryption routines
7-
- build and run [Confidential Micro Services](#confidential-micro-services) on the Cosmian Confidential Cloud
7+
- build and run [Secure Computations](#secure-computations) on the Cosmian Confidential Cloud
88
- managed keys with the [Cosmian Confidential Key Management Service (KMS)](#confidential-kms)
99

1010

1111
:warning: This is the public release of the java library for Cosmian Ubiquitous Encryption. Only a limited set of the operations is currently publicly supported. Ask us for details.
1212

1313

14-
- [Confidential Data Access](#confidential-data-access)
15-
- [Quick Start](#quick-start)
16-
- [Local encryption and decryption](#local-encryption-and-decryption)
17-
- [Confidential Micro Services](#confidential-micro-services)
18-
- [Confidential KMS](#confidential-kms)
19-
2014

2115
This library is available on Maven Central
2216

2317
```xml
2418
<dependency>
2519
<groupId>com.cosmian</groupId>
2620
<artifactId>cosmian_java_lib</artifactId>
27-
<version>0.5.0</version>
21+
<version>0.5.1</version>
2822
</dependency>
2923
```
3024

25+
26+
27+
- [Confidential Data Access](#confidential-data-access)
28+
- [Versions Correspondence](#versions-correspondence)
29+
- [Quick Start ABE+AES](#quick-start-abeaes)
30+
- [Local ABE+AES encryption and decryption](#local-abeaes-encryption-and-decryption)
31+
- [Building the the ABE GPSW native lib](#building-the-the-abe-gpsw-native-lib)
32+
- [Using the native library](#using-the-native-library)
33+
- [Secure Computations](#secure-computations)
34+
- [Confidential KMS](#confidential-kms)
35+
36+
37+
3138
## Confidential Data Access
3239

3340
Cosmian Ubiquitous Encryption provides the ability to encrypt data - locally or inside the KMS - using policy attributes. The only users able to decrypt the data are those possessing a key holding the correct access policy.
@@ -36,6 +43,15 @@ Attributes Based Encryption (ABE) allows building secure data lakes, repositorie
3643

3744
In addition, Cosmian Confidential Data Access allows building secure indexes on the data, to efficiently search the encrypted data, without the cloud learning anything about the search query, the response or the underlying data itself.
3845

46+
47+
### Versions Correspondence
48+
49+
KMS Server | Java Lib | abe_gpsw lib
50+
-----------|----------|--------------
51+
1.2.0 | 0.5.0 | 0.3.0
52+
1.2.1 | 0.5.1 | 0.4.0
53+
54+
3955
### Quick Start ABE+AES
4056

4157
Head for [demo.java](./src/test/java/com/cosmian/Demo.java) which demonstrates the use of the Abe class to exercise the Cosmian KMS server to create keys, encrypt and decrypt messages.
@@ -65,7 +81,9 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
6581
2. Check out the [ABE GPSW library](https://github.com/Cosmian/abe_gpsw)
6682

6783
```sh
68-
git clone https://github.com/Cosmian/abe_gpsw.git
84+
git clone https://github.com/Cosmian/abe_gpsw.git && \
85+
cd abe_gpsw && \
86+
git checkout v0.4.0
6987
```
7088

7189
3. Build the native library, which will be available as `libabe_gpsw.so` (linux) or `libabe_gpsw.dylib` (macos) in the `target` directory
@@ -74,12 +92,19 @@ git clone https://github.com/Cosmian/abe_gpsw.git
7492
cargo build --release --all-features
7593
```
7694

95+
*Note for MacOS M1 machines*
96+
If java is running in intel x86_64 emulation mode, the library must be built for an x86_64 target, i.e.
97+
98+
```sh
99+
cargo build --release --all-features --target x86_64-apple-darwin
100+
```
101+
77102
4. Place the library on the dynamic libraries path of your system, or a path indicated by `LD_LIBRARY_PATH` on Linux. Alternatively, If you are using tis library in a java project, you can place the library in
78103

79104

80105
- `src/main/resources/linux-x86-64` folder for a Linux Intel machine
81106
- `src/main/resources/linux-amd64` folder for a Linux AMD machine
82-
- `src/main/resources/darwin` folder for a Mac running MacOS
107+
- `src/main/resources/darwin` folder for a Mac running MacOS (M1 and Intel)
83108
- `src/main/resources/win32-x86` folder for a Windows machine (untested)
84109

85110
#### Using the native library
@@ -160,11 +185,12 @@ byte[] data_ = FFI.decryptBlock(decryptedHeader.getSymmetricKey(), uid, 0, encry
160185
assertTrue(Arrays.equals(data, data_));
161186
```
162187

163-
## Confidential Micro Services
188+
189+
## Secure Computations
164190

165191
*Not publicly available yet. Call Cosmian for early access*
166192

167-
Cosmian Confidential Micro Services allows building micro services in Python (soon Java) that can be deployed on the Cosmian Confidential Cloud.
193+
Cosmian Secure Computations allows building micro services in Python (soon Java) that can be deployed on the Cosmian Confidential Cloud.
168194

169195
The code, the data and the results are encrypted at all times, so the Cosmian Cloud does not learn anything about the data or the algorithm.
170196

@@ -181,10 +207,10 @@ Also, data sources, code and results can be encrypted under different keys enabl
181207

182208
## Confidential KMS
183209

184-
Cosmian offers a confidential KMS in the Cosmian Confidential Cloud. The KMS operations are protected with the same technology used for the Confidential Micro Services, so Cosmian never learns anything about the keys stored in the KMS or the operations performed with those keys inside the KMS (encryption, decryption, signature,...).
210+
Cosmian offers a confidential KMS in the Cosmian Confidential Cloud. The KMS operations are protected with the same technology used for the Secure Computations, so Cosmian never learns anything about the keys stored in the KMS or the operations performed with those keys inside the KMS (encryption, decryption, signature,...).
185211

186212
Use of Cosmian KMS is included with the services above.
187213

188214
The KMS offers a KMIP 2.1 interface.
189215

190-
*Only the KMS operations required to enable the Confidential Data Access and Confidential Micro Services are publicly available for now. Contact Cosmian for full KMS access*
216+
*Only the KMS operations required to enable the Confidential Data Access and Secure Computations are publicly available for now. Contact Cosmian for full KMS access*

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.cosmian</groupId>
55
<artifactId>cosmian_java_lib</artifactId>
6-
<version>0.5.1-SNAPSHOT</version>
6+
<version>0.5.1</version>
77

88
<name>cosmian_java_lib</name>
99
<description>The Cosmian Java Lib that provides local encryption/decyption and access to the Cosmian public platform APIs</description>

src/main/java/com/cosmian/jna/Ffi.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,21 @@ public int symmetricEncryptionOverhead() {
298298
return FfiWrapper.INSTANCE.h_aes_symmetric_encryption_overhead();
299299
}
300300

301+
/**
302+
* Symmetrically encrypt a block of clear text data.
303+
*
304+
* No resource UID is used for authentication and the block number is assumed to
305+
* be zero
306+
*
307+
* @param symmetricKey The key to use to symmetrically encrypt the block
308+
* @param clearText the clear text to encrypt
309+
* @return the encrypted block
310+
* @throws FfiException in case of native library error
311+
*/
312+
public byte[] encryptBlock(byte[] symmetricKey, byte[] clearText) throws FfiException {
313+
return encryptBlock(symmetricKey, new byte[] {}, 0, clearText);
314+
}
315+
301316
/**
302317
* Symmetrically encrypt a block of clear text data.
303318
*
@@ -324,8 +339,13 @@ public byte[] encryptBlock(byte[] symmetricKey, byte[] uid, int blockNumber,
324339
symmetricKeyPointer.write(0, symmetricKey, 0, symmetricKey.length);
325340

326341
// Uid
327-
final Pointer uidPointer = new Memory(uid.length);
328-
uidPointer.write(0, uid, 0, uid.length);
342+
final Pointer uidPointer;
343+
if (uid.length > 0) {
344+
uidPointer = new Memory(uid.length);
345+
uidPointer.write(0, uid, 0, uid.length);
346+
} else {
347+
uidPointer = Pointer.NULL;
348+
}
329349

330350
// Additional Data
331351
final Pointer dataPointer = new Memory(clearText.length);
@@ -339,6 +359,23 @@ public byte[] encryptBlock(byte[] symmetricKey, byte[] uid, int blockNumber,
339359
return Arrays.copyOfRange(cipherTextBuffer, 0, cipherTextBufferSize.getValue());
340360
}
341361

362+
/**
363+
* Symmetrically decrypt a block of encrypted data.
364+
*
365+
* No resource UID is used for authentication and the block number is assumed to
366+
* be zero
367+
*
368+
* @param symmetricKey the symmetric key to use
369+
* @param encryptedBytes the encrypted block bytes
370+
* @return the clear text bytes
371+
* @throws FfiException in case of native library error
372+
*/
373+
public byte[] decryptBlock(byte[] symmetricKey, byte[] encryptedBytes)
374+
throws FfiException {
375+
376+
return decryptBlock(symmetricKey, new byte[] {}, 0, encryptedBytes);
377+
}
378+
342379
/**
343380
* Symmetrically decrypt a block of encrypted data.
344381
*
@@ -365,8 +402,13 @@ public byte[] decryptBlock(byte[] symmetricKey, byte[] uid, int blockNumber, byt
365402
symmetricKeyPointer.write(0, symmetricKey, 0, symmetricKey.length);
366403

367404
// Uid
368-
final Pointer uidPointer = new Memory(uid.length);
369-
uidPointer.write(0, uid, 0, uid.length);
405+
final Pointer uidPointer;
406+
if (uid.length > 0) {
407+
uidPointer = new Memory(uid.length);
408+
uidPointer.write(0, uid, 0, uid.length);
409+
} else {
410+
uidPointer = Pointer.NULL;
411+
}
370412

371413
// Encrypted Data
372414
final Pointer encryptedBytesPointer = new Memory(encryptedBytes.length);

src/main/java/com/cosmian/rest/abe/Abe.java

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,14 @@ public String importUserDecryptionKey(String uniqueIdentifier, PrivateKey userDe
297297
/**
298298
* Encrypt data in the KMS using the given Policy Attributes (@see {@link Attr})
299299
* and Public Master Key.
300-
* The data is encrypted using an hybrid encryption scheme ABE + AÉS 256 GCM
300+
* The data is encrypted using an hybrid encryption scheme ABE + AÉS 256 GCM.
301+
* No Metadata is added to the header and no resource uid is used in the AES
302+
* AEAD scheme.
303+
*
304+
* The generated cipher text is made of 3 parts
305+
* - the length of the encrypted header as a u32 in big endian format (4 bytes)
306+
* - the header
307+
* - the AES GCM encrypted content
301308
*
302309
* @param publicMasterKeyUniqueIdentifier the UID of the Public Key
303310
* @param data the data to encrypt
@@ -307,11 +314,37 @@ public String importUserDecryptionKey(String uniqueIdentifier, PrivateKey userDe
307314
*/
308315
public byte[] kmsEncrypt(String publicMasterKeyUniqueIdentifier, byte[] data, Attr[] attributes)
309316
throws CosmianException {
317+
return kmsEncrypt(publicMasterKeyUniqueIdentifier, data, attributes, Optional.empty());
318+
}
319+
320+
/**
321+
* Encrypt data in the KMS using the given Policy Attributes (@see {@link Attr})
322+
* and Public Master Key.
323+
* The data is encrypted using an hybrid encryption scheme ABE + AÉS 256 GCM.
324+
*
325+
* The uid, is used in the authentication of the AES GCM scheme.
326+
* It is not saved ith the header and must be resupplied on decryption
327+
*
328+
* The generated cipher text is made of 3 parts
329+
* - the length of the encrypted header as a u32 in big endian format (4 bytes)
330+
* - the header
331+
* - the AES GCM encrypted content
332+
*
333+
* @param publicMasterKeyUniqueIdentifier the UID of the Public Key
334+
* @param data the data to encrypt
335+
* @param attributes the Policy Attributes
336+
* @return the encrypted data
337+
* @throws CosmianException if the encryption fails
338+
*/
339+
public byte[] kmsEncrypt(String publicMasterKeyUniqueIdentifier, byte[] data, Attr[] attributes,
340+
Optional<byte[]> uid)
341+
throws CosmianException {
310342
try {
311343
DataToEncrypt dataToEncrypt = new DataToEncrypt(attributes, data);
312344
ObjectMapper mapper = new ObjectMapper();
313345
byte[] bytes = mapper.writeValueAsBytes(dataToEncrypt);
314-
Encrypt request = new Encrypt(publicMasterKeyUniqueIdentifier, bytes, Optional.empty(), Optional.empty());
346+
Encrypt request = new Encrypt(publicMasterKeyUniqueIdentifier, bytes, Optional.empty(),
347+
uid.isPresent() ? Optional.of(uid.get()) : Optional.empty());
315348
EncryptResponse response = this.kmip.encrypt(request);
316349
if (response.getData().isPresent()) {
317350
return response.getData().get();
@@ -329,14 +362,40 @@ public byte[] kmsEncrypt(String publicMasterKeyUniqueIdentifier, byte[] data, At
329362
/**
330363
* Decrypt the data in the KMS using the given User Decryption Key
331364
*
365+
* The encryptedData should be made of 3 parts:
366+
* - the length of the encrypted header as a u32 in big endian format (4 bytes)
367+
* - the header
368+
* - the AES GCM encrypted content
369+
*
332370
* @param userDecryptionKeyUniqueIdentifier the key UID
333371
* @param encryptedData the cipher text
334372
* @return the clear text data
335373
* @throws CosmianException if the decryption fails
336374
*/
337375
public byte[] kmsDecrypt(String userDecryptionKeyUniqueIdentifier, byte[] encryptedData) throws CosmianException {
376+
return this.kmsDecrypt(userDecryptionKeyUniqueIdentifier, encryptedData, Optional.empty());
377+
}
378+
379+
/**
380+
* Decrypt the data in the KMS using the given User Decryption Key
381+
*
382+
* The encryptedData should be made of 3 parts:
383+
* - the length of the encrypted header as a u32 in big endian format (4 bytes)
384+
* - the header
385+
* - the AES GCM encrypted content
386+
*
387+
* @param userDecryptionKeyUniqueIdentifier the key UID
388+
* @param encryptedData the cipher text
389+
* @param uid the resource uid to use in the
390+
* authentication of the symmetric
391+
* scheme
392+
* @return the clear text data
393+
* @throws CosmianException if the decryption fails
394+
*/
395+
public byte[] kmsDecrypt(String userDecryptionKeyUniqueIdentifier, byte[] encryptedData, Optional<byte[]> uid)
396+
throws CosmianException {
338397
try {
339-
Decrypt request = new Decrypt(userDecryptionKeyUniqueIdentifier, encryptedData, Optional.empty());
398+
Decrypt request = new Decrypt(userDecryptionKeyUniqueIdentifier, encryptedData, uid);
340399
DecryptResponse response = this.kmip.decrypt(request);
341400
if (response.getData().isPresent()) {
342401
return response.getData().get();

0 commit comments

Comments
 (0)