Layer 2: Cryptographic Layer
Background
Cryptography is employed for permissioning (ex. who can modify databases) and for database consensus.
Each client application has a public and private key-pair. Any message sent is signed and sent in an envelope. (See Bluzelle's Protobuf API).
The private key is an argument to the Bluzelle client.
The public key can be generated from the private key.
Specifications
All Bluzelle keys are ECDSA on the curve
secp256k1
.The client must accept a key argument in a way that is reasonable to the application. For desktop applications, this may be through a
.pem
file on the filesystem. For web applications, it may be through an argument.
Outgoing Messages
Given a completed message that is a
database_msg
orstatus_request
, serialize it and embed it as the appropriate payload type in thebzn_envelope
.If the message was a
status_request
, we are done. Otherwise, continue to the signing process.Fill in the
timestamp
field with current time as milliseconds since UNIX epoch (seen here).Fill in the
sender
field with the public key in PEM format. It should look like this: "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEY6L6fb2Xd9KZi05LQlZ83+0pIrjOIFvy0azEA+cDf7L7hMgRXrXj5+u6ys3ZSp2Wj58hTXsiiEPrRMMO1pwjRg=="The last step is to fill in the signature. Follow these steps closely:
Take the sender, payloadCase (you should be able to get it from protobuf), payload, and timestamp.
Encode them as ascii.
For each ascii string, create a new string that contains its length, a pipe character, then the string itself. For example, the timestamp would be
13|1549394321578
.Concatenate all of the strings in the same order that they were given. Empty message example: "120|MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEHLmWG+xY1lZak68iQMFCh2Vm1EfkEOkbclWWbEO1s+qpf6D6D/Yjo9CR2/zLHWkgTqo71nnjWWEU5FekTHjVmQ==2|100|1|0"
Convert this string to binary with ascii as the encoding.
Sign the binary with the ECDSA private key.
Embed the signature in the
bzn_envelope
.
Incoming Messages
Cryptography is not verified for incoming messages. Interpret the payload as a
database_response
orstatus_response
and continue to higher layers.
Last updated
Was this helpful?