private void processHelloAnswer(Binder result) throws EncryptionError { byte[] data = result.getBinaryOrThrow("data"); byte[] signature = result.getBinaryOrThrow("signature"); setRemoteKey(result.getBinaryOrThrow("public_key")); if (!remoteKey.verify(data, signature, HashType.SHA256)) throw new EncryptionError("bad signature in hello answer"); Binder answer = Boss.unpack(myKey.decrypt(data)); if (!Arrays.equals(answer.getBinaryOrThrow("nonce"), myNonce)) throw new EncryptionError("nonce mismatch"); remoteSessionKey = new SymmetricKey(answer.getBinary("session_key")); }
/** * Get the binary parameter as byte[] and throws exception if it is missing * * @param key * @return * @throws IllegalArgumentException */ @NonNull public byte[] getBinaryOrThrow(String key) throws IllegalArgumentException { byte[] binary = getBinary(key); if (binary == null) throw new IllegalArgumentException("missing required parameter: " + key); return binary; }
/** * Deserialize some key instance from the binder using KeyInfo. Inverse of {@link #toBinder()}. Serialized data are * in binary form and are bit-effective, when using with {@link net.sergeych.boss.Boss} encoders (the default for * Attesta). * * @param binder * from where to restore. * @return ready to use key * @throws IOException * @throws EncryptionError */ static public AbstractKey fromBinder(Binder binder) throws IOException, EncryptionError { KeyInfo info = new KeyInfo(binder.getBinary("keyInfo")); return info.unpackKey(binder.getBinary("data")); }
@Override public void deserialize(Binder data, BiDeserializer deserializer) throws IOException { packedContract = data.getBinary("packedContract"); trackingContract = Contract.fromPackedTransaction(packedContract); expiresAt = data.getZonedDateTimeOrThrow("expiresAt"); }
private void checkForSetUnlimit(Contract contract) { // check unlimit contract if (!contract.isUnlimitKeyContract(config)) return; // get key for setting unlimited requests PublicKey key; try { byte[] packedKey = contract.getTransactional().getData().getBinary("unlimited_key"); if (packedKey == null) return; key = new PublicKey(packedKey); } catch (Exception e) { return; } // setting unlimited requests for a key keyRequests.remove(key); keysUnlimited.remove(key); keysUnlimited.put(key, ZonedDateTime.now().plus(config.getUnlimitPeriod())); }
@Override public void deserialize(Binder data, BiDeserializer deserializer) throws IOException { createdAt = deserializer.deserialize(data.getZonedDateTimeOrThrow("createdAt")); subscriptionsSet.addAll(deserializer.deserialize(data.getListOrThrow("subscriptions"))); storagesSet.addAll(deserializer.deserialize(data.getListOrThrow("storages"))); nameRecordsSet.addAll(deserializer.deserialize(data.getListOrThrow("nameRecords"))); contract = (NSmartContract) Contract.fromPackedTransaction(data.getBinary("contract")); kvStore = deserializer.deserialize(data.getBinderOrThrow("kvStore")); }
PublicKey k = new PublicKey(b.getBinary("key")); for (Binder sig : signatures) { AbstractKey k = (AbstractKey) signers.get(sig.getStringOrThrow("key")).get("key"); if (!k.verify(src, sig.getBinary("signature"), HashType.SHA512)) throw new BadSignatureException("signature is broken at " + sig.getStringOrThrow("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; }
byte[] packedKey = callbacksData.getBinary(URL); try { PublicKey key = new PublicKey(packedKey);
private Binder querySlotInfo(Binder params, Session session) throws IOException { checkNode(session, true); Binder res = new Binder(); res.set("slot_state", null); byte[] slot_id = params.getBinary("slot_id"); byte[] slotBin = node.getLedger().getSmartContractById(HashId.withDigest(slot_id)); if (slotBin != null) { SlotContract slotContract = (SlotContract) Contract.fromPackedTransaction(slotBin); res.set("slot_state", slotContract.getStateData()); } return res; }
private Binder queryFollowerInfo(Binder params, Session session) throws IOException { checkNode(session, true); Binder res = new Binder(); res.set("follower_state", null); byte[] follower_id = params.getBinary("follower_id"); byte[] followerBin = node.getLedger().getSmartContractById(HashId.withDigest(follower_id)); if (followerBin != null) { FollowerContract followerContract = (FollowerContract) Contract.fromPackedTransaction(followerBin); res.set("follower_state", followerContract.getStateData()); } return res; }
private Binder queryNameRecord(Binder params, Session session) throws IOException { checkNode(session, true); Binder b = new Binder(); NNameRecord loadedNameRecord; String address = params.getString("address",null); byte[] origin = params.getBinary("origin"); if (((address == null) && (origin == null)) || ((address != null) && (origin != null))) throw new IOException("invalid arguments"); if (address != null) loadedNameRecord = node.getLedger().getNameByAddress(address); else loadedNameRecord = node.getLedger().getNameByOrigin(origin); if (loadedNameRecord != null) { b.put("name", loadedNameRecord.getName()); b.put("description", loadedNameRecord.getDescription()); b.put("url", loadedNameRecord.getUrl()); } return b; }
byte[] packedKey = unlimitContract.getTransactional().getData().getBinary("unlimited_key"); PublicKey key = new PublicKey(packedKey);
byte[] packed = trackingHashesAsBase64.getBinary(k); if (packed != null) { Contract c = Contract.fromPackedTransaction(packed);
byte[] packed = trackingHashesAsBase64.getBinary(k); if (packed != null) { Contract c = Contract.fromPackedTransaction(packed);