Example #1
0
func (c *Certs) setupSigner() {
	c.certSigners = make(map[string][]string)
	for _, val := range c.Certificates {
		parent := val.CertConfig.Parent
		id := val.CertConfig.Id
		if parent == id {
			privKey := val.PrivateKey
			// self signed certificate
			val.CertBytes = certificate.Sign(val.CertTemplate, val.CertTemplate, key.PublicKey(privKey), privKey)
			val.signed = true
		} else if c.certSigners[parent] == nil {
			c.certSigners[parent] = []string{id}
		} else {
			c.certSigners[parent] = append(c.certSigners[parent], id)
		}
	}
}
Example #2
0
func (c *Certs) signAll() {
	for {
		sign := findSigners(c)
		if len(sign) == 0 {
			break
		}
		for _, s := range sign {
			id := s.CertConfig.Id
			signer, _ := c.findByid(id)
			list := c.certSigners[id]
			for _, certId := range list {
				cert, _ := c.findByid(certId)
				cert.CertBytes = certificate.Sign(cert.CertTemplate, signer.CertTemplate, key.PublicKey(cert.PrivateKey), signer.PrivateKey)
				cert.signed = true
				if s.Signers == nil {
					cert.Signers = []string{id}
				} else {
					cert.Signers = append(s.Signers, id)
				}
			}
		}
	}
}