tickets

package module
Version: v0.0.0-...-b45967e Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

README

Tickets aka tokens used for access defined here.

See: type KnotFreePayload struct

and MakeTicket(data *KnotFreePayload, privateKey []byte) ([]byte, error)

and func VerifyTicket(ticket []byte, publicKey []byte) (*KnotFreePayload, bool)

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSamplePrivate

func GetSamplePrivate() []byte

GetSamplePrivate is

func GetSamplePublic

func GetSamplePublic() []byte

GetSamplePublic is

func MakeTicket

func MakeTicket(data *KnotFreePayload, privateKey []byte) ([]byte, error)

MakeTicket is

func ParseOpenSSHPrivateKey

func ParseOpenSSHPrivateKey(in []byte) []byte

ParseOpenSSHPrivateKey parses openssh private key in the file here.

func ParseOpenSSHPublicKey

func ParseOpenSSHPublicKey(in []byte) []byte

ParseOpenSSHPublicKey an ed25519 result is 32 bytes

Types

type KnotFreePayload

type KnotFreePayload struct {
	//jwt.Payload
	ExpirationTime uint32 `json:"exp"`
	Issuer         string `json:"iss"`
	JWTID          string `json:"jti"`

	Input         float32 `json:"in"`  // bytes per hour
	Output        float32 `json:"out"` // bytes per hour
	Subscriptions float32 `json:"su"`  // per hour
	Connections   float32 `json:"co"`  // per hour

	URL string `json:"url"` // address of the service eg. "knotfreeiot.io"
}

KnotFreePayload is

func VerifyTicket

func VerifyTicket(ticket []byte, publicKey []byte) (*KnotFreePayload, bool)

VerifyTicket is

type ZeroReader

type ZeroReader struct{}

ZeroReader is too public

Example
package main

import (
	"crypto/ed25519"
	"encoding/base64"
	"fmt"

	"github.com/awootton/knotfreeiot/tickets"
)

func main() {

	var zero tickets.ZeroReader
	public, private, _ := ed25519.GenerateKey(zero)

	fmt.Println(base64.StdEncoding.WithPadding(base64.NoPadding).EncodeToString(public))
	fmt.Println(base64.StdEncoding.WithPadding(base64.NoPadding).EncodeToString(private))

	message := []byte("test message")
	sig := ed25519.Sign(private, message)
	if !ed25519.Verify(public, message, sig) {
		fmt.Println("valid signature rejected")
	} else {
		fmt.Println("good")
	}

	// Expected: O2onvM62pC1io6jQKm8Nc2UyFXcd4kOmOsBIoYtZ2ik
	// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA7aie8zrakLWKjqNAqbw1zZTIVdx3iQ6Y6wEihi1naKQ
	// good

}
Output:

func (ZeroReader) Read

func (ZeroReader) Read(buf []byte) (int, error)

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL