Skip to content

Commit 05dd8e2

Browse files
committed
Update cover_crypt to 4.0.0
1 parent e390edb commit 05dd8e2

24 files changed

Lines changed: 133 additions & 102 deletions

.gitlab-ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ variables:
44
CARGO_HOME: ${CI_PROJECT_DIR}/.cargo/
55
SCCACHE_DIR: ${CI_PROJECT_DIR}/.cache/sccache
66
COSMIAN_SERVER_URL: http://localhost:9998
7+
KMS_PUBLIC_PATH: /tmp
8+
KMS_PRIVATE_PATH: /tmp
9+
KMS_SHARED_PATH: /tmp
710

811
stages:
912
- build
1013

1114
build:
1215
stage: build
1316
services:
14-
- name: gitlab.cosmian.com:5000/core/kms:2.0.5_ci
17+
- name: gitlab.cosmian.com:5000/core/kms:2.1.0_ci
1518
alias: kms_ci
1619
script:
1720
- mvn package

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ KMS Server | Java Lib | GPSW lib | CoverCrypt lib | Findex
5151
1.2.1 | 0.6.1 | 0.6.1 | N/A | N/A
5252
2.0.1 | 0.7.2 | 0.6.5 | 1.0.2 | N/A
5353
2.0.2 | 0.7.5 | 0.6.10 | 2.0.0 | N/A
54-
2.0.5 | 0.7.6 | 1.1.1 | 3.2.1 | 0.2.3
54+
2.1.0 | 0.7.6 | 1.1.1 | 4.0.0 | 0.2.3
5555

5656
## Update native libraries
5757

src/main/java/com/cosmian/jna/findex/Callbacks/FetchChain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public int apply(Pointer output, IntByReference outputSize, Pointer uidsPointer,
2929
//
3030
// Deserialize Chain Table uids
3131
//
32-
List<byte[]> chainTableUids = Leb128Serializer.deserialize(uids);
32+
List<byte[]> chainTableUids = Leb128Serializer.deserializeList(uids);
3333

3434
//
3535
// Select uid and value in EntryTable
@@ -40,7 +40,7 @@ public int apply(Pointer output, IntByReference outputSize, Pointer uidsPointer,
4040
// Serialize results
4141
//
4242
if (values.size() > 0) {
43-
byte[] valuesBytes = Leb128Serializer.serialize(values);
43+
byte[] valuesBytes = Leb128Serializer.serializeList(values);
4444

4545
output.write(0, valuesBytes, 0, valuesBytes.length);
4646
outputSize.setValue(valuesBytes.length);

src/main/java/com/cosmian/jna/findex/Callbacks/FetchEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public int apply(Pointer output, IntByReference outputSize, Pointer uidsPointer,
2929
//
3030
// Deserialize Entry Table uids
3131
//
32-
List<byte[]> entryTableUids = Leb128Serializer.deserialize(uids);
32+
List<byte[]> entryTableUids = Leb128Serializer.deserializeList(uids);
3333

3434
//
3535
// Select uids and values in EntryTable
@@ -40,7 +40,7 @@ public int apply(Pointer output, IntByReference outputSize, Pointer uidsPointer,
4040
// Serialize results
4141
//
4242
if (uidsAndValues.size() > 0) {
43-
byte[] uidsAndValuesBytes = Leb128Serializer.serialize(uidsAndValues);
43+
byte[] uidsAndValuesBytes = Leb128Serializer.serializeHashMap(uidsAndValues);
4444
output.write(0, uidsAndValuesBytes, 0, uidsAndValuesBytes.length);
4545
outputSize.setValue(uidsAndValuesBytes.length);
4646
} else {

src/main/java/com/cosmian/jna/findex/Callbacks/UpsertChain.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.cosmian.jna.findex.Callbacks;
22

3+
import java.util.HashMap;
4+
35
import com.cosmian.jna.FfiException;
46
import com.cosmian.jna.findex.FfiWrapper.UpsertChainCallback;
57
import com.cosmian.jna.findex.FfiWrapper.UpsertChainInterface;
8+
import com.cosmian.jna.findex.Leb128Serializer;
69
import com.sun.jna.Pointer;
710

811
public class UpsertChain implements UpsertChainCallback {
@@ -14,19 +17,22 @@ public UpsertChain(UpsertChainInterface upsert) {
1417
}
1518

1619
@Override
17-
public int apply(Pointer uid, int uidLength, Pointer value, int valueLength) throws FfiException {
20+
public int apply(Pointer items, int itemsLength) throws FfiException {
21+
//
22+
// Read `items` until `itemsLength`
23+
//
24+
byte[] itemsBytes = new byte[itemsLength];
25+
items.read(0, itemsBytes, 0, itemsLength);
26+
1827
//
19-
// Read `uid` until `uidLength` and `value` until `valueLength`
28+
// Deserialize the chain table items
2029
//
21-
byte[] uidBytes = new byte[uidLength];
22-
uid.read(0, uidBytes, 0, uidLength);
23-
byte[] valueBytes = new byte[valueLength];
24-
value.read(0, valueBytes, 0, valueLength);
30+
HashMap<byte[], byte[]> uidsAndValues = Leb128Serializer.deserializeHashmap(itemsBytes);
2531

2632
//
2733
// Insert in database
2834
//
29-
this.upsert.upsert(uidBytes, valueBytes);
35+
this.upsert.upsert(uidsAndValues);
3036

3137
return 0;
3238
}

src/main/java/com/cosmian/jna/findex/Callbacks/UpsertEntry.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.cosmian.jna.findex.Callbacks;
22

3+
import java.util.HashMap;
4+
35
import com.cosmian.jna.FfiException;
46
import com.cosmian.jna.findex.FfiWrapper.UpsertEntryCallback;
57
import com.cosmian.jna.findex.FfiWrapper.UpsertEntryInterface;
8+
import com.cosmian.jna.findex.Leb128Serializer;
69
import com.sun.jna.Pointer;
710

811
public class UpsertEntry implements UpsertEntryCallback {
@@ -14,19 +17,22 @@ public UpsertEntry(UpsertEntryInterface upsert) {
1417
}
1518

1619
@Override
17-
public int apply(Pointer uid, int uidLength, Pointer value, int valueLength) throws FfiException {
20+
public int apply(Pointer items, int itemsLength) throws FfiException {
21+
//
22+
// Read `items` until `itemsLength`
23+
//
24+
byte[] itemsBytes = new byte[itemsLength];
25+
items.read(0, itemsBytes, 0, itemsLength);
26+
1827
//
19-
// Read `uid` until `uidLength` and `value` until `valueLength`
28+
// Deserialize the entry table items
2029
//
21-
byte[] uidBytes = new byte[uidLength];
22-
uid.read(0, uidBytes, 0, uidLength);
23-
byte[] valueBytes = new byte[valueLength];
24-
value.read(0, valueBytes, 0, valueLength);
30+
HashMap<byte[], byte[]> uidsAndValues = Leb128Serializer.deserializeHashmap(itemsBytes);
2531

2632
//
2733
// Insert in database
2834
//
29-
this.upsert.upsert(uidBytes, valueBytes);
35+
this.upsert.upsert(uidsAndValues);
3036

3137
return 0;
3238
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static List<byte[]> search(MasterKeys masterKeys, String[] words, int loo
119119

120120
byte[] dbUidsBytes = Arrays.copyOfRange(dbUidsBuffer, 0, dbUidsBufferSize.getValue());
121121

122-
List<byte[]> dbUidsList = Leb128Serializer.deserialize(dbUidsBytes);
122+
List<byte[]> dbUidsList = Leb128Serializer.deserializeList(dbUidsBytes);
123123

124124
return dbUidsList;
125125
}

src/main/java/com/cosmian/jna/findex/FfiWrapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ interface FetchChainCallback extends Callback {
2626
int apply(Pointer output, IntByReference outputSize, Pointer uidsPointer, int uidsLength) throws FfiException;
2727
}
2828
interface UpsertEntryCallback extends Callback {
29-
int apply(Pointer uid, int uidLength, Pointer value, int valueLength) throws FfiException;
29+
int apply(Pointer entries, int entriesLength) throws FfiException;
3030
}
3131
interface UpsertChainCallback extends Callback {
32-
int apply(Pointer uid, int uidLength, Pointer value, int valueLength) throws FfiException;
32+
int apply(Pointer chains, int chainsLength) throws FfiException;
3333
}
3434

3535
/* Customer high-level callbacks */
@@ -40,10 +40,10 @@ interface FetchChainInterface {
4040
public List<byte[]> fetch(List<byte[]> uids) throws FfiException;
4141
}
4242
interface UpsertEntryInterface {
43-
public void upsert(byte[] uid, byte[] value) throws FfiException;
43+
public void upsert(HashMap<byte[], byte[]> uidsAndValues) throws FfiException;
4444
}
4545
interface UpsertChainInterface {
46-
public void upsert(byte[] uid, byte[] value) throws FfiException;
46+
public void upsert(HashMap<byte[], byte[]> uidsAndValues) throws FfiException;
4747
}
4848

4949
int h_upsert(String masterKeysJson, String dbUidsAndWordsJson, FetchEntryCallback fetchEntry,

src/main/java/com/cosmian/jna/findex/Leb128Serializer.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,50 @@
1111

1212
public class Leb128Serializer {
1313

14-
public static List<byte[]> deserialize(byte[] serializedUids) {
15-
List<byte[]> uids = new ArrayList<byte[]>();
14+
public static List<byte[]> deserializeList(byte[] serializedUids) {
15+
List<byte[]> result = new ArrayList<byte[]>();
1616
ByteArrayByteInput in = new ByteArrayByteInput(serializedUids);
1717
int len = 0;
1818
while ((len = Leb128.readUnsignedLeb128(in)) >= 0) {
1919
if (len == 0) {
2020
break;
2121
}
22-
byte[] uid = new byte[len];
22+
byte[] element = new byte[len];
2323
for (int i = 0; i < len; i++) {
24-
uid[i] = in.readByte();
24+
element[i] = in.readByte();
2525
}
26-
uids.add(uid);
26+
result.add(element);
2727
}
28-
return uids;
28+
return result;
2929
}
3030

31-
public static byte[] serialize(HashMap<byte[], byte[]> uidsAndValues) {
31+
public static HashMap<byte[], byte[]> deserializeHashmap(byte[] serializedUids) {
32+
HashMap<byte[], byte[]> result = new HashMap<byte[], byte[]>();
33+
ByteArrayByteInput in = new ByteArrayByteInput(serializedUids);
34+
int len = 0;
35+
while ((len = Leb128.readUnsignedLeb128(in)) >= 0) {
36+
if (len == 0) {
37+
break;
38+
}
39+
byte[] key = new byte[len];
40+
for (int i = 0; i < len; i++) {
41+
key[i] = in.readByte();
42+
}
43+
44+
len = Leb128.readUnsignedLeb128(in);
45+
if (len == 0) {
46+
throw new IllegalArgumentException("HashMap `value` should be serialized after `key`");
47+
}
48+
byte[] value = new byte[len];
49+
for (int i = 0; i < len; i++) {
50+
value[i] = in.readByte();
51+
}
52+
result.put(key, value);
53+
}
54+
return result;
55+
}
56+
57+
public static byte[] serializeHashMap(HashMap<byte[], byte[]> uidsAndValues) {
3258
ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput();
3359
for (Entry<byte[], byte[]> entry : uidsAndValues.entrySet()) {
3460
byte[] uid = entry.getKey();
@@ -45,7 +71,7 @@ public static byte[] serialize(HashMap<byte[], byte[]> uidsAndValues) {
4571
return uidsAndValuesBytes;
4672
}
4773

48-
public static byte[] serialize(List<byte[]> values) {
74+
public static byte[] serializeList(List<byte[]> values) {
4975
ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput();
5076
for (byte[] bs : values) {
5177
Leb128.writeUnsignedLeb128(out, bs.length);

src/test/java/com/cosmian/Demo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public class Demo {
3232
@Test
3333
public void test_abe() throws Exception {
3434

35-
if (!TestUtils.isGitlab()) {
36-
System.out.println("Ignoring this test since not on Gitlab CI");
35+
if (!TestUtils.serverAvailable(TestUtils.kmsServerUrl())) {
36+
System.out.println("Demo: No KMS Server: ignoring");
3737
return;
3838
}
3939

0 commit comments

Comments
 (0)