Esempio n. 1
0
// purgeSecring deletes old keys and counts active ones.  If no active keys
// are found, it triggers a generation.
func purgeSecring(secret *keymgr.Secring) (active int) {
	active, expiring, expired, purged := secret.Purge()
	Info.Printf(
		"Key purge complete. Active=%d, Expiring=%d, Expired=%d, "+
			"Purged=%d",
		active,
		expiring,
		expired,
		purged,
	)
	return
}
Esempio n. 2
0
// refreshPubkey updates an existing Public key file
func refreshPubkey(secret *keymgr.Secring) {
	tmpKey := cfg.Files.Pubkey + ".tmp"
	keyidstr := secret.WriteMyKey(tmpKey)
	Info.Printf("Advertising keyid: %s", keyidstr)
	Trace.Printf("Writing current public key to %s", tmpKey)
	// Overwrite the published key with the refreshed version
	Trace.Printf("Renaming %s to %s", tmpKey, cfg.Files.Pubkey)
	err := os.Rename(tmpKey, cfg.Files.Pubkey)
	if err != nil {
		Warn.Println(err)
	}
}
Esempio n. 3
0
// decodeMsg is the actual YAMN message decoder.  It's output is always a
// pooled file, either in the Inbound or Outbound queue.
func decodeMsg(rawMsg []byte, secret *keymgr.Secring) (err error) {

	// At this point, rawMsg should always be messageBytes in length
	err = lenCheck(len(rawMsg), messageBytes)
	if err != nil {
		Error.Println(err)
		return
	}

	d := newDecMessage(rawMsg)
	// Extract the top header
	header := newDecodeHeader(d.getHeader())
	recipientKeyID := header.getRecipientKeyID()
	recipientSK, err := secret.GetSK(recipientKeyID)
	if err != nil {
		Warn.Printf("Failed to ascertain Recipient SK: %s", err)
		return
	}
	header.setRecipientSK(recipientSK)

	slotDataBytes, packetVersion, err := header.decode()
	if err != nil {
		Warn.Printf("Header decode failed: %s", err)
		return
	}
	switch packetVersion {
	case 2:
		err = decodeV2(d, slotDataBytes)
		return
	default:
		err = fmt.Errorf(
			"Cannot decode packet version %d",
			packetVersion,
		)
		return
	}
	return
}
Esempio n. 4
0
// generateKeypair creates a new keypair and publishes it
func generateKeypair(secret *keymgr.Secring) {
	Info.Println("Generating and advertising a new key pair")
	pub, sec := eccGenerate()
	keyidstr := secret.Insert(pub, sec)
	Info.Printf("Generated new keypair with keyid: %s", keyidstr)
	Info.Println("Writing new Public Key to disc")
	secret.WritePublic(pub, keyidstr)
	Info.Println("Inserting Secret Key into Secring")
	secret.WriteSecret(keyidstr)
}