Ejemplo n.º 1
0
vector<unsigned> Arbiter::sellerResolveI(const ResolutionPair &keyMessagePair){
	// first, store the keys
	keys = keyMessagePair.first;
	// now, unwrap and check the buyMessage, then store everything
	BuyMessage* buyMessage = keyMessagePair.second;
	Coin coinPrime = buyMessage->getCoinPrime();
	VECiphertext escrow = *buyMessage->getEscrow();
	// want to store the contract as well (for stage II)
	contract = *buyMessage->getContract();
	// check the timeout to make sure it hasn't passed
	if(contract.checkTimeout(timeoutTolerance)) {
		endorsement = verifiableDecrypter->decrypt(escrow.getCiphertext(), 
												   saveString(contract), hashAlg);
		// make sure the endorsement on the coin is valid
		if(coinPrime.verifyEndorsement(endorsement)){
			// construct verifiers based on the data in the contract and 
			// return a set of challenges
			hash_t ptHash = contract.getPTHashB();
			hash_t ctHash = contract.getCTHashB();
			ptVerifier = shared_ptr<MerkleVerifier>(new MerkleVerifier(ptHash, 
										contract.getNumPTHashBlocksB(), 
										MerkleContract(ptHash.key,ptHash.alg)));
			ctVerifier = shared_ptr<MerkleVerifier>(new MerkleVerifier(ctHash, 
										contract.getNumCTHashBlocksB(), 
										MerkleContract(ctHash.key,ctHash.alg)));
			return ptVerifier->getChallenges();
		} else {
			throw CashException(CashException::CE_FE_ERROR,
				"[Arbiter::sellerResolveI] invalid endorsement");
		}
	} else {
		throw CashException(CashException::CE_FE_ERROR, 
			"[Arbiter::sellerResolveI] contract has expired");
	}
}
Ejemplo n.º 2
0
// this method sets up the resolve for a failed barter
vector<unsigned> Arbiter::responderResolveI(const vector<string> &ks,		
											const FEMessage* msg, 
											const FESetupMessage* setup) {
	// stores keys and message
	keys = ks;
	message = msg;
	Coin coinPrime = setup->getCoinPrime();
	// this is the regular encryption
	vector<ZZ> sigEscrow = message->getEscrow();
	// this is the verifiable encryption
	VECiphertext vEscrow = *setup->getEscrow();
	contract = message->getContract();
	const Signature::Key* sigPK = setup->getPK();
	
	// verify that the signature given in BarterMessage is correct
	bool sigCorrect = Signature::verify(*sigPK, message->getSignature(), 
										CommonFunctions::vecToString(sigEscrow), 
										hashAlg);	
	if (!sigCorrect){
		throw CashException(CashException::CE_FE_ERROR,
				"[Arbiter::responderResolveI] signature was malformed"); 
	}

	// also need to make sure the contract hasn't expired
	if (!contract.checkTimeout(timeoutTolerance)){
		throw CashException(CashException::CE_FE_ERROR, 
			"[Arbiter::responderResolveI] contract has expired");
	}

	vector<ZZ> end = verifiableDecrypter->decrypt(vEscrow.getCiphertext(),
												  sigPK->publicKeyString(), 
												  hashAlg);
	// now verify the endorsement (and store it if it's valid)
	if(coinPrime.verifyEndorsement(end)){
		// first store endorsement
		endorsement = end;
														
		// set up merkle verifiers and return challenges
		hash_t ptHash = contract.getPTHashB();
		hash_t ctHash = contract.getCTHashB();
		ptVerifier = boost::shared_ptr<MerkleVerifier>(new MerkleVerifier(ptHash, 
										contract.getNumPTHashBlocksB(), 
										MerkleContract(ptHash.key,ptHash.alg)));
		ctVerifier = boost::shared_ptr<MerkleVerifier>(new MerkleVerifier(ctHash, 
										contract.getNumCTHashBlocksB(), 
										MerkleContract(ctHash.key,ctHash.alg)));
		// XXX: right now this is only returning 0 every time!!
		return ptVerifier->getChallenges();
	} else {
		throw CashException(CashException::CE_FE_ERROR,
			"[Arbiter::responderResolveI] invalid endorsement");
	}
}