Exemple #1
0
func verifyOcSig(reqHash []byte, ocID msg.OcID, sig string) bool {
	ocCredReader := strings.NewReader(ocID.String())
	var x, y, r, s big.Int
	n, err := fmt.Fscanf(ocCredReader, string(OC_ID_PREFIX)+"%x,%x", &x, &y)
	if err != nil {
		return false
	}
	n, err = ocCredReader.Read(make([]byte, 1))
	if n != 0 || err != io.EOF {
		return false
	}

	sigReader := strings.NewReader(sig)
	n, err = fmt.Fscanf(sigReader, "%x,%x", &r, &s)
	if err != nil {
		return false
	}
	n, err = sigReader.Read(make([]byte, 1))
	if n != 0 || err != io.EOF {
		return false
	}

	curve := elliptic.P256()
	pub := ecdsa.PublicKey{
		Curve: curve,
		X:     &x,
		Y:     &y,
	}
	return ecdsa.Verify(&pub, reqHash, &r, &s)
}
Exemple #2
0
func setOcIDForCoin(coin string, ocID *msg.OcID) error {
	fmt.Printf("set oc ID for coin %v\n", coin)
	d := util.GetOrCreateDB(peerDBPath())
	err := d.Write(coin, []byte(ocID.String()))
	util.Ferr(err)

	return nil
}
Exemple #3
0
func NewContainerFromDisk(id msg.OcID) *Container {
	d := util.GetOrCreateDB(containersDB())
	containerID := ocIDToContainerID(id)
	ser, _ := d.Read(id.String())
	if ser == nil || len(ser) == 0 {
		return &Container{ID: containerID, OwnerID: id}
	} else {
		var container Container
		err := json.Unmarshal(ser, &container)
		util.Ferr(err)
		return &container
	}
}
Exemple #4
0
func ocIDToContainerID(id msg.OcID) ContainerID {
	return ContainerID(util.Sha256AsString([]byte(id.String())))
}