From 13337b64716141995e49f3f0b81e6356fc05a06a Mon Sep 17 00:00:00 2001 From: "Mark S. Lewis" Date: Thu, 25 May 2017 09:51:16 +0100 Subject: [PATCH] [FAB-4258] Fix compile warnings for redundant code Also fix checkstyle errors in modified files. Update Eclipse .classpath for Maven POM changes. Update checkstyle configuration to allow suppression. Fix compile warnings in test code. Change-Id: I91b5cf5e6f3085431d490b8d821d72a5dba50c57 Signed-off-by: Mark S. Lewis Signed-off-by: rickr --- .project | 6 + checkstyle-config.xml | 12 +- pom.xml | 6 +- .../hyperledger/fabric/sdk/BlockEvent.java | 12 +- .../org/hyperledger/fabric/sdk/BlockInfo.java | 4 +- .../hyperledger/fabric/sdk/BlockListener.java | 2 +- .../sdk/ChaincodeEndorsementPolicy.java | 2 +- .../fabric/sdk/ChaincodeLanguage.java | 6 +- .../fabric/sdk/ChaincodeResponse.java | 28 ++-- .../org/hyperledger/fabric/sdk/Channel.java | 96 ++++++----- .../fabric/sdk/ChannelConfiguration.java | 2 +- .../fabric/sdk/EndorserClient.java | 10 +- .../hyperledger/fabric/sdk/Enrollment.java | 8 +- .../fabric/sdk/GetTCertBatchRequest.java | 2 +- .../org/hyperledger/fabric/sdk/HFClient.java | 4 +- .../sdk/InstantiateProposalRequest.java | 2 +- .../org/hyperledger/fabric/sdk/Orderer.java | 8 +- .../hyperledger/fabric/sdk/OrdererClient.java | 4 +- .../fabric/sdk/PayloadDeserializer.java | 3 +- .../java/org/hyperledger/fabric/sdk/Peer.java | 8 +- .../fabric/sdk/ProposalResponse.java | 4 +- .../org/hyperledger/fabric/sdk/SDKUtils.java | 3 + .../fabric/sdk/TransactionDeserializer.java | 1 - .../fabric/sdk/TransactionInfo.java | 2 +- .../sdk/TransactionPayloadDeserializer.java | 2 +- .../sdk/TransactionProposalRequest.java | 2 +- .../fabric/sdk/TransactionResponse.java | 2 +- .../fabric/sdk/UpgradeProposalRequest.java | 2 +- .../java/org/hyperledger/fabric/sdk/User.java | 9 +- .../fabric/sdk/exception/BaseException.java | 2 +- .../sdk/exception/ChaincodeException.java | 10 +- .../fabric/sdk/exception/CryptoException.java | 16 +- .../sdk/exception/EventHubException.java | 2 +- .../sdk/exception/ExecuteException.java | 2 +- .../sdk/exception/GetTCertBatchException.java | 2 +- .../exception/InvalidArgumentException.java | 2 +- ...InvalidProtocolBufferRuntimeException.java | 7 +- .../InvalidTransactionException.java | 5 +- .../fabric/sdk/exception/InvokeException.java | 2 +- .../exception/NoAvailableTCertException.java | 2 +- .../sdk/exception/NoValidPeerException.java | 10 +- .../fabric/sdk/exception/PeerException.java | 17 +- .../sdk/exception/ProposalException.java | 2 +- .../fabric/sdk/exception/QueryException.java | 2 +- .../exception/TransactionEventException.java | 2 +- .../sdk/exception/TransactionException.java | 2 +- .../hyperledger/fabric/sdk/helper/Config.java | 10 +- .../hyperledger/fabric/sdk/helper/Utils.java | 14 +- .../fabric/sdk/security/CryptoPrimitives.java | 68 +++----- .../fabric/sdk/security/CryptoSuite.java | 48 +++--- .../sdk/transaction/CSCCProposalBuilder.java | 2 +- .../transaction/InstallProposalBuilder.java | 18 +- .../InstantiateProposalBuilder.java | 11 +- .../transaction/JoinPeerProposalBuilder.java | 7 +- .../sdk/transaction/LSCCProposalBuilder.java | 2 +- .../sdk/transaction/ProposalBuilder.java | 17 +- .../fabric/sdk/transaction/ProtoUtils.java | 23 +-- .../QueryInstalledChaincodesBuilder.java | 12 +- .../QueryInstantiatedChaincodesBuilder.java | 2 +- .../transaction/QueryPeerChannelsBuilder.java | 4 +- .../sdk/transaction/TransactionBuilder.java | 14 +- .../sdk/transaction/TransactionContext.java | 28 +--- .../transaction/UpgradeProposalBuilder.java | 8 +- .../hyperledger/fabric_ca/sdk/Attribute.java | 46 ++--- .../hyperledger/fabric_ca/sdk/HFCAClient.java | 51 +----- .../fabric_ca/sdk/HFCAEnrollment.java | 2 +- .../fabric_ca/sdk/RegistrationRequest.java | 2 +- .../fabric_ca/sdk/RevocationRequest.java | 4 +- .../sdk/exception/BaseException.java | 2 +- .../sdk/exception/EnrollmentException.java | 2 +- .../exception/InvalidArgumentException.java | 2 +- .../sdk/exception/RegistrationException.java | 2 +- .../sdk/exception/RevocationException.java | 2 +- .../fabric_ca/sdk/helper/Config.java | 13 +- .../fabric/sdk/BlockEventTest.java | 10 +- .../sdk/ChaincodeEndorsementPolicyTest.java | 13 +- .../hyperledger/fabric/sdk/ChannelTest.java | 45 +++-- .../hyperledger/fabric/sdk/ClientTest.java | 47 ++---- .../hyperledger/fabric/sdk/EndpointTest.java | 77 +++++---- .../hyperledger/fabric/sdk/OrdererTest.java | 157 ++++++++---------- .../org/hyperledger/fabric/sdk/PeerTest.java | 140 ++++++---------- .../hyperledger/fabric/sdk/TestHFClient.java | 4 +- .../fabric/sdk/helper/ConfigTest.java | 15 +- .../sdk/security/CryptoPrimitivesTest.java | 58 ++++--- .../fabric/sdk/testutils/TestConfig.java | 66 +------- .../sdkintegration/End2endAndBackAgainIT.java | 5 +- .../fabric/sdkintegration/End2endIT.java | 48 ++---- .../fabric/sdkintegration/SampleStore.java | 30 ++-- .../fabric/sdkintegration/SampleUser.java | 33 +--- 89 files changed, 608 insertions(+), 895 deletions(-) diff --git a/.project b/.project index a2238889..d4e2cd76 100644 --- a/.project +++ b/.project @@ -15,9 +15,15 @@ + + net.sf.eclipsecs.core.CheckstyleBuilder + + + org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + net.sf.eclipsecs.core.CheckstyleNature diff --git a/checkstyle-config.xml b/checkstyle-config.xml index 87f23653..640b2188 100644 --- a/checkstyle-config.xml +++ b/checkstyle-config.xml @@ -46,15 +46,23 @@ + + + + + + + + + - + diff --git a/pom.xml b/pom.xml index 56ffd862..0f3e4c24 100644 --- a/pom.xml +++ b/pom.xml @@ -305,9 +305,9 @@ false - false - false - false + true + true + true ${project.build.sourceDirectory} checkstyle-config.xml diff --git a/src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java b/src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java index c781ca13..b46ba131 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java +++ b/src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java @@ -18,27 +18,23 @@ import java.util.List; import com.google.protobuf.InvalidProtocolBufferException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.hyperledger.fabric.protos.common.Common.Block; +import org.hyperledger.fabric.protos.peer.PeerEvents.Event; import org.hyperledger.fabric.sdk.exception.InvalidProtocolBufferRuntimeException; -import static org.hyperledger.fabric.protos.peer.PeerEvents.Event; - /** * A wrapper for the Block returned in an Event * * @see Block */ public class BlockEvent extends BlockInfo { - private static final Log logger = LogFactory.getLog(BlockEvent.class); +// private static final Log logger = LogFactory.getLog(BlockEvent.class); /** - * Get eventhub that received the event + * Get the Event Hub that received the event. * - * @return eventhub that received the event + * @return an Event Hub. */ - public EventHub getEventHub() { return eventHub; } diff --git a/src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java b/src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java index 5f879991..500f00c8 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java +++ b/src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java @@ -118,14 +118,12 @@ public int getEnvelopCount() { public class EnvelopeInfo { private final EnvelopeDeserializer envelopeDeserializer; HeaderDeserializer headerDeserializer; - private final int blockIndex; //private final EnvelopeDeserializer envelopeDeserializer; EnvelopeInfo(EnvelopeDeserializer envelopeDeserializer, int blockIndex) { this.envelopeDeserializer = envelopeDeserializer; headerDeserializer = envelopeDeserializer.getPayload().getHeader(); - this.blockIndex = blockIndex; headerDeserializer.getChannelHeader().getType(); } @@ -198,7 +196,7 @@ public EnvelopeInfo getEnvelopeInfo(int blockIndex) throws InvalidProtocolBuffer return ret; } catch (InvalidProtocolBufferRuntimeException e) { - throw (InvalidProtocolBufferException) e.getCause(); + throw e.getCause(); } } diff --git a/src/main/java/org/hyperledger/fabric/sdk/BlockListener.java b/src/main/java/org/hyperledger/fabric/sdk/BlockListener.java index 0ff731e0..246ae091 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/BlockListener.java +++ b/src/main/java/org/hyperledger/fabric/sdk/BlockListener.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java b/src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java index a7f45802..9705b5ea 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java +++ b/src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java @@ -95,7 +95,7 @@ private static SignaturePolicy parsePolicy(IndexedHashMap throw new ChaincodeEndorsementPolicyParseException(format("%s expected to have list but found %s.", key, String.valueOf(vo))); } - @SuppressWarnings ("unchecked") final List> voList = (List>) vo; + @SuppressWarnings("unchecked") final List> voList = (List>) vo; if (voList.size() < matchNo) { diff --git a/src/main/java/org/hyperledger/fabric/sdk/ChaincodeLanguage.java b/src/main/java/org/hyperledger/fabric/sdk/ChaincodeLanguage.java index 3a456ff7..3eda1c95 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/ChaincodeLanguage.java +++ b/src/main/java/org/hyperledger/fabric/sdk/ChaincodeLanguage.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,6 +15,6 @@ package org.hyperledger.fabric.sdk; public enum ChaincodeLanguage { - GO_LANG, - JAVA + GO_LANG, + JAVA } diff --git a/src/main/java/org/hyperledger/fabric/sdk/ChaincodeResponse.java b/src/main/java/org/hyperledger/fabric/sdk/ChaincodeResponse.java index d7609b95..e40c845f 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/ChaincodeResponse.java +++ b/src/main/java/org/hyperledger/fabric/sdk/ChaincodeResponse.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -31,33 +31,31 @@ public int getStatus() { } } - private Status status = Status.UNDEFINED; - private String message = null; - private String transactionID = null; - private String chaincodeID = null; + private final Status status; + private final String message; + private final String transactionID; public ChaincodeResponse(String transactionID, String chaincodeID, Status status, String message) { this.status = status; this.message = message; this.transactionID = transactionID; - this.chaincodeID = chaincodeID; } public ChaincodeResponse(String transactionID, String chaincodeID, int istatus, String message) { switch (istatus) { - case 200: - this.status = Status.SUCCESS; - break; - case 500: - this.status = Status.FAILURE; - break; - - + case 200: + this.status = Status.SUCCESS; + break; + case 500: + this.status = Status.FAILURE; + break; + default: + this.status = Status.UNDEFINED; + break; } this.message = message; this.transactionID = transactionID; - this.chaincodeID = chaincodeID; } /** diff --git a/src/main/java/org/hyperledger/fabric/sdk/Channel.java b/src/main/java/org/hyperledger/fabric/sdk/Channel.java index 25132dc4..1a4b3404 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/Channel.java +++ b/src/main/java/org/hyperledger/fabric/sdk/Channel.java @@ -48,15 +48,18 @@ import org.hyperledger.fabric.protos.common.Common.ChannelHeader; import org.hyperledger.fabric.protos.common.Common.Envelope; import org.hyperledger.fabric.protos.common.Common.Header; +import org.hyperledger.fabric.protos.common.Common.HeaderType; import org.hyperledger.fabric.protos.common.Common.LastConfig; import org.hyperledger.fabric.protos.common.Common.Metadata; import org.hyperledger.fabric.protos.common.Common.Payload; +import org.hyperledger.fabric.protos.common.Common.SignatureHeader; +import org.hyperledger.fabric.protos.common.Common.Status; import org.hyperledger.fabric.protos.common.Configtx.ConfigEnvelope; import org.hyperledger.fabric.protos.common.Configtx.ConfigGroup; import org.hyperledger.fabric.protos.common.Configtx.ConfigSignature; import org.hyperledger.fabric.protos.common.Configtx.ConfigUpdateEnvelope; +import org.hyperledger.fabric.protos.common.Configtx.ConfigValue; import org.hyperledger.fabric.protos.common.Ledger; -import org.hyperledger.fabric.protos.common.Policies.Policy; import org.hyperledger.fabric.protos.msp.Identities; import org.hyperledger.fabric.protos.msp.MspConfig; import org.hyperledger.fabric.protos.orderer.Ab; @@ -118,7 +121,7 @@ */ public class Channel { private static final Log logger = LogFactory.getLog(Channel.class); - private static final boolean isDebugLevel = logger.isDebugEnabled(); + private static final boolean IS_DEBUG_LEVEL = logger.isDebugEnabled(); private static final Config config = Config.getConfig(); private static final String SYSTEM_CHANNEL_NAME = ""; @@ -128,23 +131,19 @@ public class Channel { // The peers on this channel to which the client can connect private final Collection peers = new Vector<>(); - // Security enabled flag - private boolean securityEnabled = true; - // Temporary variables to control how long to wait for deploy and invoke to complete before // emitting events. This will be removed when the SDK is able to receive events from the private int deployWaitTime = 20; private int transactionWaitTime = 5; // contains the anchor peers parsed from the channel's configBlock - private Set anchorPeers; +// private Set anchorPeers; // The crypto primitives object private CryptoSuite cryptoSuite; private final Collection orderers = new LinkedList<>(); HFClient client; private boolean initialized = false; - private int max_message_count = 50; private boolean shutdown = false; /** @@ -221,7 +220,7 @@ private Channel(String name, HFClient hfClient, Orderer orderer, ChannelConfigur ByteString payloadSignature = transactionContext.signByteStrings(payloadByteString); - if (isDebugLevel) { + if (IS_DEBUG_LEVEL) { logger.debug(format("Sending to orderer payloadSignature: 0x%s ", toHexString(payloadSignature))); } @@ -292,7 +291,7 @@ private Channel(String name, HFClient client, final boolean systemChannel) throw this.systemChannel = systemChannel; if (systemChannel) { - name = SYSTEM_CHANNEL_NAME; ///It's special ! + name = SYSTEM_CHANNEL_NAME; //It's special ! initialized = true; } else { if (Utils.isNullOrEmpty(name)) { @@ -671,7 +670,7 @@ private Block getGenesisBlock(Orderer order) throws TransactionException { ChannelHeader deliverChainHeader = createChannelHeader(HeaderType.DELIVER_SEEK_INFO, "4", name, 0, getCurrentFabricTimestamp(), null); - String mspid = client.getUserContext().getMSPID(); + String mspid = client.getUserContext().getMspId(); String cert = getEnrollment().getCert(); Identities.SerializedIdentity identity = Identities.SerializedIdentity.newBuilder() @@ -882,7 +881,7 @@ protected void parseConfigBlock() throws TransactionException { msps = Collections.unmodifiableMap(newMSPS); - anchorPeers = Collections.unmodifiableSet(traverseConfigGroupsAnchors("", channelGroup, new HashSet<>())); +// anchorPeers = Collections.unmodifiableSet(traverseConfigGroupsAnchors("", channelGroup, new HashSet<>())); } catch (TransactionException e) { logger.error(e.getMessage(), e); @@ -894,24 +893,24 @@ protected void parseConfigBlock() throws TransactionException { } - private Set traverseConfigGroupsAnchors(String name, ConfigGroup configGroup, Set anchorPeers) throws InvalidProtocolBufferException, InvalidArgumentException { - ConfigValue anchorsConfig = configGroup.getValuesMap().get("AnchorPeers"); - if (anchorsConfig != null) { - AnchorPeers anchors = AnchorPeers.parseFrom(anchorsConfig.getValue()); - for (AnchorPeer anchorPeer : anchors.getAnchorPeersList()) { - String hostName = anchorPeer.getHost(); - int port = anchorPeer.getPort(); - logger.debug(format("parsed from config block: anchor peer %s:%d", hostName, port)); - anchorPeers.add(new Anchor(hostName, port)); - } - } - - for (Map.Entry gm : configGroup.getGroupsMap().entrySet()) { - traverseConfigGroupsAnchors(gm.getKey(), gm.getValue(), anchorPeers); - } - - return anchorPeers; - } +// private Set traverseConfigGroupsAnchors(String name, ConfigGroup configGroup, Set anchorPeers) throws InvalidProtocolBufferException, InvalidArgumentException { +// ConfigValue anchorsConfig = configGroup.getValuesMap().get("AnchorPeers"); +// if (anchorsConfig != null) { +// AnchorPeers anchors = AnchorPeers.parseFrom(anchorsConfig.getValue()); +// for (AnchorPeer anchorPeer : anchors.getAnchorPeersList()) { +// String hostName = anchorPeer.getHost(); +// int port = anchorPeer.getPort(); +// logger.debug(format("parsed from config block: anchor peer %s:%d", hostName, port)); +// anchorPeers.add(new Anchor(hostName, port)); +// } +// } +// +// for (Map.Entry gm : configGroup.getGroupsMap().entrySet()) { +// traverseConfigGroupsAnchors(gm.getKey(), gm.getValue(), anchorPeers); +// } +// +// return anchorPeers; +// } private Map traverseConfigGroupsMSP(String name, ConfigGroup configGroup, Map msps) throws InvalidProtocolBufferException { @@ -1154,22 +1153,22 @@ private Block getLatestBlock(Orderer orderer) throws CryptoException, Transactio return latestBlock; } - private static Policy buildPolicyEnvelope(int nOf) { - - SignaturePolicy.NOutOf nOutOf = SignaturePolicy.NOutOf.newBuilder().setN(nOf).build(); - - SignaturePolicy signaturePolicy = SignaturePolicy.newBuilder().setNOutOf(nOutOf) - .build(); - - SignaturePolicyEnvelope signaturePolicyEnvelope = SignaturePolicyEnvelope.newBuilder() - .setVersion(0) - .setRule(signaturePolicy).build(); - - return Policy.newBuilder() - .setType(Policy.PolicyType.SIGNATURE.getNumber()) - .setValue(signaturePolicyEnvelope.toByteString()) - .build(); - } +// private static Policy buildPolicyEnvelope(int nOf) { +// +// SignaturePolicy.NOutOf nOutOf = SignaturePolicy.NOutOf.newBuilder().setN(nOf).build(); +// +// SignaturePolicy signaturePolicy = SignaturePolicy.newBuilder().setNOutOf(nOutOf) +// .build(); +// +// SignaturePolicyEnvelope signaturePolicyEnvelope = SignaturePolicyEnvelope.newBuilder() +// .setVersion(0) +// .setPolicy(signaturePolicy).build(); +// +// return Policy.newBuilder() +// .setType(Policy.PolicyType.SIGNATURE.getNumber()) +// .setPolicy(signaturePolicyEnvelope.toByteString()) +// .build(); +// } public Collection getOrderers() { return Collections.unmodifiableCollection(orderers); @@ -1245,7 +1244,6 @@ public Collection sendInstantiationProposal(InstantiateProposa transactionContext.setProposalWaitTime(instantiateProposalRequest.getProposalWaitTime()); InstantiateProposalBuilder instantiateProposalbuilder = InstantiateProposalBuilder.newBuilder(); instantiateProposalbuilder.context(transactionContext); - instantiateProposalbuilder.setChaincodeLanguage(instantiateProposalRequest.getChaincodeLanguage()); instantiateProposalbuilder.argss(instantiateProposalRequest.getArgs()); instantiateProposalbuilder.chaincodeName(instantiateProposalRequest.getChaincodeName()); instantiateProposalbuilder.chaincodePath(instantiateProposalRequest.getChaincodePath()); @@ -2409,8 +2407,8 @@ boolean addBEvent(BlockEvent event) { return false; } - Block block = event.getBlock(); - final long num = block.getHeader().getNumber(); +// Block block = event.getBlock(); +// final long num = block.getHeader().getNumber(); // May be fed by multiple eventhubs but BlockingQueue.add() is thread-safe events.add(event); @@ -2759,7 +2757,7 @@ public synchronized void shutdown(boolean force) { initialized = false; shutdown = true; - anchorPeers = null; +// anchorPeers = null; executorService = null; for (EventHub eh : getEventHubs()) { diff --git a/src/main/java/org/hyperledger/fabric/sdk/ChannelConfiguration.java b/src/main/java/org/hyperledger/fabric/sdk/ChannelConfiguration.java index 59a3c574..189def04 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/ChannelConfiguration.java +++ b/src/main/java/org/hyperledger/fabric/sdk/ChannelConfiguration.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/EndorserClient.java b/src/main/java/org/hyperledger/fabric/sdk/EndorserClient.java index 59bd5276..70749397 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/EndorserClient.java +++ b/src/main/java/org/hyperledger/fabric/sdk/EndorserClient.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -43,7 +43,7 @@ class EndorserClient { * * @param channelBuilder The ChannelBuilder to build the endorser client */ - public EndorserClient(ManagedChannelBuilder channelBuilder) { + EndorserClient(ManagedChannelBuilder channelBuilder) { managedChannel = channelBuilder.build(); blockingStub = EndorserGrpc.newBlockingStub(managedChannel); futureStub = EndorserGrpc.newFutureStub(managedChannel); @@ -71,7 +71,7 @@ synchronized void shutdown(boolean force) { try { isTerminated = lchannel.shutdown().awaitTermination(3, TimeUnit.SECONDS); } catch (Exception e) { - logger.debug(e);//best effort + logger.debug(e); //best effort } if (!isTerminated) { lchannel.shutdownNow(); @@ -101,9 +101,9 @@ public FabricProposalResponse.ProposalResponse sendProposal(FabricProposal.Signe } } - boolean isChannelActive(){ + boolean isChannelActive() { ManagedChannel lchannel = managedChannel; - return lchannel != null && !lchannel.isShutdown() && ! lchannel.isTerminated(); + return lchannel != null && !lchannel.isShutdown() && !lchannel.isTerminated(); } @Override diff --git a/src/main/java/org/hyperledger/fabric/sdk/Enrollment.java b/src/main/java/org/hyperledger/fabric/sdk/Enrollment.java index 0119b68b..f786d8e6 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/Enrollment.java +++ b/src/main/java/org/hyperledger/fabric/sdk/Enrollment.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,14 +23,16 @@ public interface Enrollment { /** * Get the user's private key + * * @return private key. */ - public PrivateKey getKey(); + PrivateKey getKey(); /** * Get the user's signed certificate. + * * @return a certificate. */ - public String getCert(); + String getCert(); } diff --git a/src/main/java/org/hyperledger/fabric/sdk/GetTCertBatchRequest.java b/src/main/java/org/hyperledger/fabric/sdk/GetTCertBatchRequest.java index 33b884ce..ab9a8bd3 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/GetTCertBatchRequest.java +++ b/src/main/java/org/hyperledger/fabric/sdk/GetTCertBatchRequest.java @@ -24,7 +24,7 @@ class GetTCertBatchRequest { private int num; private List attrs; - public GetTCertBatchRequest(String name, Enrollment enrollment, int num, List attrs) { + GetTCertBatchRequest(String name, Enrollment enrollment, int num, List attrs) { this.name = name; this.enrollment = enrollment; this.num = num; diff --git a/src/main/java/org/hyperledger/fabric/sdk/HFClient.java b/src/main/java/org/hyperledger/fabric/sdk/HFClient.java index 1c8a5539..a0f0562c 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/HFClient.java +++ b/src/main/java/org/hyperledger/fabric/sdk/HFClient.java @@ -258,7 +258,7 @@ public void setUserContext(User userContext) throws InvalidArgumentException { throw new InvalidArgumentException(format("setUserContext for user %s has no Enrollment set", userName)); } - if (Utils.isNullOrEmpty(userContext.getMSPID())) { + if (Utils.isNullOrEmpty(userContext.getMspId())) { throw new InvalidArgumentException(format("setUserContext for user %s has user's MSPID is missing", userName)); } @@ -273,7 +273,7 @@ public void setUserContext(User userContext) throws InvalidArgumentException { throw new InvalidArgumentException(format("setUserContext for user %s has Enrollment missing signing key", userName)); } - logger.debug(format("Setting user context to MSPID: %s user: %s", userContext.getMSPID(), userContext.getName())); + logger.debug(format("Setting user context to MSPID: %s user: %s", userContext.getMspId(), userContext.getName())); this.userContext = userContext; } diff --git a/src/main/java/org/hyperledger/fabric/sdk/InstantiateProposalRequest.java b/src/main/java/org/hyperledger/fabric/sdk/InstantiateProposalRequest.java index 46fad6d4..d844af24 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/InstantiateProposalRequest.java +++ b/src/main/java/org/hyperledger/fabric/sdk/InstantiateProposalRequest.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/Orderer.java b/src/main/java/org/hyperledger/fabric/sdk/Orderer.java index 3e5b5b56..eca59279 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/Orderer.java +++ b/src/main/java/org/hyperledger/fabric/sdk/Orderer.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -125,7 +125,8 @@ Ab.BroadcastResponse sendTransaction(Common.Envelope transaction) throws Excepti OrdererClient localOrdererClient = ordererClient; if (localOrdererClient == null || !localOrdererClient.isChannelActive()) { - localOrdererClient = ordererClient = new OrdererClient(this, new Endpoint(url, properties).getChannelBuilder()); + ordererClient = new OrdererClient(this, new Endpoint(url, properties).getChannelBuilder()); + localOrdererClient = ordererClient; } try { @@ -160,7 +161,8 @@ DeliverResponse[] sendDeliver(Common.Envelope transaction) throws TransactionExc logger.debug(format("Order.sendDeliver name: %s, url: %s", name, url)); if (localOrdererClient == null || !localOrdererClient.isChannelActive()) { - ordererClient = localOrdererClient = new OrdererClient(this, new Endpoint(url, properties).getChannelBuilder()); + localOrdererClient = new OrdererClient(this, new Endpoint(url, properties).getChannelBuilder()); + ordererClient = localOrdererClient; } try { diff --git a/src/main/java/org/hyperledger/fabric/sdk/OrdererClient.java b/src/main/java/org/hyperledger/fabric/sdk/OrdererClient.java index a7d5a530..e73e6476 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/OrdererClient.java +++ b/src/main/java/org/hyperledger/fabric/sdk/OrdererClient.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -73,7 +73,7 @@ synchronized void shutdown(boolean force) { try { isTerminated = lchannel.shutdown().awaitTermination(3, TimeUnit.SECONDS); } catch (Exception e) { - logger.debug(e);//best effort + logger.debug(e); //best effort } if (!isTerminated) { lchannel.shutdownNow(); diff --git a/src/main/java/org/hyperledger/fabric/sdk/PayloadDeserializer.java b/src/main/java/org/hyperledger/fabric/sdk/PayloadDeserializer.java index 82fee0f9..0178b1b0 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/PayloadDeserializer.java +++ b/src/main/java/org/hyperledger/fabric/sdk/PayloadDeserializer.java @@ -26,9 +26,8 @@ class PayloadDeserializer { private final ByteString byteString; private WeakReference payload; - private WeakReference transactionDeserialize; - public PayloadDeserializer(ByteString byteString) { + PayloadDeserializer(ByteString byteString) { this.byteString = byteString; } diff --git a/src/main/java/org/hyperledger/fabric/sdk/Peer.java b/src/main/java/org/hyperledger/fabric/sdk/Peer.java index fc003c85..ba69b5a5 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/Peer.java +++ b/src/main/java/org/hyperledger/fabric/sdk/Peer.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -149,7 +149,8 @@ ListenableFuture sendProposalAsync(Fabr EndorserClient localEndorserClient = endorserClent; //work off thread local copy. if (null == localEndorserClient || !localEndorserClient.isChannelActive()) { - endorserClent = localEndorserClient = new EndorserClient(new Endpoint(url, properties).getChannelBuilder()); + endorserClent = new EndorserClient(new Endpoint(url, properties).getChannelBuilder()); + localEndorserClient = endorserClent; } try { @@ -172,7 +173,8 @@ FabricProposalResponse.ProposalResponse sendProposal(FabricProposal.SignedPropos EndorserClient localEndorserClient = endorserClent; //work off thread local copy. if (null == localEndorserClient || !localEndorserClient.isChannelActive()) { - endorserClent = localEndorserClient = new EndorserClient(new Endpoint(url, properties).getChannelBuilder()); + endorserClent = new EndorserClient(new Endpoint(url, properties).getChannelBuilder()); + localEndorserClient = endorserClent; } try { diff --git a/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java b/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java index 8a13fadd..1fc3bf26 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java +++ b/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java @@ -24,8 +24,7 @@ public class ProposalResponse extends ChaincodeResponse { private static final Log logger = LogFactory.getLog(ProposalResponse.class); - final static Config config = Config.getConfig(); - private FabricProposal.SignedProposal signedProposal; + private static final Config config = Config.getConfig(); private boolean isVerified = false; @@ -116,7 +115,6 @@ public FabricProposal.Proposal getProposal() { public void setProposal(FabricProposal.SignedProposal signedProposal) throws ProposalException { try { - this.signedProposal = signedProposal; this.proposal = FabricProposal.Proposal.parseFrom(signedProposal.getProposalBytes()); } catch (InvalidProtocolBufferException e) { throw new ProposalException("Proposal exception", e); diff --git a/src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java b/src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java index 492146d7..aa6a99da 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java +++ b/src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java @@ -31,6 +31,9 @@ import org.hyperledger.fabric.sdk.security.CryptoSuite; public class SDKUtils { + private SDKUtils() { + + } public static CryptoSuite suite = null; diff --git a/src/main/java/org/hyperledger/fabric/sdk/TransactionDeserializer.java b/src/main/java/org/hyperledger/fabric/sdk/TransactionDeserializer.java index ebfe6913..a84dae61 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/TransactionDeserializer.java +++ b/src/main/java/org/hyperledger/fabric/sdk/TransactionDeserializer.java @@ -31,7 +31,6 @@ class TransactionDeserializer { private final ByteString byteString; private WeakReference transaction; - private WeakReference payload; private final Map> transactionActions = Collections.synchronizedMap(new WeakHashMap>()); diff --git a/src/main/java/org/hyperledger/fabric/sdk/TransactionInfo.java b/src/main/java/org/hyperledger/fabric/sdk/TransactionInfo.java index 243556bd..a47f8d8d 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/TransactionInfo.java +++ b/src/main/java/org/hyperledger/fabric/sdk/TransactionInfo.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/TransactionPayloadDeserializer.java b/src/main/java/org/hyperledger/fabric/sdk/TransactionPayloadDeserializer.java index ff08cacd..4e3ecb7b 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/TransactionPayloadDeserializer.java +++ b/src/main/java/org/hyperledger/fabric/sdk/TransactionPayloadDeserializer.java @@ -24,7 +24,7 @@ class TransactionPayloadDeserializer extends PayloadDeserializer { private WeakReference transactionDeserialize; - public TransactionPayloadDeserializer(ByteString byteString) { + TransactionPayloadDeserializer(ByteString byteString) { super(byteString); } diff --git a/src/main/java/org/hyperledger/fabric/sdk/TransactionProposalRequest.java b/src/main/java/org/hyperledger/fabric/sdk/TransactionProposalRequest.java index db78ad31..1a0e8523 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/TransactionProposalRequest.java +++ b/src/main/java/org/hyperledger/fabric/sdk/TransactionProposalRequest.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/TransactionResponse.java b/src/main/java/org/hyperledger/fabric/sdk/TransactionResponse.java index e06d9886..c58f3c63 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/TransactionResponse.java +++ b/src/main/java/org/hyperledger/fabric/sdk/TransactionResponse.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/UpgradeProposalRequest.java b/src/main/java/org/hyperledger/fabric/sdk/UpgradeProposalRequest.java index 7215a963..6b76e8f8 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/UpgradeProposalRequest.java +++ b/src/main/java/org/hyperledger/fabric/sdk/UpgradeProposalRequest.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/User.java b/src/main/java/org/hyperledger/fabric/sdk/User.java index 040893d9..cdcabd33 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/User.java +++ b/src/main/java/org/hyperledger/fabric/sdk/User.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,6 +23,7 @@ public interface User { /** * Get the name that identifies the user. + * * @return the user name. */ @@ -30,18 +31,21 @@ public interface User { /** * Get the roles to which the user belongs. + * * @return role names. */ Set getRoles(); /** * Get the user's account + * * @return the account name */ String getAccount(); /** * Get the user's affiliation. + * * @return the affiliation. */ String getAffiliation(); @@ -55,7 +59,8 @@ public interface User { /** * Get the ID provided by the user's organization. + * * @return msp ID. */ - String getMSPID(); + String getMspId(); } diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/BaseException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/BaseException.java index 455059da..23a03443 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/BaseException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/BaseException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/ChaincodeException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/ChaincodeException.java index 0ead5bd0..fc786e1d 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/ChaincodeException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/ChaincodeException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,9 +16,9 @@ public class ChaincodeException extends BaseException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public ChaincodeException(String message, Exception parent) { - super(message, parent); - } + public ChaincodeException(String message, Exception parent) { + super(message, parent); + } } diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/CryptoException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/CryptoException.java index fe686842..66b4ee37 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/CryptoException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/CryptoException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,14 +16,14 @@ public class CryptoException extends BaseException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public CryptoException(String message, Exception parent) { - super(message, parent); - } + public CryptoException(String message, Exception parent) { + super(message, parent); + } - public CryptoException(String message) { - super(message); - } + public CryptoException(String message) { + super(message); + } } diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/EventHubException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/EventHubException.java index 73b0d15f..31e4dba0 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/EventHubException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/EventHubException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/ExecuteException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/ExecuteException.java index 86b4717c..589b68d8 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/ExecuteException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/ExecuteException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/GetTCertBatchException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/GetTCertBatchException.java index 93f8b9c4..8aa62db9 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/GetTCertBatchException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/GetTCertBatchException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidArgumentException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidArgumentException.java index 47dbed15..6c19a7d5 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidArgumentException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidArgumentException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidProtocolBufferRuntimeException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidProtocolBufferRuntimeException.java index 5b8bf2c3..400e3554 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidProtocolBufferRuntimeException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidProtocolBufferRuntimeException.java @@ -14,14 +14,12 @@ * */ - package org.hyperledger.fabric.sdk.exception; import com.google.protobuf.InvalidProtocolBufferException; public class InvalidProtocolBufferRuntimeException extends RuntimeException { - private static final long serialVersionUID = 1L; public InvalidProtocolBufferRuntimeException(String message, InvalidProtocolBufferException parent) { @@ -32,11 +30,10 @@ public InvalidProtocolBufferRuntimeException(InvalidProtocolBufferException pare super(parent); } - public synchronized InvalidProtocolBufferException getCause(){ + public synchronized InvalidProtocolBufferException getCause() { - return (InvalidProtocolBufferException) super.getCause(); + return (InvalidProtocolBufferException) super.getCause(); } - } diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidTransactionException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidTransactionException.java index 34e0e2b9..795a1c2a 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidTransactionException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/InvalidTransactionException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,8 +14,7 @@ package org.hyperledger.fabric.sdk.exception; - -public class InvalidTransactionException extends BaseException{ +public class InvalidTransactionException extends BaseException { private static final long serialVersionUID = -1510202790871884019L; public InvalidTransactionException(String message, Exception parent) { diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/InvokeException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/InvokeException.java index 756c5473..31bd0114 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/InvokeException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/InvokeException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/NoAvailableTCertException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/NoAvailableTCertException.java index fc98d7be..6a4b2d54 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/NoAvailableTCertException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/NoAvailableTCertException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/NoValidPeerException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/NoValidPeerException.java index fb0a2043..040fc7b1 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/NoValidPeerException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/NoValidPeerException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,10 +16,10 @@ public class NoValidPeerException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public NoValidPeerException(String message) { - super(message); - } + public NoValidPeerException(String message) { + super(message); + } } diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/PeerException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/PeerException.java index 102a6987..0da938b6 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/PeerException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/PeerException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,13 +16,14 @@ public class PeerException extends BaseException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public PeerException(String message, Exception parent) { - super(message, parent); - } - public PeerException(String message ) { - super(message); - } + public PeerException(String message, Exception parent) { + super(message, parent); + } + + public PeerException(String message) { + super(message); + } } diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/ProposalException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/ProposalException.java index 41fe622d..886e5619 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/ProposalException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/ProposalException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/QueryException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/QueryException.java index dddd409c..86af1b90 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/QueryException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/QueryException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/TransactionEventException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/TransactionEventException.java index edf7cb94..498121b2 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/TransactionEventException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/TransactionEventException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/exception/TransactionException.java b/src/main/java/org/hyperledger/fabric/sdk/exception/TransactionException.java index 4705f287..b6c46a10 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/exception/TransactionException.java +++ b/src/main/java/org/hyperledger/fabric/sdk/exception/TransactionException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/helper/Config.java b/src/main/java/org/hyperledger/fabric/sdk/helper/Config.java index 3da25c27..7707eba4 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/helper/Config.java +++ b/src/main/java/org/hyperledger/fabric/sdk/helper/Config.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -56,7 +56,7 @@ public class Config { public static final String LOGGERLEVEL = "org.hyperledger.fabric.sdk.loglevel"; // ORG_HYPERLEDGER_FABRIC_SDK_LOGLEVEL=TRACE,DEBUG private static Config config; - private final static Properties sdkProperties = new Properties(); + private static final Properties sdkProperties = new Properties(); private Config() { File loadFile; @@ -124,6 +124,10 @@ private Config() { setTo = Level.ERROR; break; + default: + setTo = Level.INFO; + break; + } if (null != setTo) { @@ -165,7 +169,7 @@ private String getProperty(String property) { return ret; } - static private void defaultProperty(String key, String value) { + private static void defaultProperty(String key, String value) { String ret = System.getProperty(key); if (ret != null) { diff --git a/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java b/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java index f6ba54d0..53874c07 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java +++ b/src/main/java/org/hyperledger/fabric/sdk/helper/Utils.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -55,8 +55,8 @@ public final class Utils { private static final Log logger = LogFactory.getLog(Utils.class); - private static final Config confg = Config.getConfig(); - private static final int maxLogStringLength = confg.maxLogStringLength(); + private static final Config config = Config.getConfig(); + private static final int MAX_LOG_STRING_LENGTH = config.maxLogStringLength(); /** * Generate parameter hash for the given chaincode path,func and args @@ -304,7 +304,7 @@ public static Properties parseGrpcUrl(String url) { public static Exception checkGrpcUrl(String url) { try { - Properties props = parseGrpcUrl(url); + parseGrpcUrl(url); return null; } catch (Exception e) { @@ -347,7 +347,7 @@ public static String logString(final String string) { String ret = string.replaceAll("[^\\p{Print}]", "?"); - ret = ret.substring(0, Math.min(ret.length(), maxLogStringLength)) + (ret.length() > maxLogStringLength ? "..." : ""); + ret = ret.substring(0, Math.min(ret.length(), MAX_LOG_STRING_LENGTH)) + (ret.length() > MAX_LOG_STRING_LENGTH ? "..." : ""); return ret; @@ -356,12 +356,12 @@ public static String logString(final String string) { private static final int NONONCE_LENGTH = 24; - private final static SecureRandom random = new SecureRandom(); + private static final SecureRandom RANDOM = new SecureRandom(); public static byte[] generateNonce() { byte[] values = new byte[NONONCE_LENGTH]; - random.nextBytes(values); + RANDOM.nextBytes(values); return values; } diff --git a/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java b/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java index 387a24a9..39d0c91e 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java +++ b/src/main/java/org/hyperledger/fabric/sdk/security/CryptoPrimitives.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -292,7 +292,7 @@ public KeyStore getTrustStore() throws CryptoException { */ public void addCACertificateToTrustStore(File caCertPem, String alias) throws CryptoException, InvalidArgumentException { - if (alias==null || alias.isEmpty()) { + if (alias == null || alias.isEmpty()) { throw new InvalidArgumentException("You must assign an alias to a certificate when adding to the trust store."); } @@ -317,7 +317,7 @@ public void addCACertificateToTrustStore(File caCertPem, String alias) throws Cr */ public void addCACertificateToTrustStore(Certificate caCert, String alias) throws InvalidArgumentException, CryptoException { - if (alias==null || alias.isEmpty()) { + if (alias == null || alias.isEmpty()) { throw new InvalidArgumentException("You must assign an alias to a certificate when adding to the trust store."); } if (caCert == null) { @@ -325,7 +325,7 @@ public void addCACertificateToTrustStore(Certificate caCert, String alias) throw } try { - if(config.extraLogLevel(10)) { + if (config.extraLogLevel(10)) { logger.trace("Adding cert to trust store. alias: " + alias + "cert: " + caCert.toString()); } getTrustStore().setCertificateEntry(alias, caCert); @@ -337,13 +337,13 @@ public void addCACertificateToTrustStore(Certificate caCert, String alias) throw } @Override - public void loadCACertificates(Collection CACertificates) throws CryptoException { - if (CACertificates == null || CACertificates.size() == 0) { + public void loadCACertificates(Collection certificates) throws CryptoException { + if (certificates == null || certificates.size() == 0) { throw new CryptoException("Unable to load CA certificates. List is empty"); } try { - for (Certificate cert : CACertificates) { + for (Certificate cert : certificates) { addCACertificateToTrustStore(cert, Integer.toString(cert.hashCode())); } } catch (InvalidArgumentException e) { @@ -357,36 +357,18 @@ public void loadCACertificates(Collection CACertificates) throws Cr * @see org.hyperledger.fabric.sdk.security.CryptoSuite#loadCACertificatesAsBytes(java.util.Collection) */ @Override - public void loadCACertificatesAsBytes(Collection CACertificatesBytes) throws CryptoException { - if (CACertificatesBytes == null || CACertificatesBytes.size() == 0) { + public void loadCACertificatesAsBytes(Collection certificatesBytes) throws CryptoException { + if (certificatesBytes == null || certificatesBytes.size() == 0) { throw new CryptoException("List of CA certificates is empty. Nothing to load."); } ArrayList certList = new ArrayList<>(); - for (byte[] certBytes : CACertificatesBytes) { + for (byte[] certBytes : certificatesBytes) { logger.trace("certificate to load:\n" + new String(certBytes)); certList.add(bytesToCertificate(certBytes)); } loadCACertificates(certList); } - /** - * loadCACerts loads into the trust stores all the certificates it finds in the cacert directory. - * This method assumes that any file with extension .pem is a certificate file - */ - private void loadCACerts() { - File certsFolder = new File("cacerts").getAbsoluteFile(); - Collection certFiles = FileUtils.listFiles(certsFolder, new String[] {"pem"}, false); - for (File certFile : certFiles) { - try { - addCACertificateToTrustStore(certFile, certFile.getName()); - logger.debug("adding " + certFile.getName() + "to truststore."); - } catch (CryptoException | InvalidArgumentException e) { - logger.error("Unable to load certificate " + certFile.getName() + "Error: " + e.getMessage(), e); - // ignore cert files we can't read - } - } - } - /** * validateCertificate checks whether the given certificate is trusted. It * checks if the certificate is signed by one of the trusted certs in the @@ -525,13 +507,13 @@ public PublicKey decodePublicKey(String data) throws CryptoException { public byte[] eciesDecrypt(KeyPair keyPair, byte[] data) throws CryptoException { try { - int ek_len = (int) (Math.floor((this.securityLevel + 7) / 8) * 2 + 1); - int mk_len = this.securityLevel >> 3; - int em_len = data.length - ek_len - mk_len; + int ephemeralKeyLength = (int) (Math.floor((this.securityLevel + 7) / 8) * 2 + 1); + int mkLen = this.securityLevel >> 3; + int encryptedMessageLength = data.length - ephemeralKeyLength - mkLen; - byte[] ephemeralPublicKeyBytes = Arrays.copyOfRange(data, 0, ek_len); - byte[] encryptedMessage = Arrays.copyOfRange(data, ek_len, ek_len + em_len); - byte[] tag = Arrays.copyOfRange(data, ek_len + em_len, data.length); + byte[] ephemeralPublicKeyBytes = Arrays.copyOfRange(data, 0, ephemeralKeyLength); + byte[] encryptedMessage = Arrays.copyOfRange(data, ephemeralKeyLength, ephemeralKeyLength + encryptedMessageLength); + byte[] tag = Arrays.copyOfRange(data, ephemeralKeyLength + encryptedMessageLength, data.length); // Parsing public key. ECParameterSpec asymmetricKeyParams = generateECParameterSpec(); @@ -634,9 +616,9 @@ public byte[] ecdsaSignToBytes(ECPrivateKey privateKey, byte[] data) throws Cryp // encoded = new String(hexenncoded).getBytes(); X9ECParameters params = NISTNamedCurves.getByName(this.curveName); - BigInteger curve_N = params.getN(); + BigInteger curveN = params.getN(); - ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(), params.getG(), curve_N, + ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(), params.getG(), curveN, params.getH()); ECDSASigner signer = new ECDSASigner(); @@ -645,7 +627,7 @@ public byte[] ecdsaSignToBytes(ECPrivateKey privateKey, byte[] data) throws Cryp signer.init(true, privKey); BigInteger[] sigs = signer.generateSignature(encoded); - sigs = preventMalleability(sigs, curve_N); + sigs = preventMalleability(sigs, curveN); ByteArrayOutputStream s = new ByteArrayOutputStream(); @@ -667,7 +649,7 @@ public byte[] ecdsaSignToBytes(ECPrivateKey privateKey, byte[] data) throws Cryp */ @Override public byte[] sign(PrivateKey key, byte[] data) throws CryptoException { - return ecdsaSignToBytes((ECPrivateKey)key, data); + return ecdsaSignToBytes((ECPrivateKey) key, data); } /* * code for signing using JCA/JSSE methods only . Still needed ? @@ -694,14 +676,14 @@ public byte[] sign(PrivateKey key, byte[] data) throws CryptoException { } */ - private BigInteger[] preventMalleability(BigInteger[] sigs, BigInteger curve_n) { - BigInteger cmpVal = curve_n.divide(BigInteger.valueOf(2l)); + private BigInteger[] preventMalleability(BigInteger[] sigs, BigInteger curveN) { + BigInteger cmpVal = curveN.divide(BigInteger.valueOf(2L)); BigInteger sval = sigs[1]; if (sval.compareTo(cmpVal) == 1) { - sigs[1] = curve_n.subtract(sval); + sigs[1] = curveN.subtract(sval); } return sigs; @@ -864,9 +846,9 @@ public Properties getProperties() { return properties; } - public byte[] certificateToDER(String certricatePEM){ + public byte[] certificateToDER(String certricatePEM) { - try (final PemReader pemReader = new PemReader(new StringReader(certricatePEM))) { + try (PemReader pemReader = new PemReader(new StringReader(certricatePEM))) { final PemObject pemObject = pemReader.readPemObject(); return pemObject.getContent(); diff --git a/src/main/java/org/hyperledger/fabric/sdk/security/CryptoSuite.java b/src/main/java/org/hyperledger/fabric/sdk/security/CryptoSuite.java index b0a6ef53..c20c847a 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/security/CryptoSuite.java +++ b/src/main/java/org/hyperledger/fabric/sdk/security/CryptoSuite.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -13,9 +13,9 @@ */ package org.hyperledger.fabric.sdk.security; -import java.security.cert.Certificate; import java.security.KeyPair; import java.security.PrivateKey; +import java.security.cert.Certificate; import java.util.Collection; import java.util.Properties; @@ -24,36 +24,38 @@ /** * All packages for PKI key creation/signing/verification implement this interface - * */ public interface CryptoSuite { /** * implementation specific initialization. Whoever constructs a CryptoSuite instance MUST call * init before using the instance + * * @throws CryptoException * @throws InvalidArgumentException */ - public void init() throws CryptoException, InvalidArgumentException; + void init() throws CryptoException, InvalidArgumentException; /** * Pass in implementation specific properties to the CryptoSuite + * * @param properties A {@link java.util.Properties} object. The key/value pairs are implementation specific * @throws CryptoException * @throws InvalidArgumentException */ - public void setProperties(Properties properties) throws CryptoException, InvalidArgumentException; + void setProperties(Properties properties) throws CryptoException, InvalidArgumentException; /** * @return the {@link Properties} object containing implementation specific key generation properties */ - public Properties getProperties(); + Properties getProperties(); /** * Set the Certificate Authority certificates to be used when validating a certificate chain of trust - * @param CACertificates A collection of {@link java.security.cert.Certificate}s + * + * @param certificates A collection of {@link java.security.cert.Certificate}s * @throws CryptoException */ - public void loadCACertificates(Collection CACertificates) throws CryptoException; + void loadCACertificates(Collection certificates) throws CryptoException; /** * Set the Certificate Authority certificates to be used when validating a certificate chain of trust. @@ -61,49 +63,57 @@ public interface CryptoSuite { * @param certificates a collection of certificates in PEM format * @throws CryptoException */ - public void loadCACertificatesAsBytes(Collection certificates) throws CryptoException; + void loadCACertificatesAsBytes(Collection certificates) throws CryptoException; /** * Generate a key. + * * @return the generated key. * @throws CryptoException */ - public KeyPair keyGen() throws CryptoException; + KeyPair keyGen() throws CryptoException; /** * Sign the specified byte string. - * @param key the {@link java.security.PrivateKey} to be used for signing + * + * @param key the {@link java.security.PrivateKey} to be used for signing * @param plainText the byte string to sign * @return the signed data. * @throws CryptoException */ - public byte[] sign(PrivateKey key, byte[] plainText) throws CryptoException; + byte[] sign(PrivateKey key, byte[] plainText) throws CryptoException; /** * Verify the specified signature - * @param plainText the original text - * @param signature the signature to verify + * + * @param plainText the original text + * @param signature the signature to verify * @param certificate the certificate of the signer as the contents of the PEM file * @return {@code true} if the signature is successfully verified; otherwise {@code false}. * @throws CryptoException */ - public boolean verify(byte[] plainText, byte[] signature, byte[] certificate) throws CryptoException; + boolean verify(byte[] plainText, byte[] signature, byte[] certificate) throws CryptoException; /** * Hash the specified text byte data. + * * @param plainText the text to hash * @return the hashed data. */ - public byte[] hash(byte[] plainText); + byte[] hash(byte[] plainText); /** * The CryptoSuite factory. Currently {@link #getCryptoSuite} will always * give you a {@link CryptoPrimitives} object - * */ - public static class Factory { + + class Factory { + private Factory() { + + } + public static CryptoSuite getCryptoSuite() { - return new CryptoPrimitives() ; + return new CryptoPrimitives(); } /* TODO create a version of getCryptoSuite that allows pluggable implementations diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/CSCCProposalBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/CSCCProposalBuilder.java index ecd3602e..5a6cb6e8 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/CSCCProposalBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/CSCCProposalBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/InstallProposalBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/InstallProposalBuilder.java index bcf7856f..564a181f 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/InstallProposalBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/InstallProposalBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -37,7 +37,7 @@ public class InstallProposalBuilder extends LSCCProposalBuilder { - private final static Log logger = LogFactory.getLog(InstallProposalBuilder.class); + private static final Log logger = LogFactory.getLog(InstallProposalBuilder.class); private String chaincodePath; @@ -181,20 +181,6 @@ private void createNetModeTransaction() throws Exception { } - private void createDevModeTransaction() { - logger.debug("newDevModeTransaction"); - - ChaincodeDeploymentSpec depspec = createDeploymentSpec(Type.GOLANG, - chaincodeName, null, null, null, null); - - List argList = new ArrayList<>(); - argList.add(ByteString.copyFrom("install", StandardCharsets.UTF_8)); - argList.add(depspec.toByteString()); - - args(argList); - - } - public void setChaincodeLanguage(TransactionRequest.Type chaincodeLanguage) { this.chaincodeLanguage = chaincodeLanguage; } diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/InstantiateProposalBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/InstantiateProposalBuilder.java index da1c707e..7b2e0c05 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/InstantiateProposalBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/InstantiateProposalBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -26,7 +26,6 @@ import org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeDeploymentSpec; import org.hyperledger.fabric.protos.peer.FabricProposal; import org.hyperledger.fabric.sdk.ChaincodeEndorsementPolicy; -import org.hyperledger.fabric.sdk.TransactionRequest; import org.hyperledger.fabric.sdk.exception.InvalidArgumentException; import org.hyperledger.fabric.sdk.exception.ProposalException; @@ -34,14 +33,12 @@ public class InstantiateProposalBuilder extends LSCCProposalBuilder { - private final static Log logger = LogFactory.getLog(InstantiateProposalBuilder.class); + private static final Log logger = LogFactory.getLog(InstantiateProposalBuilder.class); private String chaincodePath; - private String chaincodeSource; private String chaincodeName; private List argList; - private TransactionRequest.Type chaincodeLanguage; private String chaincodeVersion; private byte[] chaincodePolicy = null; @@ -133,10 +130,6 @@ private void createNetModeTransaction() throws Exception { } - public void setChaincodeLanguage(TransactionRequest.Type chaincodeLanguage) { - this.chaincodeLanguage = chaincodeLanguage; - } - public void chaincodeVersion(String chaincodeVersion) { this.chaincodeVersion = chaincodeVersion; } diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/JoinPeerProposalBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/JoinPeerProposalBuilder.java index c7171d65..5fa3dc34 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/JoinPeerProposalBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/JoinPeerProposalBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,13 +23,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hyperledger.fabric.protos.common.Common.Block; -import org.hyperledger.fabric.protos.peer.Chaincode; -import org.hyperledger.fabric.protos.peer.FabricProposal; -import org.hyperledger.fabric.sdk.exception.CryptoException; import org.hyperledger.fabric.sdk.exception.ProposalException; -import static org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeSpec.Type.GOLANG; - public class JoinPeerProposalBuilder extends CSCCProposalBuilder { private static final Log logger = LogFactory.getLog(JoinPeerProposalBuilder.class); diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/LSCCProposalBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/LSCCProposalBuilder.java index a876e95b..d9a4bfd9 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/LSCCProposalBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/LSCCProposalBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/ProposalBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/ProposalBuilder.java index 822bff33..63e06776 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/ProposalBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/ProposalBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -44,12 +44,11 @@ public class ProposalBuilder { - private final static Log logger = LogFactory.getLog(ProposalBuilder.class); - private final static boolean isDebugLevel = logger.isDebugEnabled(); + private static final Log logger = LogFactory.getLog(ProposalBuilder.class); + private static final boolean IS_DEBUG_LEVEL = logger.isDebugEnabled(); private Chaincode.ChaincodeID chaincodeID; private List argList; - private List argBytesList; protected TransactionContext context; protected TransactionRequest request; protected ChaincodeSpec.Type ccType = ChaincodeSpec.Type.GOLANG; @@ -73,11 +72,6 @@ public ProposalBuilder args(List argList) { return this; } - public ProposalBuilder argBytes(List argBytesList) { - this.argBytesList = argBytesList; - return this; - } - public ProposalBuilder context(TransactionContext context) { this.context = context; if (null == channelID) { @@ -120,8 +114,7 @@ private FabricProposal.Proposal createFabricProposal(String channelID, Chaincode transientMap = Collections.emptyMap(); } - if (isDebugLevel) { - + if (IS_DEBUG_LEVEL) { for (Entry tme : transientMap.entrySet()) { logger.debug(format("transientMap('%s', '%s'))", logString(tme.getKey()), logString(new String(tme.getValue(), UTF_8)))); @@ -191,7 +184,7 @@ private ChaincodeInvocationSpec createChaincodeInvocationSpec(Chaincode.Chaincod } } - if (isDebugLevel) { + if (IS_DEBUG_LEVEL) { StringBuilder logout = new StringBuilder(1000); diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/ProtoUtils.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/ProtoUtils.java index 53b40c7f..5904af2c 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/ProtoUtils.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/ProtoUtils.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -43,17 +43,17 @@ public final class ProtoUtils { - private final static Log logger = LogFactory.getLog(ProtoUtils.class); - private final static boolean isDebugLevel = logger.isDebugEnabled(); + private static final Log logger = LogFactory.getLog(ProtoUtils.class); + private static final boolean isDebugLevel = logger.isDebugEnabled(); /** * createChannelHeader create chainHeader * - * @param type header type. See {@link ChannelHeader.Builder#setType}. - * @param txID transaction ID. See {@link ChannelHeader.Builder#setTxId}. - * @param channelID channel ID. See {@link ChannelHeader.Builder#setChannelId}. - * @param epoch the epoch in which this header was generated. See {@link ChannelHeader.Builder#setEpoch}. - * @param timeStamp local time when the message was created. See {@link ChannelHeader.Builder#setTimestamp}. + * @param type header type. See {@link ChannelHeader.Builder#setType}. + * @param txID transaction ID. See {@link ChannelHeader.Builder#setTxId}. + * @param channelID channel ID. See {@link ChannelHeader.Builder#setChannelId}. + * @param epoch the epoch in which this header was generated. See {@link ChannelHeader.Builder#setEpoch}. + * @param timeStamp local time when the message was created. See {@link ChannelHeader.Builder#setTimestamp}. * @param chaincodeHeaderExtension extension to attach dependent on the header type. See {@link ChannelHeader.Builder#setExtension}. * @return a new chain header. */ @@ -187,7 +187,7 @@ public static ByteString getSignatureHeaderAsByteString(User user, TransactionCo if (isDebugLevel) { String cert = user.getEnrollment().getCert(); - // logger.debug(format(" User: %s Certificate:\n%s", user.getName(), cert)); + // logger.debug(format(" User: %s Certificate:\n%s", user.getName(), cert)); if (null == suite) { @@ -229,7 +229,7 @@ public static Identities.SerializedIdentity createSerializedIdentity(User user) return Identities.SerializedIdentity.newBuilder() .setIdBytes(ByteString.copyFromUtf8(user.getEnrollment().getCert())) - .setMspid(user.getMSPID()).build(); + .setMspid(user.getMspId()).build(); } public static Timestamp getCurrentFabricTimestamp() { @@ -250,6 +250,7 @@ public static Date getDateFromTimestamp(Timestamp timestamp) { /** * Private constructor to prevent instantiation. */ - private ProtoUtils() { } + private ProtoUtils() { + } } diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryInstalledChaincodesBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryInstalledChaincodesBuilder.java index b256ce4c..acd31400 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryInstalledChaincodesBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryInstalledChaincodesBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,25 +14,19 @@ package org.hyperledger.fabric.sdk.transaction; - import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import com.google.protobuf.ByteString; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; public class QueryInstalledChaincodesBuilder extends LSCCProposalBuilder { - private static final Log logger = LogFactory.getLog(QueryInstalledChaincodesBuilder.class); - +// private static final Log logger = LogFactory.getLog(QueryInstalledChaincodesBuilder.class); private QueryInstalledChaincodesBuilder() { - List argList = new ArrayList<>(); argList.add(ByteString.copyFrom("getinstalledchaincodes", StandardCharsets.UTF_8)); args(argList); - } @Override @@ -45,6 +39,4 @@ public static QueryInstalledChaincodesBuilder newBuilder() { return new QueryInstalledChaincodesBuilder(); } - } - diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryInstantiatedChaincodesBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryInstantiatedChaincodesBuilder.java index 2abceed3..e5b789c7 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryInstantiatedChaincodesBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryInstantiatedChaincodesBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryPeerChannelsBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryPeerChannelsBuilder.java index 29615940..f0851323 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryPeerChannelsBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/QueryPeerChannelsBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,7 +14,6 @@ package org.hyperledger.fabric.sdk.transaction; - import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -41,6 +40,5 @@ public static QueryPeerChannelsBuilder newBuilder() { return new QueryPeerChannelsBuilder(); } - } diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/TransactionBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/TransactionBuilder.java index a71dd44a..fc6cebe4 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/TransactionBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/TransactionBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -29,7 +29,7 @@ public class TransactionBuilder { - private final static Log logger = LogFactory.getLog(TransactionBuilder.class); + private static final Log logger = LogFactory.getLog(TransactionBuilder.class); Config config = Config.getConfig(); private FabricProposal.Proposal chaincodeProposal; private Collection endorsements; @@ -54,18 +54,15 @@ public TransactionBuilder proposalResponsePayload(ByteString proposalResponsePay return this; } - public Common.Payload build() throws InvalidProtocolBufferException { return createTransactionCommonPayload(chaincodeProposal, proposalResponsePayload, endorsements); } - - private Common.Payload createTransactionCommonPayload(FabricProposal.Proposal chaincodeProposal, ByteString proposalResponsePayload, + private Common.Payload createTransactionCommonPayload(FabricProposal.Proposal chaincodeProposal, ByteString proposalResponsePayload, Collection endorsements) throws InvalidProtocolBufferException { - FabricTransaction.ChaincodeEndorsedAction.Builder chaincodeEndorsedActionBuilder = FabricTransaction.ChaincodeEndorsedAction.newBuilder(); chaincodeEndorsedActionBuilder.setProposalResponsePayload(proposalResponsePayload); chaincodeEndorsedActionBuilder.addAllEndorsements(endorsements); @@ -90,12 +87,11 @@ private Common.Payload createTransactionCommonPayload(FabricProposal.Proposal ch logger.trace("transaction header sig bytes:" + Arrays.toString(header.getSignatureHeader().toByteArray())); } - transactionActionBuilder.setHeader(header.getSignatureHeader()); FabricTransaction.ChaincodeActionPayload chaincodeActionPayload = chaincodeActionPayloadBuilder.build(); if (config.extraLogLevel(10)) { - logger.trace("transactionActionBuilder.setPayload" + Arrays.toString(chaincodeActionPayload.toByteString().toByteArray())); + logger.trace("transactionActionBuilder.setPayload" + Arrays.toString(chaincodeActionPayload.toByteString().toByteArray())); } transactionActionBuilder.setPayload(chaincodeActionPayload.toByteString()); @@ -103,14 +99,12 @@ private Common.Payload createTransactionCommonPayload(FabricProposal.Proposal ch FabricTransaction.Transaction.Builder transactionBuilder = FabricTransaction.Transaction.newBuilder(); transactionBuilder.addActions(transactionActionBuilder.build()); - Common.Payload.Builder payload = Common.Payload.newBuilder(); payload.setHeader(header); payload.setData(transactionBuilder.build().toByteString()); return payload.build(); - } } diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/TransactionContext.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/TransactionContext.java index d990c60b..3c6c65ca 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/TransactionContext.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/TransactionContext.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,13 +14,10 @@ package org.hyperledger.fabric.sdk.transaction; -import java.nio.Buffer; import java.util.List; import com.google.protobuf.ByteString; import com.google.protobuf.Timestamp; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1EncodableVector; import org.bouncycastle.asn1.ASN1Primitive; @@ -41,7 +38,7 @@ */ public class TransactionContext { private static final Config config = Config.getConfig(); - private static final Log logger = LogFactory.getLog(TransactionContext.class); +// private static final Log logger = LogFactory.getLog(TransactionContext.class); //TODO right now the server does not care need to figure out private final ByteString nonce = ByteString.copyFrom(Utils.generateNonce()); @@ -146,19 +143,6 @@ public void setProposalWaitTime(long proposalWaitTime) { this.proposalWaitTime = proposalWaitTime; } - private void decryptResult(Buffer ct) { - /* TODO implement decryptResult function - let key = new Buffer( - this.channel.cryptoPrimitives.hmacAESTruncated( - this.user.getEnrollment().queryStateKey, - [CONFIDENTIALITY_1_2_STATE_KD_C6].concat(this.nonce)) - ); - - logger.debug("Decrypt Result [%s]", ct.toString("hex")); - return this.channel.cryptoPrimitives.aes256GCMDecrypt(key, ct); - */ - } - Timestamp currentTimeStamp = null; public Timestamp getFabricTimestamp() { @@ -183,12 +167,6 @@ public boolean getVerify() { return verify; } - private static class SerializedIdentity { - String Mspid; - byte[] IdBytes; - - } - /* Implementation of an example ASN .1 structure. * < pre > *MyStructure:: = SEQUENCE { *version INTEGER DEFAULT 0, *created GeneralizedTime, *baseData OCTET STRING, *extraData[0] UTF8String OPTIONAL, *commentData[1] UTF8String OPTIONAL @@ -217,7 +195,7 @@ public ASN1Primitive toASN1Primitive() { } String getMSPID() { - return user.getMSPID(); + return user.getMspId(); } String getCreator() { diff --git a/src/main/java/org/hyperledger/fabric/sdk/transaction/UpgradeProposalBuilder.java b/src/main/java/org/hyperledger/fabric/sdk/transaction/UpgradeProposalBuilder.java index 34637c38..e57d4356 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/transaction/UpgradeProposalBuilder.java +++ b/src/main/java/org/hyperledger/fabric/sdk/transaction/UpgradeProposalBuilder.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,14 +14,10 @@ package org.hyperledger.fabric.sdk.transaction; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - - public class UpgradeProposalBuilder extends InstantiateProposalBuilder { - private final static Log logger = LogFactory.getLog(UpgradeProposalBuilder.class); +// private final static Log logger = LogFactory.getLog(UpgradeProposalBuilder.class); private UpgradeProposalBuilder() { diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/Attribute.java b/src/main/java/org/hyperledger/fabric_ca/sdk/Attribute.java index 539d9cf6..7ff5956d 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/Attribute.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/Attribute.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,27 +20,27 @@ // An attribute name and value which is used when registering a new user public class Attribute { - private String name; - private String value; - - public Attribute(String name, String value) { - this.name = name; - this.value = value; - } - - public String getName() { - return this.name; - } - - public String getValue() { - return this.value; - } - - public JsonObject toJsonObject() { - JsonObjectBuilder ob = Json.createObjectBuilder(); - ob.add("name", this.name); - ob.add("value", this.value); - return ob.build(); - } + private String name; + private String value; + + public Attribute(String name, String value) { + this.name = name; + this.value = value; + } + + public String getName() { + return this.name; + } + + public String getValue() { + return this.value; + } + + public JsonObject toJsonObject() { + JsonObjectBuilder ob = Json.createObjectBuilder(); + ob.add("name", this.name); + ob.add("value", this.value); + return ob.build(); + } } diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java b/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java index 7f6cd90d..b1177ba0 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -34,13 +34,8 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Base64; -import java.util.Collections; -import java.util.HashSet; import java.util.Properties; -import java.util.Set; import javax.json.Json; import javax.json.JsonArray; @@ -98,6 +93,7 @@ /** * HFCAClient Hyperledger Fabric Certificate Authority Client. */ +@SuppressWarnings ("deprecation") public class HFCAClient { private static final Log logger = LogFactory.getLog(HFCAClient.class); Config config = Config.getConfig(); //Load config so enable logging setting. @@ -108,11 +104,6 @@ public class HFCAClient { private static final String HFCA_REVOKE = HFCA_CONTEXT_ROOT + "revoke"; static final String FABRIC_CA_REQPROP = "caname"; - private static final int DEFAULT_SECURITY_LEVEL = 256; //TODO make configurable //Right now by default FAB services is using - private static final String DEFAULT_HASH_ALGORITHM = "SHA2"; //Right now by default FAB services is using SHA2 - - private static final Set VALID_KEY_SIZES = - Collections.unmodifiableSet(new HashSet<>(Arrays.asList(256, 384))); private final String url; private final boolean isSSL; @@ -211,10 +202,10 @@ public CryptoSuite getCryptoSuite() { /** * Register a user. * - * @param request Registration request with the following fields: name, role. + * @param request Registration request with the following fields: name, role. * @param registrar The identity of the registrar (i.e. who is performing the registration). * @return the enrollment secret. - * @throws RegistrationException if registration fails. + * @throws RegistrationException if registration fails. * @throws InvalidArgumentException */ @@ -631,8 +622,8 @@ private JsonObject httpPost(String url, String body, String authHTTPCert) throws boolean success = jobj.getBoolean("success"); if (!success) { EnrollmentException e = new EnrollmentException( - format("POST request to %s failed request body %s Body of response did not contain success", url, body) - , new Exception()); + format("POST request to %s failed request body %s Body of response did not contain success", url, body), + new Exception()); logger.error(e.getMessage()); throw e; } @@ -664,36 +655,6 @@ private String getHTTPAuthCertificate(Enrollment enrollment, String body) throws return cert + "." + b64.encodeToString(signature); } - /* - * Convert a list of member type names to the role mask currently used by the peer - */ - private int rolesToMask(ArrayList roles) { - int mask = 0; - if (roles != null) { - for (String role : roles) { - switch (role) { - case "client": - mask |= 1; - break; // Client mask - case "peer": - mask |= 2; - break; // Peer mask - case "validator": - mask |= 4; - break; // Validator mask - case "auditor": - mask |= 8; - break; // Auditor mask - } - } - } - - if (mask == 0) { - mask = 1; // Client - } - return mask; - } - private Registry registry = null; private void setUpSSL() throws InvalidArgumentException { diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAEnrollment.java b/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAEnrollment.java index 40515164..24ac7dca 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAEnrollment.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAEnrollment.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/RegistrationRequest.java b/src/main/java/org/hyperledger/fabric_ca/sdk/RegistrationRequest.java index 1213930d..42b33666 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/RegistrationRequest.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/RegistrationRequest.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/RevocationRequest.java b/src/main/java/org/hyperledger/fabric_ca/sdk/RevocationRequest.java index 1213881f..96071b75 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/RevocationRequest.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/RevocationRequest.java @@ -110,8 +110,8 @@ private JsonObject toJsonObject() { factory.add("reason", reason); } - if(caName != null){ - factory.add( HFCAClient.FABRIC_CA_REQPROP, caName); + if (caName != null) { + factory.add(HFCAClient.FABRIC_CA_REQPROP, caName); } factory.add("reason", reason); return factory.build(); diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/BaseException.java b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/BaseException.java index ac3a75bb..d963984f 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/BaseException.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/BaseException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/EnrollmentException.java b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/EnrollmentException.java index 2480a0a8..7ccdcbbd 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/EnrollmentException.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/EnrollmentException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/InvalidArgumentException.java b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/InvalidArgumentException.java index 6e333a3a..6e01caf0 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/InvalidArgumentException.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/InvalidArgumentException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/RegistrationException.java b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/RegistrationException.java index 6f749725..dd156f9d 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/RegistrationException.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/RegistrationException.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/RevocationException.java b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/RevocationException.java index a5924bb6..0e7bbac2 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/exception/RevocationException.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/exception/RevocationException.java @@ -2,7 +2,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/helper/Config.java b/src/main/java/org/hyperledger/fabric_ca/sdk/helper/Config.java index d6060ac9..9f1df22b 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/helper/Config.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/helper/Config.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -54,7 +54,7 @@ public class Config { public static final String LOGGERLEVEL = "org.hyperledger.fabric_ca.sdk.loglevel"; // ORG_HYPERLEDGER_FABRIC_CA_SDK_LOGLEVEL=TRACE,DEBUG private static Config config; - private final static Properties sdkProperties = new Properties(); + private static final Properties sdkProperties = new Properties(); private Config() { File loadFile; @@ -121,10 +121,14 @@ private Config() { setTo = Level.ERROR; break; + default: + setTo = Level.INFO; + break; + } if (null != setTo) { - org.apache.log4j.Logger.getLogger("org.hyperledger.fabric_ca").setLevel(setTo); + org.apache.log4j.Logger.getLogger("org.hyperledger.fabric_ca").setLevel(setTo); } } @@ -162,8 +166,7 @@ private String getProperty(String property) { return ret; } - static private void defaultProperty(String key, String value) { - + private static void defaultProperty(String key, String value) { String ret = System.getProperty(key); if (ret != null) { diff --git a/src/test/java/org/hyperledger/fabric/sdk/BlockEventTest.java b/src/test/java/org/hyperledger/fabric/sdk/BlockEventTest.java index 1a6c2794..980a75fa 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/BlockEventTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/BlockEventTest.java @@ -139,9 +139,6 @@ public static void setUpBeforeClass() throws Exception { badEventBlock = PeerEvents.Event.newBuilder().setBlock(badBlock).build(); } - /** - * Test method for {@link org.hyperledger.fabric.sdk.BlockEvent#BlockEvent(EventHub, PeerEvents.Event)}. - */ @Test public void testBlockEvent() { try { @@ -160,12 +157,7 @@ public void testBlockEvent() { } } - /** - * Test method for {@link org.hyperledger.fabric.sdk.BlockEvent#BlockEvent(EventHub, PeerEvents.Event)}. - * With bad block inputted, BlockEvent ctor will throw an exception - * - * @throws InvalidProtocolBufferException - */ + // Bad block input causes constructor to throw exception @Test (expected = InvalidProtocolBufferException.class) public void testBlockEventBadBlock() throws InvalidProtocolBufferException { BlockEvent be = new BlockEvent(eventHub, badEventBlock); diff --git a/src/test/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicyTest.java b/src/test/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicyTest.java index efa6b196..9bb3a721 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicyTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicyTest.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -88,8 +88,9 @@ public void testPolicyCtorByteArray() { /** * Test method for {@link ChaincodeEndorsementPolicy#fromYamlFile(File)} + * @throws IOException + * @throws ChaincodeEndorsementPolicyParseException */ - @Test public void testSDKIntegrationYaml() throws IOException, ChaincodeEndorsementPolicyParseException { @@ -115,16 +116,8 @@ public void testSDKIntegrationYaml() throws IOException, ChaincodeEndorsementPol Policies.SignaturePolicy rule = sigPolEnv.getRule(); TypeCase typeCase = rule.getTypeCase(); assertEquals(TypeCase.N_OUT_OF.getNumber(), typeCase.getNumber()); - - } - /** - * Test method for {@link ChaincodeEndorsementPolicy#fromYamlFile(File)} - * - * @throws ChaincodeEndorsementPolicyParseException - */ - @Test public void testBadYaml() throws IOException, ChaincodeEndorsementPolicyParseException { diff --git a/src/test/java/org/hyperledger/fabric/sdk/ChannelTest.java b/src/test/java/org/hyperledger/fabric/sdk/ChannelTest.java index 1ab3428f..bf5385c6 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/ChannelTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/ChannelTest.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +20,6 @@ import org.junit.Test; public class ChannelTest { - private static final String CHANNEL_NAME = "channel1"; static HFClient hfclient = null; @@ -44,9 +43,9 @@ public void testChannelCreation() { try { - final String CHANNEL_NAME = "channel3"; - Channel testchannel = new Channel(CHANNEL_NAME, hfclient); - Assert.assertEquals(CHANNEL_NAME, testchannel.getName()); + final String channelNamre = "channel3"; + Channel testchannel = new Channel(channelNamre, hfclient); + Assert.assertEquals(channelNamre, testchannel.getName()); Assert.assertEquals(testchannel.client, hfclient); Assert.assertEquals(testchannel.getOrderers().size(), 0); Assert.assertEquals(testchannel.getPeers().size(), 0); @@ -64,9 +63,9 @@ public void testChannelAddPeer() { try { - final String CHANNEL_NAME = "channel3"; - final Channel testchannel = new Channel(CHANNEL_NAME, hfclient); - final Peer peer = hfclient.newPeer("peer_" , "grpc://localhost:7051"); + final String channelName = "channel3"; + final Channel testchannel = new Channel(channelName, hfclient); + final Peer peer = hfclient.newPeer("peer_", "grpc://localhost:7051"); testchannel.addPeer(peer); @@ -85,8 +84,8 @@ public void testChannelAddOrder() { try { - final String CHANNEL_NAME = "channel3"; - final Channel testChannel = new Channel(CHANNEL_NAME, hfclient); + final String channelName = "channel3"; + final Channel testChannel = new Channel(channelName, hfclient); final Orderer orderer = hfclient.newOrderer("testorder", "grpc://localhost:7051"); testChannel.addOrderer(orderer); @@ -107,8 +106,8 @@ public void testChannelAddNullPeer() { try { - final String CHANNEL_NAME = "channel3"; - testChannel = new Channel(CHANNEL_NAME, hfclient); + final String channelName = "channel3"; + testChannel = new Channel(channelName, hfclient); testChannel.addPeer(null); @@ -128,9 +127,9 @@ public void testChannelAddNoNamePeer() { try { - final String CHANNEL_NAME = "channel3"; - testChannel = new Channel(CHANNEL_NAME, hfclient); - final Peer peer = hfclient.newPeer(null , "grpc://localhost:7051"); + final String channelName = "channel3"; + testChannel = new Channel(channelName, hfclient); + final Peer peer = hfclient.newPeer(null, "grpc://localhost:7051"); testChannel.addPeer(peer); Assert.fail("Expected no named peer to throw exception."); @@ -149,8 +148,8 @@ public void testChannelAddNullOrder() { try { - final String CHANNEL_NAME = "channel3"; - testChannel = new Channel(CHANNEL_NAME, hfclient); + final String channelName = "channel3"; + testChannel = new Channel(channelName, hfclient); testChannel.addOrderer(null); @@ -175,14 +174,14 @@ class MockChannel extends Channel { } @Override - protected void parseConfigBlock(){ + protected void parseConfigBlock() { } } - final String CHANNEL_NAME = "channel3"; - final Channel testChannel = new MockChannel(CHANNEL_NAME, hfclient); - final Peer peer = hfclient.newPeer("peer_" , "grpc://localhost:7051"); + final String channelName = "channel3"; + final Channel testChannel = new MockChannel(channelName, hfclient); + final Peer peer = hfclient.newPeer("peer_", "grpc://localhost:7051"); testChannel.addPeer(peer); Assert.assertEquals(testChannel.isInitialized(), false); @@ -202,8 +201,8 @@ public void testChannelInitializeNoPeer() { try { - final String CHANNEL_NAME = "channel3"; - testChannel = new Channel(CHANNEL_NAME, hfclient); + final String channelName = "channel3"; + testChannel = new Channel(channelName, hfclient); Assert.assertEquals(testChannel.isInitialized(), false); testChannel.initialize(); diff --git a/src/test/java/org/hyperledger/fabric/sdk/ClientTest.java b/src/test/java/org/hyperledger/fabric/sdk/ClientTest.java index 963dc354..a1963ab4 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/ClientTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/ClientTest.java @@ -47,21 +47,16 @@ public void testNewChannel() { } } - @Test - public void testSetNullChannel() { - try { - Channel testChannel = hfclient.newChannel(null); - Assert.fail("Expected null channel to throw exception."); - - } catch (Exception e) { - Assert.assertTrue( e.getClass() == InvalidArgumentException.class); - } - } + @Test (expected = InvalidArgumentException.class) + public void testSetNullChannel() throws InvalidArgumentException { + hfclient.newChannel(null); + Assert.fail("Expected null channel to throw exception."); + } @Test public void testNewPeer() { try { - Peer peer = hfclient.newPeer("peer_" , "grpc://localhost:7051"); + Peer peer = hfclient.newPeer("peer_", "grpc://localhost:7051"); Assert.assertTrue(peer != null); } catch (Exception e) { e.printStackTrace(); @@ -69,35 +64,27 @@ public void testNewPeer() { } } - @Test - public void testBadURL() { - try { - Peer peer = hfclient.newPeer("peer_", " "); - Assert.fail("Expected peer with no channel throw exception"); - } catch (Exception e) { - Assert.assertTrue( e.getClass() == InvalidArgumentException.class); - } - } + @Test(expected = InvalidArgumentException.class) + public void testBadURL() throws InvalidArgumentException { + hfclient.newPeer("peer_", " "); + Assert.fail("Expected peer with no channel throw exception"); + } @Test public void testNewOrderer() { - try { + try { Orderer orderer = hfclient.newOrderer("xx", "grpc://localhost:5005"); Assert.assertTrue(orderer != null); - } catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); Assert.fail("Unexpected Exception " + e.getMessage()); } } - @Test - public void testBadAddress() { - try { - Orderer orderer= hfclient.newOrderer("xx","xxxxxx"); - Assert.fail("Orderer did not allow setting bad URL."); - } catch (Exception e) { - Assert.assertTrue( e.getClass() == InvalidArgumentException.class); - } + @Test (expected = InvalidArgumentException.class) + public void testBadAddress() throws InvalidArgumentException { + hfclient.newOrderer("xx", "xxxxxx"); + Assert.fail("Orderer allowed setting bad URL."); } } diff --git a/src/test/java/org/hyperledger/fabric/sdk/EndpointTest.java b/src/test/java/org/hyperledger/fabric/sdk/EndpointTest.java index c1530bf0..bb2734f4 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/EndpointTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/EndpointTest.java @@ -16,47 +16,44 @@ import org.junit.Assert; import org.junit.Test; -import org.junit.Ignore; -//@Ignore public class EndpointTest { - @Test - public void testEndpointNonPEM() { - Endpoint ep = new Endpoint("grpc://localhost:524", null); - Assert.assertEquals("localhost", ep.getHost()); - Assert.assertEquals(524, ep.getPort()); - - ep = new Endpoint( "grpcs://localhost:524", null); - Assert.assertEquals("localhost", ep.getHost()); - - try { - ep = new Endpoint("grpcs2://localhost:524",null); - Assert.fail("protocol grpcs2 should have been invalid"); - } catch(RuntimeException rex) { - Assert.assertEquals("Invalid protocol expected grpc or grpcs and found grpcs2.", rex.getMessage()); - } - - try { - ep = new Endpoint("grpcs://localhost", null); - Assert.fail("should have thrown error as there is no port in the url"); - } catch(RuntimeException rex) { - Assert.assertEquals("URL must be of the format protocol://host:port", rex.getMessage()); - } - - try { - ep = new Endpoint("", null); - Assert.fail("should have thrown error as url is empty"); - } catch(RuntimeException rex) { - Assert.assertEquals("URL cannot be null or empty", rex.getMessage()); - } - - try { - ep = new Endpoint(null, null); - Assert.fail("should have thrown error as url is empty"); - } catch(RuntimeException rex) { - Assert.assertEquals("URL cannot be null or empty", rex.getMessage()); - } - } - + @Test + public void testEndpointNonPEM() { + Endpoint ep = new Endpoint("grpc://localhost:524", null); + Assert.assertEquals("localhost", ep.getHost()); + Assert.assertEquals(524, ep.getPort()); + + ep = new Endpoint("grpcs://localhost:524", null); + Assert.assertEquals("localhost", ep.getHost()); + + try { + ep = new Endpoint("grpcs2://localhost:524", null); + Assert.fail("protocol grpcs2 should have been invalid"); + } catch (RuntimeException rex) { + Assert.assertEquals("Invalid protocol expected grpc or grpcs and found grpcs2.", rex.getMessage()); + } + + try { + ep = new Endpoint("grpcs://localhost", null); + Assert.fail("should have thrown error as there is no port in the url"); + } catch (RuntimeException rex) { + Assert.assertEquals("URL must be of the format protocol://host:port", rex.getMessage()); + } + + try { + ep = new Endpoint("", null); + Assert.fail("should have thrown error as url is empty"); + } catch (RuntimeException rex) { + Assert.assertEquals("URL cannot be null or empty", rex.getMessage()); + } + + try { + ep = new Endpoint(null, null); + Assert.fail("should have thrown error as url is empty"); + } catch (RuntimeException rex) { + Assert.assertEquals("URL cannot be null or empty", rex.getMessage()); + } + } } diff --git a/src/test/java/org/hyperledger/fabric/sdk/OrdererTest.java b/src/test/java/org/hyperledger/fabric/sdk/OrdererTest.java index c79bd04d..b5d963c9 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/OrdererTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/OrdererTest.java @@ -16,110 +16,85 @@ import java.io.File; -import org.hyperledger.fabric.protos.orderer.Ab; import org.hyperledger.fabric.sdk.exception.InvalidArgumentException; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -public class OrdererTest { - private static final String CHANNEL_NAME = "channel1"; - static HFClient hfclient = null; - static Orderer orderer = null; - static File tempFile; - - @BeforeClass - public static void setupClient() throws Exception { - - - try { - //hfclient = HFClient.createNewInstance(); - hfclient = TestHFClient.newInstance(); - orderer= hfclient.newOrderer("myorder", "grpc://localhost:5151"); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail("Unexpected Exception " + e.getMessage()); - } - } - - @Test - public void testSetChannel() { - try { - Channel channel = hfclient.newChannel("channel"); - orderer.setChannel(channel); - Assert.assertTrue(channel == orderer.getChannel()); - } catch (Exception e) { - Assert.fail("Unexpected Exception " + e.getMessage()); - } +public class OrdererTest { + static HFClient hfclient = null; + static Orderer orderer = null; + static File tempFile; + + @BeforeClass + public static void setupClient() throws Exception { + hfclient = TestHFClient.newInstance(); + orderer = hfclient.newOrderer("myorder", "grpc://localhost:5151"); + } + + @AfterClass + public static void cleanUp() { + if (tempFile != null) { + tempFile.delete(); + tempFile = null; } + } - @Test - public void testSetNullChannel() { - - try { + @Test + public void testSetChannel() { - orderer.setChannel(null); - Assert.fail("Expected null channel to throw exception."); + try { + Channel channel = hfclient.newChannel("channel"); + orderer.setChannel(channel); + Assert.assertTrue(channel == orderer.getChannel()); - } catch (Exception e) { - Assert.assertTrue( e.getClass() == InvalidArgumentException.class); - } - } - - @Test - public void testBadAddress() { - try { - orderer= hfclient.newOrderer("badorderer", "xxxxxx"); - Assert.fail("Orderer did not allow setting bad URL."); - } catch (Exception e) { - Assert.assertTrue( e.getClass() == InvalidArgumentException.class); - } - } - @Test - public void testMissingAddress() { - try { - orderer= hfclient.newOrderer("badaddress", ""); - Assert.fail("Orderer did not allow setting a missing address."); - } catch (Exception e) { - Assert.assertTrue( e.getClass() == InvalidArgumentException.class); - } - } - @Ignore - public void testGetChannel() { - try { - Channel channel = hfclient.newChannel("channel"); - orderer = hfclient.newOrderer("odererName", "grpc://localhost:5151"); - channel.addOrderer(orderer); - } catch (Exception e) { - Assert.fail("Unexpected Exception " + e.getMessage()); - } - Assert.assertTrue("Test passed - ", orderer.getChannel().getName().equalsIgnoreCase("channel")); + } catch (Exception e) { + Assert.fail("Unexpected Exception " + e.getMessage()); } - @Test(expected=AssertionError.class) - public void testBroadcast() { - try { - orderer = hfclient.newOrderer("orderertest", "grpc://localhost:5151"); - } catch (Exception e) { - e.printStackTrace(); - } - try { - Ab.BroadcastResponse resp = orderer.sendTransaction(null); - Assert.fail("Transaction should not be null."); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail("Expected null channel to throw exception."); - } + } + + @Test(expected = InvalidArgumentException.class) + public void testSetNullChannel() throws InvalidArgumentException { + orderer.setChannel(null); + Assert.fail("Expected null channel to throw exception."); + } + + @Test(expected = InvalidArgumentException.class) + public void testBadAddress() throws InvalidArgumentException { + orderer = hfclient.newOrderer("badorderer", "xxxxxx"); + Assert.fail("Orderer did not allow setting bad URL."); + } + + @Test(expected = InvalidArgumentException.class) + public void testMissingAddress() throws InvalidArgumentException { + orderer = hfclient.newOrderer("badaddress", ""); + Assert.fail("Orderer did not allow setting a missing address."); + } + + @Ignore + public void testGetChannel() { + try { + Channel channel = hfclient.newChannel("channel"); + orderer = hfclient.newOrderer("odererName", "grpc://localhost:5151"); + channel.addOrderer(orderer); + } catch (Exception e) { + Assert.fail("Unexpected Exception " + e.getMessage()); } - @Override - protected void finalize() throws Throwable { - super.finalize(); - if( tempFile != null){ - tempFile.delete(); - tempFile = null; - - } + Assert.assertTrue("Test passed - ", orderer.getChannel().getName().equalsIgnoreCase("channel")); + } + + @Test(expected = Exception.class) + public void testSendNullTransactionThrowsException() throws Exception { + try { + orderer = hfclient.newOrderer("orderertest", "grpc://localhost:5151"); + } catch (InvalidArgumentException e) { + Assert.fail("Failed to create new orderer: " + e); } + orderer.sendTransaction(null); + Assert.fail("Transaction should not be null."); + } } diff --git a/src/test/java/org/hyperledger/fabric/sdk/PeerTest.java b/src/test/java/org/hyperledger/fabric/sdk/PeerTest.java index 50b66909..b54d9815 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/PeerTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/PeerTest.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,112 +21,68 @@ import org.junit.BeforeClass; import org.junit.Test; -//import org.hyperledger.fabric.protos.peer.FabricProposal; - public class PeerTest { - private static final String CHANNEL_NAME = "channel1"; - static HFClient hfclient = null; - static Peer peer = null; - + static HFClient hfclient = null; + static Peer peer = null; - @BeforeClass - public static void setupClient() { + @BeforeClass + public static void setupClient() { try { - hfclient = TestHFClient.newInstance(); - - peer= hfclient.newPeer("peer_" , "grpc://localhost:7051"); + hfclient = TestHFClient.newInstance(); + peer = hfclient.newPeer("peer_", "grpc://localhost:7051"); } catch (Exception e) { e.printStackTrace(); Assert.fail("Unexpected Exception " + e.getMessage()); - } } - @Test - public void testgetName() { - final String PEER_NAME = "peertest"; - - - Assert.assertTrue(peer != null); - try { - peer =new Peer(PEER_NAME, "grpc://localhost:4", null); - - Assert.assertEquals(PEER_NAME,peer.getName()); - } catch (InvalidArgumentException e) { - Assert.fail("Unexpected Exeception " + e.getMessage()); - } - - } - @Test - public void testSetNullName() { - - try { - peer =new Peer(null, "grpc://localhost:4", null); - Assert.fail("expected set null name to throw exception."); - } catch (Exception e) { - Assert.assertTrue( e.getClass() == InvalidArgumentException.class); - } - } - @Test - public void testSetEmptyName() { - - try { - peer =new Peer("", "grpc://localhost:4", null); - Assert.fail("expected set empty name to throw exception."); - } catch (Exception e) { - Assert.assertTrue( e.getClass() == InvalidArgumentException.class); - } - } - - - - @Test - public void testSendNullProposal() { - - try { - - peer.sendProposal(null); - Assert.fail("Expected null proposal to throw exception."); - - } catch (Exception e) { - Assert.assertTrue( e.getClass() == PeerException.class); - } - } - @Test - public void testSendNullChannel() { - - try { - - Peer badpeer = hfclient.newPeer("badpeer", "grpc://localhost:7051"); - - - badpeer.sendProposal(FabricProposal.SignedProposal.newBuilder().build()); - Assert.fail("Expected peer with no channel throw exception"); - - } catch (Exception e) { - Assert.assertTrue( e.getClass() == PeerException.class); - } - } - - @Test(expected = PeerException.class) - public void testSendAsyncNullProposal() throws Exception { - peer.sendProposalAsync(null); - } + @Test + public void testGetName() { + final String peerName = "peertest"; + Assert.assertTrue(peer != null); + try { + peer = new Peer(peerName, "grpc://localhost:4", null); + Assert.assertEquals(peerName, peer.getName()); + } catch (InvalidArgumentException e) { + Assert.fail("Unexpected Exeception " + e.getMessage()); + } + } - @Test - public void testBadURL() { + @Test(expected = InvalidArgumentException.class) + public void testSetNullName() throws InvalidArgumentException { + peer = new Peer(null, "grpc://localhost:4", null); + Assert.fail("expected set null name to throw exception."); + } - try { + @Test(expected = InvalidArgumentException.class) + public void testSetEmptyName() throws InvalidArgumentException { + peer = new Peer("", "grpc://localhost:4", null); + Assert.fail("expected set empty name to throw exception."); + } - hfclient.newPeer("peer_", " "); + @Test(expected = PeerException.class) + public void testSendNullProposal() throws PeerException, InvalidArgumentException { + peer.sendProposal(null); + Assert.fail("Expected null proposal to throw exception."); + } - Assert.fail("Expected peer with no channel throw exception"); + @Test(expected = PeerException.class) + public void testSendNullChannel() throws InvalidArgumentException, PeerException { + Peer badpeer = hfclient.newPeer("badpeer", "grpc://localhost:7051"); + badpeer.sendProposal(FabricProposal.SignedProposal.newBuilder().build()); + Assert.fail("Expected peer with no channel throw exception"); + } - } catch (Exception e) { - Assert.assertTrue( e.getClass() == InvalidArgumentException.class); - } - } + @Test(expected = PeerException.class) + public void testSendAsyncNullProposal() throws PeerException, InvalidArgumentException { + peer.sendProposalAsync(null); + } + @Test(expected = InvalidArgumentException.class) + public void testBadURL() throws InvalidArgumentException { + hfclient.newPeer("peer_", " "); + Assert.fail("Expected peer with no channel throw exception"); + } } diff --git a/src/test/java/org/hyperledger/fabric/sdk/TestHFClient.java b/src/test/java/org/hyperledger/fabric/sdk/TestHFClient.java index 5770a072..7201b830 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/TestHFClient.java +++ b/src/test/java/org/hyperledger/fabric/sdk/TestHFClient.java @@ -44,7 +44,7 @@ public static HFClient newInstance() throws Exception { final SampleStore sampleStore = new SampleStore(sampleStoreFile); SampleUser someTestUSER = sampleStore.getMember("someTestUSER", "someTestORG"); - someTestUSER.setMPSID("testMSPID?"); + someTestUSER.setMspId("testMSPID?"); HFClient hfclient = HFClient.createNewInstance(); @@ -52,6 +52,8 @@ public static HFClient newInstance() throws Exception { @Override public PrivateKey getKey() { return new PrivateKey() { + private static final long serialVersionUID = -7506317638561401152L; + @Override public String getAlgorithm() { return "algorithm?"; diff --git a/src/test/java/org/hyperledger/fabric/sdk/helper/ConfigTest.java b/src/test/java/org/hyperledger/fabric/sdk/helper/ConfigTest.java index 1c0d07c9..b50da7cb 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/helper/ConfigTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/helper/ConfigTest.java @@ -14,20 +14,17 @@ package org.hyperledger.fabric.sdk.helper; -import static org.junit.Assert.assertEquals; - -import java.util.Properties; - import org.hyperledger.fabric.sdk.TestConfigHelper; import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; +import static org.junit.Assert.assertEquals; + public class ConfigTest { - private TestConfigHelper configHelper = new TestConfigHelper() ; - private String originalValue; + private TestConfigHelper configHelper = new TestConfigHelper(); + private String originalValue; @Before public void setUp() throws Exception { @@ -37,9 +34,9 @@ public void setUp() throws Exception { } @After - public void tearDown() { + public void tearDown() throws Exception { // reset Config after each test. We do not want to interfere with the next test or the next test suite - try {configHelper.clearConfig();} catch (Exception e) {} ; + configHelper.clearConfig(); } @Test diff --git a/src/test/java/org/hyperledger/fabric/sdk/security/CryptoPrimitivesTest.java b/src/test/java/org/hyperledger/fabric/sdk/security/CryptoPrimitivesTest.java index ec773599..9d6f1fe8 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/security/CryptoPrimitivesTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/security/CryptoPrimitivesTest.java @@ -63,17 +63,15 @@ public class CryptoPrimitivesTest { // run End2EndIT test and copy from first peer ProposalResponse ( fabric at // commit level 230f3cc ) - public static final String plainTextHex = "0A205E87B04D3B137E4F2BD2B7E435C96D86E62F3DA5147863A2051F39803AB519BD12E60F0AE30F02046C636363010D6578616D706C655F63632E676F00010D6578616D706C655F63632E676F009D0F0A0D6578616D706C655F63632E676F1201301A880F0A2B0801120F120D6578616D706C655F63632E676F1A160A04696E69740A01610A033130300A01620A03323030120708B2B4FFAF9D2B1ACF0E1F8B08000000000000FFED586D73DA4610CE57F42BB69A26869420C0A49E71EB0F603B2D93165C709A64624FE610075C2D24727702D34EFE7B77EF2410183B4E4CD2990E3B9380B8BBBD67DF9E5DF924F2AFB81C88803FFA6A52AE94CB3FD66A50B6B2FE59AE1E54A0B25FAE552BFBD5F2F30328572ACF0F6A8FA0FCF5202D25569AC947E507DFB56EDC16A07D0B79D169FF0EA3F984CB80F7875C7A03D693C27FE6FB3C9C3A8072DC3E7B0B25F8FE97F659FDFC574F49DFEBC522E83FF3474C847ED4E79ED9F7BADD7979D2ECA41BCD6F9D572D18462042747210C0DA3980274F603C5DA8EE89705DF5CA1ABF66E349C0DFFB7E6918FDD78EFB9FC8B7F0E9DDF55FA9D69E574DFD570EF66BCF0FF6B1FEABD5DAC1AEFEBF85784F9DE36832976238D2D06CFC0EC7919C94A05AAEFC08752CD90E2D28E870C5E594F74B8EF39B406A50BC0F71D8E712F488437DC27CFC48568AF027974A4421544B65C8D3063759720B3F39F32886319B4318698815470542013520E0D73E9F68640BF0234C4AC1429FC34CE891B924515172DE260AA29E46960086BB27F834C8EE02A61D27978391D69343CF9BCD66256640962239F402BB4979BF358F4F5BDDD36708D4715E8501570A24FF100B89F6F5E6C02608C3673D0417B0194412D850725CD3446A3093428B705804150DF48C49EEF485D252F462BDE29F14141A9ADD801E6221B8F52E34BB2E34EADD66B7E8BC6E9EFFDA7E750EAFEB9D4EBD75DE3CED42BB8324DC3A699E37DB2D7C7A01F5D65B78D96C9D1481A377F0127E3D91841D010AF21C05AACBF9CAE583C8825113EE8B81F0D1A27018B32147869E7219A221806D602C14C54E21B4BE1388B1D04C9BE71BE6949CA79EE3A057AF48C91863E1380E5E1F490D7927E7722923A95CFC36186BFA40CBFD289CBA18197788C0E35E0903EDDDEC3E9E1F49EE2DFB8B1A89B1EB141CC7F3A04B06F2E3458348080C94F91D960BE679CC438BDFD178CB8DC38828F635FCE37C749C411CFA98ADF0746D53019AA1D079A5E31E1090D262A58B3F35438DE313F3715BFEDD656FAE31FD8DE105D49A7B5F0426870A0E8F80CE977EE1FA055E4380EA61FF8C4936E6785EE50B4E6ECA24D48BD02050140B1434F734D498635C25EB5316E016FC1FD34FD37A5D29AE6114057D3C93ECC2FB2D0674B41840C0C33CA128C0774750235839C9752C43084590A055A5169FE5DD26DA2525479784F1B887E1C6AAC2A331B95195E0F41A7387321E6A2E2246A7E51002B947B040FC6DF36D11362757872363FFBBF2253E18EC848D9C6132A154D79130D8DE552E0B062CAD234C447627D02512F403C7CC01D41EDB24675997589CB9468AA48A481A7722D9FFBA48B0164A6718603DC8BBE412C4F0B89FC494BE5E846E3113E782F5F16B641AEB5E6C57F42D320FB66A9C5C6A0BA6D859ACBBB4258FB96413329FDAD8D411CB93EA42E13E26DA006F52DDD8ACBAF199AAB33FE27F7717E11F3197F32FABC25B63F72ABC0AA359082A9E106B2125FB38A662A03E1AAA39972C54CC542BD2DB15573061732A052A8B374888023BE3404663A853401A7752C834BAE25F067F9030C667708909417A8EE2E00A03C0BD973B1607136F9860AD10C9CF50DD0E8F308D5A99D250CDDC9350061C21EE3E0FD02A8B1B4372621EA9390127669C5BFF53204C612C31E9923D6A7C6E5DB7F9860F94588B0BE849AC5C7043EF87452666D4AE6B1D634FFD22D474F086F24F458C250982038E7F65986120247A35F57911C638E7428FE3CCC129187BD6397B45D833E6E017E4AB3DBA7CCFE6FFEDB9BC4078572627C9FAEED276B38D898D9E4961A1676C866EB30FBE318B0B59AB6843D3DFAE61169765358882209AD909B30A21D6AD99B6A06231A595B0E89E95CBD506663C87E59FE907269FB21D818C6D9FB40F717EA6176F8ED07DD336466C8AEEA6E338DE1B3A37654E4BE959F22EC54AD92699219CA4B37C56837CC170B63713F310211BB8EEA264165751D17CB2D5DADAA117874184E368A2C626C3FBF5666ED327BFB8A140ADB4F109D31ADB33ADB105D31A779AD658310D237E86B517499B08FC9AFBB1997C736FB636EC601BC3410F2DCED4111B23606418BE24F5D551281326C4603E9EC11B6B1CFE603E7EA01FB6331AF51851E0FF613EF2BCF50929DD976827877527198F1DA5FE2277AD3AABB098B16E6F48B619DDCEFC998EFA50EE5FA7D9CA7668B6B224CFC3257B3ACB266CD2E28ACF978C69B306DFE6B3C99212031E7A18E7599765B961E3DC8BF8CC806BB8D864B0E4F44A4FD141B308A7E9D3C6F0CC2BD6EDB1FA70AF79F91EA14A3A6EDA8E6FF4E2BB9AE796A6446A91E91F782638E222EBA06BEDE0B6A159DEA73F7E598FFB0BAFEE7035A1FDEE3F17EE295973E11E5E6C6A05E615D0456AABE33FF7C2FDE8DEEE8B54F17244DDD8196FBFBF853B2C133FE0DA75F52DF4BBD19E5157BC70EBE69EC5C28D46BBBC37CBE836BF497D142A7EF858193ACF2048306622937D29A4BF2FE50D75A4F1A2ACC660499D0FD194F502D818BF2C1EE33B8A94343966CF2F4BEB101E2BD738CB38E7A3F35FFFA576273BD9C94E76B2939DEC64273BD9C94E1E26FF02F35EC2D1002800000D6578616D706C655F63632E676F000201610003313030016200033230300A0744454641554C54129A072D2D2D2D2D424547494E202D2D2D2D2D0A4D4949436A444343416A4B6741774942416749554245567773537830546D7164627A4E776C654E42427A6F4954307777436759494B6F5A497A6A3045417749770A667A454C4D416B474131554542684D4356564D78457A415242674E5642416754436B4E6862476C6D62334A7561574578466A415542674E564241635444564E680A62694247636D467559326C7A59323878487A416442674E5642416F54466B6C7564475679626D5630494664705A47646C64484D7349456C75597934784444414B0A42674E564241735441316458567A45554D4249474131554541784D4C5A586868625842735A53356A623230774868634E4D5459784D5445784D5463774E7A41770A5768634E4D5463784D5445784D5463774E7A4177576A426A4D517377435159445651514745774A56557A45584D4255474131554543424D4F546D3979644767670A5132467962327870626D45784544414F42674E564241635442314A68624756705A326778477A415A42674E5642416F54456B6835634756796247566B5A3256790A49455A68596E4A70597A454D4D416F474131554543784D44513039514D466B77457759484B6F5A497A6A3043415159494B6F5A497A6A304441516344516741450A4842754B73414F34336873344A4770466669474D6B422F7873494C54734F766D4E32576D77707350485A4E4C36773848576533784350517464472F584A4A765A0A2B433735364B457355424D337977355054666B7538714F42707A43427044414F42674E56485138424166384542414D4342614177485159445652306C424259770A464159494B7759424251554841774547434373474151554642774D434D41774741315564457745422F7751434D414177485159445652304F42425945464F46430A6463555A346573336C746943674156446F794C66567050494D42384741315564497751594D4261414642646E516A32716E6F492F784D55646E3176446D6447310A6E4567514D43554741315564455151654D427943436D31356147397A6443356A62323243446E6433647935746557687663335175593239744D416F47434371470A534D343942414D43413067414D4555434944663948626C34786E337A3445774E4B6D696C4D396C58324671346A5770416152564239374F6D56456579416945410A32356144505148474771324176684B54307776743038635831475447434962666D754C704D774B516A33383D0A2D2D2D2D2D454E44202D2D2D2D2D0A"; - public static final String sigHex = "3045022100880FFD28A54ACDCBDC8C54EC7927143A734199EF6BC659FBE5312C736F40769E02202A4EA0F2060AEE5E59D9440F31748E1BD01DB32031DBD7A12791B16A8E3E4D3D"; - public static final String pemCertHex = "2D2D2D2D2D424547494E202D2D2D2D2D0A4D4949436A444343416A4B6741774942416749554245567773537830546D7164627A4E776C654E42427A6F4954307777436759494B6F5A497A6A3045417749770A667A454C4D416B474131554542684D4356564D78457A415242674E5642416754436B4E6862476C6D62334A7561574578466A415542674E564241635444564E680A62694247636D467559326C7A59323878487A416442674E5642416F54466B6C7564475679626D5630494664705A47646C64484D7349456C75597934784444414B0A42674E564241735441316458567A45554D4249474131554541784D4C5A586868625842735A53356A623230774868634E4D5459784D5445784D5463774E7A41770A5768634E4D5463784D5445784D5463774E7A4177576A426A4D517377435159445651514745774A56557A45584D4255474131554543424D4F546D3979644767670A5132467962327870626D45784544414F42674E564241635442314A68624756705A326778477A415A42674E5642416F54456B6835634756796247566B5A3256790A49455A68596E4A70597A454D4D416F474131554543784D44513039514D466B77457759484B6F5A497A6A3043415159494B6F5A497A6A304441516344516741450A4842754B73414F34336873344A4770466669474D6B422F7873494C54734F766D4E32576D77707350485A4E4C36773848576533784350517464472F584A4A765A0A2B433735364B457355424D337977355054666B7538714F42707A43427044414F42674E56485138424166384542414D4342614177485159445652306C424259770A464159494B7759424251554841774547434373474151554642774D434D41774741315564457745422F7751434D414177485159445652304F42425945464F46430A6463555A346573336C746943674156446F794C66567050494D42384741315564497751594D4261414642646E516A32716E6F492F784D55646E3176446D6447310A6E4567514D43554741315564455151654D427943436D31356147397A6443356A62323243446E6433647935746557687663335175593239744D416F47434371470A534D343942414D43413067414D4555434944663948626C34786E337A3445774E4B6D696C4D396C58324671346A5770416152564239374F6D56456579416945410A32356144505148474771324176684B54307776743038635831475447434962666D754C704D774B516A33383D0A2D2D2D2D2D454E44202D2D2D2D2D0A"; + public static final String PLAIN_TEXT_HEX = "0A205E87B04D3B137E4F2BD2B7E435C96D86E62F3DA5147863A2051F39803AB519BD12E60F0AE30F02046C636363010D6578616D706C655F63632E676F00010D6578616D706C655F63632E676F009D0F0A0D6578616D706C655F63632E676F1201301A880F0A2B0801120F120D6578616D706C655F63632E676F1A160A04696E69740A01610A033130300A01620A03323030120708B2B4FFAF9D2B1ACF0E1F8B08000000000000FFED586D73DA4610CE57F42BB69A26869420C0A49E71EB0F603B2D93165C709A64624FE610075C2D24727702D34EFE7B77EF2410183B4E4CD2990E3B9380B8BBBD67DF9E5DF924F2AFB81C88803FFA6A52AE94CB3FD66A50B6B2FE59AE1E54A0B25FAE552BFBD5F2F30328572ACF0F6A8FA0FCF5202D25569AC947E507DFB56EDC16A07D0B79D169FF0EA3F984CB80F7875C7A03D693C27FE6FB3C9C3A8072DC3E7B0B25F8FE97F659FDFC574F49DFEBC522E83FF3474C847ED4E79ED9F7BADD7979D2ECA41BCD6F9D572D18462042747210C0DA3980274F603C5DA8EE89705DF5CA1ABF66E349C0DFFB7E6918FDD78EFB9FC8B7F0E9DDF55FA9D69E574DFD570EF66BCF0FF6B1FEABD5DAC1AEFEBF85784F9DE36832976238D2D06CFC0EC7919C94A05AAEFC08752CD90E2D28E870C5E594F74B8EF39B406A50BC0F71D8E712F488437DC27CFC48568AF027974A4421544B65C8D3063759720B3F39F32886319B4318698815470542013520E0D73E9F68640BF0234C4AC1429FC34CE891B924515172DE260AA29E46960086BB27F834C8EE02A61D27978391D69343CF9BCD66256640962239F402BB4979BF358F4F5BDDD36708D4715E8501570A24FF100B89F6F5E6C02608C3673D0417B0194412D850725CD3446A3093428B705804150DF48C49EEF485D252F462BDE29F14141A9ADD801E6221B8F52E34BB2E34EADD66B7E8BC6E9EFFDA7E750EAFEB9D4EBD75DE3CED42BB8324DC3A699E37DB2D7C7A01F5D65B78D96C9D1481A377F0127E3D91841D010AF21C05AACBF9CAE583C8825113EE8B81F0D1A27018B32147869E7219A221806D602C14C54E21B4BE1388B1D04C9BE71BE6949CA79EE3A057AF48C91863E1380E5E1F490D7927E7722923A95CFC36186BFA40CBFD289CBA18197788C0E35E0903EDDDEC3E9E1F49EE2DFB8B1A89B1EB141CC7F3A04B06F2E3458348080C94F91D960BE679CC438BDFD178CB8DC38828F635FCE37C749C411CFA98ADF0746D53019AA1D079A5E31E1090D262A58B3F35438DE313F3715BFEDD656FAE31FD8DE105D49A7B5F0426870A0E8F80CE977EE1FA055E4380EA61FF8C4936E6785EE50B4E6ECA24D48BD02050140B1434F734D498635C25EB5316E016FC1FD34FD37A5D29AE6114057D3C93ECC2FB2D0674B41840C0C33CA128C0774750235839C9752C43084590A055A5169FE5DD26DA2525479784F1B887E1C6AAC2A331B95195E0F41A7387321E6A2E2246A7E51002B947B040FC6DF36D11362757872363FFBBF2253E18EC848D9C6132A154D79130D8DE552E0B062CAD234C447627D02512F403C7CC01D41EDB24675997589CB9468AA48A481A7722D9FFBA48B0164A6718603DC8BBE412C4F0B89FC494BE5E846E3113E782F5F16B641AEB5E6C57F42D320FB66A9C5C6A0BA6D859ACBBB4258FB96413329FDAD8D411CB93EA42E13E26DA006F52DDD8ACBAF199AAB33FE27F7717E11F3197F32FABC25B63F72ABC0AA359082A9E106B2125FB38A662A03E1AAA39972C54CC542BD2DB15573061732A052A8B374888023BE3404663A853401A7752C834BAE25F067F9030C667708909417A8EE2E00A03C0BD973B1607136F9860AD10C9CF50DD0E8F308D5A99D250CDDC9350061C21EE3E0FD02A8B1B4372621EA9390127669C5BFF53204C612C31E9923D6A7C6E5DB7F9860F94588B0BE849AC5C7043EF87452666D4AE6B1D634FFD22D474F086F24F458C250982038E7F65986120247A35F57911C638E7428FE3CCC129187BD6397B45D833E6E017E4AB3DBA7CCFE6FFEDB9BC4078572627C9FAEED276B38D898D9E4961A1676C866EB30FBE318B0B59AB6843D3DFAE61169765358882209AD909B30A21D6AD99B6A06231A595B0E89E95CBD506663C87E59FE907269FB21D818C6D9FB40F717EA6176F8ED07DD336466C8AEEA6E338DE1B3A37654E4BE959F22EC54AD92699219CA4B37C56837CC170B63713F310211BB8EEA264165751D17CB2D5DADAA117874184E368A2C626C3FBF5666ED327BFB8A140ADB4F109D31ADB33ADB105D31A779AD658310D237E86B517499B08FC9AFBB1997C736FB636EC601BC3410F2DCED4111B23606418BE24F5D551281326C4603E9EC11B6B1CFE603E7EA01FB6331AF51851E0FF613EF2BCF50929DD976827877527198F1DA5FE2277AD3AABB098B16E6F48B619DDCEFC998EFA50EE5FA7D9CA7668B6B224CFC3257B3ACB266CD2E28ACF978C69B306DFE6B3C99212031E7A18E7599765B961E3DC8BF8CC806BB8D864B0E4F44A4FD141B308A7E9D3C6F0CC2BD6EDB1FA70AF79F91EA14A3A6EDA8E6FF4E2BB9AE796A6446A91E91F782638E222EBA06BEDE0B6A159DEA73F7E598FFB0BAFEE7035A1FDEE3F17EE295973E11E5E6C6A05E615D0456AABE33FF7C2FDE8DEEE8B54F17244DDD8196FBFBF853B2C133FE0DA75F52DF4BBD19E5157BC70EBE69EC5C28D46BBBC37CBE836BF497D142A7EF858193ACF2048306622937D29A4BF2FE50D75A4F1A2ACC660499D0FD194F502D818BF2C1EE33B8A94343966CF2F4BEB101E2BD738CB38E7A3F35FFFA576273BD9C94E76B2939DEC64273BD9C94E1E26FF02F35EC2D1002800000D6578616D706C655F63632E676F000201610003313030016200033230300A0744454641554C54129A072D2D2D2D2D424547494E202D2D2D2D2D0A4D4949436A444343416A4B6741774942416749554245567773537830546D7164627A4E776C654E42427A6F4954307777436759494B6F5A497A6A3045417749770A667A454C4D416B474131554542684D4356564D78457A415242674E5642416754436B4E6862476C6D62334A7561574578466A415542674E564241635444564E680A62694247636D467559326C7A59323878487A416442674E5642416F54466B6C7564475679626D5630494664705A47646C64484D7349456C75597934784444414B0A42674E564241735441316458567A45554D4249474131554541784D4C5A586868625842735A53356A623230774868634E4D5459784D5445784D5463774E7A41770A5768634E4D5463784D5445784D5463774E7A4177576A426A4D517377435159445651514745774A56557A45584D4255474131554543424D4F546D3979644767670A5132467962327870626D45784544414F42674E564241635442314A68624756705A326778477A415A42674E5642416F54456B6835634756796247566B5A3256790A49455A68596E4A70597A454D4D416F474131554543784D44513039514D466B77457759484B6F5A497A6A3043415159494B6F5A497A6A304441516344516741450A4842754B73414F34336873344A4770466669474D6B422F7873494C54734F766D4E32576D77707350485A4E4C36773848576533784350517464472F584A4A765A0A2B433735364B457355424D337977355054666B7538714F42707A43427044414F42674E56485138424166384542414D4342614177485159445652306C424259770A464159494B7759424251554841774547434373474151554642774D434D41774741315564457745422F7751434D414177485159445652304F42425945464F46430A6463555A346573336C746943674156446F794C66567050494D42384741315564497751594D4261414642646E516A32716E6F492F784D55646E3176446D6447310A6E4567514D43554741315564455151654D427943436D31356147397A6443356A62323243446E6433647935746557687663335175593239744D416F47434371470A534D343942414D43413067414D4555434944663948626C34786E337A3445774E4B6D696C4D396C58324671346A5770416152564239374F6D56456579416945410A32356144505148474771324176684B54307776743038635831475447434962666D754C704D774B516A33383D0A2D2D2D2D2D454E44202D2D2D2D2D0A"; + public static final String SIGNATURE_HEX = "3045022100880FFD28A54ACDCBDC8C54EC7927143A734199EF6BC659FBE5312C736F40769E02202A4EA0F2060AEE5E59D9440F31748E1BD01DB32031DBD7A12791B16A8E3E4D3D"; + public static final String PEM_CERT_HEX = "2D2D2D2D2D424547494E202D2D2D2D2D0A4D4949436A444343416A4B6741774942416749554245567773537830546D7164627A4E776C654E42427A6F4954307777436759494B6F5A497A6A3045417749770A667A454C4D416B474131554542684D4356564D78457A415242674E5642416754436B4E6862476C6D62334A7561574578466A415542674E564241635444564E680A62694247636D467559326C7A59323878487A416442674E5642416F54466B6C7564475679626D5630494664705A47646C64484D7349456C75597934784444414B0A42674E564241735441316458567A45554D4249474131554541784D4C5A586868625842735A53356A623230774868634E4D5459784D5445784D5463774E7A41770A5768634E4D5463784D5445784D5463774E7A4177576A426A4D517377435159445651514745774A56557A45584D4255474131554543424D4F546D3979644767670A5132467962327870626D45784544414F42674E564241635442314A68624756705A326778477A415A42674E5642416F54456B6835634756796247566B5A3256790A49455A68596E4A70597A454D4D416F474131554543784D44513039514D466B77457759484B6F5A497A6A3043415159494B6F5A497A6A304441516344516741450A4842754B73414F34336873344A4770466669474D6B422F7873494C54734F766D4E32576D77707350485A4E4C36773848576533784350517464472F584A4A765A0A2B433735364B457355424D337977355054666B7538714F42707A43427044414F42674E56485138424166384542414D4342614177485159445652306C424259770A464159494B7759424251554841774547434373474151554642774D434D41774741315564457745422F7751434D414177485159445652304F42425945464F46430A6463555A346573336C746943674156446F794C66567050494D42384741315564497751594D4261414642646E516A32716E6F492F784D55646E3176446D6447310A6E4567514D43554741315564455151654D427943436D31356147397A6443356A62323243446E6433647935746557687663335175593239744D416F47434371470A534D343942414D43413067414D4555434944663948626C34786E337A3445774E4B6D696C4D396C58324671346A5770416152564239374F6D56456579416945410A32356144505148474771324176684B54307776743038635831475447434962666D754C704D774B516A33383D0A2D2D2D2D2D454E44202D2D2D2D2D0A"; // File create_key_cert_for_testing.md has info on the other keys and // certificates used in this test suite private static byte[] plainText, sig, pemCert; - private static KeyStore trustStore; - private static KeyFactory kf; private static CertificateFactory cf; @@ -82,15 +80,15 @@ public class CryptoPrimitivesTest { private static Certificate testCACert; - private static Config config ; + private static Config config; @BeforeClass public static void setUpBeforeClass() throws Exception { config = Config.getConfig(); - plainText = DatatypeConverter.parseHexBinary(plainTextHex); - sig = DatatypeConverter.parseHexBinary(sigHex); - pemCert = DatatypeConverter.parseHexBinary(pemCertHex); + plainText = DatatypeConverter.parseHexBinary(PLAIN_TEXT_HEX); + sig = DatatypeConverter.parseHexBinary(SIGNATURE_HEX); + pemCert = DatatypeConverter.parseHexBinary(PEM_CERT_HEX); kf = KeyFactory.getInstance("EC"); @@ -127,8 +125,8 @@ public void setUp() throws Exception { @Test public void testGetSetProperties() { - CryptoPrimitives testCrypto = new CryptoPrimitives() ; - Properties cryptoProps = testCrypto.getProperties() ; + CryptoPrimitives testCrypto = new CryptoPrimitives(); + Properties cryptoProps = testCrypto.getProperties(); String hashAlg = config.getHashAlgorithm(); assertEquals(cryptoProps.getProperty(Config.HASH_ALGORITHM), hashAlg); Properties propsIn = new Properties(); @@ -146,21 +144,21 @@ public void testGetSetProperties() { } } - @Test(expected=InvalidArgumentException.class) + @Test(expected = InvalidArgumentException.class) public void testSecurityLevel() throws InvalidArgumentException { - CryptoPrimitives testCrypto = new CryptoPrimitives() ; + CryptoPrimitives testCrypto = new CryptoPrimitives(); testCrypto.setSecurityLevel(2001); } - @Test(expected=InvalidArgumentException.class) + @Test(expected = InvalidArgumentException.class) public void testSetHashAlgorithm() throws InvalidArgumentException { - CryptoPrimitives testCrypto = new CryptoPrimitives() ; + CryptoPrimitives testCrypto = new CryptoPrimitives(); testCrypto.setHashAlgorithm(null); } - @Test(expected=InvalidArgumentException.class) + @Test(expected = InvalidArgumentException.class) public void testSetHashAlgorithmBadArg() throws InvalidArgumentException { - CryptoPrimitives testCrypto = new CryptoPrimitives() ; + CryptoPrimitives testCrypto = new CryptoPrimitives(); testCrypto.setHashAlgorithm("FAKE"); } @@ -172,7 +170,7 @@ public void testGetTrustStore() { CryptoPrimitives myCrypto = new CryptoPrimitives(); assertNotNull(myCrypto.getTrustStore()); } catch (CryptoException e) { - fail("getTrustStore() fails with : "+ e.getMessage()); + fail("getTrustStore() fails with : " + e.getMessage()); } } @@ -221,7 +219,7 @@ public void testSetTrustStoreDuplicateCert() { } } - @Test(expected=InvalidArgumentException.class) + @Test(expected = InvalidArgumentException.class) public void testAddCACertificateToTrustStoreNoAlias() throws InvalidArgumentException { try { crypto.addCACertificateToTrustStore(new File("something"), null); @@ -230,7 +228,7 @@ public void testAddCACertificateToTrustStoreNoAlias() throws InvalidArgumentExce } } - @Test(expected=CryptoException.class) + @Test(expected = CryptoException.class) public void testAddCACertificateToTrustStoreNoFile() throws CryptoException { try { crypto.addCACertificateToTrustStore(new File("does/not/exist"), "abc"); @@ -239,7 +237,7 @@ public void testAddCACertificateToTrustStoreNoFile() throws CryptoException { } } - @Test(expected=InvalidArgumentException.class) + @Test(expected = InvalidArgumentException.class) public void testAddCACertificateToTrustStoreNoCert() throws InvalidArgumentException { try { crypto.addCACertificateToTrustStore((Certificate) null, "abc"); @@ -248,12 +246,12 @@ public void testAddCACertificateToTrustStoreNoCert() throws InvalidArgumentExcep } } - @Test(expected=CryptoException.class) + @Test(expected = CryptoException.class) public void testLoadCACertsBadInput() throws CryptoException { crypto.loadCACertificates(null); } - @Test(expected=CryptoException.class) + @Test(expected = CryptoException.class) public void testLoadCACertsBytesBadInput() throws CryptoException { crypto.loadCACertificatesAsBytes(null); } @@ -277,7 +275,7 @@ public void testLoadCACerts() { certIDs.add(Integer.toString(cf.generateCertificate(bis).hashCode())); } crypto.loadCACertificatesAsBytes(certBytesList); - assertEquals(crypto.getTrustStore().size(), numStore+numFiles); + assertEquals(crypto.getTrustStore().size(), numStore + numFiles); for (String cID : certIDs) { assertTrue(crypto.getTrustStore().containsAlias(cID)); } @@ -351,21 +349,21 @@ public void testVerifyNullInput() { } } // testVerifyNullInput - @Test(expected=CryptoException.class) + @Test(expected = CryptoException.class) public void testVerifyBadCert() throws CryptoException { - byte[] badCert = new byte[] { (byte) 0x00 }; + byte[] badCert = new byte[] {(byte) 0x00}; crypto.verify(plainText, sig, badCert); } // testVerifyBadCert - @Test(expected=CryptoException.class) + @Test(expected = CryptoException.class) public void testVerifyBadSig() throws CryptoException { - byte[] badSig = new byte[] { (byte) 0x00 }; + byte[] badSig = new byte[] {(byte) 0x00}; crypto.verify(plainText, badSig, pemCert); } // testVerifyBadSign @Test public void testVerifyBadPlaintext() { - byte[] badPlainText = new byte[] { (byte) 0x00 }; + byte[] badPlainText = new byte[] {(byte) 0x00}; try { assertFalse(crypto.verify(badPlainText, sig, pemCert)); } catch (CryptoException e) { @@ -385,7 +383,7 @@ public void testVerify() { @Test public void testSignNullKey() { try { - crypto.sign(null, new byte[] { (byte) 0x00 }); + crypto.sign(null, new byte[] {(byte) 0x00}); Assert.fail("sign() should have thrown an exception"); } catch (CryptoException e) { } diff --git a/src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java b/src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java index e00b6e67..757dad21 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java +++ b/src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -170,7 +170,7 @@ private TestConfig() { Properties properties = new Properties(); properties.setProperty("pemFile", cf.getAbsolutePath()); - properties.setProperty("allowAllHostNames", "true");//testing environment only NOT FOR PRODUCTION! + properties.setProperty("allowAllHostNames", "true"); //testing environment only NOT FOR PRODUCTION! sampleOrg.setCAProperties(properties); } @@ -227,20 +227,7 @@ private String getProperty(String property) { return ret; } - /** - * getProperty returns the value for given property key. If not found, it - * will set the property to defaultValueidea-IC-171.3780.107 - * - * @param property - * @param defaultValue - * @return property value as a String - */ - private String getProperty(String property, String defaultValue) { - - return sdkProperties.getProperty(property, defaultValue); - } - - static private void defaultProperty(String key, String value) { + private static void defaultProperty(String key, String value) { String ret = System.getProperty(key); if (ret != null) { @@ -272,11 +259,6 @@ public int getGossipWaitTime() { return Integer.parseInt(getProperty(GOSSIPWAITTIME)); } - /** - * Time to wait for proposal to complete - * - * @return - */ public long getProposalWaitTime() { return Integer.parseInt(getProperty(PROPOSALWAITTIME)); } @@ -290,7 +272,6 @@ public SampleOrg getIntegrationTestsSampleOrg(String name) { } - private final static String tlsbase = "src/test/fixture/sdkintegration/e2e-2Orgs/tls/"; public Properties getPeerProperties(String name) { @@ -309,11 +290,11 @@ private Properties getEndPointProperties(final String type, final String name) { final String domainName = getDomainName(name); - File cert = Paths.get(getTestChannlePath(), "crypto-config/ordererOrganizations".replace("orderer", type), domainName, type +"s", + File cert = Paths.get(getTestChannlePath(), "crypto-config/ordererOrganizations".replace("orderer", type), domainName, type + "s", name, "tls/server.crt").toFile(); - if(!cert.exists()){ + if (!cert.exists()) { throw new RuntimeException(String.format("Missing cert file for: %s. Could not find at location: %s", name, - cert.getAbsolutePath()) ); + cert.getAbsolutePath())); } Properties ret = new Properties(); @@ -332,39 +313,6 @@ public Properties getEventHubProperties(String name) { } - private Properties getTLSProperties(String type, String name) { - Properties ret = null; - if (runningFabricTLS) { - String cert = tlsbase + "/" + type + "/" + name + "/cert.pem"; - File cf = new File(cert); - if (!cf.exists() || !cf.isFile()) { - throw new RuntimeException("Missing cert file " + cf.getAbsolutePath()); - } - ret = new Properties(); - ret.setProperty("pemFile", cert); - ret.setProperty("trustServerCertificate", "true"); //testing environment only NOT FOR PRODUCTION! - ret.setProperty("sslProvider", "openSSL"); - ret.setProperty("negotiationType", "TLS"); - } - return ret; - } - - private Properties getTLSProperties(String cert) { - Properties ret = null; - if (runningFabricTLS) { - // String cert = tlsbase + "/" + type + "/" + name + "/ca.pem"; - File cf = new File(tlsbase + cert); - if (!cf.exists() || !cf.isFile()) { - throw new RuntimeException("TEST error missing cert file " + cf.getAbsolutePath()); - } - ret = new Properties(); - ret.setProperty("pemFile", cf.getAbsolutePath()); - ret.setProperty("trustServerCertificate", "true"); //testing environment only NOT FOR PRODUCTION! - ret.setProperty("sslProvider", "openSSL"); - ret.setProperty("negotiationType", "TLS"); - } - return ret; - } public String getTestChannlePath() { @@ -377,7 +325,7 @@ private String getDomainName(final String name) { if (-1 == dot) { return null; } else { - return name.substring(dot+1); + return name.substring(dot + 1); } } diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java index 5326e003..0439c16b 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java @@ -20,6 +20,7 @@ import java.util.Hashtable; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -66,8 +67,6 @@ public class End2endAndBackAgainIT { private static final String TESTUSER_1_NAME = "user1"; private static final String TEST_FIXTURES_PATH = "src/test/fixture"; - private final int gossipWaitTime = testConfig.getGossipWaitTime(); - private static final String CHAIN_CODE_NAME = "example_cc_go"; private static final String CHAIN_CODE_PATH = "github.com/example_cc"; private static final String CHAIN_CODE_VERSION = "1"; @@ -83,8 +82,6 @@ public class End2endAndBackAgainIT { private static final String FOO_CHANNEL_NAME = "foo"; private static final String BAR_CHANNEL_NAME = "bar"; - private Hashtable fabricCAs = new Hashtable<>(); - String testTxID = null; // save the CC invoke TxID and use in queries private final TestConfigHelper configHelper = new TestConfigHelper(); diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java index 6caf91b6..a5166676 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java @@ -80,8 +80,6 @@ public class End2endIT { private static final String TESTUSER_1_NAME = "user1"; private static final String TEST_FIXTURES_PATH = "src/test/fixture"; - private final int gossipWaitTime = testConfig.getGossipWaitTime(); - private static final String CHAIN_CODE_NAME = "example_cc_go"; private static final String CHAIN_CODE_PATH = "github.com/example_cc"; private static final String CHAIN_CODE_VERSION = "1"; @@ -159,7 +157,7 @@ public void setup() { SampleUser admin = sampleStore.getMember(TEST_ADMIN_NAME, orgName); if (!admin.isEnrolled()) { //Preregistered admin only needs to be enrolled with Fabric caClient. admin.setEnrollment(ca.enroll(admin.getName(), "adminpw")); - admin.setMPSID(mspid); + admin.setMspId(mspid); } sampleOrg.setAdmin(admin); // The admin of this org -- @@ -171,7 +169,7 @@ public void setup() { } if (!user.isEnrolled()) { user.setEnrollment(ca.enroll(user.getName(), user.getEnrollmentSecret())); - user.setMPSID(mspid); + user.setMspId(mspid); } sampleOrg.addUser(user); //Remember user belongs to this Org @@ -181,7 +179,7 @@ public void setup() { // src/test/fixture/sdkintegration/e2e-2Orgs/channel/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/ SampleUser peerOrgAdmin = sampleStore.getMember(sampleOrgName + "Admin", sampleOrgName, sampleOrg.getMSPID(), - findFile_sk(Paths.get(testConfig.getTestChannlePath(), "crypto-config/peerOrganizations/", + findFileSk(Paths.get(testConfig.getTestChannlePath(), "crypto-config/peerOrganizations/", sampleOrgDomainName, format("/users/Admin@%s/msp/keystore", sampleOrgDomainName)).toFile()), Paths.get(testConfig.getTestChannlePath(), "crypto-config/peerOrganizations/", sampleOrgDomainName, format("/users/Admin@%s/msp/signcerts/Admin@%s-cert.pem", sampleOrgDomainName, sampleOrgDomainName)).toFile()); @@ -216,6 +214,7 @@ sampleOrgDomainName, format("/users/Admin@%s/msp/keystore", sampleOrgDomainName) } + //CHECKSTYLE.OFF: Method length is 320 lines (max allowed is 150). void runChannel(HFClient client, Channel channel, boolean installChaincode, SampleOrg sampleOrg, int delta) { try { @@ -537,6 +536,7 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei fail("Test failed with error : " + e.getMessage()); } } + //CHECKSTYLE.ON: Method length is 320 lines (max allowed is 150). private Channel constructChannel(String name, HFClient client, SampleOrg sampleOrg) throws Exception { //////////////////////////// @@ -637,7 +637,7 @@ private void waitOnFabric(int additional) { // } } - File findFile_sk(File directory) { + File findFileSk(File directory) { File[] matches = directory.listFiles((dir, name) -> name.endsWith("_sk")); @@ -653,16 +653,15 @@ File findFile_sk(File directory) { } - private static final Map txExpected; + private static final Map TX_EXPECTED; static { - txExpected = new HashMap(); - txExpected.put("readset1", "Missing readset for channel bar block 1"); - txExpected.put("writeset1", "Missing writeset for channel bar block 1"); + TX_EXPECTED = new HashMap(); + TX_EXPECTED.put("readset1", "Missing readset for channel bar block 1"); + TX_EXPECTED.put("writeset1", "Missing writeset for channel bar block 1"); } void blockWalker(Channel channel) throws InvalidProtocolBufferException, InvalidArgumentException, ProposalException, UnsupportedEncodingException, IOException { - try { BlockchainInfo channelInfo = channel.queryBlockchainInfo(); @@ -707,9 +706,9 @@ void blockWalker(Channel channel) throws InvalidProtocolBufferException, Invalid assertEquals(200, transactionActionInfo.getResponseStatus()); out(" Transaction action %d has response message bytes as string: %s", j, printableString(new String(transactionActionInfo.getResponseMessageBytes(), "UTF-8"))); - out(" Transaction action %d has %d endorsements", j, transactionActionInfo.getEndorsementsCount()); assertEquals(2, transactionActionInfo.getEndorsementsCount()); + for (int n = 0; n < transactionActionInfo.getEndorsementsCount(); ++n) { BlockInfo.EndorserInfo endorserInfo = transactionActionInfo.getEndorsementInfo(n); out("Endorser %d signature: %s", n, Hex.encodeHexString(endorserInfo.getSignature())); @@ -717,24 +716,20 @@ void blockWalker(Channel channel) throws InvalidProtocolBufferException, Invalid } out(" Transaction action %d has %d chaincode input arguments", j, transactionActionInfo.getChaincodeInputArgsCount()); for (int z = 0; z < transactionActionInfo.getChaincodeInputArgsCount(); ++z) { - out(" Transaction action %d has chaincode input argument %d is: %s", j, z, printableString(new String(transactionActionInfo.getChaincodeInputArgs(z), "UTF-8"))); } out(" Transaction action %d proposal response status: %d", j, transactionActionInfo.getProposalResponseStatus()); - out(" Transaction action %d proposal response payload: %s", j, printableString(new String(transactionActionInfo.getProposalResponsePayload()))); TxReadWriteSetInfo rwsetInfo = transactionActionInfo.getTxReadWriteSet(); if (null != rwsetInfo) { - out(" Transaction action %d has %d name space read write sets", j, rwsetInfo.getNsRwsetCount()); for (TxReadWriteSetInfo.NsRwsetInfo nsRwsetInfo : rwsetInfo.getNsRwsetInfos()) { - final String namespace = nsRwsetInfo.getNaamespace(); KvRwset.KVRWSet rws = nsRwsetInfo.getRwset(); @@ -746,7 +741,6 @@ void blockWalker(Channel channel) throws InvalidProtocolBufferException, Invalid readList.getVersion().getBlockNum(), readList.getVersion().getTxNum()); if ("bar".equals(channelId) && blockNumber == 2) { - if ("example_cc_go".equals(namespace)) { if (rs == 0) { assertEquals("a", readList.getKey()); @@ -760,17 +754,14 @@ void blockWalker(Channel channel) throws InvalidProtocolBufferException, Invalid fail(format("unexpected readset %d", rs)); } - txExpected.remove("readset1"); + TX_EXPECTED.remove("readset1"); } } - } rs = -1; - for (KvRwset.KVWrite writeList : rws.getWritesList()) { rs++; - String valAsString = printableString(new String(writeList.getValue().toByteArray(), "UTF-8")); out(" Namespace %s write set %d key %s has value '%s' ", namespace, rs, @@ -780,38 +771,29 @@ void blockWalker(Channel channel) throws InvalidProtocolBufferException, Invalid if ("bar".equals(channelId) && blockNumber == 2) { if (rs == 0) { assertEquals("a", writeList.getKey()); - assertEquals("400", valAsString); } else if (rs == 1) { assertEquals("b", writeList.getKey()); - assertEquals("400", valAsString); } else { fail(format("unexpected writeset %d", rs)); } - txExpected.remove("writeset1"); + TX_EXPECTED.remove("writeset1"); } - } } - } - } - } - } - } - if (!txExpected.isEmpty()) { - fail(txExpected.get(0)); + if (!TX_EXPECTED.isEmpty()) { + fail(TX_EXPECTED.get(0)); } } catch (InvalidProtocolBufferRuntimeException e) { throw e.getCause(); } - } static String printableString(final String string) { diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/SampleStore.java b/src/test/java/org/hyperledger/fabric/sdkintegration/SampleStore.java index b3d5effb..24ef3d6a 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/SampleStore.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/SampleStore.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -105,7 +105,8 @@ public void setValue(String name, String value) { /** * Get the user with a given name - * + * @param name + * @param org * @return user */ public SampleUser getMember(String name, String org) { @@ -125,10 +126,18 @@ public SampleUser getMember(String name, String org) { /** * Get the user with a given name - * + * @param name + * @param org + * @param mspId + * @param privateKeyFile + * @param certificateFile * @return user + * @throws IOException + * @throws NoSuchAlgorithmException + * @throws NoSuchProviderException + * @throws InvalidKeySpecException */ - public SampleUser getMember(String name, String org, String MSPID, File privateKeyFile, + public SampleUser getMember(String name, String org, String mspId, File privateKeyFile, File certificateFile) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException { try { @@ -140,11 +149,10 @@ public SampleUser getMember(String name, String org, String MSPID, File privateK // Create the SampleUser and try to restore it's state from the key value store (if found). sampleUser = new SampleUser(name, org, this); - sampleUser.setMPSID(MSPID); + sampleUser.setMspId(mspId); String certificate = new String(IOUtils.toByteArray(new FileInputStream(certificateFile)), "UTF-8"); - //PrivateKey privateKey = getPrivateKeyFromFile(privateKeyFile); PrivateKey privateKey = getPrivateKeyFromBytes(IOUtils.toByteArray(new FileInputStream(privateKeyFile))); sampleUser.setEnrollment(new SampleStoreEnrollement(privateKey, certificate)); @@ -165,7 +173,7 @@ public SampleUser getMember(String name, String org, String MSPID, File privateK } catch (InvalidKeySpecException e) { e.printStackTrace(); throw e; - } catch (ClassCastException e){ + } catch (ClassCastException e) { e.printStackTrace(); throw e; } @@ -180,8 +188,8 @@ static PrivateKey getPrivateKeyFromBytes(byte[] data) throws IOException, NoSuch final Reader pemReader = new StringReader(new String(data)); final PrivateKeyInfo pemPair; - try (final PEMParser pemParser = new PEMParser(pemReader)) { - pemPair = (PrivateKeyInfo)pemParser.readObject(); + try (PEMParser pemParser = new PEMParser(pemReader)) { + pemPair = (PrivateKeyInfo) pemParser.readObject(); } PrivateKey privateKey = new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME).getPrivateKey(pemPair); @@ -191,8 +199,8 @@ static PrivateKey getPrivateKeyFromBytes(byte[] data) throws IOException, NoSuch static final class SampleStoreEnrollement implements Enrollment, Serializable { - private PrivateKey privateKey; - // private transient PrivateKey privateKey; + private static final long serialVersionUID = -2784835212445309006L; + private final PrivateKey privateKey; private final String certificate; diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/SampleUser.java b/src/test/java/org/hyperledger/fabric/sdkintegration/SampleUser.java index 9aaf337d..127d7150 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/SampleUser.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/SampleUser.java @@ -4,7 +4,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +20,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; -import java.util.List; import java.util.Set; import io.netty.util.internal.StringUtil; @@ -42,7 +41,6 @@ public class SampleUser implements User, Serializable { private transient SampleStore keyValStore; private String keyValStoreName; - SampleUser(String name, String org, SampleStore fs) { this.name = name; @@ -50,13 +48,12 @@ public class SampleUser implements User, Serializable { this.organization = org; this.keyValStoreName = toKeyValStoreName(this.name, org); String memberStr = keyValStore.getValue(keyValStoreName); - if(null == memberStr){ + if (null == memberStr) { saveState(); - }else { + } else { restoreState(); } - } @Override @@ -128,15 +125,6 @@ public boolean isEnrolled() { return this.enrollment != null; } - - private String getAttrsKey(List attrs) { - if (attrs == null || attrs.isEmpty()) { - return null; - } - return String.join(",", attrs); - } - - /** * Save the state of this user to the key value store. */ @@ -153,7 +141,6 @@ void saveState() { } } - /** * Restore the state of this user from the key value store (if found). If not found, do nothing. */ @@ -175,7 +162,7 @@ SampleUser restoreState() { this.organization = state.organization; this.enrollmentSecret = state.enrollmentSecret; this.enrollment = state.enrollment; - this.mspID = state.mspID; + this.mspId = state.mspId; return this; } } catch (Exception e) { @@ -194,7 +181,6 @@ public void setEnrollmentSecret(String enrollmentSecret) { saveState(); } - public void setEnrollment(Enrollment enrollment) { this.enrollment = enrollment; @@ -206,16 +192,15 @@ public static String toKeyValStoreName(String name, String org) { return "user." + name + org; } - @Override - public String getMSPID() { - return mspID; + public String getMspId() { + return mspId; } - String mspID; + String mspId; - public void setMPSID(String mspID) { - this.mspID = mspID; + public void setMspId(String mspID) { + this.mspId = mspID; saveState(); }