Beispiel #1
0
func main() {
	ks := make([]Key, 0)
	for _, name := range names {
		entity, err := newEntity(name)
		if err != nil {
			log.Fatal(err)
		}

		privateKeyBuf := bytes.NewBuffer(nil)
		w0, err := armor.Encode(privateKeyBuf, openpgp.PrivateKeyType, nil)
		if err != nil {
			log.Fatal(err)
		}
		if err := entity.SerializePrivate(w0, nil); err != nil {
			log.Fatal(err)
		}
		w0.Close()

		publicKeyBuf := bytes.NewBuffer(nil)
		w1, err := armor.Encode(publicKeyBuf, openpgp.PublicKeyType, nil)
		if err != nil {
			log.Fatal(err)
		}
		if err := entity.Serialize(w1); err != nil {
			log.Fatal(err)
		}
		w1.Close()

		fingerprint := fmt.Sprintf("%x", entity.PrimaryKey.Fingerprint)
		key := Key{
			Name:              name,
			Fingerprint:       fingerprint,
			ArmoredPublicKey:  publicKeyBuf.String(),
			ArmoredPrivateKey: privateKeyBuf.String(),
		}
		ks = append(ks, key)
	}
	tmpl, err := template.New("keymap").Parse(keymapTemplate)
	if err != nil {
		log.Fatal(err)
	}
	f, err := os.Create(output)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	err = tmpl.Execute(f, ks)
	if err != nil {
		log.Fatal(err)
	}
}
Beispiel #2
0
func (d *dashEscaper) Close() (err error) {
	if !d.atBeginningOfLine {
		if err = d.buffered.WriteByte(lf); err != nil {
			return
		}
	}
	sig := new(packet.Signature)
	sig.SigType = packet.SigTypeText
	sig.PubKeyAlgo = d.privateKey.PubKeyAlgo
	sig.Hash = d.hashType
	sig.CreationTime = d.config.Now()
	sig.IssuerKeyId = &d.privateKey.KeyId

	if err = sig.Sign(d.h, d.privateKey, d.config); err != nil {
		return
	}

	out, err := armor.Encode(d.buffered, "PGP SIGNATURE", nil)
	if err != nil {
		return
	}

	if err = sig.Serialize(out); err != nil {
		return
	}
	if err = out.Close(); err != nil {
		return
	}
	if err = d.buffered.Flush(); err != nil {
		return
	}
	return
}
Beispiel #3
0
func armoredDetachSign(w io.Writer, signer *Entity, message io.Reader, sigType packet.SignatureType, config *packet.Config) (err error) {
	out, err := armor.Encode(w, SignatureType, nil)
	if err != nil {
		return
	}
	err = detachSign(out, signer, message, sigType, config)
	if err != nil {
		return
	}
	return out.Close()
}