client.go 1.02 KB
Newer Older
1 2 3
// Package user handles all the user-related logic
package user

Caro Axel's avatar
Caro Axel committed
4 5 6 7 8 9
import (
	"dfss/dfssc/security"
	pb "dfss/dfssp/api"
	"dfss/net"
)

10 11 12 13 14 15
// Register a user using the provided parameters
func Register(fileCA, fileCert, fileKey, addrPort, passphrase, country, organization, unit, mail string, bits int) error {
	manager, err := NewRegisterManager(fileCA, fileCert, fileKey, addrPort, passphrase, country, organization, unit, mail, bits)
	if err != nil {
		return err
	}
16
	return manager.GetCertificate()
17
}
Caro Axel's avatar
Caro Axel committed
18 19 20 21 22 23 24

// Authenticate a user using the provided parameters
func Authenticate(fileCA, fileCert, addrPort, mail, token string) error {
	manager, err := NewAuthManager(fileCA, fileCert, addrPort, mail, token)
	if err != nil {
		return err
	}
25
	return manager.Authenticate()
Caro Axel's avatar
Caro Axel committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
}

func connect(fileCA, addrPort string) (pb.PlatformClient, error) {
	ca, err := security.GetCertificate(fileCA)
	if err != nil {
		return nil, err
	}

	conn, err := net.Connect(addrPort, nil, nil, ca)
	if err != nil {
		return nil, err
	}

	return pb.NewPlatformClient(conn), nil
}