Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

feat: #2246 Support for DID Web Method #2288

Merged
merged 1 commit into from
Dec 2, 2020
Merged

feat: #2246 Support for DID Web Method #2288

merged 1 commit into from
Dec 2, 2020

Conversation

amodkala
Copy link
Contributor

@amodkala amodkala commented Nov 2, 2020

Adds ability to resolve did:web dids, addresses issue #2246

Signed off by: Amod Kala amod.kala@securekey.com

@codecov
Copy link

codecov bot commented Nov 2, 2020

Codecov Report

Merging #2288 (c991bb8) into master (006e0f2) will decrease coverage by 0.02%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2288      +/-   ##
==========================================
- Coverage   89.48%   89.46%   -0.03%     
==========================================
  Files         223      228       +5     
  Lines       15885    15928      +43     
==========================================
+ Hits        14215    14250      +35     
- Misses        985      989       +4     
- Partials      685      689       +4     
Impacted Files Coverage Δ
pkg/vdr/web/resolver.go 73.91% <73.91%> (ø)
pkg/vdr/web/did.go 86.66% <86.66%> (ø)
pkg/doc/did/doc.go 89.37% <100.00%> (ø)
pkg/vdr/web/creator.go 100.00% <100.00%> (ø)
pkg/vdr/web/store.go 100.00% <100.00%> (ø)
pkg/vdr/web/vdr.go 100.00% <100.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 006e0f2...c991bb8. Read the comment docs.

pkg/vdr/web/did.go Outdated Show resolved Hide resolved
pkg/vdr/web/did_test.go Outdated Show resolved Hide resolved
pkg/vdr/web/did_test.go Outdated Show resolved Hide resolved
pkg/vdr/web/resolver.go Outdated Show resolved Hide resolved
Copy link
Contributor

@llorllale llorllale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments about the test URLs

@amodkala
Copy link
Contributor Author

amodkala commented Nov 2, 2020

addressed changes requested to test urls and tidied up the did parsing code, working on making the http client more robust now as per your recommendations

.vscode/settings.json Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Nov 5, 2020

This pull request introduces 1 alert when merging 866fc34 into e8a7705 - view on LGTM.com

new alerts:

  • 1 for Disabled TLS certificate check

pkg/vdr/web/resolver.go Outdated Show resolved Hide resolved
pkg/vdr/web/resolver.go Outdated Show resolved Hide resolved
pkg/vdr/web/did.go Outdated Show resolved Hide resolved
pkg/vdr/web/resolver_test.go Outdated Show resolved Hide resolved
pkg/vdr/web/resolver_test.go Outdated Show resolved Hide resolved
pkg/vdr/web/resolver.go Outdated Show resolved Hide resolved
pkg/vdr/web/resolver.go Outdated Show resolved Hide resolved
pkg/vdr/web/resolver.go Outdated Show resolved Hide resolved
pkg/vdr/web/creator.go Outdated Show resolved Hide resolved
pkg/vdr/web/resolver.go Outdated Show resolved Hide resolved
pkg/vdr/web/resolver_test.go Show resolved Hide resolved
}

switch pathComponents[0] {
case "localhost", "127.0.0.1":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code added just for testing purposes? If so you should elaborate why because we usually don't add extra code to support testing.
Is this valid scenario for "web" VDR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's just for testing, web dids shouldn't be originating from any site with a host:port url really as any organization trusted enough to have did:web would likely have a proper url

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the spec: "The method specific identifier MUST match the common name used in the SSL/TLS certificate, and it MUST NOT include IP addresses or port numbers. Directories and subdirectories MAY optionally be included, delimited by colons rather than slashes. " https://w3c-ccg.github.io/did-method-web/#method-specific-identifier

Copy link
Contributor Author

@amodkala amodkala Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch pathComponents[0] {
// This is for testing purposes ONLY and should not be used in production
case "localhost", "127.0.0.1":
	urlString = "https://" + strings.Join(pathComponents[0:2], ":") + "/" + strings.Join(pathComponents[2:], "/")

	log.New("aries-framework/pkg/vdr/web").Warnf("using an ip address or port number does not conform to spec")

would something like this be acceptable ? @sandrask

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not acceptable.

Yes, 127.0.0.1 is not allowed by the spec, but localhost is.

Also, ports will be supported. There is a proposed solution to base64url-encode the host portion: w3c-ccg/did-method-web#7 (comment). At least one implementation has adopted the proposal: https://github.com/ProjectProvenance/proof-points/pull/42/files.

@amodkala let's adopt the proposal - assume ports are allowed and the host:port portion is base64url-encoded.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amodkala my apologies - somehow I mixed up url-encoding with base64url-encoding this morning. The proposal for the did:web ID to have the host:port portion and all path components url-encoded. See the issue I linked to above for more details.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized url-encoding the path components makes it non-compliant with the generic did-core syntax

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followup: #2336

pkg/vdr/web/resolver.go Outdated Show resolved Hide resolved
@amodkala
Copy link
Contributor Author

@llorllale @sandrask

pkg/vdr/web/resolver.go Outdated Show resolved Hide resolved
}

pathComponents := strings.Split(parsedDID.MethodSpecificID, ":")
pathComponents[0], err = url.QueryUnescape(pathComponents[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should actually do this in did.Parse() (#2336).

return nil, fmt.Errorf("error resolving did:web did --> could not parse did:web did --> %w", err)
}

resp, err := docOpts.HTTPClient.Get(url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the http client is configured properly, it will validate the certificate against the configured root authorities. This is good.

Is this also ensuring this part of the did:web spec (important):

The method specific identifier MUST match the common name used in the SSL/TLS certificate, and it MUST NOT include IP addresses or port numbers.

So for instance if you resolve did:web:acme.org and the server's certificate's common name is "Faber College" - does it fail or not? This might be a followup PR - can you confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some digging through the http and tls packages I don't think we explicitly check for that at the moment. Would this just require a comparison between the two (common cert name and method specific identifier)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amodkala

Would this just require a comparison between the two (common cert name and method specific identifier)?

Roughly, yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amodkala are we updating this PR any time soon? Or would we rather add this verification in a followup?

require.Contains(t, err.Error(), "error parsing did doc")
})
/*
t.Run("test resolve did with certificate mismatch failure", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amodkala can we enable this test?

Signed-off-by: Amod Kala <amod.kala@securekey.com>
@llorllale llorllale merged commit b76c2d4 into hyperledger-archives:master Dec 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants