Prevent that a dev arbitrator can be published on Mainnet

This commit is contained in:
Manfred Karrer 2017-10-17 12:56:58 -05:00
parent 5f9d59143e
commit 4c2f06f0be
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
2 changed files with 80 additions and 5 deletions

View File

@ -17,8 +17,11 @@
package io.bisq.core.arbitration;
import io.bisq.common.app.DevEnv;
import io.bisq.common.handlers.ErrorMessageHandler;
import io.bisq.common.handlers.ResultHandler;
import io.bisq.common.util.Utilities;
import io.bisq.core.app.BisqEnvironment;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.P2PService;
import io.bisq.network.p2p.storage.HashMapChangedListener;
@ -59,12 +62,18 @@ public class ArbitratorService {
public void addArbitrator(Arbitrator arbitrator, final ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
log.debug("addArbitrator arbitrator.hashCode() " + arbitrator.hashCode());
boolean result = p2PService.addData(arbitrator, true);
if (result) {
log.trace("Add arbitrator to network was successful. Arbitrator.hashCode() = " + arbitrator.hashCode());
resultHandler.handleResult();
if (!BisqEnvironment.getBaseCurrencyNetwork().isMainnet() ||
!Utilities.encodeToHex(arbitrator.getRegistrationPubKey()).equals(DevEnv.DEV_PRIVILEGE_PUB_KEY)) {
boolean result = p2PService.addData(arbitrator, true);
if (result) {
log.trace("Add arbitrator to network was successful. Arbitrator.hashCode() = " + arbitrator.hashCode());
resultHandler.handleResult();
} else {
errorMessageHandler.handleErrorMessage("Add arbitrator failed");
}
} else {
errorMessageHandler.handleErrorMessage("Add arbitrator failed");
log.error("Attempt to publish dev arbitrator on mainnet.");
errorMessageHandler.handleErrorMessage("Add arbitrator failed. Attempt to publish dev arbitrator on mainnet.");
}
}

View File

@ -0,0 +1,66 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bisq.core.trade.protocol.tasks;
import io.bisq.common.taskrunner.TaskRunner;
import io.bisq.core.payment.AccountAgeWitness;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.trade.Trade;
import io.bisq.core.trade.protocol.tasks.TradeTask;
import lombok.extern.slf4j.Slf4j;
import java.security.PublicKey;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j
public class VerifyPeersAgeWitnessAge extends TradeTask {
@SuppressWarnings({"WeakerAccess", "unused"})
public VerifyPeersAgeWitnessAge(TaskRunner taskHandler, Trade trade) {
super(taskHandler, trade);
}
@Override
protected void run() {
try {
runInterceptHook();
final PaymentAccountPayload paymentAccountPayload = checkNotNull(processModel.getTradingPeer().getPaymentAccountPayload()
, "Peers paymentAccountPayload must not be null");
byte[] peersAgeWitnessInputData = null;
AccountAgeWitness witness = null;
byte[] peersSalt = null;
PublicKey peersPublicKey = null;
int nonce = 0;
byte[] signatureOfNonce = null;
checkArgument(processModel.getAccountAgeWitnessService().verifyAgeWitness(peersAgeWitnessInputData,
witness,
peersSalt,
peersPublicKey,
nonce,
signatureOfNonce), "verifyOffersAccountAgeWitness failed");
complete();
} catch (Throwable t) {
failed(t);
}
}
}