feat: try using the new ClientId & Handle format (i.e. plain URIs)

This commit is contained in:
beltram 2024-01-02 14:38:41 +01:00 committed by Herman Slatman
parent 39bf889925
commit 90b5347887
No known key found for this signature in database
GPG Key ID: F4D8A44EA0A75A4F
5 changed files with 23 additions and 24 deletions

View File

@ -199,7 +199,7 @@ func TestIMIntegration(t *testing.T) {
Identifiers: []acme.Identifier{ Identifiers: []acme.Identifier{
{ {
Type: "wireapp-id", Type: "wireapp-id",
Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "im:wireapp=75d73550-16e0-4027-abfd-0137e32180cc/ed416ce8ecdd9fad@example.com", "handle": "im:wireapp=alice.smith.qa@example.com"}`, Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "wireapp://lJGYPz0ZRq2kvc_XpdaDlA:ed416ce8ecdd9fad@example.com", "handle": "wireapp://%40alice.smith.qa@example.com"}`,
}, },
}, },
} }
@ -377,12 +377,12 @@ func TestIMIntegration(t *testing.T) {
}, },
}) })
qUserID, err := url.Parse("im:wireapp=75d73550-16e0-4027-abfd-0137e32180cc/ed416ce8ecdd9fad@example.com") qUserID, err := url.Parse("wireapp://lJGYPz0ZRq2kvc_XpdaDlA:ed416ce8ecdd9fad@example.com")
if err != nil { if err != nil {
t.Fatal("parse user ID URI", err) t.Fatal("parse user ID URI", err)
} }
_ = qUserID _ = qUserID
qUserName, err := url.Parse("im:wireapp=alice.smith.qa@example.com") qUserName, err := url.Parse("wireapp://%40alice.smith.qa@example.com")
if err != nil { if err != nil {
t.Fatal("parse user name URI", err) t.Fatal("parse user name URI", err)
} }

View File

@ -5,6 +5,7 @@ import (
"crypto/x509" "crypto/x509"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"go.step.sm/crypto/kms/uri"
"net" "net"
"net/http" "net/http"
"strings" "strings"
@ -54,8 +55,12 @@ func (n *NewOrderRequest) Validate() error {
if err != nil { if err != nil {
return acme.NewError(acme.ErrorMalformedType, "ID cannot be parsed") return acme.NewError(acme.ErrorMalformedType, "ID cannot be parsed")
} }
if !strings.HasPrefix(orderValue.ClientID, "im:wireapp=") { clientIdUri, err := uri.Parse(orderValue.ClientID)
return acme.NewError(acme.ErrorMalformedType, "missing client ID prefix") if err != nil {
return acme.NewError(acme.ErrorMalformedType, "invalid client ID, it's supposed to be a valid URI")
}
if clientIdUri.Scheme != "wireapp" {
return acme.NewError(acme.ErrorMalformedType, "invalid client ID scheme")
} }
default: default:
return acme.NewError(acme.ErrorMalformedType, "identifier type unsupported: %s", id.Type) return acme.NewError(acme.ErrorMalformedType, "identifier type unsupported: %s", id.Type)

View File

@ -190,7 +190,7 @@ func TestNewOrderRequest_Validate(t *testing.T) {
return test{ return test{
nor: &NewOrderRequest{ nor: &NewOrderRequest{
Identifiers: []acme.Identifier{ Identifiers: []acme.Identifier{
{Type: "wireapp-id", Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "im:wireapp=75d73550-16e0-4027-abfd-0137e32180cc/ed416ce8ecdd9fad@example.com", "handle": "im:wireapp=alice.smith.qa@example.com"}`}, {Type: "wireapp-id", Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "wireapp://lJGYPz0ZRq2kvc_XpdaDlA:ed416ce8ecdd9fad@example.com", "handle": "wireapp://%40alice.smith.qa@example.com"}`},
}, },
NotAfter: naf, NotAfter: naf,
NotBefore: nbf, NotBefore: nbf,
@ -785,7 +785,7 @@ func TestHandler_newAuthorization(t *testing.T) {
AccountID: "accID", AccountID: "accID",
Identifier: acme.Identifier{ Identifier: acme.Identifier{
Type: "wireapp", Type: "wireapp",
Value: "im:wireapp=user/client@domain", Value: "wireapp://user:client@domain",
}, },
Status: acme.StatusPending, Status: acme.StatusPending,
ExpiresAt: clock.Now(), ExpiresAt: clock.Now(),
@ -1699,7 +1699,7 @@ func TestHandler_NewOrder(t *testing.T) {
acc := &acme.Account{ID: "accID"} acc := &acme.Account{ID: "accID"}
nor := &NewOrderRequest{ nor := &NewOrderRequest{
Identifiers: []acme.Identifier{ Identifiers: []acme.Identifier{
{Type: "wireapp-id", Value: `{"client-id": "im:wireapp=user/client@domain"}`}, {Type: "wireapp-id", Value: `{"client-id": "wireapp://user:client@domain"}`},
}, },
} }
b, err := json.Marshal(nor) b, err := json.Marshal(nor)
@ -1736,7 +1736,7 @@ func TestHandler_NewOrder(t *testing.T) {
assert.Equals(t, ch.AccountID, "accID") assert.Equals(t, ch.AccountID, "accID")
assert.NotEquals(t, ch.Token, "") assert.NotEquals(t, ch.Token, "")
assert.Equals(t, ch.Status, acme.StatusPending) assert.Equals(t, ch.Status, acme.StatusPending)
assert.Equals(t, ch.Value, `{"client-id": "im:wireapp=user/client@domain"}`) assert.Equals(t, ch.Value, `{"client-id": "wireapp://user:client@domain"}`)
return nil return nil
}, },
MockCreateAuthorization: func(ctx context.Context, az *acme.Authorization) error { MockCreateAuthorization: func(ctx context.Context, az *acme.Authorization) error {

View File

@ -19,7 +19,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
"net" "net"
"net/url" "net/url"
"os" "os"
@ -464,8 +463,6 @@ func wireDPOP01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSO
kid := base64.RawURLEncoding.EncodeToString(rawKid) kid := base64.RawURLEncoding.EncodeToString(rawKid)
log.Printf("kid: %s", kid)
dpopOptions := provisioner.GetOptions().GetDPOPOptions() dpopOptions := provisioner.GetOptions().GetDPOPOptions()
key := dpopOptions.GetSigningKey() key := dpopOptions.GetSigningKey()

View File

@ -3,7 +3,7 @@ package wire
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings" "go.step.sm/crypto/kms/uri"
) )
type WireIDJSON struct { type WireIDJSON struct {
@ -25,18 +25,15 @@ type ClientID struct {
} }
func ParseClientID(clientID string) (ClientID, error) { func ParseClientID(clientID string) (ClientID, error) {
at := strings.SplitN(clientID, "@", 2) clientIdUri, err := uri.Parse(clientID)
if len(at) != 2 { if err != nil {
return ClientID{}, fmt.Errorf("could not match client ID format: %s", clientID) return ClientID{}, fmt.Errorf("invalid client id URI")
}
comp := at[0]
slash := strings.SplitN(comp, "/", 2)
if len(slash) != 2 {
return ClientID{}, fmt.Errorf("could not match client ID format: %s", clientID)
} }
username := clientIdUri.User.Username()
deviceId, _ := clientIdUri.User.Password()
return ClientID{ return ClientID{
Username: slash[0], Username: username,
DeviceID: slash[1], DeviceID: deviceId,
Domain: at[1], Domain: clientIdUri.Host,
}, nil }, nil
} }