From a384644cb4f52106d987a2d4673ad29cae65a2fa Mon Sep 17 00:00:00 2001 From: Christian Stewart Date: Sun, 17 Nov 2024 22:18:26 -0800 Subject: [PATCH] feat: add read-public read-private utils Signed-off-by: Christian Stewart --- cli/util/cli.go | 26 ++++++++++++++++++++++++++ cli/util/util.go | 21 +++++++++++++++++++++ go.sum | 4 ---- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/cli/util/cli.go b/cli/util/cli.go index 6387a970..7c712684 100644 --- a/cli/util/cli.go +++ b/cli/util/cli.go @@ -47,6 +47,32 @@ func (a *UtilArgs) BuildCommands() []*ucli.Command { }, }, }, + { + Name: "read-private", + Usage: "loads a private key pem and prints the peer id", + Action: a.RunReadPrivatePeerId, + Flags: []ucli.Flag{ + &ucli.StringFlag{ + Name: "file", + Aliases: []string{"f"}, + Usage: "file to load pem formatted private key", + Destination: &a.FilePath, + }, + }, + }, + { + Name: "read-public", + Usage: "loads a public key pem and prints the peer id", + Action: a.RunReadPublicPeerId, + Flags: []ucli.Flag{ + &ucli.StringFlag{ + Name: "file", + Aliases: []string{"f"}, + Usage: "file to load pem formatted public key", + Destination: &a.FilePath, + }, + }, + }, { Name: "derive-public", Usage: "loads a private key pem and writes a public key", diff --git a/cli/util/util.go b/cli/util/util.go index 18f849d8..df679784 100644 --- a/cli/util/util.go +++ b/cli/util/util.go @@ -59,6 +59,26 @@ func (a *UtilArgs) RunGeneratePrivate(_ *cli.Context) error { return nil } +// RunReadPublicPeerId loads a public key and prints the peer ID. +func (a *UtilArgs) RunReadPublicPeerId(_ *cli.Context) error { + rp, err := a.readInputFilePubKey() + if err != nil { + return err + } + _, err = os.Stdout.WriteString(rp.GetPeerID().String() + "\n") + return err +} + +// RunReadPrivatePeerId loads a private key and prints the peer ID. +func (a *UtilArgs) RunReadPrivatePeerId(_ *cli.Context) error { + rp, err := a.readInputFilePrivKey() + if err != nil { + return err + } + _, err = os.Stdout.WriteString(rp.GetPeerID().String() + "\n") + return err +} + // RunDerivePublic derives the public key from a private pem. func (a *UtilArgs) RunDerivePublic(_ *cli.Context) error { rp, err := a.readInputFilePrivKey() @@ -76,6 +96,7 @@ func (a *UtilArgs) RunDerivePublic(_ *cli.Context) error { return nil } + // RunDerivePublic derives the ssh public key from a private or public pem. func (a *UtilArgs) RunDeriveSshPublic(_ *cli.Context) error { rp, err := a.readInputFilePubKey() diff --git a/go.sum b/go.sum index 52a4d74a..856ba5b6 100644 --- a/go.sum +++ b/go.sum @@ -120,8 +120,6 @@ github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 h1:Dx7Ovyv/SFnMFw github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/pion/datachannel v1.5.9 h1:LpIWAOYPyDrXtU+BW7X0Yt/vGtYxtXQ8ql7dFfYUVZA= github.com/pion/datachannel v1.5.9/go.mod h1:kDUuk4CU4Uxp82NH4LQZbISULkX/HtzKa4P7ldf9izE= -github.com/pion/dtls/v3 v3.0.3 h1:j5ajZbQwff7Z8k3pE3S+rQ4STvKvXUdKsi/07ka+OWM= -github.com/pion/dtls/v3 v3.0.3/go.mod h1:weOTUyIV4z0bQaVzKe8kpaP17+us3yAuiQsEAG1STMU= github.com/pion/dtls/v3 v3.0.4 h1:44CZekewMzfrn9pmGrj5BNnTMDCFwr+6sLH+cCuLM7U= github.com/pion/dtls/v3 v3.0.4/go.mod h1:R373CsjxWqNPf6MEkfdy3aSe9niZvL/JaKlGeFphtMg= github.com/pion/ice/v4 v4.0.2 h1:1JhBRX8iQLi0+TfcavTjPjI6GO41MFn4CeTBX+Y9h5s= @@ -150,8 +148,6 @@ github.com/pion/transport/v3 v3.0.7 h1:iRbMH05BzSNwhILHoBoAPxoB9xQgOaJk+591KC9P1 github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uPLGhhz9rwo= github.com/pion/turn/v4 v4.0.0 h1:qxplo3Rxa9Yg1xXDxxH8xaqcyGUtbHYw4QSCvmFWvhM= github.com/pion/turn/v4 v4.0.0/go.mod h1:MuPDkm15nYSklKpN8vWJ9W2M0PlyQZqYt1McGuxG7mA= -github.com/pion/webrtc/v4 v4.0.1 h1:6Unwc6JzoTsjxetcAIoWH81RUM4K5dBc1BbJGcF9WVE= -github.com/pion/webrtc/v4 v4.0.1/go.mod h1:SfNn8CcFxR6OUVjLXVslAQ3a3994JhyE3Hw1jAuqEto= github.com/pion/webrtc/v4 v4.0.2 h1:fBwm5/hqSUybrCWl0DDBSTDrpbkcgkqpeLmXw9CsBQA= github.com/pion/webrtc/v4 v4.0.2/go.mod h1:moylBT2A4dNoEaYBCdV1nThM3TLwRHzWszIG+eSPaqQ= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=