Esempio n. 1
0
File: agent.go Progetto: logan/heim
func newAgentCredentials(agent *proto.Agent, agentKey *security.ManagedKey) (*agentCredentials, error) {
	if agentKey.Encrypted() {
		return nil, security.ErrKeyMustBeDecrypted
	}

	ac := &agentCredentials{
		ID:  agent.IDString(),
		Key: agentKey.Plaintext,
	}
	return ac, nil
}
Esempio n. 2
0
func (atb *AgentTrackerBinding) Register(ctx scope.Context, agent *proto.Agent) error {
	row := &Agent{
		ID:      agent.IDString(),
		IV:      agent.IV,
		MAC:     agent.MAC,
		Created: agent.Created,
	}
	if agent.EncryptedClientKey != nil {
		row.EncryptedClientKey = agent.EncryptedClientKey.Ciphertext
	}

	if err := atb.Backend.DbMap.Insert(row); err != nil {
		if strings.HasPrefix(err.Error(), "pq: duplicate key value") {
			return proto.ErrAgentAlreadyExists
		}
		return err
	}

	backend.Logger(ctx).Printf("registered agent %s", agent.IDString())
	return nil
}
Esempio n. 3
0
func (t *agentTracker) Register(ctx scope.Context, agent *proto.Agent) error {
	t.b.Lock()
	defer t.b.Unlock()

	if _, ok := t.b.agents[agent.IDString()]; ok {
		return proto.ErrAgentAlreadyExists
	}
	if t.b.agents == nil {
		t.b.agents = map[string]*proto.Agent{agent.IDString(): agent}
	} else {
		t.b.agents[agent.IDString()] = agent
	}
	return nil
}