|
|
@ -1,14 +1,21 @@
|
|
|
|
# Implementation
|
|
|
|
# Implementation
|
|
|
|
|
|
|
|
|
|
|
|
## Behavior Driven Development
|
|
|
|
This section describes the salient implementation details of the Zencode DSL, the smart-rule language for DECODE, tailored on its use-cases and based on the Zenroom controlled execution environment (VM). Implementation details refer only to Zencode and not to how Zenroom is implemented, since the latter is already covered in other documents.
|
|
|
|
|
|
|
|
|
|
|
|
In Behavior Driven Development (BDD), the important role of software integration and unit tests is extended to serve both the purposes of designing the human-machine interaction flow (user journey in UX terms) and of laying down a common ground for interaction between designers and stakeholders. In this Agile software development methodology the software testing suite is based on natural language units that grant a common understanding for all participants and observers.
|
|
|
|
The implementation section contains three parts explaining:
|
|
|
|
|
|
|
|
- the language model inherited by Behaviour Driven Development
|
|
|
|
|
|
|
|
- the data validation model based on Schema Validation
|
|
|
|
|
|
|
|
- the implementation of implicit certificates
|
|
|
|
|
|
|
|
|
|
|
|
To implement BDD the first step is that of mapping a series of combinable, cascading sentences to actual source code; this implementation is usually done manually by programmers that have knowledge of the higher level application protocol interface (API) that grants communication between the backend and the frontend of a software application. The BDD implementation can then be seen as an alternative frontend whose purpose is that of lowering the distance between expression and execution by means of utterances expressed in human language.
|
|
|
|
## Behaviour Driven Development
|
|
|
|
|
|
|
|
|
|
|
|
Far from giving an exhaustive description of BDD implementations and characteristics, this brief chapter intends to summarize the features of this approach where they specifically apply to the development goals of Zencode (previously stated) and the solution provided.
|
|
|
|
In Behaviour Driven Development (BDD), the important role of software integration and unit tests is extended to serve both the purposes of designing the human-machine interaction flow (user journey in UX terms) and of laying down a common ground for interaction between designers and stakeholders. In this Agile software development methodology the software testing suite is based on natural language units that grant a common understanding for all participants and observers.
|
|
|
|
|
|
|
|
|
|
|
|
Referring to the Cucumber implementation of BDD, arguably the most popular in use by the industry to day and de-facto standard, the grammar of utterances is very simple and definible as a "cascading" flow indeed, since the fixed sequence of lines can follow only one fixed order:
|
|
|
|
To implement BDD the first step is that of mapping a series of interconnected cascading sentences to actual source code; this implementation is usually done manually by programmers that have knowledge of the higher level application protocol interface (API) that grants communication between the backend and the frontend of a software application. The BDD implementation can then be seen as an alternative frontend whose purpose is that of lowering the distance between expression and execution by means of utterances expressed in human language.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Far from giving an exhaustive description of BDD implementations and characteristics, this brief chapter intends to summarise the features of this approach where they specifically apply to the development goals of Zencode (previously stated) and the solution provided.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Referring to the Cucumber implementation of BDD, arguably the most popular in use by the industry to day and factual standard, the grammar of utterances is very simple and definable as a "cascading" flow indeed, since the fixed sequence of lines can follow only one fixed order:
|
|
|
|
|
|
|
|
|
|
|
|
- Given
|
|
|
|
- Given
|
|
|
|
- and*
|
|
|
|
- and*
|
|
|
@ -24,16 +31,16 @@ The underlying parser acts upon a positive, unique and so far non-flexible match
|
|
|
|
|
|
|
|
|
|
|
|
Brief examples of this implementation follow:
|
|
|
|
Brief examples of this implementation follow:
|
|
|
|
|
|
|
|
|
|
|
|
```lua
|
|
|
|
```
|
|
|
|
Given("I introduce myself as ''", function(name) whoami = name end)
|
|
|
|
Given("I introduce myself as ''", function(name) whoami = name end)
|
|
|
|
Given("I am known as ''", function(name) whoami = name end)
|
|
|
|
Given("I am known as ''", function(name) whoami = name end)
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
The above definition of two lines possibly occurring within the utterances in Zencode are demonstrating how a state "who am I" basically my own name can be set using two different phrases, leading to the execution of the same function which basically operates a simple assignment to the variable `whoami`. This simple demonstration is a hint to the fact that multiple patterns can be defined also in different ways, making the Zencode DSL implementation very easy to translate across different spoken languages as well contextualized within specific idiolects adopted by humans.
|
|
|
|
The above definition of two lines possibly occurring within the utterances in Zencode are demonstrating how a state "who am I" basically my own name can be set using two different phrases, leading to the execution of the same function which basically operates a simple assignment to the variable *whoami*. This simple demonstration is a hint to the fact that multiple patterns can be defined also in different ways, making the Zencode DSL implementation very easy to translate across different spoken languages as well contextualised within specific idiolects adopted by humans.
|
|
|
|
|
|
|
|
|
|
|
|
Furthermore, another example of implementation:
|
|
|
|
Furthermore, another example of implementation:
|
|
|
|
|
|
|
|
|
|
|
|
```lua
|
|
|
|
```
|
|
|
|
Given("that '' declares to be ''",function(who, decl)
|
|
|
|
Given("that '' declares to be ''",function(who, decl)
|
|
|
|
-- declaration
|
|
|
|
-- declaration
|
|
|
|
if not declared then declared = decl
|
|
|
|
if not declared then declared = decl
|
|
|
@ -48,11 +55,19 @@ Given("declares also to be ''", function(decl)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Shows how is possible to accept multiple variables and process them through more complex transformations that also contemplate the concatenation of contents to previous states. States are in fact permanent within the scope of the execution of a single utterance and will be modified in the same deterministic order by which they are expressed across lines. What is also visible within this example implementation, which we intend to facilitate by customisations made by people who have a simple knowledge of Zenroom's API and LUA scripting, is that the `ZEN.` namespace makes available a number of utility functions to easily check states (asserts) and propagate meaningful error messages that are then part of a traceback output given to the calling application (host) on occurrence of an error.
|
|
|
|
Shows how is possible to accept multiple variables and process them through more complex transformations that also contemplate the concatenation of contents to previous states. States are in fact permanent within the scope of the execution of a single utterance and will be modified in the same deterministic order by which they are expressed across lines. What is also visible within this example implementation, which we intend to facilitate by customisation made by people who have a simple knowledge of Zenroom's API and LUA scripting, is that the 'ZEN.' namespace makes available a number of utility functions to easily check states (asserts) and propagate meaningful error messages that are then part of a backtrace output given to the calling application (host) on occurrence of an error.
|
|
|
|
|
|
|
|
|
|
|
|
The full implementation of Zencode available at the time of publishing this document is inside the sourcecode files `zenroom/src/lua/zencode_*` and is relatively easy to maintain for the pilots analysed in our project, as well easy to extend to more usecases. At the dawn of piloting sessions, due to the lack of actual feedback so far given in field trials, this implementation does not addresses specific schemes beyond a simple Diffie-Helman asymmetric key encryption (AES-GCM) and an even simplier symmetric encryption of ciphertext by means of a PIN and KDF transformations. On top of that, perhaps the most complex implementation of Zencode so far is the "implicit certificate" crypto scheme (Qu-Vanstone, ECQV) still limited to first order curve transformations, which applies widely to pilots requiring simple certification schemes and is illustrated in more detail in the following chapters[^ecqv].
|
|
|
|
The full implementation of Zencode available at the time of publishing this document is inside the source-code files 'zenroom/src/lua/zencode_*' and is relatively easy to maintain for the pilots analysed in our project, as well easy to extend to more use-cases. The current implementation addresses specific schemes that useful to the pilots in DECODE, while contemplating future extension:
|
|
|
|
|
|
|
|
- Simple symmetric encryption of ciphertext by means of a PIN and KDF transformations (pilot: Amsterdam Register)
|
|
|
|
|
|
|
|
- Diffie-Hellman asymmetric key encryption (AES-GCM) (pilot: Making Sense IoT)
|
|
|
|
|
|
|
|
- Blind-sign credentials for unlinkable selective attribute revelations[^coconut] (pilot: DECIDIM and Gebied Online)
|
|
|
|
|
|
|
|
In addition there is also the implementation of an "implicit certificate" crypto scheme (Qu-Vanstone, ECQV) that is limited to first order curve transformations, which may apply to pilots requiring simple certification schemes[^ecqv]. All the implementations are illustrated in more detail in the following chapters.
|
|
|
|
|
|
|
|
|
|
|
|
[^ecqv] It is important to note that while the ECQV scheme was not examined by other partners in our project, it has been choosen for its stable role in the industry and for its augmented complexity within an approachable implementation, complexity which could better inform the Zencode implementation. Without that complexity and without implementation feedback by other partners, it wouldn't have been possible to work on Zencode and bring it to what it is today, since both the Petition contract and the Coconut implementation in Zenroom are not available as of today and need to be completed in a later stage of the DECODE project.
|
|
|
|
|
|
|
|
|
|
|
|
[^coconut] This implementation refers to work on the Coconut credential system (Sonnino et. al, 2018) designed after specific needs in DECODE's pilots. It does not implement, however, the threshold issuance part, which is only required in the scenario of a fully open blockchain implementation, which is still work in progress.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[^ecqv] It is important to note that while the ECQV scheme was not examined by other partners in our project, it has been choosen for its stable role in the industry and for its augmented complexity within an approachable implementation, complexity which could better inform the Zencode implementation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -64,7 +79,7 @@ The data schemas are added on a per-usecase basis: they refer to specific crypto
|
|
|
|
|
|
|
|
|
|
|
|
Schemas are expressed in a simple format using Lua scripting syntax, for example:
|
|
|
|
Schemas are expressed in a simple format using Lua scripting syntax, for example:
|
|
|
|
|
|
|
|
|
|
|
|
```lua
|
|
|
|
```
|
|
|
|
-- zencode_keypair
|
|
|
|
-- zencode_keypair
|
|
|
|
keypair = S.record {
|
|
|
|
keypair = S.record {
|
|
|
|
schema = S.Optional(S.string),
|
|
|
|
schema = S.Optional(S.string),
|
|
|
@ -75,13 +90,13 @@ keypair = S.record {
|
|
|
|
|
|
|
|
|
|
|
|
The schema above is the smallest and most commonly used one, composed by one required field and two optional ones, used to validate the input and output of public/private keypairs to be used in transformations.
|
|
|
|
The schema above is the smallest and most commonly used one, composed by one required field and two optional ones, used to validate the input and output of public/private keypairs to be used in transformations.
|
|
|
|
|
|
|
|
|
|
|
|
The only required field in the schema is the `public` key which is validated using the `ECP` type (`S.` is an abbreviation for the `SCHEMA.` namespace). The validation of `S.ECP` is an actual cryptographic validation: Zenroom will check that the big integer number represented by the field corresponds to a valid point on the curve. In case the validation is not passed, the execution of the Zencode script will not take place and Zenroom will return a meaningful error message indicating the wrong field.
|
|
|
|
The only required field in the schema is the 'public' key which is validated using the 'ECP' type ('S.' is an abbreviation for the 'SCHEMA.' namespace). The validation of 'S.ECP' is an actual cryptographic validation: Zenroom will check that the big integer number represented by the field corresponds to a valid point on the curve. In case the validation is not passed, the execution of the Zencode script will not take place and Zenroom will return a meaningful error message indicating the wrong field.
|
|
|
|
|
|
|
|
|
|
|
|
The other optional field is the `private` key which can correspond to any sequence of values, therefore no cryptographic validation is possible for it; in this case then the validation used is one that refers to the encoding of the field: `S.hex` is verifying that the value is encoded with a sequence of characters that express only hexadecimal numbers (that is, 0..9 numbers and case-insensitive letters from A to Z). Other encoding tests are also available, for instance `S.base64` if that is the encoding used in the specific implementation.
|
|
|
|
The other optional field is the 'private' key which can correspond to any sequence of values, therefore no cryptographic validation is possible for it; in this case then the validation used is one that refers to the encoding of the field: 'S.hex' is verifying that the value is encoded with a sequence of characters that express only hexadecimal numbers (that is, 0..9 numbers and case-insensitive letters from A to Z). Other encoding tests are also available, for instance 'S.base64' if that is the encoding used in the specific implementation.
|
|
|
|
|
|
|
|
|
|
|
|
Another more complex example follows:
|
|
|
|
Another more complex example follows:
|
|
|
|
|
|
|
|
|
|
|
|
```lua
|
|
|
|
```
|
|
|
|
-- packets encoded with AES GCM
|
|
|
|
-- packets encoded with AES GCM
|
|
|
|
AES-GCM = S.record {
|
|
|
|
AES-GCM = S.record {
|
|
|
|
checksum = S.hex,
|
|
|
|
checksum = S.hex,
|
|
|
@ -95,12 +110,12 @@ AES-GCM = S.record {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
In this example no new validations are being used and in fact it just adds fields compared to the previous: it defines a portable packet of ciphertext data that is returned as output of AES-GCM asymmetric encryption as well is accepted as input to AES-GCM decryption. A similarity between these two examples is evident: the presence of the `schema` field. This field is a sort of "introspective" indication matching the data structure to its schema specification. If this field is not present (as it is always optional) then no validation on the data structure will take place, meaning the Zencode implementation leaves the risk (and hopefully the validation task) to the host.
|
|
|
|
In this example no new validations are being used and in fact it just adds fields compared to the previous: it defines a portable packet of ciphertext data that is returned as output of AES-GCM asymmetric encryption as well is accepted as input to AES-GCM decryption. A similarity between these two examples is evident: the presence of the 'schema' field. This field is a sort of "introspective" indication matching the data structure to its schema specification. If this field is not present (as it is always optional) then no validation on the data structure will take place, meaning the Zencode implementation leaves the risk (and hopefully the validation task) to the host.
|
|
|
|
|
|
|
|
|
|
|
|
This chapter ends with the current implementation of schema validation data types that are currently implemented for symmetric and asymmetric encryption of ciphertexts as well for implicit certificates. The schema implementation for Zencode is maintained into the sourcecode within the source file `src/lua/zencode_schemas.lua` and can be accessed by the function `ZEN.validate(data,'schema','error')` which is a wrapper of `ZEN.assert(validate(data,schemas['schema']),'error')`.
|
|
|
|
This chapter ends with the current implementation of schema validation data types that are currently implemented for symmetric and asymmetric encryption of ciphertexts as well for implicit certificates. The schema implementation for Zencode is maintained into the sourcecode within the source file 'src/lua/zencode_schemas.lua' and can be accessed by the function 'ZEN.validate(data,'schema','error')' which is a wrapper of 'ZEN.assert(validate(data,schemas['schema']),'error')'.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```lua
|
|
|
|
```
|
|
|
|
_G['schemas'] = {
|
|
|
|
_G['schemas'] = {
|
|
|
|
|
|
|
|
|
|
|
|
-- packets encoded with AES GCM
|
|
|
|
-- packets encoded with AES GCM
|
|
|
|