trustedtimestamps

package module
v0.0.0-...-b048252 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 16 Imported by: 0

README

Trusted Timestamps

Go Report Card

Implementation of Trusted Timestamps in golang.

package main

import (
	"fmt"
	tts "gitlab.com/mae.earth/pkg/trustedtimestamps"
	"io/ioutil"
	"os"
)

func main() {

	/* setup server */

	config := &tts.Configuration{Domain: "time.example.org",
		Hash: "sha1",
	}

	server, err := tts.NewServer(config)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error creating new tts server -- %v", err)
		os.Exit(1)
	}

	if err := server.GenerateKey(); err != nil {
		fmt.Fprintf(os.Stderr, "error generating server key -- %v", err)
		os.Exit(1)
	}

	/* export banner from server */

	banner, err := server.ExportBanner()
	if err != nil {
		fmt.Fprintf(os.Stderr, "error exporting banner -- %v", err)
		os.Exit(1)
	}

	if err := ioutil.WriteFile("banner.pem", banner, 0664); err != nil {
		fmt.Fprintf(os.Stderr, "error writing %q to disk -- %v", "banner.pem", err)
		os.Exit(1)
	}

	/* setup client */

	config = &tts.Configuration{Domain: "client.example.org",
		Hash: "sha1",
	}

	client, err := tts.NewClient(config)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error creating new tts client -- %v", err)
		os.Exit(1)
	}

	/* add server (from banner) to client */

	if err := client.AddToKeychain(banner); err != nil {
		fmt.Fprintf(os.Stderr, "error adding banner to keychain -- %v", err)
		os.Exit(1)
	}

	/* create timestamp, prepared from the client and generated at the server */

	timestamp, err := server.Timestamp(client.Prepare([]byte("payload")))
	if err != nil {
		fmt.Fprintf(os.Stderr, "error timestamping client data -- %v", err)
		os.Exit(1)
	}

	/* armour timestamp for writing to file etc.. */

	armour := tts.ArmourTimestamps([]*tts.Timestamp{timestamp})

	if err := ioutil.WriteFile("timestamp.pem", armour[0], 0664); err != nil {
		fmt.Fprintf(os.Stderr, "error writing %q to disk -- %v", "timestamp.pem", err)
		os.Exit(1)
	}

	/* dearmout timestamp from file */

	timestamps, err := tts.DearmourTimestamps(armour)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error dearmour timestamp -- %v", err)
		os.Exit(1)
	}

	/* verify timestamp at the client */

	ok, err := client.Verify(timestamps[0])
	if err != nil {
		fmt.Fprintf(os.Stderr, "error verifying timestamp with client -- %v", err)
		os.Exit(1)
	}

	if !ok {
		fmt.Fprintf(os.Stderr, "bad timestamp")
		os.Exit(2)
	}

}

banner.pem

-----BEGIN TRUSTED TIMESTAMP BANNER-----
fingerprint: b:10:a5:a7:cb:68:fc:91:6f:75:de:fa:9d:1a:10:61:b7:cc:d6:fa
key-type: ecdsa
source: time.example.org
timestamp: Wed, 24 Jan 2018 13:36:26 +0000

ME4wEAYHKoZIzj0CAQYFK4EEACEDOgAEa/WUtnrhMc1pt9kMVp2glb5YFI1s4PV7
7rMovJMOT2T/Egjep14yNwUUHqDQObvSTJuQYPTVsAw=
-----END TRUSTED TIMESTAMP BANNER-----

timestamp.pem

-----BEGIN TRUSTED TIMESTAMP-----
data-hash: f07e5a815613c5abeddc4b682247a4c42d8a95df
fingerprint: b:10:a5:a7:cb:68:fc:91:6f:75:de:fa:9d:1a:10:61:b7:cc:d6:fa
hash: sha1;data-hash+timestamp;delimited;edb189c59930ffba5be24a5539703c962cd17239
source: time.example.org
timestamp: Wed, 24 Jan 2018 13:36:26 +0000
verify: source+hash+timestamp;delimited

/n/8j64+zhEUKI5+JAx3azKsjrZYXv0q/SuBGhWbQ6fMnxUzbmasdBbujIuhwf3s
4eAcOFxnP54=
-----END TRUSTED TIMESTAMP-----

Documentation

Overview

mae.earth/pkg/trustedtimestamps/client.go
* mae 12017

mae.earth/pkg/trustedtimestamps/definitions.go
* mae 12017

mae.earth/pkg/trustedtimestamps/funcs.go
* mae 12017

mae.earth/pkg/trustedtimestamps/server.go
* mae 12017

mae.earth/pkg/trustedtimestamps/timestamps.go
* mae 12017

Package trustedtimestamps

mae.earth/pkg/trustedtimestamps/utils.go
* mae 12017

Index

Constants

View Source
const (
	BannerType = "TRUSTED TIMESTAMP BANNER"
)
View Source
const (
	TimestampFormat = time.RFC1123Z
)

Variables

View Source
var (
	ErrNoKey                = errors.New("No Key")
	ErrInvalidBanner        = errors.New("Invalid Banner")
	ErrBlockIsEncrypted     = errors.New("Block is Encrypted")
	ErrInvalidBlockType     = errors.New("Invalid block type")
	ErrBadKeyType           = errors.New("Bad Key Type")
	ErrBadKey               = errors.New("Bad Key")
	ErrAlreadyPresent       = errors.New("Already Present")
	ErrInvalidTimestamp     = errors.New("Invalid Timestamp")
	ErrEmptyKeychain        = errors.New("Empty Keychain")
	ErrUnknownSource        = errors.New("Unknown Source")
	ErrRequireConfiguration = errors.New("Require Configuration")
	ErrInvalidHashFunc      = errors.New("Invalid Hash Function")
)
View Source
var (
	ErrEmptyDataHash     = errors.New("Empty Data Hash")
	ErrInvalidPrivateKey = errors.New("Invalid Private Key")
	ErrInvalidPublicKey  = errors.New("Invalid Public Key")
)
View Source
var (
	Delimiter = []byte(":")
)

Functions

func ArmourTimestamps

func ArmourTimestamps(timestamps []*Timestamp) [][]byte

ArmourTimestamps

func CompressArmoured

func CompressArmoured(armoured [][]byte) ([][]byte, error)

CompressArmoured

func EqualsFingerprint

func EqualsFingerprint(pub *ecdsa.PublicKey, fnger [20]byte) bool

EqualsFingerprint

func Fingerprint

func Fingerprint(pub *ecdsa.PublicKey) ([20]byte, error)

Fingerprint

func Fuzz

func Fuzz(data []byte) int

Fuzz see https://github.com/dvyukov/go-fuzz

func TimestampArmourCompress

func TimestampArmourCompress(datahash []byte, source string, prv *ecdsa.PrivateKey) ([]byte, error)

TimestampArmourCompress

func UncompressArmoured

func UncompressArmoured(armoured [][]byte) ([][]byte, error)

UncompressArmoured

func VerifyTimestamp

func VerifyTimestamp(timestamp *Timestamp, pub *ecdsa.PublicKey) bool

VerifyTimestamp

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client

func NewClient

func NewClient(conf *Configuration) (*Client, error)

NewClient

func (*Client) AddToKeychain

func (client *Client) AddToKeychain(data []byte) error

TODO: replace source with server options structure

func (*Client) KnownFingerprints

func (client *Client) KnownFingerprints() []string

KnownFingerprints

func (*Client) Prepare

func (client *Client) Prepare(data []byte) []byte

Prepare

func (*Client) RemoveFromKeychain

func (client *Client) RemoveFromKeychain(fingerprint [20]byte) error

RemoveFromKeychain

func (*Client) Stat

func (client *Client) Stat() Stat

Stat

func (*Client) Verify

func (client *Client) Verify(timestamp *Timestamp) (bool, error)

Verify

type Configuration

type Configuration struct {

	/* TODO: add in the hash functions etc */
	Domain string

	Hash string
}

type HashFunc

type HashFunc func([]byte) []byte

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server

func NewServer

func NewServer(conf *Configuration) (*Server, error)

NewServer

func (*Server) ExportBanner

func (server *Server) ExportBanner() ([]byte, error)

ExportBanner

func (*Server) GenerateKey

func (server *Server) GenerateKey() error

GenerateKey

func (*Server) HaveKey

func (server *Server) HaveKey() bool

HaveKey

func (*Server) Key

func (server *Server) Key() *ecdsa.PrivateKey

Key

func (*Server) Stat

func (server *Server) Stat() Stat

func (*Server) Timestamp

func (server *Server) Timestamp(datahash []byte) (*Timestamp, error)

Timstamp

func (*Server) UseKey

func (server *Server) UseKey(prv *ecdsa.PrivateKey) error

UseKey

type ServerBanner

type ServerBanner struct {
	Source      string
	Fingerprint [20]byte
	PublicKey   *ecdsa.PublicKey
}

type Stat

type Stat struct {
	Requests int
}

type Timestamp

type Timestamp struct {
	Headers map[string]string /* comma seperated tags, hash = sha1,delimited */

	Source    string
	DataHash  []byte
	Hash      []byte
	Timestamp time.Time

	Fingerprint [20]byte
	Signature   []byte
}

Timestamp

func CreateTimestamp

func CreateTimestamp(datahash []byte, source string, prv *ecdsa.PrivateKey, hashfunc HashFunc) (*Timestamp, error)

CreateTimestamp -- TODO: adds an options structure for setting hash functions etc

func DearmourTimestamps

func DearmourTimestamps(armours [][]byte) ([]*Timestamp, error)

DearmourTimestamps

func NewTimestamp

func NewTimestamp(datahash []byte, source string, prv *ecdsa.PrivateKey) (*Timestamp, error)

FIXME: not used anymore -- see CreateTimestamp instead

func (*Timestamp) Armour

func (ts *Timestamp) Armour() []byte

func (*Timestamp) Equals

func (ts *Timestamp) Equals(o *Timestamp) bool

func (*Timestamp) String

func (ts *Timestamp) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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