Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit eecc997

Browse files
committed
FAB-6411 generate CRL
Change-Id: I3110f26d653a47da443f0baad86eb60960745513 Signed-off-by: rickr <cr22rc@gmail.com>
1 parent 65a94a6 commit eecc997

File tree

8 files changed

+256
-47
lines changed

8 files changed

+256
-47
lines changed

src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import java.io.ByteArrayInputStream;
1919
import java.io.File;
2020
import java.io.IOException;
21+
import java.io.PrintWriter;
2122
import java.io.StringReader;
23+
import java.io.StringWriter;
2224
import java.net.MalformedURLException;
2325
import java.net.Socket;
2426
import java.net.URL;
@@ -33,14 +35,18 @@
3335
import java.security.cert.CertificateException;
3436
import java.security.cert.CertificateFactory;
3537
import java.security.cert.X509Certificate;
38+
import java.text.SimpleDateFormat;
3639
import java.util.Base64;
40+
import java.util.Date;
3741
import java.util.Properties;
42+
import java.util.TimeZone;
3843

3944
import javax.json.Json;
4045
import javax.json.JsonArray;
4146
import javax.json.JsonObject;
4247
import javax.json.JsonObjectBuilder;
4348
import javax.json.JsonReader;
49+
import javax.json.JsonWriter;
4450
import javax.net.ssl.SSLContext;
4551
import javax.net.ssl.TrustManager;
4652
import javax.net.ssl.X509TrustManager;
@@ -81,6 +87,7 @@
8187
import org.hyperledger.fabric.sdk.security.CryptoPrimitives;
8288
import org.hyperledger.fabric.sdk.security.CryptoSuite;
8389
import org.hyperledger.fabric_ca.sdk.exception.EnrollmentException;
90+
import org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException;
8491
import org.hyperledger.fabric_ca.sdk.exception.InfoException;
8592
import org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException;
8693
import org.hyperledger.fabric_ca.sdk.exception.RegistrationException;
@@ -102,6 +109,7 @@ public class HFCAClient {
102109
private static final String HFCA_REENROLL = HFCA_CONTEXT_ROOT + "reenroll";
103110
private static final String HFCA_REVOKE = HFCA_CONTEXT_ROOT + "revoke";
104111
private static final String HFCA_INFO = HFCA_CONTEXT_ROOT + "cainfo";
112+
private static final String HFCA_GENCRL = HFCA_CONTEXT_ROOT + "gencrl";
105113

106114
static final String FABRIC_CA_REQPROP = "caname";
107115

@@ -603,6 +611,81 @@ public void revoke(User revoker, String revokee, String reason) throws Revocatio
603611
}
604612
}
605613

614+
/**
615+
* Generate certificate revocation list.
616+
*
617+
* @param registrar admin user configured in CA-server
618+
* @param revokedBefore Restrict certificates returned to revoked before this date if not null.
619+
* @param revokedAfter Restrict certificates returned to revoked after this date if not null.
620+
* @param expireBefore Restrict certificates returned to expired before this date if not null.
621+
* @param expireAfter Restrict certificates returned to expired after this date if not null.
622+
* @throws InvalidArgumentException
623+
*/
624+
625+
public String generateCRL(User registrar, Date revokedBefore, Date revokedAfter, Date expireBefore, Date expireAfter)
626+
throws InvalidArgumentException, GenerateCRLException {
627+
628+
if (cryptoSuite == null) {
629+
throw new InvalidArgumentException("Crypto primitives not set.");
630+
}
631+
632+
if (registrar == null) {
633+
throw new InvalidArgumentException("registrar is not set");
634+
}
635+
636+
try {
637+
setUpSSL();
638+
639+
//---------------------------------------
640+
JsonObjectBuilder factory = Json.createObjectBuilder();
641+
if (revokedBefore != null) {
642+
factory.add("revokedBefore", toJson(revokedBefore));
643+
}
644+
if (revokedAfter != null) {
645+
factory.add("revokedAfter", toJson(revokedAfter));
646+
}
647+
if (expireBefore != null) {
648+
factory.add("expireBefore", toJson(expireBefore));
649+
}
650+
if (expireAfter != null) {
651+
factory.add("expireAfter", toJson(expireAfter));
652+
}
653+
if (caName != null) {
654+
factory.add(HFCAClient.FABRIC_CA_REQPROP, caName);
655+
}
656+
657+
JsonObject jsonObject = factory.build();
658+
659+
StringWriter stringWriter = new StringWriter();
660+
JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter));
661+
jsonWriter.writeObject(jsonObject);
662+
jsonWriter.close();
663+
String body = stringWriter.toString();
664+
665+
//---------------------------------------
666+
667+
// build auth header
668+
String authHdr = getHTTPAuthCertificate(registrar.getEnrollment(), body);
669+
670+
// send revoke request
671+
JsonObject ret = httpPost(url + HFCA_GENCRL, body, authHdr);
672+
673+
return ret.getString("CRL");
674+
675+
} catch (Exception e) {
676+
logger.error(e.getMessage(), e);
677+
throw new GenerateCRLException(e.getMessage(), e);
678+
}
679+
}
680+
681+
private String toJson(Date date) {
682+
final TimeZone utc = TimeZone.getTimeZone("UTC");
683+
684+
SimpleDateFormat tformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
685+
tformat.setTimeZone(utc);
686+
return tformat.format(date);
687+
}
688+
606689
/**
607690
* Http Post Request.
608691
*
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
*
3+
* Copyright 2016,2017 DTCC, Fujitsu Australia Software Technology, IBM - All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
*/
16+
17+
package org.hyperledger.fabric_ca.sdk.exception;
18+
19+
public class GenerateCRLException extends BaseException {
20+
21+
private static final long serialVersionUID = 1L;
22+
23+
public GenerateCRLException(String message, Exception parent) {
24+
super(message, parent);
25+
}
26+
27+
}

src/main/proto/common/configuration.proto

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,43 @@ message Consortium {
4747
string name = 1;
4848
}
4949

50-
// Capabilities message contains all the capabilities that a channel requires
51-
// participant entities to comply with. The entity should drop off the channel
52-
// if it can't fulfill any of the required capabilities.
53-
// Capabilities is encoded into the configuaration as Values of each type
54-
// Orderer, Channel, or Application.
55-
// The key string should represent the capability name, and it must be unique
56-
// within each type. For readability, it may be advisable to prefix the key with
57-
// its type (eg app-acl)
50+
// Capabilities message defines the capabilities a particular binary must implement
51+
// for that binary to be able to safely participate in the channel. The capabilities
52+
// message is defined at the /Channel level, the /Channel/Application level, and the
53+
// /Channel/Orderer level.
54+
//
55+
// The /Channel level capabilties define capabilities which both the orderer and peer
56+
// binaries must satisfy. These capabilties might be things like a new MSP type,
57+
// or a new policy type.
58+
//
59+
// The /Channel/Orderer level capabilties define capabilities which must be supported
60+
// by the orderer, but which have no bearing on the behavior of the peer. For instance
61+
// if the orderer changes the logic for how it constructs new channels, only all orderers
62+
// must agree on the new logic. The peers do not need to be aware of this change as
63+
// they only interact with the channel after it has been constructed.
64+
//
65+
// Finally, the /Channel/Application level capabilities define capabilities which the peer
66+
// binary must satisfy, but which have no bearing on the orderer. For instance, if the
67+
// peer adds a new UTXO transaction type, or changes the chaincode lifecycle requirements,
68+
// all peers must agree on the new logic. However, orderers never inspect transactions
69+
// this deeply, and therefore have no need to be aware of the change.
70+
//
71+
// The capabilities strings defined in these messages typically correspond to release
72+
// binary versions (e.g. "V1.1"), and are used primarilly as a mechanism for a fully
73+
// upgraded network to switch from one set of logic to a new one.
74+
//
75+
// Although for V1.1, the orderers must be upgraded to V1.1 prior to the rest of the
76+
// network, going forward, because of the split between the /Channel, /Channel/Orderer
77+
// and /Channel/Application capabilities. It should be possible for the orderer and
78+
// application networks to upgrade themselves independently (with the exception of any
79+
// new capabilities defined at the /Channel level).
5880
message Capabilities {
5981
map<string, Capability> capabilities = 1;
6082
}
6183

62-
// Capability holds a set of options. We can add more as needed in the
63-
// future. For now, whether it is required or not. If a configured capability
64-
// is not required, it must be completely compatible with previous releases.
65-
// Compatible features are not required to be encoded as capabilities; they
66-
// only provide flexibility for the admins to control the features.
84+
// Capability is an empty message for the time being. It is defined as a protobuf
85+
// message rather than a constant, so that we may extend capabilities with other fields
86+
// if the need arises in the future. For the time being, a capability being in the
87+
// capabilities map requires that that capability be supported.
6788
message Capability {
68-
bool required = 1;
6989
}

src/main/proto/ledger/rwset/rwset.proto

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,3 @@ message CollectionPvtReadWriteSet {
6363
string collection_name = 1;
6464
bytes rwset = 2; // Data model specific serialized proto message (e.g., kvrwset.KVRWSet for KV and Document data models)
6565
}
66-
67-
// CollectionProperty defines an element of a private data that corresponds
68-
// to a certain transaction and collection
69-
message CollectionCriteria {
70-
string channel = 1;
71-
string tx_id = 2;
72-
string collection = 3;
73-
}

src/main/proto/msp/identities.proto

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
syntax = "proto3";
@@ -31,3 +21,25 @@ message SerializedIdentity {
3121
// the Identity, serialized according to the rules of its MPS
3222
bytes id_bytes = 2;
3323
}
24+
25+
// This struct represents an Idemix Identity
26+
// to be used to serialize it and deserialize it.
27+
// The IdemixMSP will first serialize an idemix identity to bytes using
28+
// this proto, and then uses these bytes as id_bytes in SerializedIdentity
29+
message SerializedIdemixIdentity {
30+
// NymX is the X-component of the pseudonym elliptic curve point.
31+
// It is a []byte representation of an amcl.BIG
32+
// The pseudonym can be seen as a public key of the identity, it is used to verify signatures.
33+
bytes NymX = 1;
34+
35+
// NymX is the Y-component of the pseudonym elliptic curve point.
36+
// It is a []byte representation of an amcl.BIG
37+
// The pseudonym can be seen as a public key of the identity, it is used to verify signatures.
38+
bytes NymY = 2;
39+
40+
// OU contains the organizational unit of the idemix identity
41+
bytes OU = 3;
42+
43+
// Role contains the role of this identity (e.g., ADMIN or MEMBER)
44+
bytes Role = 4;
45+
}

src/main/proto/msp/msp_config.proto

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
syntax = "proto3";
@@ -110,6 +100,34 @@ message FabricCryptoConfig {
110100

111101
}
112102

103+
// IdemixMSPConfig collects all the configuration information for
104+
// an Idemix MSP.
105+
message IdemixMSPConfig {
106+
// Name holds the identifier of the MSP
107+
string name = 1;
108+
109+
// IPk represents the (serialized) issuer public key
110+
bytes IPk = 2;
111+
112+
// signer may contain crypto material to configure a default signer
113+
IdemixMSPSignerConfig signer = 3;
114+
}
115+
116+
// IdemixMSPSIgnerConfig contains the crypto material to set up an idemix signing identity
117+
message IdemixMSPSignerConfig {
118+
// Cred represents the serialized idemix credential of the default signer
119+
bytes Cred = 1;
120+
121+
// Sk is the secret key of the default signer, corresponding to credential Cred
122+
bytes Sk = 2;
123+
124+
// organizational_unit_identifier defines the organizational unit the default signer is in
125+
string organizational_unit_identifier = 3;
126+
127+
// is_admin defines whether the default signer is admin or not
128+
bool is_admin = 4;
129+
}
130+
113131
// SigningIdentityInfo represents the configuration information
114132
// related to the signing identity the peer is to use for generating
115133
// endorsements

src/main/proto/peer/events.proto

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum EventType {
3434
BLOCK = 1;
3535
CHAINCODE = 2;
3636
REJECTION = 3;
37+
FILTEREDBLOCK = 4;
3738
}
3839

3940
//ChaincodeReg is used for registering chaincode Interests
@@ -74,6 +75,22 @@ message Unregister {
7475
repeated Interest events = 1;
7576
}
7677

78+
//FilteredBlock is sent by producers and contains minimal information
79+
//about the block.
80+
message FilteredBlock {
81+
string channel_id = 1;
82+
uint64 number = 2; // The position in the blockchain
83+
repeated FilteredTransaction filtered_tx = 3;
84+
}
85+
86+
//FilteredTransaction is a minimal set of information about a transaction
87+
//within a block.
88+
message FilteredTransaction {
89+
string txid = 1;
90+
TxValidationCode tx_validation_code = 2;
91+
ChaincodeEvent ccEvent = 3;
92+
}
93+
7794
// SignedEvent is used for any communication between consumer and producer
7895
message SignedEvent {
7996
// Signature over the event bytes
@@ -99,6 +116,8 @@ message Event {
99116

100117
//Unregister consumer sent events
101118
Unregister unregister = 5;
119+
120+
FilteredBlock filtered_block = 7;
102121
}
103122
// Creator of the event, specified as a certificate chain
104123
bytes creator = 6;

0 commit comments

Comments
 (0)