Documentation
¶
Overview ¶
Package user handles user creation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Auth ¶
func Auth(pid *authority.PlatformID, manager *mgdb.MongoManager, in *api.AuthRequest) (*api.RegisteredUser, error)
Auth checks if the authentication request is valid, and if so, generate the certificate and certificate hash for the user, and updates the user's entry in the database
If there is already an entry in the database with the same email, and that this entry already has a certificate and certificate hash, evaluates the request as invalid
The user's ConnectionInfo field is NOT handled here This data should be gathered upon beginning the signing sequence
Example ¶
package main import ( "crypto/rsa" "crypto/x509" "fmt" "io/ioutil" "os" "path/filepath" "dfss/auth" "dfss/dfssp/api" "dfss/dfssp/entities" "dfss/net" "golang.org/x/net/context" ) var ( mail string csr []byte rootCA *x509.Certificate rootKey, pkey *rsa.PrivateKey ) func init() { mail = "foo@foo.foo" pkey, _ = auth.GeneratePrivateKey(512) path := filepath.Join(os.Getenv("GOPATH"), "src", "dfss", "dfssp", "testdata", "dfssp_rootCA.pem") CAData, _ := ioutil.ReadFile(path) rootCA, _ = auth.PEMToCertificate(CAData) path = filepath.Join(os.Getenv("GOPATH"), "src", "dfss", "dfssp", "testdata", "dfssp_pkey.pem") KeyData, _ := ioutil.ReadFile(path) rootKey, _ = auth.PEMToPrivateKey(KeyData) csr, _ = auth.GetCertificateRequest("country", "organization", "unit", mail, pkey) } var err error var repository *entities.UserRepository func main() { mail := "example@example.example" token := "example" user := entities.NewUser() user.Email = mail user.RegToken = token user.Csr = string(csr) _, err = repository.Collection.Insert(*user) if err != nil { fmt.Println(err) } fmt.Println("User successfully inserted") conn, err := net.Connect("localhost:9090", nil, nil, rootCA, nil) if err != nil { fmt.Println("Unable to connect: ", err) } fmt.Println("Client successfully connected") client := api.NewPlatformClient(conn) request := &api.AuthRequest{Email: user.Email, Token: user.RegToken} msg, err := client.Auth(context.Background(), request) fmt.Println("AuthRequest successfully sent") if msg == (*api.RegisteredUser)(nil) { fmt.Println("The request should have been evaluated as valid") } if err != nil { fmt.Println(err) } if msg.ClientCert == "" { fmt.Println("The certificate should have been given as an answer") } fmt.Println("Certificate successfully received") res := entities.User{} err = repository.Collection.FindByID(*user, &res) if err != nil { fmt.Println(err) } if res.Certificate == "" || res.CertHash == nil { fmt.Println("The database should have been updated") } fmt.Println("Database successfully updated with cert and certHash") }
Output: User successfully inserted Client successfully connected AuthRequest successfully sent Certificate successfully received Database successfully updated with cert and certHash
func Register ¶
func Register(manager *mgdb.MongoManager, in *api.RegisterRequest) (*api.ErrorCode, error)
Register checks if the registration request is valid, and if so, creates the user entry in the database
If there is already an entry in the database with the same email, evaluates the request as invalid
The user's ConnectionInfo field is NOT handled here This data should be gathered upon beginning the signing sequence
func Unregister ¶ added in v0.3.0
func Unregister(manager *mgdb.MongoManager, userCertificateHash []byte) *api.ErrorCode
Unregister delete a user based on the provided certificate hash
Types ¶
This section is empty.