uport-project / kotlin-did-jwt

Create and verify uPort and DID compliant JWTs in Kotlin
https://developer.uport.me
Apache License 2.0
8 stars 6 forks source link

[Bugfix] `ES256K` verification for fails for basic ethr-DID #7

Closed mirceanis closed 5 years ago

mirceanis commented 5 years ago

This fixes [#167009918] in pivotal.

Description

If ES256K algorithm is used to create a JWT with a basic ethr-did as issuer then the verification fails.

The reason is that the DID Doc for a basic ethr-DID has only one public Key Entry with ethereumAddress for publicKey. Than cannot be used to run ecVerify because the full public key is never known.

The solution proposed here is to fallback to a ES256K-R verification mechanism with a list of recovered public keys based on all possible values of the recovery parameter (0 or 1).

Testing

A test has been added to check for this situation, with the token: eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJoZWxsbyI6IndvcmxkIiwiaWF0IjoxNTYxOTcxMTE5LCJpc3MiOiJkaWQ6ZXRocjoweGNmMDNkZDBhODk0ZWY3OWNiNWI2MDFhNDNjNGIyNWUzYWU0YzY3ZWQifQ.t5o1vzZExArlrrTVHmwtti7fnicXqvWrX6SS3F-Lu3budH7p6zQHjG8X7EvUTRUxhvr-eENCbXeteSE4rgF7MA

run ./gradlew test to run through the entire test suite.