diff --git a/src/main/base/org/bdware/sc/ComponedContractResult.java b/src/main/base/org/bdware/sc/ComponedContractResult.java index 5da7838..c1bae44 100644 --- a/src/main/base/org/bdware/sc/ComponedContractResult.java +++ b/src/main/base/org/bdware/sc/ComponedContractResult.java @@ -53,9 +53,10 @@ public class ComponedContractResult { return; } } catch (Exception e) { + String str = null; cr2 = new ContractResult( - ContractResult.Status.Error, new JsonPrimitive("parse str failed:")); + ContractResult.Status.Error, new JsonPrimitive("parse str failed:" + obj.toString())); e.printStackTrace(); } // if (cr2.status == ContractResult.Status.Error) { // 结果不是Success不参与最终结果计算 diff --git a/src/main/base/org/bdware/sc/conn/ServiceServer.java b/src/main/base/org/bdware/sc/conn/ServiceServer.java index db83b34..b142fed 100644 --- a/src/main/base/org/bdware/sc/conn/ServiceServer.java +++ b/src/main/base/org/bdware/sc/conn/ServiceServer.java @@ -25,7 +25,7 @@ public class ServiceServer extends Thread { public static final ExecutorService executor = new ThreadPoolExecutor( 8, - 15, + Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue<>()); diff --git a/src/test/java/org/bdware/sc/boundary/utils/SM2UtilTest.java b/src/test/java/org/bdware/sc/boundary/utils/SM2UtilTest.java index c216d72..b6bf29a 100644 --- a/src/test/java/org/bdware/sc/boundary/utils/SM2UtilTest.java +++ b/src/test/java/org/bdware/sc/boundary/utils/SM2UtilTest.java @@ -19,8 +19,9 @@ public class SM2UtilTest { String keyPairStr = "{\"publicKey\":\"0442e39c0b1623e6f95ef896d37f41aa3cd98fbc3aea71250eedba4335c6c3aff51b5fa2352f920d1063b50a30738427c18375df886985a63e0f496293fdad22a8\",\"privateKey\":\"b7e504cf951792554bf4a9874be37cb1279d38939444388e2046ee9603b4f0c4\"}"; SM2KeyPair keyPair = SM2KeyPair.fromJson(keyPairStr); + @Test - public void verify2(){ + public void verify2() { String toVerify = "GeneralContract|plainTextTransmission|{\"ledger\":\"test\",\"data\":\"上链信息为json格式\"}|04398dfde44290595cd098cd2f904b36367c69f9011719d43fb0955f823cf1386764769bc7c0a5649dcb316d552998a5c106afd268d9db8b6482ce527544a7bd15"; String sign = "30440220137771d7505abde700c89cfa376f67c564dfdec6ffdb08cb08ff70544be6cb6f0220587296439bedf43f4b0bfec2d7030a8250d369e53af623e50a734e3b6cb780cb"; String pubkey = "04398dfde44290595cd098cd2f904b36367c69f9011719d43fb0955f823cf1386764769bc7c0a5649dcb316d552998a5c106afd268d9db8b6482ce527544a7bd15"; @@ -33,13 +34,14 @@ public class SM2UtilTest { System.out.println(cr.verifySignature()); } + @Test public void base64() { String gstr = "09146332716e7767327923056946406e49570e5909146332716e7767327923056946406e49570e59"; byte[] bytes = ByteUtils.fromHexString(gstr); - // String str = new BASE64Encoder().encode(bytes); - // System.out.println(str); + // String str = new BASE64Encoder().encode(bytes); + // System.out.println(str); } @Test @@ -128,6 +130,24 @@ public class SM2UtilTest { } + @Test + public void dosignTest() throws Exception { + String tosign = "action=startContract&script=contract%20shortc%7B%0A%09export%20function%20main(arg)%7B%0A%09%09return%20arg.length%3B%09%0A%09%7D%0A%7D&pubKey=041a3875bb1a8d6acfc1142c60e3cc7c11831d4878c6dbbf9bb0929716d6cf402492b9629a4ced9198ae2c419f8d3d6ae810a431458d38901e5597636b715584d4"; + // keyPair = SM2KeyPair.fromJson("{\"privateKey\":\"94728f3d95f19b3b5b11a31fdb603b5b2e8b377d9520d0680ac4f270cc82ec51\",\"publicKey\":\"041a3875bb1a8d6acfc1142c60e3cc7c11831d4878c6dbbf9bb0929716d6cf402492b9629a4ced9198ae2c419f8d3d6ae810a431458d38901e5597636b715584d4\"}"); + keyPair = SM2KeyPair.fromJson("{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"); + String signature = ByteUtils.toHexString( + SM2Util.sign( + keyPair.getPrivateKeyParameter(), tosign.getBytes())); + System.out.println(signature); + ECPublicKeyParameters pubKey = + BCECUtil.createECPublicKeyFromStrParameters( + keyPair.getPublicKeyStr(), SM2Util.CURVE, SM2Util.DOMAIN_PARAMS); + boolean verify = SM2Util.verify( + pubKey, tosign.getBytes(), ByteUtils.fromHexString(signature)); + System.out.println(verify); + + + } // Deprecated // @Test // public void signAtServer() {