public boolean isMatchingKey(AbstractKey key) { for (KeyAddress addr: unsAddresses) if (addr.isMatchingKey(key)) return true; return false; }
/** * Check that the address matches role. * * @param keyAddress address for matching with role * @return true if match or false * @deprecated the only usable check allowance method is isAllowedForKeys */ @Deprecated public boolean isMatchingKeyAddress(KeyAddress keyAddress) { for (KeyAddress ka : this.getKeyAddresses()) { if (keyAddress.isMatchingKeyAddress(ka)) return true; } for (PublicKey pk : this.getKeys()) { if (keyAddress.isMatchingKey(pk)) return true; } return false; } /**
config.getNetworkAdminKeyAddress().isMatchingKey(key) || getNodeKey().equals(key) || config.getKeysWhiteList().contains(key) || config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(key))) return true;
@Test public void serialize() throws IOException { KeyAddress a = key1.address(true, 8); KeyAddress b = key1.address(false, 9); Boss.Reader r = new Boss.Reader(Boss.dump(a,b).toArray()); KeyAddress x = r.read(); KeyAddress y = r.read(); assertEquals(8, x.getTypeMark()); assertEquals(9, y.getTypeMark()); assertTrue(x.isMatchingKey(key1)); assertTrue(y.isMatchingKeyAddress(b)); } }
private Binder startApproval(final Binder params, Session session) throws IOException, Quantiser.QuantiserException { if (config == null || config.limitFreeRegistrations()) if(config == null || ( !config.getKeysWhiteList().contains(session.getPublicKey()) && !config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(session.getPublicKey())))) { System.out.println("startApproval ERROR: session key shoild be in the white list"); return Binder.of( "itemResult", itemResultOfError(Errors.BAD_CLIENT_KEY,"startApproval", "command needs client key from whitelist")); } int n = asyncStarts.incrementAndGet(); AtomicInteger k = new AtomicInteger(); params.getListOrThrow("packedItems").forEach((item) -> es.execute(() -> { try { checkNode(session); System.out.println("Request to start registration #"+n+":"+k.incrementAndGet()); node.registerItem(Contract.fromPackedTransaction(((Bytes)item).toArray())); } catch (Exception e) { e.printStackTrace(); } }) ); //TODO: return ItemResult return new Binder(); }
private void testMatch(boolean use384) throws KeyAddress.IllegalAddressException { KeyAddress a = key1.address(use384, 7); KeyAddress b = new KeyAddress(a.toString()); assertEquals(7, b.getTypeMark()); assertEquals(7, a.getTypeMark()); assertTrue(b.isMatchingKey(key1)); assertTrue(a.isMatchingKeyAddress(b)); assertTrue(b.isMatchingKeyAddress(a)); assertTrue(key1.isMatchingKey(key1)); assertTrue(key1.isMatchingKeyAddress(a)); assertTrue(key1.isMatchingKeyAddress(b)); byte[] pack = a.getPacked(); pack[7] ^= 71; try { new KeyAddress(pack); fail("must throw error on spoiled address"); } catch(KeyAddress.IllegalAddressException e) { } }
bResult = keyAddress.isMatchingKey(key); } catch (Exception e) { bResult = false;
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)); }
private static void doAddressMatch(String address, String keyFilePath) throws IOException { boolean bResult = false; try { PublicKey key = readKeyAndGetPublic(keyFilePath); KeyAddress keyAddress = new KeyAddress(address); bResult = keyAddress.isMatchingKey(key); } catch (Exception e) {}; report("Matching address: " + address + " with key: "+ keyFilePath); report("Matching result: " + bResult); finish(); }
private Binder resyncItem(Binder params, Session session) throws CommandFailedException { checkNode(session, true); KeyAddress tmpAddress = null; try { tmpAddress = new KeyAddress("JKEgDs9CoCCymD9TgmjG8UBLxuJwT5GZ3PaZyG6o2DQVGRQPjXHCG8JouC8eZw5Nd1w9krCS"); } catch (KeyAddress.IllegalAddressException e) { e.printStackTrace(); } if (config.limitFreeRegistrations()) if(!( tmpAddress.isMatchingKey(session.getPublicKey()) || config.getNetworkAdminKeyAddress().isMatchingKey(session.getPublicKey()) || config.getKeysWhiteList().contains(session.getPublicKey()) || config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(session.getPublicKey())) )) { System.out.println("approve ERROR: command needs client key from whitelist"); return Binder.of( "itemResult", itemResultOfError(Errors.BAD_CLIENT_KEY,"resyncItem", "command needs client key from whitelist")); } try { Binder result = Binder.of("itemResult", node.checkItem((HashId) params.get("itemId"))); node.resync((HashId) params.get("itemId")); return result; } catch (Exception e) { System.out.println("getState ERROR: " + e.getMessage()); return Binder.of( "itemResult", itemResultOfError(Errors.COMMAND_FAILED,"resyncItem", e.getMessage())); } }
@SuppressWarnings("deprecation") //outdated method. will be replaced with new one soon private void checkForNetConfig(Contract contract) { if (contract.getIssuer().getKeys().stream().anyMatch(key -> config.getNetworkReconfigKeyAddress().isMatchingKey(key))) { if(contract.getParent() == null) return; if(contract.getRevoking().size() == 0 || !contract.getRevoking().get(0).getId().equals(contract.getParent())) return; Contract parent = contract.getRevoking().get(0); if(!checkContractCorrespondsToConfig(parent,network.allNodes())) { return; } if(!checkIfContractContainsNetConfig(contract)) { return; } List<NodeInfo> networkNodes = network.allNodes(); List contractNodes = (List)DefaultBiMapper.getInstance().deserializeObject(contract.getStateData().get("net_config")); contractNodes.stream().forEach(nodeInfo -> { if(!networkNodes.contains(nodeInfo)) { addNode((NodeInfo) nodeInfo); } networkNodes.remove(nodeInfo); }); networkNodes.stream().forEach( nodeInfo -> removeNode(nodeInfo)); } }
if(!(tmpAddress.isMatchingKey(session.getPublicKey()) || config.getNetworkAdminKeyAddress().isMatchingKey(session.getPublicKey()) || config.getKeysWhiteList().contains(session.getPublicKey()) || config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(session.getPublicKey())) )) { System.out.println("approve ERROR: command needs client key from whitelist");
config.getNetworkAdminKeyAddress().isMatchingKey(session.getPublicKey()) || config.getKeysWhiteList().contains(session.getPublicKey()) || config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(session.getPublicKey())) ))) {
addError(Errors.FAILED_CHECK, NAMES_FIELD_NAME, "name " + n.getUnsName() + ": Addresses list may only contain one short and one long addresses"); if(!unsRecord.getAddresses().stream().allMatch(keyAddress -> getEffectiveKeys().stream().anyMatch(key -> keyAddress.isMatchingKey(key)))) { addError(Errors.FAILED_CHECK, NAMES_FIELD_NAME, "name " + n.getUnsName() + " using address that missing corresponding key UNS contract signed with."); return false;
assertTrue(contractImported.getOwner().getKeyAddresses().iterator().next().isMatchingKey(TestKeys.privateKey(0).getPublicKey()));