@Test public void testValidateOp() throws FailedVerificationException { String id = "openplacereviews", oauthMethod = "oauth"; OpObject opObject = new OpObject(); opObject.setId(id + 1); opObject.putStringValue(F_AUTH_METHOD, oauthMethod); OpOperation opOperation = new OpOperation(); opOperation.setType(OpBlockchainRules.OP_SIGNUP); opOperation.addCreated(opObject); generateHashAndSignForOperation(opOperation, blc, true, serverKeyPair); opOperation.makeImmutable(); assertTrue(blc.validateOperation(opOperation)); }
public boolean validateOp(OpBlockChain opBlockChain, OpOperation u, LocalValidationCtx ctx) { Metric mt = mValidTotal.start(); if(!OUtils.equals(calculateOperationHash(u, false), u.getHash())) { return error(u, ErrorType.OP_HASH_IS_NOT_CORRECT, calculateOperationHash(u, false), u.getHash()); } int sz = formatter.opToJson(u).length(); if (sz > OpBlockchainRules.MAX_OP_SIZE_MB) { return error(u, ErrorType.OP_SIZE_IS_EXCEEDED, u.getHash(), sz, OpBlockchainRules.MAX_OP_SIZE_MB); } Metric m = mValidSig.start(); boolean valid = validateSignatures(opBlockChain, u); m.capture(); if(!valid) { return valid; } valid = validateRules(opBlockChain, u, ctx); mt.capture(); if(!valid) { return valid; } return true; }
OpBlockchainRules { public boolean validateOp(OpBlockChain opBlockChain, OpOperation u, LocalValidationCtx ctx) { Metric mt = mValidTotal.start(); if(!OUtils.equals(calculateOperationHash(u, false), u.getHash())) { return error(u, ErrorType.OP_HASH_IS_NOT_CORRECT, calculateOperationHash(u, false), u.getHash()); } int sz = formatter.opToJson(u).length(); if (sz > OpBlockchainRules.MAX_OP_SIZE_MB) { return error(u, ErrorType.OP_SIZE_IS_EXCEEDED, u.getHash(), sz, OpBlockchainRules.MAX_OP_SIZE_MB); } Metric m = mValidSig.start(); boolean valid = validateSignatures(opBlockChain, u); m.capture(); if(!valid) { return valid; } valid = validateRules(opBlockChain, u, ctx); mt.capture(); if(!valid) { return valid; } return true; } }
OpBlockchainRules { public boolean validateOp(OpBlockChain opBlockChain, OpOperation u, LocalValidationCtx ctx) { Metric mt = mValidTotal.start(); if(!OUtils.equals(calculateOperationHash(u, false), u.getHash())) { return error(u, ErrorType.OP_HASH_IS_NOT_CORRECT, calculateOperationHash(u, false), u.getHash()); } int sz = formatter.opToJson(u).length(); if (sz > OpBlockchainRules.MAX_OP_SIZE_MB) { return error(u, ErrorType.OP_SIZE_IS_EXCEEDED, u.getHash(), sz, OpBlockchainRules.MAX_OP_SIZE_MB); } Metric m = mValidSig.start(); boolean valid = validateSignatures(opBlockChain, u); m.capture(); if(!valid) { return valid; } valid = validateRules(opBlockChain, u, ctx); mt.capture(); if(!valid) { return valid; } return true; } OpBlockchainRules(JsonFormatter formatter, ValidationListener logValidation); }
OpBlockchainRules { public boolean validateOp(OpBlockChain opBlockChain, OpOperation u, LocalValidationCtx ctx) { Metric mt = mValidTotal.start(); if(!OUtils.equals(calculateOperationHash(u, false), u.getHash())) { return error(u, ErrorType.OP_HASH_IS_NOT_CORRECT, calculateOperationHash(u, false), u.getHash()); } int sz = formatter.opToJson(u).length(); if (sz > OpBlockchainRules.MAX_OP_SIZE_MB) { return error(u, ErrorType.OP_SIZE_IS_EXCEEDED, u.getHash(), sz, OpBlockchainRules.MAX_OP_SIZE_MB); } Metric m = mValidSig.start(); boolean valid = validateSignatures(opBlockChain, u); m.capture(); if(!valid) { return valid; } valid = validateRules(opBlockChain, u, ctx); mt.capture(); if(!valid) { return valid; } return true; } OpBlockchainRules(JsonFormatter formatter, ValidationListener logValidation); static boolean validateNickname(String name); static String getRawHash(String hs); static String getSiteFromUser(String name); static String getNicknameFromUser(String name); static String getUserFromNicknameAndSite(String nickname, String site); String calculateMerkleTreeHash(OpBlock op); String calculateSigMerkleTreeHash(OpBlock op); String calculateOperationHash(OpOperation ob, boolean set); int calculateBlockSize(OpBlock cp); JsonFormatter getFormatter(); OpOperation generateHashAndSign(OpOperation op, KeyPair... keyPair); boolean validateRules(OpBlockChain blockchain, OpOperation o, LocalValidationCtx ctx); @SuppressWarnings("unchecked") Map<String, Set<String>> getRoles(OpBlockChain blockchain); boolean validateBlock(OpBlockChain blockChain, OpBlock block, OpBlock prevBlockHeader, boolean validateSignature); boolean validateSignatures(OpBlockChain ctx, OpOperation ob); boolean validateOp(OpBlockChain opBlockChain, OpOperation u, LocalValidationCtx ctx); KeyPair getLoginKeyPair(OpBlockChain ctx, String signedByName, String privateKey); OpObject getLoginKeyObj(OpBlockChain ctx, String signedByName); KeyPair getSignUpKeyPairFromPwd(OpBlockChain blc,
			String name, String pwd); OpBlock createAndSignBlock(Collection<OpOperation> ops, OpBlock prevOpBlockHeader, String serverUser, KeyPair serverKeyPair); static String calculateSuperblockHash(int size, String lastBlockHash); static String calculateHash(OpBlock block); boolean error(OpObject o, ErrorType e, Object... args); boolean error(OpObject o, Exception cause, ErrorType e, Object... args); }
OpBlockchainRules { public boolean validateOp(OpBlockChain opBlockChain, OpOperation u, LocalValidationCtx ctx) { Metric mt = mValidTotal.start(); if(!OUtils.equals(calculateOperationHash(u, false), u.getHash())) { return error(u, ErrorType.OP_HASH_IS_NOT_CORRECT, calculateOperationHash(u, false), u.getHash()); } int sz = formatter.opToJson(u).length(); if (sz > OpBlockchainRules.MAX_OP_SIZE_MB) { return error(u, ErrorType.OP_SIZE_IS_EXCEEDED, u.getHash(), sz, OpBlockchainRules.MAX_OP_SIZE_MB); } Metric m = mValidSig.start(); boolean valid = validateSignatures(opBlockChain, u); m.capture(); if(!valid) { return valid; } valid = validateRules(opBlockChain, u, ctx); mt.capture(); if(!valid) { return valid; } return true; } OpBlockchainRules(JsonFormatter formatter, ValidationListener logValidation); static boolean validateNickname(String name); static String getRawHash(String hs); static String getSiteFromUser(String name); static String getNicknameFromUser(String name); static String getUserFromNicknameAndSite(String nickname, String site); String calculateMerkleTreeHash(OpBlock op); String calculateSigMerkleTreeHash(OpBlock op); String calculateOperationHash(OpOperation ob, boolean set); int calculateBlockSize(OpBlock cp); JsonFormatter getFormatter(); OpOperation generateHashAndSign(OpOperation op, KeyPair... keyPair); boolean validateRules(OpBlockChain blockchain, OpOperation o, LocalValidationCtx ctx); @SuppressWarnings("unchecked") Map<String, Set<String>> getRoles(OpBlockChain blockchain); boolean validateBlock(OpBlockChain blockChain, OpBlock block, OpBlock prevBlockHeader, boolean validateSignature); boolean validateSignatures(OpBlockChain ctx, OpOperation ob); boolean validateOp(OpBlockChain opBlockChain, OpOperation u, LocalValidationCtx ctx); KeyPair getLoginKeyPair(OpBlockChain ctx, String signedByName, String privateKey); OpObject getLoginKeyObj(OpBlockChain ctx, String signedByName); KeyPair getSignUpKeyPairFromPwd(OpBlockChain blc,
			String name, String pwd); OpBlock createAndSignBlock(Collection<OpOperation> ops, OpBlock prevOpBlockHeader, String serverUser, KeyPair serverKeyPair); static String calculateSuperblockHash(int size, String lastBlockHash); static String calculateHash(OpBlock block); boolean error(OpObject o, ErrorType e, Object... args); boolean error(OpObject o, Exception cause, ErrorType e, Object... args); static final int MAX_BLOCK_SIZE_OPS; static final int MAX_BLOCKHEADER_SIZE; static final int MAX_ALL_OP_SIZE_MB; static final int MAX_BLOCK_SIZE_MB; static final int MAX_AMOUNT_CREATED_OBJ_FOR_OP; static final int MAX_OP_SIZE_MB; static final int BLOCK_VERSION; static final String OP_TYPE_SYS; static final String OP_LOGIN; static final String OP_SIGNUP; static final String OP_ROLE; static final String OP_GRANT; static final String OP_VALIDATE; static final String OP_VOTE; static final String OP_LIMIT; static final String OP_TABLE; static final String OP_OPERATION; static final String OP_BOT; static final String F_DIGEST; static final String F_ALGO; static final String F_PUBKEY; static final String F_NAME; static final String F_SALT; static final String F_AUTH_METHOD; static final String F_OAUTH_PROVIDER; static final String F_OAUTHID_HASH; static final String F_KEYGEN_METHOD; static final String F_DETAILS; static final String F_TYPE; static final String F_SUPER_ROLES; static final String F_ROLES; static final String F_ERROR_MESSAGE; static final String F_PRIVATEKEY; static final String F_UID; static final String F_VALIDATE; static final String F_IF; static final String METHOD_OAUTH; static final String METHOD_PWD; static final String METHOD_PROVIDED; static final String JSON_MSG_TYPE; static final char USER_LOGIN_CHAR; }