Skip to content

Commit 1069d65

Browse files
committed
Fixing registration
1 parent cc1d868 commit 1069d65

File tree

3 files changed

+229
-10
lines changed

3 files changed

+229
-10
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ORION_VERSION=3.8.1
88

99
# Orion variables
1010
ORION_LD_PORT=1026
11-
ORION_LD_VERSION=1.8.0
11+
ORION_LD_VERSION=1.10.0
1212

1313
# Scorpio variables
1414
SCORPIO_PORT=9090

README.md

Lines changed: 175 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ with the `type: VerifiableCredential` - in the example below, the **Animal Welfa
195195
the role for **Data Access** are the claim. Since **Animal Welfare** is creating the credential, they are the issuer, and **Alice** is the subject. The issuer
196196
signs the credential with their private key.
197197
198-
The private key `0b6366519a40eb4f384f7f84cf8bb716683ad1af8adbe60e59fe24ba042e396a` is used for all users throughout the tutorial,
199-
since the associated public key is the one that has been stored on the public web as a decentralised identifier. The necessary information
198+
The private key used for signing the credential should not be shared, but for this tutorial,
199+
`0b6366519a40eb4f384f7f84cf8bb716683ad1af8adbe60e59fe24ba042e396a` is used for all users throughout
200+
the requests,
201+
since the associated public key is the one that has been stored on the public web as a [decentralised identifier](https://fiware.github.io//tutorials.Step-by-Step/alice/did.json). The necessary information
200202
can be generated using a script as shown.
201203
202204
@@ -209,7 +211,7 @@ const size = parseInt(process.argv.slice(2)[0]) || 32;
209211
const randomString = crypto.randomBytes(size).toString("hex");
210212
const key = randomString;
211213
212-
console.log(`Key (hex): ${key}`) // ee48d32e6c724c4d
214+
console.log(`Key (hex): ${key}`) // 0b6366519a40eb4f384 etc.
213215
214216
// Calculate the `secp256k1` curve and build the public key
215217
const ec = new elliptic.ec('secp256k1');
@@ -580,7 +582,7 @@ curl -L 'localhost:3000/vc/verify' \
580582

581583
Now that Alice has been given a Verifiable credential, she can use it to claim the role of Operator within the Data Space and gain Access to the Vetenary Records. A First attempt to access the records without holding a token results in an error, indicating that the verifier is present on port `1030`
582584

583-
#### Accessing the Vetenary Records without a Veriable Credential
585+
#### Accessing the Vetenary Records without a Verifiable Credential
584586

585587
#### 5️⃣ Request:
586588

@@ -602,7 +604,7 @@ The response is a **401 - Unauthorized** error code with the following response
602604
```
603605

604606

605-
### Accessing the Vetenary Records with an invalid Veriable Credential
607+
### Accessing the Vetenary Records with an invalid Verifiable Credential
606608

607609
The Verifiable Credential is added as a Bearer token to the Authorization header. The bearer token is a JWT which is then decoded and verified - if the content of the Bearer token does not match the claimed issuer, then the token is rejected.
608610

@@ -631,7 +633,7 @@ In the case of a rejected credentila The response is a **401 - Unauthorized** er
631633

632634
Note that a real Credential Verifier would not only check that all the claimed issuers of credentials had really signed each verifiable credential, but also ensure that the `exp` and `nbf` are also in range.
633635

634-
### Accessing the Vetenary Records with a valid Veriable Credential
636+
### Accessing the Vetenary Records with a valid Verifiable Credential
635637

636638
With a proper Verifiable Presentation, the **Animal** records can be accessed:
637639

@@ -679,7 +681,7 @@ following output:
679681
OperatorCredential issued by did:web:fiware.github.io:tutorials.Step-by-Step:animal-welfare was NOT TRUSTED
680682
```
681683

682-
This is because a further check is required. Not only must the Verifiable Credential be signed by the issuer, but the issuer must be a valid issuer of credentials within the data space. The way that a verifier checks this, is that it must contact a trusted issuers list. The location of this list is defined within the configuration service associated to the Verifiable Credentials verifier.
684+
This is because in reality, a further check is required. Not only must the Verifiable Credential be signed by the issuer, but the issuer must be a valid issuer of credentials within the data space. The way that a verifier checks this, is that it must contact a trusted issuers list. The location of this list is defined within the configuration service associated to the Verifiable Credentials verifier.
683685

684686
### Checking for trusted issuers
685687

@@ -719,25 +721,189 @@ The response indicates that VerifiableCredentials can be checked against the tru
719721

720722
### Reading a trusted issuers list
721723

724+
The trusted issuers list is usually maintained by the operator of the data space. It holds information about who is a valid user, and what sort of actions that issuer is allowed to generate, A trusted issuers list can be found running on port 8080 - initially there are no valid issuers available.
725+
722726
#### 9️⃣ Request:
723727

724728
```console
725-
729+
curl -L 'localhost:8080/v4/issuers'
726730
```
727731

728732
#### Response:
729733

734+
```json
735+
{
736+
"self": "/v4/issuers/",
737+
"items": [],
738+
"total": 0,
739+
"pageSize": 0,
740+
"links": null
741+
}
742+
```
743+
730744

731-
### Verifying a Verifiable Credential
745+
### Adding a trusted issuer to the trusted issuers list
746+
747+
To Add a trusted issuer, make a **POST** request to the `/issuer` endpoint. You can see here that the issuer is `did:web:fiware.github.io:tutorials.Step-by-Step:animal-welfare` and that organisation is allowed to Create **OperatorCredentials** with two separate roles - `OPERATOR` and `VISITOR`
732748

733749
#### 1️⃣0️⃣ Request:
734750

735751
```console
752+
curl -L 'localhost:8080/issuer' \
753+
-H 'Content-Type: application/json' \
754+
-d '{
755+
"did": "did:web:fiware.github.io:tutorials.Step-by-Step:animal-welfare",
756+
"credentials": [
757+
{
758+
"validFor": {
759+
"from": "2017-07-21T17:32:28Z",
760+
"to": "2023-07-21T17:32:28Z"
761+
},
762+
"credentialsType": "OperatorCredential",
763+
"claims": [
764+
{
765+
"name": "roles",
766+
"allowedValues": [
767+
"OPERATOR",
768+
"VISITOR"
769+
]
770+
}
771+
]
772+
}
773+
]
774+
}'
775+
```
776+
777+
778+
### Reading from the trusted issuers list
779+
780+
781+
This trusted issuers list is able to retrieve issuer rights in two different formats. Initially we shall retrieve plain-text issuer information by making a **GET** request to the
782+
`/issuer/did:web:fiware.github.io:tutorials.Step-by-Step:animal-welfare` endpoint
783+
784+
#### 1️⃣1️⃣ Request:
785+
786+
```console
787+
curl -L 'localhost:8080/issuer/did:web:fiware.github.io:tutorials.Step-by-Step:animal-welfare'
788+
```
789+
790+
791+
#### Response:
792+
793+
The response can be seen below
794+
795+
```json
796+
{
797+
"did": "did:web:fiware.github.io:tutorials.Step-by-Step:animal-welfare",
798+
"credentials": [
799+
{
800+
"credentialsType": "OperatorCredential",
801+
"claims": [
802+
{
803+
"name": "roles",
804+
"allowedValues": [
805+
"OPERATOR",
806+
"VISITOR"
807+
]
808+
}
809+
]
810+
}
811+
]
812+
}
813+
```
814+
815+
816+
#### 1️⃣2️⃣ Request:
817+
818+
The trusted issuers list is able to retrieve issuer data in [EBSI compatible](https://hub.ebsi.eu/#/) format
819+
820+
821+
```console
822+
curl -L 'localhost:8080/v4/issuers/did:web:fiware.github.io:tutorials.Step-by-Step:animal-welfare'
823+
```
824+
825+
826+
#### Response:
827+
828+
The response can be seen below, where the `hash` and `body` are the sha256 hash of the payload
829+
body, and a base64 encoded string respectively.
830+
831+
832+
```json
833+
{
834+
"did": "did:web:fiware.github.io:tutorials.Step-by-Step:animal-welfare",
835+
"attributes": [
836+
{
837+
"hash": "LIayBgwZ84KzjTIe9bHQfKE1/NRJIhPHrWE3NUiwuBI=",
838+
"body": "eyJjcmVkZW50aWFsc1R5cGUiOiJPcGVyYXRvckNyZWRlbnRpYWwiLCJjbGFpbXMiOlt7Im5hbWUiOiJyb2xlcyIsImFsbG93ZWRWYWx1ZXMiOlsiT1BFUkFUT1IiLCJWSVNJVE9SIl19XX0=",
839+
"issuerType": "Undefined"
840+
}
841+
]
842+
}
843+
```
844+
845+
846+
847+
Now, with a proper Verifiable Presentation, the **Animal** records can be accessed:
848+
849+
#### 1️⃣2️⃣ Request:
850+
851+
```console
852+
curl -L 'localhost:1030/ngsi-ld/v1/entities?local=true' \
853+
-H 'Link: <http://context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
854+
-H 'Authorization: Bearer eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJ2cCI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVQcmVzZW50YXRpb24iXSwidmVyaWZpYWJsZUNyZWRlbnRpYWwiOlsiZXlKaGJHY2lPaUpGVXpJMU5rc2lMQ0owZVhBaU9pSktWMVFpZlEuZXlKMll5STZleUpBWTI5dWRHVjRkQ0k2V3lKb2RIUnd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+
```json
861+
[
862+
{
863+
"id": "urn:ngsi-ld:Animal:cow006",
864+
"type": "Animal",
865+
"fedWith": { "type": "Property", "value": "Oats"},
866+
"species": { "type": "Property", "value": "dairy cattle"},
867+
"name": { "type": "Property", "value": "Twilight"},
868+
"sex": { "type": "VocabProperty", "vocab": "Female"},
869+
"phenologicalCondition": { "type": "VocabProperty", "vocab": "femaleAdult"},
870+
"healthCondition": {
871+
"type": "VocabProperty",
872+
"vocab": "healthy",
873+
"observedAt": "2024-02-02T15:00:00.000Z"
874+
},
875+
"reproductiveCondition": {
876+
"type": "VocabProperty",
877+
"vocab": "noStatus",
878+
"observedAt": "2024-02-02T15:00:00.000Z"
879+
}
880+
},
881+
... etc
882+
]
883+
```
884+
885+
The response contains a series of **Animal** records, and checking the output within the
886+
[Verifiable Presentation Monitor](http://localhost:3000/vp/monitor) at `http://localhost:3000/vp/monitor`, you will find the
887+
following output:
888+
889+
```text
890+
The following claims were made [{"name":"roles","allowedValues":["VISITOR","OPERATOR"]}]
891+
892+
{
893+
"firstName": "Alice",
894+
"lastName": "User",
895+
"eMail": "[email protected]",
896+
"roles": [
897+
"OPERATOR"
898+
],
899+
"id": "did:web:fiware.github.io:tutorials.Step-by-Step:alice"
900+
}
901+
```
902+
903+
904+
As you can see the `role:OPERATOR` is indeed a valid setting for `did:web:fiware.github.io:tutorials.Step-by-Step:animal-welfare` to create. Matching these values
905+
would allow a real data space connector to permit or deny access using their PEP.
906+
741907

742908

743909
# Next Steps

import-data

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,4 +812,57 @@ curl -s -o /dev/null -X POST 'http://'"${CONTEXT_BROKER}"'/ngsi-ld/v1/entityOper
812812
}
813813
]'
814814

815+
curl -s -o /dev/null -X POST 'http://'"${CONTEXT_BROKER}"'/ngsi-ld/v1/csourceRegistrations/' \
816+
-H 'Link: <'"${TUTORIAL_DATA_MODELS_CONTEXT}"'> rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
817+
-H 'Content-Type: application/json' \
818+
-d '{
819+
"type": "ContextSourceRegistration",
820+
"information": [
821+
{
822+
"entities": [
823+
{
824+
"type": "AgriParcel"
825+
},
826+
{
827+
"type": "Animal"
828+
}
829+
]
830+
}
831+
],
832+
"mode": "redirect",
833+
"management": {
834+
"timeout": 1000
835+
},
836+
"operations": [
837+
"redirectionOps"
838+
],
839+
"endpoint": "http://farmer"
840+
}'
841+
842+
843+
curl -s -o /dev/null -X POST 'http://'"${CONTEXT_BROKER}"'/ngsi-ld/v1/csourceRegistrations/' \
844+
-H 'Link: <'"${TUTORIAL_DATA_MODELS_CONTEXT}"'> rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
845+
-H 'NGSILD-Tenant: farmer' \
846+
-H 'Content-Type: application/json' \
847+
-d '{
848+
"type": "ContextSourceRegistration",
849+
"information": [
850+
{
851+
"entities": [
852+
{
853+
"type": "Animal"
854+
}
855+
]
856+
}
857+
],
858+
"mode": "inclusive",
859+
"operations": [
860+
"federationOps"
861+
],
862+
"management": {
863+
"timeout": 1000
864+
},
865+
"endpoint": "http://vet"
866+
}'
867+
815868
echo -e "\n \033[1;32mdone\033[0m"

0 commit comments

Comments
 (0)