feat: remove username from passkey creation

This commit is contained in:
Prad Nukala
2024-12-08 23:30:17 -05:00
parent 5280209075
commit b7a40ac3d7
7 changed files with 31 additions and 121 deletions
+3 -92
View File
@@ -1,18 +1,14 @@
package handlers
import (
"fmt"
"net/http"
"github.com/go-webauthn/webauthn/protocol"
"github.com/go-webauthn/webauthn/protocol/webauthncose"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/crypto/mpc"
"github.com/onsonr/sonr/pkg/common"
"github.com/onsonr/sonr/pkg/common/response"
"github.com/onsonr/sonr/pkg/gateway/config"
"github.com/onsonr/sonr/pkg/gateway/internal/pages/register"
"github.com/onsonr/sonr/pkg/gateway/internal/session"
)
func HandleRegisterView(env config.Env) echo.HandlerFunc {
@@ -24,101 +20,16 @@ func HandleRegisterView(env config.Env) echo.HandlerFunc {
func HandleRegisterStart(c echo.Context) error {
challenge, _ := protocol.CreateChallenge()
handle := c.FormValue("handle")
firstName := c.FormValue("first_name")
lastName := c.FormValue("last_name")
fullName := fmt.Sprintf("%s %s", firstName, lastName)
// firstName := c.FormValue("first_name")
// lastName := c.FormValue("last_name")
ks, err := mpc.NewKeyset()
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
return response.TemplEcho(c, register.LinkCredentialView(ks.Address(), handle, fullName, challenge.String()))
return response.TemplEcho(c, register.LinkCredentialView(ks.Address(), handle, challenge.String()))
}
func HandleRegisterFinish(c echo.Context) error {
// cred := c.FormValue("credential")
return response.TemplEcho(c, register.LoadingVaultView())
}
// ╭───────────────────────────────────────────────────────────╮
// │ Registration Components │
// ╰───────────────────────────────────────────────────────────╯
func getLinkCredentialRequest(c echo.Context, addr string, handle string, userKSJSON string) register.LinkCredentialRequest {
cc, err := session.Get(c)
if err != nil {
return register.LinkCredentialRequest{
Handle: handle,
Address: addr,
RegisterOptions: buildRegisterOptions(buildUserEntity(addr, handle), buildLargeBlob(userKSJSON), buildServiceEntity(c)),
}
}
data := cc.Session()
usr := buildUserEntity(addr, handle)
blob := buildLargeBlob(userKSJSON)
service := buildServiceEntity(c)
return register.LinkCredentialRequest{
Platform: data.BrowserName,
Handle: data.UserHandle,
DeviceModel: data.BrowserVersion,
Address: addr,
RegisterOptions: buildRegisterOptions(usr, blob, service),
}
}
func buildRegisterOptions(user protocol.UserEntity, blob common.LargeBlob, service protocol.RelyingPartyEntity) protocol.PublicKeyCredentialCreationOptions {
return protocol.PublicKeyCredentialCreationOptions{
Timeout: 10000,
Attestation: protocol.PreferDirectAttestation,
AuthenticatorSelection: protocol.AuthenticatorSelection{
AuthenticatorAttachment: "platform",
ResidentKey: protocol.ResidentKeyRequirementPreferred,
UserVerification: "preferred",
},
RelyingParty: service,
User: user,
Extensions: protocol.AuthenticationExtensions{
"largeBlob": blob,
},
Parameters: []protocol.CredentialParameter{
{
Type: "public-key",
Algorithm: webauthncose.AlgES256,
},
{
Type: "public-key",
Algorithm: webauthncose.AlgES256K,
},
{
Type: "public-key",
Algorithm: webauthncose.AlgEdDSA,
},
},
}
}
func buildLargeBlob(userKeyshareJSON string) common.LargeBlob {
return common.LargeBlob{
Support: "required",
Write: userKeyshareJSON,
}
}
func buildUserEntity(userAddress string, userHandle string) protocol.UserEntity {
return protocol.UserEntity{
ID: userAddress,
DisplayName: userHandle,
CredentialEntity: protocol.CredentialEntity{
Name: userAddress,
},
}
}
func buildServiceEntity(c echo.Context) protocol.RelyingPartyEntity {
return protocol.RelyingPartyEntity{
CredentialEntity: protocol.CredentialEntity{
Name: "Sonr.ID",
},
ID: c.Request().Host,
}
}
+8 -5
View File
@@ -3,6 +3,7 @@ package database
import (
"net/http"
"github.com/go-webauthn/webauthn/protocol"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
)
@@ -18,11 +19,11 @@ var (
type User struct {
gorm.Model
Address string `json:"address"`
Handle string `json:"handle"`
FirstName string `json:"firstName"`
LastInitial string `json:"lastInitial"`
VaultCID string `json:"vaultCID"`
Address string `json:"address"`
Handle string `json:"handle"`
Name string `json:"name"`
CID string `json:"cid"`
Credentials []*protocol.CredentialDescriptor `json:"credentials"`
}
type Session struct {
@@ -38,4 +39,6 @@ type Session struct {
FirstName string `json:"firstName"`
LastInitial string `json:"lastInitial"`
VaultAddress string `json:"vaultAddress"`
HumanSum int `json:"humanSum"`
Challenge string `json:"challenge"`
}
@@ -21,11 +21,11 @@ templ ProfileFormView(turnstileSiteKey string) {
}
}
templ LinkCredentialView(addr string, handle string, name string, challenge string) {
templ LinkCredentialView(addr string, handle string, challenge string) {
@layout.Root("Register | Sonr.ID") {
@layout.Container() {
@text.Header("Link a PassKey", "This will be used to login to your vault.")
@form.Form("/register/finish", "POST", form.PasskeyInput(addr, handle, name, challenge), "65", false) {
@form.Form("/register/finish", "POST", form.PasskeyInput(addr, handle, challenge), "65", false) {
@details.PropertyList() {
@details.Property("Address", addr, "wallet")
@details.Property("Handle", handle, "at-sign")
@@ -122,7 +122,7 @@ func ProfileFormView(turnstileSiteKey string) templ.Component {
})
}
func LinkCredentialView(addr string, handle string, name string, challenge string) templ.Component {
func LinkCredentialView(addr string, handle string, challenge string) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@@ -219,7 +219,7 @@ func LinkCredentialView(addr string, handle string, name string, challenge strin
}
return templ_7745c5c3_Err
})
templ_7745c5c3_Err = form.Form("/register/finish", "POST", form.PasskeyInput(addr, handle, name, challenge), "65", false).Render(templ.WithChildren(ctx, templ_7745c5c3_Var8), templ_7745c5c3_Buffer)
templ_7745c5c3_Err = form.Form("/register/finish", "POST", form.PasskeyInput(addr, handle, challenge), "65", false).Render(templ.WithChildren(ctx, templ_7745c5c3_Var8), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
+1
View File
@@ -0,0 +1 @@
package session