use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class Channel method serializeChannel.
/**
* Serialize channel to a byte array using Java serialization.
* Deserialized channel will NOT be in an initialized state.
*
* @throws InvalidArgumentException
* @throws IOException
*/
public byte[] serializeChannel() throws IOException, InvalidArgumentException {
if (isShutdown()) {
throw new InvalidArgumentException(format("Channel %s has been shutdown.", getName()));
}
ObjectOutputStream out = null;
try {
ByteArrayOutputStream bai = new ByteArrayOutputStream();
out = new ObjectOutputStream(bai);
out.writeObject(this);
out.flush();
return bai.toByteArray();
} finally {
if (null != out) {
try {
out.close();
} catch (IOException e) {
// best effort.
logger.error(e);
}
}
}
}
use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class Channel method queryBlockchainInfo.
/**
* query for chain information
*
* @param peers The peers to try send the request.
* @param userContext the user context.
* @return a {@link BlockchainInfo} object containing the chain info requested
* @throws InvalidArgumentException
* @throws ProposalException
*/
public BlockchainInfo queryBlockchainInfo(Collection<Peer> peers, User userContext) throws ProposalException, InvalidArgumentException {
checkChannelState();
checkPeers(peers);
User.userContextCheck(userContext);
try {
logger.debug("queryBlockchainInfo to peer " + " on channel " + name);
QuerySCCRequest querySCCRequest = new QuerySCCRequest(userContext);
querySCCRequest.setFcn(QuerySCCRequest.GETCHAININFO);
querySCCRequest.setArgs(name);
ProposalResponse proposalResponse = sendProposalSerially(querySCCRequest, peers);
return new BlockchainInfo(Ledger.BlockchainInfo.parseFrom(proposalResponse.getProposalResponse().getResponse().getPayload()));
} catch (Exception e) {
logger.error(e);
throw new ProposalException(e);
}
}
use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class CryptoPrimitives method setProperties.
// /* (non-Javadoc)
// * @see org.hyperledger.fabric.sdk.security.CryptoSuite#setProperties(java.util.Properties)
// */
// @Override
void setProperties(Properties properties) throws CryptoException, InvalidArgumentException {
if (properties == null) {
throw new InvalidArgumentException("properties must not be null");
}
// if (properties != null) {
hashAlgorithm = Optional.ofNullable(properties.getProperty(Config.HASH_ALGORITHM)).orElse(hashAlgorithm);
String secLevel = Optional.ofNullable(properties.getProperty(Config.SECURITY_LEVEL)).orElse(Integer.toString(securityLevel));
securityLevel = Integer.parseInt(secLevel);
if (properties.containsKey(Config.SECURITY_CURVE_MAPPING)) {
securityCurveMapping = Config.parseSecurityCurveMappings(properties.getProperty(Config.SECURITY_CURVE_MAPPING));
} else {
securityCurveMapping = config.getSecurityCurveMapping();
}
final String providerName = properties.containsKey(Config.SECURITY_PROVIDER_CLASS_NAME) ? properties.getProperty(Config.SECURITY_PROVIDER_CLASS_NAME) : config.getSecurityProviderClassName();
try {
SECURITY_PROVIDER = setUpExplictProvider(providerName);
} catch (Exception e) {
throw new InvalidArgumentException(format("Getting provider for class name: %s", providerName), e);
}
CERTIFICATE_FORMAT = Optional.ofNullable(properties.getProperty(Config.CERTIFICATE_FORMAT)).orElse(CERTIFICATE_FORMAT);
DEFAULT_SIGNATURE_ALGORITHM = Optional.ofNullable(properties.getProperty(Config.SIGNATURE_ALGORITHM)).orElse(DEFAULT_SIGNATURE_ALGORITHM);
resetConfiguration();
}
use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class CryptoPrimitives method addCACertificateToTrustStore.
/**
* addCACertificateToTrustStore adds a CA cert to the set of certificates used for signature validation
*
* @param caCertPem an X.509 certificate in PEM format
* @param alias an alias associated with the certificate. Used as shorthand for the certificate during crypto operations
* @throws CryptoException
* @throws InvalidArgumentException
*/
public void addCACertificateToTrustStore(File caCertPem, String alias) throws CryptoException, InvalidArgumentException {
if (caCertPem == null) {
throw new InvalidArgumentException("The certificate cannot be null");
}
if (alias == null || alias.isEmpty()) {
throw new InvalidArgumentException("You must assign an alias to a certificate when adding to the trust store");
}
BufferedInputStream bis;
try {
bis = new BufferedInputStream(new ByteArrayInputStream(FileUtils.readFileToByteArray(caCertPem)));
Certificate caCert = cf.generateCertificate(bis);
addCACertificateToTrustStore(caCert, alias);
} catch (CertificateException | IOException e) {
throw new CryptoException("Unable to add CA certificate to trust store. Error: " + e.getMessage(), e);
}
}
use of org.hyperledger.fabric.sdk.exception.InvalidArgumentException in project fabric-sdk-java by hyperledger.
the class CryptoPrimitives method createTrustStore.
private void createTrustStore() throws CryptoException {
try {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
setTrustStore(keyStore);
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | InvalidArgumentException e) {
throw new CryptoException("Cannot create trust store. Error: " + e.getMessage(), e);
}
}
Aggregations