onionutil

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2018 License: CC0-1.0 Imports: 24 Imported by: 7

Documentation

Index

Constants

View Source
const (
	PublicationTimeFormat = "2006-01-02 15:04:05"
	NTorOnionKeySize      = 32
)
View Source
const Curve25519PubkeySize = 32
View Source
const Ed25519PubkeySize = 32
View Source
const Ed25519SignatureSize = 64
View Source
const HashType = crypto.SHA1
View Source
const RSAPubkeySize = 128
View Source
const RSASignatureSize = 128

Variables

View Source
var (
	OnionAddressChecksumLengthV3     = 2
	OnionAddressVersionFieldV3       = []byte{0x03}
	OnionAddressVersionFieldLengthV3 = 1
	OnionAddressLengthV3             = ed25519.PublicKeySize +
		OnionAddressVersionFieldLengthV3 +
		OnionAddressChecksumLengthV3
	OnionChecksumPrefix = []byte(".onion checksum")
)

v3 onion addresses

View Source
var (
	MinReplica       = 0
	MaxReplica       = 1
	DescVersion      = 2
	ProtocolVersions = []int{2, 3}
)
View Source
var (
	OnionAddressLengthV2 = 10
)

v2 onion addresses

Functions

func Base32Decode

func Base32Decode(b32 string) (binary []byte, err error)

func Base32Encode

func Base32Encode(binary []byte) string

XXX: here might be an error for new ed25519 addresses (! mod 5bits=0)

func CalcDescIDByOnion

func CalcDescIDByOnion(onion string, t time.Time, replica int) (string, error)

func CalcDescriptorID

func CalcDescriptorID(permID, secretID []byte) (descID []byte)

func CalcPermanentID

func CalcPermanentID(pk *rsa.PublicKey) (permId []byte, err error)

Calculate permanent ID from RSA public key

func CalcSecretID

func CalcSecretID(permID []byte, now time.Time, replica byte) (secretID []byte)

TODO: there is no `descriptor-cookie` now (because we need IP list encryption etc)

func GenerateOnionKey

func GenerateOnionKey(rand io.Reader, version string) (crypto.PrivateKey, error)

Generate private key for onion service using rand as the entropy source. Recognized versions are "2", "3", "current", "best".

func GenerateOnionKeyV2

func GenerateOnionKeyV2(rand io.Reader) (crypto.PrivateKey, error)

Generate v2 onion service key (RSA-1024) using rand as the entropy source.

func GenerateOnionKeyV3

func GenerateOnionKeyV3(rand io.Reader) (crypto.PrivateKey, error)

Generate v3 onion address key (Ed25519) using rand as the entropy source

func Hash

func Hash(data []byte) (hash []byte)

func InetPortFromByteString

func InetPortFromByteString(str []byte) (port uint16, err error)

func LoadPrivateKeyFile

func LoadPrivateKeyFile(filename string) (crypto.PrivateKey, crypto.PublicKey, error)

func OnionAddress

func OnionAddress(pk crypto.PublicKey) (string, error)

OnionAddress returns onion address corresponding to public/private key pk.

func OnionAddressChecksumV3

func OnionAddressChecksumV3(pk []byte) []byte

Calculate onion address checksum (v3) from byte-encoded Ed25519 key

func OnionAddressIsValid

func OnionAddressIsValid(onionAddress string) bool

Check whether onion address is a valid one.

func OnionAddressIsValidV2

func OnionAddressIsValidV2(onionAddress string) bool

Check whether onion address is a valid v2 one.

func OnionAddressIsValidV3

func OnionAddressIsValidV3(onionAddress string) bool

Check whether onion address is a valid v3 one.

func OnionAddressPublicKeyV3

func OnionAddressPublicKeyV3(onionAddress string) (ed25519.PublicKey, error)

Extract Ed25519 public key from the onion address.

func OnionAddressV2

func OnionAddressV2(pk *rsa.PublicKey) (onionAddress string, err error)

OnionAddress returns the Tor Onion Service address corresponding to a given rsa.PublicKey.

func OnionAddressV3

func OnionAddressV3(pk ed25519.PublicKey) (onionAddress string, err error)

Calculate onion address v3 from public key pk.

func RSAPubkeyHash

func RSAPubkeyHash(pk *rsa.PublicKey) (derHash []byte, err error)

Calculate hash (SHA1) of DER-encoded RSA public key pk.

Types

type Bandwidth

type Bandwidth struct {
	Average  uint64
	Burst    uint64
	Observed uint64
}

func ParseBandwidthEntry

func ParseBandwidthEntry(bandwidthE [][]byte) (bandwidth Bandwidth, err error)

type Certificate

type Certificate struct {
	Version        uint8
	CertType       byte
	ExpirationDate time.Time
	CertKeyType    byte
	CertifiedKey   Ed25519Pubkey
	NExtensions    uint8
	Extensions     map[ExtType]Extension
	Signature      Ed25519Signature
	PubkeySign     bool
}

func ParseCertFromBytes

func ParseCertFromBytes(binCert []byte) (cert Certificate, err error)

type Curve25519Pubkey

type Curve25519Pubkey [Curve25519PubkeySize]byte

type Descriptor

type Descriptor struct {
	Nickname        string
	InternetAddress net.IP
	ORPort          uint16
	SOCKSPort       uint16
	DirPort         uint16
	ORAddrs         []net.TCPAddr

	IdentityEd25519       *Certificate
	MasterKeyEd25519      Ed25519Pubkey
	Bandwidth             Bandwidth
	Platform              Platform
	Published             time.Time
	Fingerprint           string
	Hibernating           bool
	Uptime                time.Duration
	ExtraInfoDigest       string
	OnionKey              *rsa.PublicKey
	OnionKeyCrosscert     []byte
	SigningKey            *rsa.PublicKey
	HSDirVersions         []uint8
	Contact               string
	NTorOnionKey          Curve25519Pubkey
	NTorOnionKeyCrossCert *Certificate
	ExitPolicy            ExitPolicy
	Exit6Policy           *Exit6Policy
	CachesExtraInfo       bool
	AllowSingleHopExits   bool

	RouterSigEd25519 Ed25519Signature
	RouterSignature  RSASignature
}

func ParseServerDescriptors

func ParseServerDescriptors(descs_str []byte) (descs []Descriptor, rest string)

TODO return a pointer to descs not descs themselves?

type Ed25519Pubkey

type Ed25519Pubkey [Ed25519PubkeySize]byte

type Ed25519Signature

type Ed25519Signature [Ed25519SignatureSize]byte

type Exit6Policy

type Exit6Policy struct {
	Accept   bool
	PortList []string
}

type ExitPolicy

type ExitPolicy struct {
	Reject []string
	Accept []string
}

type ExtType

type ExtType byte

type Extension

type Extension struct {
	Type  ExtType
	Flags byte
	Data  []byte
}

type IntroductionPoint

type IntroductionPoint struct {
	Identity        []byte
	InternetAddress net.IP
	OnionPort       uint16
	OnionKey        *rsa.PublicKey
	ServiceKey      *rsa.PublicKey
}

func ParseIntroPoints

func ParseIntroPoints(ips_str []byte) (ips []IntroductionPoint, rest string)

func (IntroductionPoint) Bytes

func (ip IntroductionPoint) Bytes() (encodedIP []byte)

XXX: replace Falalf's with graceful errors

func (*IntroductionPoint) String

func (ip *IntroductionPoint) String() string

type OnionDescriptor

type OnionDescriptor struct {
	DescID           []byte
	Version          int
	PermanentKey     *rsa.PublicKey
	SecretIDPart     []byte
	PublicationTime  time.Time
	ProtocolVersions []int
	IntropointsBlock []byte
	Signature        []byte
	Replica          int
}

func ParseOnionDescriptors

func ParseOnionDescriptors(descsData []byte) (descs []OnionDescriptor, rest []byte)

TODO return a pointer to descs not descs themselves?

func (*OnionDescriptor) Bytes

func (desc *OnionDescriptor) Bytes() []byte

func (*OnionDescriptor) Finalize

func (desc *OnionDescriptor) Finalize(now time.Time) error

Finalize descriptor to sign.

func (*OnionDescriptor) FullSign

func (desc *OnionDescriptor) FullSign(signer crypto.Signer) error

func (*OnionDescriptor) InitDefaults

func (desc *OnionDescriptor) InitDefaults()

Initialize defaults

func (*OnionDescriptor) OnionID

func (desc *OnionDescriptor) OnionID() (string, error)

func (*OnionDescriptor) Sign

func (desc *OnionDescriptor) Sign(signer crypto.Signer) error

func (*OnionDescriptor) VerifySignature

func (desc *OnionDescriptor) VerifySignature() error

type Platform

type Platform struct {
	SoftwareName    string
	SoftwareVersion string
	Name            string
}

func ParsePlatformEntry

func ParsePlatformEntry(platformE torparse.TorEntry) (platform Platform, err error)

type RSASignature

type RSASignature [RSASignatureSize]byte

Directories

Path Synopsis
Package pkcs1 implements PKCS#1 RSA key marshalling/unmarshalling, compatibile with Tor's usage.
Package pkcs1 implements PKCS#1 RSA key marshalling/unmarshalling, compatibile with Tor's usage.

Jump to

Keyboard shortcuts

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