login

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2019 License: MIT Imports: 16 Imported by: 38

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode added in v0.1.0

func Decode(requestString []byte) (IdentityData, ClientData, error)

Decode decodes the login request string passed into an IdentityData struct, which contains trusted identity data such as the UUID of the player, and ClientData, which contains user specific data such as the skin of a player. Decode does not verify the request passed. For that reason, login.Verify() should be called on that same string before login.Decode().

func Encode

func Encode(loginChain string, data ClientData, key *ecdsa.PrivateKey) []byte

Encode encodes a login request using the encoded login chain passed and the client data. The request's client data token is signed using the private key passed. It must be the same as the one used to get the login chain.

func EncodeOffline

func EncodeOffline(identityData IdentityData, data ClientData, key *ecdsa.PrivateKey) []byte

EncodeOffline creates a login request using the identity data and client data passed. The private key passed will be used to self sign the JWTs. Unlike Encode, EncodeOffline does not have a token signed by the Mojang key. It consists of only one JWT which holds the identity data of the player.

func Verify added in v0.1.0

func Verify(requestString []byte) (publicKey *ecdsa.PublicKey, authenticated bool, err error)

Verify verifies the login request string passed. It ensures the claims found in the certificate chain are signed correctly and it looks for the Mojang public key to find out if the player was authenticated.

Types

type Chain added in v0.1.0

type Chain []string

Chain holds a chain with claims, each with their own headers, payloads and signatures. Each claim holds a public key used to verify other claims.

type ClientData

type ClientData struct {
	// CapeData is a base64 encoded string of cape data. This is usually an empty string, as skins typically
	// don't carry capes themselves.
	CapeData string
	// ClientRandomID is a random client ID number generated for the client. It usually remains consistent
	// through sessions and through game restarts.
	ClientRandomID int64 `json:"ClientRandomId"`
	// CurrentInputMode is the input mode used by the client. It is 1 for mobile and win10, but is different
	// for console input.
	CurrentInputMode int
	// DefaultInputMode is the default input mode used by the device.
	DefaultInputMode int
	// DeviceModel is a string indicating the device model used by the player. At the moment, it appears that
	// this name is always '(Standard system devices) System devices'.
	DeviceModel string
	// DeviceOS is a numerical ID indicating the OS of the device.
	DeviceOS device.OS
	// DeviceID is a UUID specific to the device. A different user will have the same UUID for this.
	DeviceID string `json:"DeviceId"`
	// GameVersion is the game version of the player that attempted to join, for example '1.11.0'.
	GameVersion string
	// GUIScale is the GUI scale of the player. It is by default 0, and is otherwise -1 or -2 for a smaller
	// GUI scale than usual.
	GUIScale int `json:"GuiScale"`
	// LanguageCode is the language code of the player. It looks like 'en_UK'. It follows the ISO language
	// codes, but hyphens ('-') are replaced with underscores. ('_')
	LanguageCode string
	// PlatformOfflineID is either a UUID or an empty string ...
	PlatformOfflineID string `json:"PlatformOfflineId"`
	// PlatformOnlineID is either a UUID or an empty string ...
	PlatformOnlineID string `json:"PlatformOnlineId"`
	// PlatformUserID holds a UUID which is only sent if the DeviceOS is of type device.XBOX. Its function
	// is not exactly clear.
	PlatformUserID string `json:"PlatformUserId,omitempty"`
	// PremiumSkin indicates if the skin the player held was a premium skin, meaning it was obtained through
	// payment.
	PremiumSkin bool
	// SelfSignedID is a UUID that remains consistent through restarts of the game and new game sessions.
	SelfSignedID string `json:"SelfSignedId"`
	// ServerAddress is the exact address the player used to join the server with. This may be either an
	// actual address, or a hostname. ServerAddress also has the port in it, in the shape of
	// 'address:port`.
	ServerAddress string
	// SkinData is a base64 encoded byte slice of 64*32*4, 64*64*4 or 128*128*4 bytes. It is a RGBA ordered
	// byte representation of the skin colours.
	SkinData string
	// SkinGeometry is a base64 JSON encoded structure of the geometry data of a skin, containing properties
	// such as bones, uv, pivot etc.
	SkinGeometry string
	// SkinGeometryName is the geometry name of the skin geometry above. This name must be equal to one of the
	// outer names found in the SkinGeometry, so that the client can find the correct geometry data.
	SkinGeometryName string
	// SkinID is a unique ID produced for the skin, for example 'c18e65aa-7b21-4637-9b63-8ad63622ef01_Alex'
	// for the default Alex skin.
	SkinID string `json:"SkinId"`
	// ThirdPartyName is the username of the player. This username should not be used however. The DisplayName
	// sent in the IdentityData should be preferred over this.
	ThirdPartyName string
	// UIProfile is the UI profile used. For the 'Pocket' UI, this is 1. For the 'Classic' UI, this is 0.
	UIProfile int
}

ClientData is a container of client specific data of a Login packet. It holds data such as the skin of a player, but also its language code and device information.

func (ClientData) Validate

func (data ClientData) Validate() error

Validate validates the client data. It returns an error if any of the fields checked did not carry a valid value.

type IdentityData

type IdentityData struct {
	// XUID is the XBOX Live user ID of the player, which will remain consistent as long as the player is
	// logged in with the XBOX Live account.
	XUID string
	// Identity is the UUID of the player, which will also remain consistent for as long as the user is logged
	// into its XBOX Live account.
	Identity string `json:"identity"`
	// DisplayName is the username of the player, which may be changed by the user. It should for that reason
	// not be used as a key to store information.
	DisplayName string `json:"displayName"`
}

IdentityData contains identity data of the player logged in. It is found in one of the JWT claims signed by Mojang, and can thus be trusted.

func (IdentityData) Validate

func (data IdentityData) Validate() error

Validate validates the identity data. It returns an error if any data contained in the IdentityData is invalid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL