Skip to content

Commit 39375d2

Browse files
authored
PEP 807: make discovery procedure reversible (#4791)
1 parent e1a1784 commit 39375d2

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

peps/pep-0807.rst

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ apply to all parts of this PEP's specification:
114114
clients **MUST** reject any URLs that do not meet this constraint.
115115

116116
In practice, this means that a discovery request to
117-
``https://upload.example.com/.well-known/pytp/{key}`` can only
117+
``https://upload.example.com/.well-known/pytp?discover={key}`` can only
118118
return URLs with the ``upload.example.com`` host.
119119

120120
* All client requests **SHOULD** have an
@@ -157,19 +157,21 @@ The discovery mechanism is as follows:
157157
For the above example, the path component is
158158
``/legacy/``.
159159

160-
3. The uploading client takes the SHA2-256 hash of the path component,
161-
producing the *discovery key*.
160+
3. The uploading client performs a query-safe URL encoding of the path component
161+
(i.e. percent-encoding as defined in :rfc:`3986`, including encoding
162+
of forward slashes and spaces), producing the *discovery key*.
162163

163164
For the above example, the discovery key is
164-
``0cace9579789849db6e16d48df183951c8f17582200d84bc93c7678d6c8f78a7``. [#fn-hash]_
165+
``%2Flegacy%2F``. [#fn-discovery-key]_
165166

166167
4. The uploading client constructs a *discovery URL* by taking the
167168
scheme and authority components (as defined in :rfc:`3986`)
168-
of the upload URL and appending ``/.well-known/pytp/``
169-
and the discovery key.
169+
of the upload URL and appending ``/.well-known/pytp`` as the path.
170+
Then, the uploading client appends the discovery key as the value
171+
of the ``discover`` query parameter.
170172

171173
For the above example, the discovery URL is
172-
``https://upload.example.com/.well-known/pytp/af030c06750716b1b35852298fe852b90def13dcbd012a5fe5148470f1206bfc``.
174+
``https://upload.example.com/.well-known/pytp?discover=%2Flegacy%2F``.
173175

174176
5. The uploading client performs an HTTP GET request to the discovery URL.
175177

@@ -445,17 +447,17 @@ This approach too has downsides:
445447
Footnotes
446448
=========
447449

448-
.. [#fn-hash]
450+
.. [#fn-discovery-key]
449451
450452
The discovery key may be computed thusly:
451453
452454
.. code-block:: pycon
453455
454-
>>> import hashlib
456+
>>> import urllib.parse
455457
>>> path = "/legacy/"
456-
>>> key = hashlib.sha256(path.encode("utf-8")).hexdigest()
458+
>>> key = urllib.parse.quote_plus(path)
457459
>>> print(key)
458-
0cace9579789849db6e16d48df183951c8f17582200d84bc93c7678d6c8f78a7
460+
'%2Flegacy%2F'
459461
460462
.. [#fn-oidc] Widely used CI/CD and cloud providers variously implement "ambient"
461463
OIDC token retrieval mechanisms that aren't standardized.

0 commit comments

Comments
 (0)