deltaDAO / self-description-signer

A simple script to create Gaia-X Self Descriptions
6 stars 6 forks source link

[BUG] Normalizing of self-description.json fails #12

Open ecoben opened 2 years ago

ecoben commented 2 years ago

Using the SD signer tool as described in Step 2 of the gx-compliance README, fails with the following error message:

Hashed canonized SD 8562727dcf1c655dc4704935ab9d3369363a72f86ba8a81242b26c1cd6051abd
'Something went wrong:'
undefined

The input used for testing is identical to the one in this API POST:

curl --location --request POST 'https://compliance.gaia-x.eu/api/v1/normalize' \
--header 'Content-Type: application/json' \
--data-raw '{
    "@context": [
        "http://www.w3.org/ns/shacl#",
        "http://www.w3.org/2001/XMLSchema#",
        "http://w3id.org/gaia-x/participant#",
        "@nest"
    ],
    "@id": "https://www.eco.de/.well-known/self-description.json",
    "@type": [
        "VerifiableCredential",
        "LegalPerson"
    ],
    "credentialSubject": {
        "id": "did:web:eco.de",
        "gx-participant:name": {
            "@value": "eco - Verband der Internetwirtschaft",
            "@type": "xsd:string"
        },
        "gx-participant:legalName": {
            "@value": "eco - Verband der Internetwirtschaft e.V.",
            "@type": "xsd:string"
        },
        "gx-participant:registrationNumber": {
            "@value": "DE182676944",
            "@type": "xsd:string"
        },
        "gx-participant:headquarterAddress": {
            "@type": "gx-participant:Address",
            "gx-participant:country": {
                "@value": "DE",
                "@type": "xsd:string"
            },
            "gx-participant:street-address": {
                "@value": "Lichtstraße 43h",
                "@type": "xsd:string"
            },
            "gx-participant:postal-code": {
                "@value": "50825",
                "@type": "xsd:string"
            },
            "gx-participant:locality": {
                "@value": "Köln/Cologne",
                "@type": "xsd:string"
            }
        },
        "gx-participant:legalAddress": {
            "@type": "gx-participant:Address",
            "gx-participant:country": {
                "@value": "DE",
                "@type": "xsd:string"
            },
            "gx-participant:street-address": {
                "@value": "Lichtstraße 43h",
                "@type": "xsd:string"
            },
            "gx-participant:postal-code": {
                "@value": "50825",
                "@type": "xsd:string"
            },
            "gx-participant:locality": {
                "@value": "Köln/Cologne",
                "@type": "xsd:string"
            }
        }
    }
}'

When checking the above SD input using the Swagger test page at https://compliance.gaia-x.eu/docs/#/Common/CommonController_normalizeSelfDescriptionRaw , I get a response of 201 Undocumented.

The sample files provided, produce the same response:

oceanByte commented 2 years ago

Hi @ecoben, thanks for the report. I am trying to reproduce the error, but everything works on my end. Normalization is working as expected but the signing might fail for you? I believe it must be a problem with your keys. Did you sign any other SDs successfully yet?

If you want to get the full error message you can change line 180 console.dir(error?.response?.data, { depth: null, colors: true }); to console.dir(error, { depth: null, colors: true });.

ecoben commented 2 years ago

Thanks @oceanByte, I will try debugging this as you suggested.

ecoben commented 2 years ago

Okay, now I got helpful messages from jose and can confirm: my .env was not in the expected format.

I had to convert the private key from pkcs1 to pkcs8 using OpenSSL:
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in pkcs1.key -out pkcs8.key (The -nocrypt flag seems to be deprecated these days, but I think that's how the input is needed here.)

I didn't actually know about the different formats - and didn't pick up on the subtle difference: the example.env begins with "PRIVATE_KEY="-----BEGIN PRIVATE KEY----- which seems to be the case in pkcs8 format rather than "PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY----- which was my pkcs1 version.

Maybe a hint on this could save others some time?