Esempio n. 1
0
func entryToAnchorRecord(entry *common.Entry) (*anchor.AnchorRecord, error) {
	content := entry.Content
	jsonARecord := content[:(len(content) - 128)]
	jsonSigBytes := content[(len(content) - 128):]
	jsonSig, err := hex.DecodeString(string(jsonSigBytes))
	if err != nil {
		fmt.Printf("*** hex.Decode jsonSigBytes error: %s\n", err.Error())
	}

	//fmt.Println("bytes decoded: ", hex.DecodedLen(len(jsonSigBytes)))
	//fmt.Printf("jsonARecord: %s\n", string(jsonARecord))
	//fmt.Printf("    jsonSig: %s\n", string(jsonSigBytes))

	pubKeySlice := make([]byte, 32, 32)
	pubKey := common.PubKeyFromString(common.SERVER_PUB_KEY)
	copy(pubKeySlice, pubKey.Key[:])
	verified := common.VerifySlice(pubKeySlice, jsonARecord, jsonSig)

	if !verified {
		fmt.Printf("*** anchor chain signature does NOT match:\n")
	} else {
		fmt.Printf("&&& anchor chain signature does MATCH:\n")
	}

	aRecord := new(anchor.AnchorRecord)
	err = json.Unmarshal(jsonARecord, aRecord)
	if err != nil {
		return nil, fmt.Errorf("json.UnMarshall error: %s", err)
	}
	fmt.Printf("entryToAnchorRecord: %s", spew.Sdump(aRecord))

	return aRecord, nil
}
Esempio n. 2
0
// Initialize server private key and server public key for milestone 1
func initServerKeys() {
	if nodeMode == common.SERVER_NODE {
		var err error
		serverPrivKey, err = common.NewPrivateKeyFromHex(serverPrivKeyHex)
		if err != nil {
			panic("Cannot parse Server Private Key from configuration file: " + err.Error())
		}
	}

	serverPubKey = common.PubKeyFromString(common.SERVER_PUB_KEY)

}
Esempio n. 3
0
// Initialize server private key and server public key for milestone 1
func initServerKeys() {
	if nodeMode == common.SERVER_NODE {
		var err error
		serverPrivKey, err = common.NewPrivateKeyFromHex(serverPrivKeyHex)
		if err != nil {
			panic("Cannot parse Server Private Key from configuration file: " + err.Error())
		}
		//Set server's public key
		serverPubKey = serverPrivKey.Pub
	} else {
		cfg := util.ReadConfig().App
		serverPubKey = common.PubKeyFromString(cfg.ServerPubKey)

	}
}