private void loadNetworkFrom(String someNodeUrl) throws IOException { URL url = new URL(someNodeUrl + "/network"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", "Universa JAVA API Client"); connection.setRequestMethod("GET"); if (connection.getResponseCode() != 200) throw new IOException("failed to access " + url + ", reponseCode " + connection.getResponseCode()); Binder bres = Boss.unpack((Do.read(connection.getInputStream()))) .getBinderOrThrow("response"); nodes.clear(); this.version = bres.getStringOrThrow("version"); for (Binder b : bres.getBinders("nodes")) nodes.add(new NodeRecord(b)); }
@Override public KeyRing updateFrom(Binder source) throws IOException, EncryptionError { for(Binder kb: source.getBinders("keys")) { KeyInfo ki = new KeyInfo(kb.getBinary("keyInfo")); AbstractKey k = ki.unpackKey(kb.getBinary("data")); keys.add(k); } return this; }
return; for (Binder b : payload.getBinders("signers")) { PublicKey k = new PublicKey(b.getBinary("key"));
@NonNull private Binder unpackPayload(byte[] packedCoffer, boolean allowPartiallySigned) throws EncryptionError { signed = false; Binder outer = Boss.unpack(packedCoffer); Collection<Binder> signatures = outer.getBinders("signatures"); final byte[] source = outer.getBinary("content"); Binder payload = Boss.unpack(source); if (!payload.get("type").equals("capsule")) throw new FormatException("not capsule/unknown type"); checkSignatures(source, signatures, payload, allowPartiallySigned); publicData = payload.getBinder("public"); return payload; }
Binder bres = Boss.unpack((Do.read(con.getInputStream()))) .getBinderOrThrow("response"); List<Binder> ni = bres.getBinders("nodes"); String pubUrls = ni.stream().map(x -> x.getStringOrThrow("url")) .collect(Collectors.toList())
for (Binder b : secret.getBinders("keys")) {
@Test public void testPartiallySigned() throws Exception { Capsule c1 = new Capsule(); c1.setPublicData("hello", "world", "I'm", "the coffer"); PrivateKey k1 = TestKeys.privateKey(0); PrivateKey k2 = TestKeys.privateKey(1); c1.addSigners(k1, k2); // Let's remove one signature byte[] packed = c1.pack(); Binder b = Boss.unpack(packed); ArrayList<Binder> ss = b.getBinders("signatures"); ss.remove(0); b.put("signatures", ss); packed = Boss.pack(b); // Now it is only partially signed Capsule c3 = new Capsule(packed, null, true, false); assertFalse(c3.isSigned()); assertTrue(c3.isPartiallySigned()); }