Skip to content

Commit 341e943

Browse files
committed
signing request
1 parent 3b41933 commit 341e943

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

README.md

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ the [OpenAPI](https://github.com/OAI/OpenAPI-Specification) (fka Swagger) specif
1515
* [Share Updating](#update)
1616
* [Resharing](#reshare)
1717
* [Invite](#invite)
18+
* [Signing Request](#signing-request)
1819

1920
* [Contributing](#contributing)
2021

@@ -35,16 +36,20 @@ If a finite whitelist of receiver servers exists on the sender side, then this l
3536

3637
When a sending server allows sharing to any internet-hosted receiving server, then discovery can happen from the sharee address, using the `/.well-known/ocm` (or `/ocm-provider`, for backwards compatibility) URL that receiving servers SHOULD provide according to this [specification](https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1.well-known~1ocm/get).
3738

39+
If the identity of an incoming request needs to be confirmed, the discovery data SHOULD contain a public key. Each incoming request that requires to origin from an authenticated source must be signed in its headers using the related private key.
40+
3841
To fill the gap between users knowning other peers' email addresses of the form `user@provider.org`, and the actual cloud storage endpoints being in the form `https://my-cloud-storage.provider.org`, a further discovery mechanism SHOULD be provided by implementations that wish to allow sending shares to any receiver, based on DNS `SRV` Service Records.
3942

4043
* A provider SHOULD ensure that a `type=SRV` DNS query to `_ocm._tcp.provider.org` resolves to e.g. `service = 10 10 443 my-cloud-storage.provider.org`
4144
* When requested to discover the EFSS endpoint for `user@provider.org`, implementations SHOULD query the corresponding `_ocm._tcp.domain` DNS record, e.g. `_ocm._tcp.provider.org`, and subsequently make a HTTP GET request to the host returned by that DNS query, followed by the `/.well-known/ocm` URL path.
4245

46+
47+
4348
### Share Creation
4449
To create a share, the sending server SHOULD make a HTTP POST request to the `/shares` endpoint of the receiving server ([docs](https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1shares/post)).
4550

4651
### Share Acceptance
47-
In response to a share creation, the receiving server MAY send back a [notification](https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post) to the sending server, with `notificationType` set to `"SHARE_ACCEPTED"` or `"SHARE_DECLINED"`. The sending server MAY expose this information to the end user.
52+
In response to a share creation, the receiving server MAY send back a [notification](https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post) to the sending server, with `notificationType` set to `"SHARE_ACCEPTED"` or `"SHARE_DECLINED"`. The sending server MAY expose this information to the end user.
4853

4954
### Share Access
5055
To access a share, the receiving server MAY use multiple ways, depending on the received payload and on the `protocol.name` property:
@@ -87,6 +92,103 @@ If an OCM provider exposes the capability `/mfa-capable`, it indicates that it w
8792
Since there is no way to guarantee that the sharee OCM provider will actually enforce the MFA requirement, it is up to the sharer OCM provider to establish a trust with the OCM sharee provider such that it is reasonable to assume that the sharee OCM provider will honor the MFA requirement. This establishment of trust will inevitably be implementation dependent, and can be done for example using a pre approved allow list of trusted OCM providers. The procedure of establishing trust is out of scope for this specification: a mechanism similar to the [ScienceMesh](https://sciencemesh.io) integration for the [Invite](#invite) capability may be envisaged.
8893

8994

95+
## Signing request
96+
97+
A request is signed by adding the signature in the headers. The sender also need to expose the public key used to generate the signature. The receiver can then validate the signature and therefore the origin of the request.
98+
To helps debugging, it is made mandatory to also add all properties used in the signature as headers, even if they can be easily re-generated from the payload.
99+
100+
Note: Signed requests prove the identity of the sender but does not encrypt nor affect its payload.
101+
102+
Here is an example of headers needed to sign a request.
103+
104+
```
105+
{
106+
"(request-target)": "post /path",
107+
"content-length": 380,
108+
"date": "Mon, 08 Jul 2024 14:16:20 GMT",
109+
"digest": "SHA-256=U7gNVUQiixe5BRbp4Tg0xCZMTcSWXXUZI2\\/xtHM40S0=",
110+
"host": "hostname.of.the.recipient",
111+
"Signature": "keyId=\"https://author.hostname/key\",algorithm=\"ras-sha256\",headers=\"content-length date digest host\",signature=\"DzN12OCS1rsA[...]o0VmxjQooRo6HHabg==\""
112+
}
113+
```
114+
115+
- '(request-target)' contains the reached endpoint and the used method,
116+
- 'content-length' is the total length of the payload of the request,
117+
- 'date' is the date and time on which the request have been emitted,
118+
- 'digest' is a checksum of the payload of the request,
119+
- 'host' is the hostname of the recipient of the request (remote when signing outgoing request, local on incoming request),
120+
- 'Signature' contains the signature generated using the private key and details on its generation:
121+
* 'keyId' is a unique id, formatted as an url. hostname is used to retrieve the public key via custom discovery
122+
* 'algorithm' specify the algorithm used to generate signature
123+
* 'headers' specify the properties used when generating the signature
124+
* 'signature' the signature of an array containing the properties listed in 'headers'. Some properties like content-length, date, digest, and host are mandatory to protect against authenticity override.
125+
126+
127+
### How to generate the Signature for outgoing request
128+
129+
After properties are set in the headers, the Signature is generated and added to the list.
130+
131+
This is a quick PHP example of headers for outgoing request:
132+
133+
```php
134+
$headers = [
135+
'(request-target)' => 'post /path',
136+
'content-length' => strlen($payload),
137+
'date' => gmdate('D, d M Y H:i:s T'),
138+
'digest': 'SHA-256=' . base64_encode(hash('sha256', utf8_encode($payload), true)),
139+
'host': 'hostname.of.the.recipient',
140+
];
141+
142+
openssl_sign(implode("\n", $headers), $signed, $privateKey, OPENSSL_ALGO_SHA256);
143+
144+
$signature = [
145+
'keyId' => 'https://author.hostname/key',
146+
'algorithm' => 'ras-sha256',
147+
'headers' => 'content-length date digest host',
148+
'signature' => $signed
149+
];
150+
151+
$headers['Signature'] = implode(',', $signature);
152+
```
153+
154+
155+
### How to confirm Signature on incoming request
156+
157+
The first step would be to confirm the validity of each properties:
158+
159+
- '(request-target)' and 'host' are immutable to the type of the request and the local/current host,
160+
- 'content-length' and 'digest' can be re-generated and compared from the payload of the request,
161+
- A maximum TTL must be applied to 'date' and current timestamp,
162+
- regarding data contained in the 'Signature' header:
163+
* using 'keyId' to get the public key from remote signatory,
164+
* 'headers' is used to generate the clear version of the signature and must contain at least 'content-length', 'date', 'digest' and 'host',
165+
* 'signature' is the encrypted version of the signature.
166+
167+
Here is an example of how to verify the signature using the headers, the signature and the public key:
168+
169+
```php
170+
$clear = [
171+
'(request-target)' => 'post /path',
172+
'content-length' => strlen($payload),
173+
'date' => 'Mon, 08 Jul 2024 14:16:20 GMT',
174+
'digest': 'SHA-256=' . base64_encode(hash('sha256', utf8_encode($payload), true)),
175+
'host': $localhost
176+
];
177+
178+
$signed = "DzN12OCS1rsA[...]o0VmxjQooRo6HHabg==";
179+
if (openssl_verify(implode("\n", $clear), $signed, $publicKey, 'sha256') !== 1) {
180+
throw new InvalidSignatureException('signature issue');
181+
}
182+
```
183+
184+
### Validating the payload
185+
186+
while signed, it is still needed to confirm the validity of the payload.
187+
The last step is to ensure that the payload implies action initiated on the behalf the source of the request.
188+
189+
As an example, if the payload is about initiating a new share the file owner has to be an account from the instance at the origin of the request.
190+
191+
90192
## Changelog
91193

92194
[Available here](CHANGELOG.md)

spec.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,23 @@ definitions:
357357
enum: ["/notifications", "/invite-accepted", "/mfa-capable"]
358358
example:
359359
["/invite-accepted"]
360+
publicKey:
361+
type: object
362+
description: |
363+
The signatory used to sign outgoing request to confirm its origin. The
364+
signatory is optional but it MUST contains `id` and `publicKeyPem`.
365+
properties:
366+
id:
367+
type: string
368+
description: |
369+
unique id of the key in URI format. The hostname set the origin of the
370+
request and MUST be identical to the current discovery endpoint.
371+
example: https://my-cloud-storage.org/ocm#signature
372+
publicKeyPem:
373+
type: string
374+
description: |
375+
PEM-encoded version of the public key.
376+
example: "-----BEGIN PRIVATE KEY-----\nMII...QDD\n-----END PRIVATE KEY-----\n"
360377
NewShare:
361378
type: object
362379
required:

0 commit comments

Comments
 (0)