Esempio n. 1
0
// highlightAlgorithm changes the color of the signing algorithm
// based on a set color map, e.g. to make SHA-1 show up red.
func highlightAlgorithm(sigAlg simpleSigAlg) string {
	sig := x509.SignatureAlgorithm(sigAlg)
	color, ok := algorithmColors[sig]
	if !ok {
		return algString(sig)
	}
	return color.SprintFunc()(algString(sig))
}
Esempio n. 2
0
func regHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		return
	}
	r.Body = http.MaxBytesReader(w, r.Body, 1024)
	postdata, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return
	}
	buf := bytes.NewBuffer(postdata)

	var voter_id uint64
	if binary.Read(buf, binary.LittleEndian, &voter_id) != nil {
		return
	}
	var voucher_type uint8
	if binary.Read(buf, binary.LittleEndian, &voucher_type) != nil {
		return
	}
	var sig_len uint16
	if binary.Read(buf, binary.LittleEndian, &sig_len) != nil {
		return
	}

	if int(sig_len+LSAGS_PK_SIZE) > len(postdata) {
		return
	}

	sig := make([]byte, sig_len)
	_, err = io.ReadFull(buf, sig)
	if err != nil {
		return
	}
	pk := make([]byte, LSAGS_PK_SIZE)
	_, err = io.ReadFull(buf, pk)
	if err != nil {
		return
	}
	cargo, err := ioutil.ReadAll(buf)
	if err != nil {
		return
	}

	sig_type := x509.SignatureAlgorithm(voucher_type)
	voter_file := filepath.Join("voters", fmt.Sprintf("%d", voter_id))
	cert_der, err := ioutil.ReadFile(voter_file + ".cer")
	if err != nil {
		return
	}
	cert, err := x509.ParseCertificate(cert_der)
	if err != nil {
		return
	}
	if cert.CheckSignature(sig_type, pk, sig) != nil {
		return
	}

	if ioutil.WriteFile(voter_file+".sig", sig, os.FileMode(0600)) != nil {
		return
	}
	if ioutil.WriteFile(voter_file+".pk", pk, os.FileMode(0600)) != nil {
		return
	}
	if ioutil.WriteFile(voter_file+".cargo", cargo, os.FileMode(0600)) != nil {
		return
	}

	h := sha256.New()
	if _, err := h.Write([]byte("REGISTER")); err != nil {
		return
	}
	if _, err := h.Write(postdata); err != nil {
		return
	}
	server_sig, err := rsa.SignPKCS1v15(rand.Reader, server_sk, crypto.SHA256, h.Sum(nil))
	if err != nil {
		return
	}

	w.Write(server_sig)
	ioutil.WriteFile(voter_file+".reg", postdata, os.FileMode(0600))
	fmt.Println(voter_id, "registered successfully")
}
Esempio n. 3
0
func (s simpleSigAlg) MarshalJSON() ([]byte, error) {
	return json.Marshal(algString(x509.SignatureAlgorithm(s)))
}