Ejemplo n.º 1
0
func NewIdentity(keys cipherset.Keys, parts cipherset.Parts, addrs []net.Addr) (*Identity, error) {
	var err error

	ident := &Identity{
		keys:  keys,
		parts: parts,
		addrs: addrs,
	}

	if len(ident.keys) == 0 {
		return nil, ErrNoKeys
	}

	if ident.parts == nil {
		ident.parts = make(cipherset.Parts, len(ident.keys))
	}

	for csid, part := range hashname.PartsFromKeys(ident.keys) {
		ident.parts[csid] = part
	}

	ident.hashname, err = hashname.FromIntermediates(ident.parts)
	if err != nil {
		return nil, err
	}

	return ident, nil
}
Ejemplo n.º 2
0
func (mod *module) introduceVia(router *e3x.Exchange, to hashname.H) error {
	localIdent, err := mod.e.LocalIdentity()
	if err != nil {
		return err
	}

	keys := localIdent.Keys()
	parts := hashname.PartsFromKeys(keys)

	for csid, key := range keys {
		inner := lob.New(key.Public())
		for partCSID, part := range parts {
			if partCSID == csid {
				inner.Header().SetBool(hex.EncodeToString([]byte{partCSID}), true)
			} else {
				inner.Header().SetString(hex.EncodeToString([]byte{partCSID}), part)
			}
		}

		body, err := lob.Encode(inner)
		if err != nil {
			return err
		}

		err = mod.peerVia(router, to, body)
		if err != nil {
			return err
		}
	}

	return nil
}
Ejemplo n.º 3
0
func main() {
	args, _ := docopt.Parse(usage, nil, true, "0.1-dev", false)

	var (
		output = args["--output"].(string)
		keys   = cipherset.Keys{}
		data   []byte
		err    error
		out    struct {
			Hashname hashname.H            `json:"hashname,omitempty"`
			Parts    cipherset.Parts       `json:"parts,omitempty"`
			Keys     cipherset.PrivateKeys `json:"keys,omitempty"`
		}
	)

	{ // CS 1a
		k, err := cipherset.GenerateKey(0x1a)
		assert(err)
		keys[0x1a] = k
	}

	{ // CS 3a
		k, err := cipherset.GenerateKey(0x3a)
		assert(err)
		keys[0x3a] = k
	}

	out.Keys = cipherset.PrivateKeys(keys)
	out.Parts = hashname.PartsFromKeys(keys)
	out.Hashname, err = hashname.FromIntermediates(out.Parts)
	assert(err)

	if len(out.Keys) == 0 {
		out.Keys = nil
	}
	if len(out.Parts) == 0 {
		out.Keys = nil
	}

	data, err = json.MarshalIndent(out, "", "  ")
	assert(err)

	fmt.Fprintf(os.Stderr, "Generated keys for: %s\n", out.Hashname)

	if output == "-" {
		fmt.Println(string(data))
	} else {
		err := ioutil.WriteFile(output, data, 0600)
		assert(err)
	}
}