Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signer-less Device Pairing #281

Merged
merged 16 commits into from
Aug 13, 2024
Merged

Signer-less Device Pairing #281

merged 16 commits into from
Aug 13, 2024

Conversation

nepet
Copy link
Collaborator

@nepet nepet commented Oct 1, 2023

This PR adds the "Pairing Process/Protocol" to the client stack. The Pairing-Process is a way to connect a signer-less client to a greenlight node. The pairing request has to be approved by a trusted device.

I'll add a more details about the process soon.

@nepet nepet force-pushed the 202309-pairing-protocol branch from 41335cf to 4050841 Compare October 2, 2023 12:56
@nepet nepet force-pushed the main-0.2 branch 2 times, most recently from 92251ee to 981db7e Compare October 9, 2023 15:55
@nepet nepet force-pushed the main-0.2 branch 2 times, most recently from 8b5a797 to 40c5809 Compare November 5, 2023 19:52
@nepet nepet force-pushed the 202309-pairing-protocol branch from 4050841 to 8fb8916 Compare November 7, 2023 12:50
@nepet nepet force-pushed the 202309-pairing-protocol branch from 8fb8916 to 5c485cd Compare November 10, 2023 16:06
@nepet nepet force-pushed the main-0.2 branch 2 times, most recently from ad9d0b4 to 180bb26 Compare November 26, 2023 13:24
@nepet nepet force-pushed the 202309-pairing-protocol branch 2 times, most recently from e0db8e2 to 157a322 Compare December 1, 2023 11:37
@nepet nepet force-pushed the 202309-pairing-protocol branch from 157a322 to ed1aed8 Compare December 3, 2023 17:12
@nepet nepet force-pushed the 202309-pairing-protocol branch from 3194f42 to 2d46078 Compare December 12, 2023 12:46
@nepet nepet force-pushed the 202309-pairing-protocol branch from 2d46078 to 9cec7a5 Compare January 10, 2024 07:34
@nepet nepet force-pushed the 202309-pairing-protocol branch from 9cec7a5 to 06d40ab Compare January 10, 2024 19:58
@nepet nepet force-pushed the 202309-pairing-protocol branch from 06d40ab to 6265146 Compare January 11, 2024 16:08
@nepet nepet force-pushed the main-0.2 branch 3 times, most recently from 644185e to d010f8d Compare February 2, 2024 18:36
@nepet nepet force-pushed the main-0.2 branch 5 times, most recently from f2b305e to f504032 Compare February 9, 2024 01:50
match self.verify_rune(PendingRequest {
request: vec![],
uri: "/cln.Node/ApprovePairing".to_string(),
signature: req.sig,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the Context need to be updated to handle the signature?

pub struct Context {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, this is independent of checking the actual context.

cdecker
cdecker previously approved these changes Jun 28, 2024
Copy link
Collaborator

@cdecker cdecker left a comment

Choose a reason for hiding this comment

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

Quite an impressive PR! I went through and all I could find were small nits. There is one comment in there about the ordering assumptions on the streams, but that can be deferred until it becomes important, if we leave enough breadcrumbs to identify the issue once it arises, otherwise just naming suggestions, that you should feel free to ignore :-)

libs/gl-client/.resources/proto/glclient/scheduler.proto Outdated Show resolved Hide resolved
libs/gl-client/.resources/proto/glclient/scheduler.proto Outdated Show resolved Hide resolved

message PairDeviceRequest {
// The tls public key of the new device.
string session_id = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: The name session_id is a bit misleading, could cert_id or client_id be better names? This is definitely bike-shedding the name, so if interested let's merge this and continue the discussion in a separate thread.

libs/gl-client/.resources/proto/glclient/scheduler.proto Outdated Show resolved Hide resolved
libs/gl-client/.resources/proto/glclient/scheduler.proto Outdated Show resolved Hide resolved
libs/gl-testing/gltesting/scheduler.py Outdated Show resolved Hide resolved
libs/gl-client/src/pairing/attestation_device.rs Outdated Show resolved Hide resolved
Comment on lines +188 to +201
fn restriction_contains_pubkey_exactly_once(s: &str, pubkey: &str) -> bool {
let search_field = format!("pubkey={}", pubkey);
match s.find(&search_field) {
Some(index) => {
// Check if 'pubkey=<pubkey>' is not preceded by '|'
if index > 0 && s.chars().nth(index - 1) == Some('|') {
return false;
}

// Check if 'pubkey=<pubkey>' is not followed by '|'
let end_index = index + search_field.len();
if end_index < s.len() && s.chars().nth(end_index) == Some('|') {
return false;
}

// Check if 'pubkey=<pubkey>' appears exactly once
s.matches(&search_field).count() == 1
}
None => false,
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we be checking for a standalone pubkey=03.... restriction? That'd mean that there cannot be any qualifiers (alternatives) on that restriction, and any rune including this restriction has to adhere to that pubkey. Attempting to parse a logical expression, and testing it doesn't somehow negate the clause we're interested in is hard (NP-hard to be precise, even if parsing works perfectly).

libs/gl-client/src/pairing/service.rs Outdated Show resolved Hide resolved
libs/gl-client/src/signer/mod.rs Outdated Show resolved Hide resolved
@nepet nepet force-pushed the 202309-pairing-protocol branch from 613af99 to 7a24cba Compare July 24, 2024 11:39
@nepet nepet marked this pull request as ready for review July 24, 2024 13:36
@nepet nepet force-pushed the 202309-pairing-protocol branch 2 times, most recently from b2cd32b to 52f60db Compare August 11, 2024 18:53
@cdecker cdecker force-pushed the 202309-pairing-protocol branch from 52f60db to f70230f Compare August 12, 2024 15:11
nepet added 16 commits August 13, 2024 17:27
We need to create a keypair before we can actually create the cert
during the pairing process.

Signed-off-by: Peter Neuroth <[email protected]>
This commit only affects the protos, generated files and places that
include the protos.

Signed-off-by: Peter Neuroth <[email protected]>
This implements the service and the methods to initialize a pairing
session on the "new device"

Signed-off-by: Peter Neuroth <[email protected]>
Adds the PairingQR proto message and pass it to the channel once we did
the request.

Signed-off-by: Peter Neuroth <[email protected]>
Adds a method that returns the relevant data for "old device" to approve
a pairing. This includes the requested restrictions that an old device
needs to sign off.

Signed-off-by: Peter Neuroth <[email protected]>
Adds the approval of the old device. This does not check the signature
and does also not check the restrictions. This soley approves the
pairing request.
This needs a tls cert and a rune to be present as we need these to sign
and attestate the approval.

Signed-off-by: Peter Neuroth <[email protected]>
This adds a method to the pairing service that allows to check the
validity of the PairingDataResponse. This is that the public key from
the session_id matches the public key from the CSR.

We may want to add a signature for the restrictions to ensure that GL
did not manipulate them. We are OK for now as a user has to aggree to
the restrictions anyway.

Signed-off-by: Peter Neuroth <[email protected]>
Signer now receives requests from the scheduler for further processing.
The signer processes a ApprovePairingRequest and responds to the
scheduler.

Signed-off-by: Peter Neuroth <[email protected]>
This commit replaces TlsConfig dependencies introduced by the
signerless device pairing with Credentials.

Signed-off-by: Peter Neuroth <[email protected]>
As we already pass the credentials to the pairing client we can also
remove parts that are part of the credentials from the client struct.
This allows to remove the node_id from `approve_pairing`.

Signed-off-by: Peter Neuroth <[email protected]>
Using a `Result<()>` instead of printing debug logs saves some lines of
code and is more idiomatic.

Signed-off-by: Peter Neuroth <[email protected]>
We expect a signer response during the pairing procedure. This adds an
extra assertion to help track down issues in the future.

Signed-off-by: Peter Neuroth <[email protected]>
@cdecker cdecker force-pushed the 202309-pairing-protocol branch from f70230f to 83d1bfb Compare August 13, 2024 15:27
@cdecker
Copy link
Collaborator

cdecker commented Aug 13, 2024

ACK f70230f

@cdecker cdecker enabled auto-merge (rebase) August 13, 2024 15:27
@cdecker cdecker merged commit edc14d0 into main Aug 13, 2024
13 checks passed
@cdecker cdecker deleted the 202309-pairing-protocol branch August 13, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants