Skip to content

Commit 4f84dc3

Browse files
committed
chore: add data_access support for encrypted endpoints
Allow queries to recognize encrypted option in mappings and encrypted data values Signed-off-by: frossq <francesco.asquini@secomind.com>
1 parent 9f4bdbe commit 4f84dc3

8 files changed

Lines changed: 51 additions & 3 deletions

File tree

apps/astarte_appengine_api/lib/astarte_appengine_api/device/queries.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ defmodule Astarte.AppEngine.API.Device.Queries do
112112
:allow_unset,
113113
:endpoint_id,
114114
:interface_id,
115-
:explicit_timestamp
115+
:explicit_timestamp,
116+
:encrypted
116117
]
117118

118119
opts = [

apps/astarte_realm_management/test/support/helpers/database.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ defmodule Astarte.Helpers.Database do
140140
description text,
141141
doc text,
142142
required boolean,
143+
encrypted boolean,
143144
144145
PRIMARY KEY ((interface_id), endpoint_id)
145146
)
@@ -180,6 +181,8 @@ defmodule Astarte.Helpers.Database do
180181
stringarray_value list<text>,
181182
binaryblobarray_value list<blob>,
182183
datetimearray_value list<timestamp>,
184+
encryptedblob_value blob,
185+
encrypted_dek blob,
183186
184187
PRIMARY KEY((device_id, interface_id), endpoint_id, path)
185188
);
@@ -208,6 +211,9 @@ defmodule Astarte.Helpers.Database do
208211
longintegerarray_value list<bigint>,
209212
string_value text,
210213
stringarray_value list<text>,
214+
encryptedblob_value blob,
215+
encrypted_dek blob,
216+
211217
PRIMARY KEY ((device_id, interface_id, endpoint_id, path), value_timestamp, reception_timestamp, reception_timestamp_submillis)
212218
)
213219
"""

libs/astarte_data_access/lib/astarte_data_access/mappings.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ defmodule Astarte.DataAccess.Mappings do
4343
:explicit_timestamp,
4444
:endpoint_id,
4545
:interface_id,
46-
:required
46+
:required,
47+
:encrypted
4748
]
4849

4950
@spec fetch_interface_mappings(String.t(), binary, keyword) ::

libs/astarte_data_access/lib/astarte_data_access/realms/endpoint.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ defmodule Astarte.DataAccess.Realms.Endpoint do
4545
:reliability,
4646
:retention,
4747
:value_type,
48-
:required
48+
:required,
49+
:encrypted
4950
] ++ @required_fields
5051

5152
@primary_key false
@@ -68,6 +69,7 @@ defmodule Astarte.DataAccess.Realms.Endpoint do
6869
field :retention, Retention
6970
field :value_type, ValueType
7071
field :required, :boolean
72+
field :encrypted, :boolean
7173
end
7274

7375
def changeset(endpoint, params \\ %{}) do

libs/astarte_data_access/lib/astarte_data_access/realms/individual_datastream.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ defmodule Astarte.DataAccess.Realms.IndividualDatastream do
5353
field :longintegerarray_value, {:array, BigInt}
5454
field :string_value, :string
5555
field :stringarray_value, {:array, :string}
56+
field :encryptedblob_value, :binary
57+
field :encrypted_dek, :binary
5658
end
5759
end

libs/astarte_data_access/lib/astarte_data_access/realms/individual_property.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ defmodule Astarte.DataAccess.Realms.IndividualProperty do
5050
field :stringarray_value, {:array, :string}
5151
field :binaryblobarray_value, {:array, :binary}
5252
field :datetimearray_value, {:array, DateTimeMs}
53+
field :encryptedblob_value, :binary
54+
field :encrypted_dek, :binary
5355
end
5456

5557
def reception(individual_property) do

libs/astarte_data_access/test/mappings_test.exs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ defmodule Astarte.DataAccess.Mappings.XandraTest do
5656
database_retention_ttl: nil,
5757
description: nil,
5858
doc: nil,
59+
encrypted: false,
5960
endpoint: "/foo/%{param}/timestampValue",
6061
endpoint_id: <<52, 108, 128, 228, 202, 153, 98, 116, 129, 246, 123, 28, 27, 229, 149, 33>>,
6162
expiry: 0,
@@ -74,6 +75,7 @@ defmodule Astarte.DataAccess.Mappings.XandraTest do
7475
database_retention_ttl: nil,
7576
description: nil,
7677
doc: nil,
78+
encrypted: false,
7779
endpoint: "/foo/%{param}/stringValue",
7880
endpoint_id: <<57, 7, 212, 29, 91, 202, 50, 157, 158, 81, 76, 234, 42, 84, 169, 154>>,
7981
expiry: 0,
@@ -92,6 +94,7 @@ defmodule Astarte.DataAccess.Mappings.XandraTest do
9294
database_retention_ttl: 120,
9395
description: nil,
9496
doc: nil,
97+
encrypted: false,
9598
endpoint: "/%{itemIndex}/value",
9699
endpoint_id: <<117, 1, 14, 27, 25, 158, 238, 252, 221, 53, 210, 84, 176, 226, 9, 36>>,
97100
expiry: 0,
@@ -110,6 +113,7 @@ defmodule Astarte.DataAccess.Mappings.XandraTest do
110113
database_retention_ttl: nil,
111114
description: nil,
112115
doc: nil,
116+
encrypted: false,
113117
endpoint: "/foo/%{param}/blobValue",
114118
endpoint_id: <<122, 164, 76, 17, 34, 115, 71, 217, 230, 36, 74, 224, 41, 222, 222, 170>>,
115119
expiry: 0,
@@ -128,6 +132,7 @@ defmodule Astarte.DataAccess.Mappings.XandraTest do
128132
database_retention_ttl: nil,
129133
description: nil,
130134
doc: nil,
135+
encrypted: false,
131136
endpoint: "/foo/%{param}/longValue",
132137
endpoint_id: <<239, 249, 87, 207, 3, 223, 222, 237, 151, 132, 168, 112, 142, 61, 140, 185>>,
133138
expiry: 0,
@@ -139,6 +144,25 @@ defmodule Astarte.DataAccess.Mappings.XandraTest do
139144
retention: :discard,
140145
type: nil,
141146
value_type: :longinteger
147+
},
148+
<<59, 57, 253, 58, 244, 150, 38, 255, 129, 246, 76, 45, 209, 80, 184, 100>> => %Mapping{
149+
allow_unset: false,
150+
database_retention_policy: :no_ttl,
151+
database_retention_ttl: nil,
152+
description: nil,
153+
doc: nil,
154+
encrypted: true,
155+
endpoint: "/encrypted/value",
156+
endpoint_id: <<59, 57, 253, 58, 244, 150, 38, 255, 129, 246, 76, 45, 209, 80, 184, 100>>,
157+
expiry: 0,
158+
explicit_timestamp: nil,
159+
interface_id:
160+
<<10, 13, 167, 125, 133, 181, 147, 217, 212, 210, 189, 38, 221, 24, 201, 175>>,
161+
path: nil,
162+
reliability: :unique,
163+
retention: :discard,
164+
type: nil,
165+
value_type: :datetime
142166
}
143167
}
144168

libs/astarte_data_access/test/support/database_test_helper.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
213213
description varchar,
214214
doc varchar,
215215
required boolean,
216+
encrypted boolean,
216217
217218
PRIMARY KEY ((interface_id), endpoint_id)
218219
);
@@ -267,6 +268,11 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
267268
INSERT INTO autotestrealm.endpoints (interface_id, endpoint_id, allow_unset, endpoint, expiry, interface_major_version, interface_minor_version, interface_name, interface_type, reliability, retention, value_type) VALUES
268269
(0a0da77d-85b5-93d9-d4d2-bd26dd18c9af, 346c80e4-ca99-6274-81f6-7b1c1be59521, False, '/foo/%{param}/timestampValue', 0, 1, 0, 'com.test.SimpleStreamTest', 2, 3, 1, 13);
269270
""",
271+
# explicitly set endpoint encryption to True
272+
"""
273+
INSERT INTO autotestrealm.endpoints (interface_id, endpoint_id, allow_unset, endpoint, expiry, interface_major_version, interface_minor_version, interface_name, interface_type, reliability, retention, value_type, encrypted) VALUES
274+
(0a0da77d-85b5-93d9-d4d2-bd26dd18c9af, 3b39fd3a-f496-26ff-81f6-4c2dd150b864, False, '/encrypted/value', 0, 1, 0, 'com.test.SimpleStreamTest', 2, 3, 1, 13, True);
275+
""",
270276
"""
271277
INSERT INTO autotestrealm.endpoints (interface_id, endpoint_id, allow_unset, endpoint, expiry, interface_major_version, interface_minor_version, interface_name, interface_type, reliability, retention, value_type) VALUES
272278
(db576345-80b1-5358-f305-d77ec39b3d84, 7c9f14e8-4f2f-977f-c126-d5e1bb9876e7, False, '/string', 0, 1, 5, 'com.example.TestObject', 2, 2, 3, 7);
@@ -311,6 +317,8 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
311317
stringarray_value list<varchar>,
312318
binaryblobarray_value list<blob>,
313319
datetimearray_value list<timestamp>,
320+
encryptedblob_value blob,
321+
encrypted_dek blob,
314322
315323
PRIMARY KEY((device_id, interface_id), endpoint_id, path)
316324
);
@@ -340,6 +348,8 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
340348
stringarray_value list<varchar>,
341349
binaryblobarray_value list<blob>,
342350
datetimearray_value list<timestamp>,
351+
encryptedblob_value blob,
352+
encrypted_dek blob,
343353
344354
PRIMARY KEY((device_id, interface_id, endpoint_id, path), value_timestamp, reception_timestamp, reception_timestamp_submillis)
345355
);

0 commit comments

Comments
 (0)