/** * Equality based on the keys. Instances are equal if keys are equal, other fields are not compared. * * @param o object to compare * * @return true if both are {@link KeyRecord} instances with equal keys, see {@link PublicKey#equals(Object)} */ @Override public boolean equals(Object o) { if (o instanceof KeyRecord) return ((KeyRecord) o).publicKey.equals(publicKey); return false; }
/** * Unpack the remote public key, check if it is trusted, if the {@link #remoteKey} is null, saves new value, * otherwise checks that it is the same key, or throws {@link IllegalArgumentException}. * <p> * Set the remote key and accurately check that it was not spoofed, e.g. only one key could be set event several * times. Because of the p2p nature of the connection we have no guarantee which way the remote key will arrive * first (in the "hello" command from the remote or from the hello answer from the remote), this method allows to * set the remote key in right mode. * * @param packedKey packed remoteKey * * @throws IllegalArgumentException if the {@link #remoteKey} is already set to a different key. */ public void setRemoteKey(@NonNull byte[] packedKey) throws EncryptionError { if (isTrustedKey != null && !isTrustedKey.test(packedKey)) throw new IllegalArgumentException("public key is not accepted"); PublicKey rk = new PublicKey(packedKey); synchronized (ready) { if (remoteKey == null) remoteKey = rk; else if (!rk.equals(remoteKey)) throw new IllegalArgumentException("remote key already set to a different value"); } }
getNodeKey().equals(key) || config.getKeysWhiteList().contains(key) || config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(key)))
private void checkNode(Session session, boolean checkKeyLimit) throws CommandFailedException { // checking node if (node == null) { throw new CommandFailedException(Errors.NOT_READY, "", "please call again after a while"); } if(node.isSanitating()) { //WHILE NODE IS SANITATING IT COMMUNICATES WITH THE OTHER NODES ONLY if(netConfig.toList().stream().anyMatch(nodeInfo -> nodeInfo.getPublicKey().equals(session.getPublicKey()))) return; throw new CommandFailedException(Errors.NOT_READY, "", "please call again after a while"); } // checking key limit if (checkKeyLimit) if (!node.checkKeyLimit(session.getPublicKey())) throw new CommandFailedException(Errors.COMMAND_FAILED, "", "exceeded the limit of requests for key per minute, please call again after a while"); }
private Binder getStats(Binder params, Session session) throws CommandFailedException { checkNode(session, true); if (config == null || node == null || !( config.getNetworkAdminKeyAddress().isMatchingKey(session.getPublicKey()) || node.getNodeKey().equals(session.getPublicKey()) || config.getKeysWhiteList().contains(session.getPublicKey()) || config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(session.getPublicKey())) )) { System.out.println("command needs admin key"); return Binder.of( "itemResult", itemResultOfError(Errors.BAD_CLIENT_KEY,"getStats", "command needs admin key")); } return node.provideStats(params.getInt("showDays",null)); }
if (!nodeKey.verify(packedData, signature, HashType.SHA512) || !nodeKeys.stream().anyMatch(n -> n.equals(nodeKey))) return Binder.EMPTY;