@@ -30,8 +30,18 @@ import (
30
30
"github.com/hyperledger/fabric/bccsp"
31
31
"github.com/hyperledger/fabric/bccsp/factory"
32
32
"github.com/hyperledger/fabric/protos/msp"
33
+ "gopkg.in/yaml.v2"
33
34
)
34
35
36
+ type OrganizationalUnitIdentifiersConfiguration struct {
37
+ Certificate string `yaml:"Certificate,omitempty"`
38
+ OrganizationalUnitIdentifier string `yaml:"OrganizationalUnitIdentifier,omitempty"`
39
+ }
40
+
41
+ type Configuration struct {
42
+ OrganizationalUnitIdentifiers []* OrganizationalUnitIdentifiersConfiguration `yaml:"OrganizationalUnitIdentifiers,omitempty"`
43
+ }
44
+
35
45
func readFile (file string ) ([]byte , error ) {
36
46
fileCont , err := ioutil .ReadFile (file )
37
47
if err != nil {
@@ -96,6 +106,7 @@ const (
96
106
keystore = "keystore"
97
107
intermediatecerts = "intermediatecerts"
98
108
crlsfolder = "crls"
109
+ configfilename = "config.yaml"
99
110
)
100
111
101
112
func SetupBCCSPKeystoreConfig (bccspConfig * factory.FactoryOpts , keystoreDir string ) {
@@ -153,6 +164,7 @@ func getMspConfig(dir string, bccspConfig *factory.FactoryOpts, ID string, sigid
153
164
admincertDir := filepath .Join (dir , admincerts )
154
165
intermediatecertsDir := filepath .Join (dir , intermediatecerts )
155
166
crlsDir := filepath .Join (dir , crlsfolder )
167
+ configFile := filepath .Join (dir , configfilename )
156
168
157
169
cacerts , err := getPemMaterialFromDir (cacertDir )
158
170
if err != nil || len (cacerts ) == 0 {
@@ -183,7 +195,45 @@ func getMspConfig(dir string, bccspConfig *factory.FactoryOpts, ID string, sigid
183
195
return nil , fmt .Errorf ("Failed loading crls ca certs at [%s]: [%s]" , intermediatecertsDir , err )
184
196
}
185
197
186
- // Load FabricCryptoConfig
198
+ // Load configuration file
199
+ // if the configuration file is there then load it
200
+ // otherwise skip it
201
+ var ouis []* msp.FabricOUIdentifier
202
+ _ , err = os .Stat (configFile )
203
+ if err == nil {
204
+ // load the file, if there is a failure in loading it then
205
+ // return an error
206
+ raw , err := ioutil .ReadFile (configFile )
207
+ if err != nil {
208
+ return nil , fmt .Errorf ("Failed loading configuration file at [%s]: [%s]" , configFile , err )
209
+ }
210
+
211
+ configuration := Configuration {}
212
+ err = yaml .Unmarshal (raw , & configuration )
213
+ if err != nil {
214
+ return nil , fmt .Errorf ("Failed unmarshalling configuration file at [%s]: [%s]" , configFile , err )
215
+ }
216
+
217
+ // Prepare OrganizationalUnitIdentifiers
218
+ if len (configuration .OrganizationalUnitIdentifiers ) > 0 {
219
+ for _ , ouID := range configuration .OrganizationalUnitIdentifiers {
220
+ f := filepath .Join (dir , ouID .Certificate )
221
+ raw , err = ioutil .ReadFile (f )
222
+ if err != nil {
223
+ return nil , fmt .Errorf ("Failed loading OrganizationalUnit certificate at [%s]: [%s]" , f , err )
224
+ }
225
+ oui := & msp.FabricOUIdentifier {
226
+ Certificate : raw ,
227
+ OrganizationalUnitIdentifier : ouID .OrganizationalUnitIdentifier ,
228
+ }
229
+ ouis = append (ouis , oui )
230
+ }
231
+ }
232
+ } else {
233
+ mspLogger .Infof ("MSP configuration file not found at [%s]: [%s]" , configFile , err )
234
+ }
235
+
236
+ // Set FabricCryptoConfig
187
237
cryptoConfig := & msp.FabricCryptoConfig {
188
238
SignatureHashFamily : bccsp .SHA2 ,
189
239
IdentityIdentifierHashFunction : bccsp .SHA256 ,
@@ -196,8 +246,9 @@ func getMspConfig(dir string, bccspConfig *factory.FactoryOpts, ID string, sigid
196
246
IntermediateCerts : intermediatecert ,
197
247
SigningIdentity : sigid ,
198
248
Name : ID ,
199
- RevocationList : crls ,
200
- CryptoConfig : cryptoConfig }
249
+ OrganizationalUnitIdentifiers : ouis ,
250
+ RevocationList : crls ,
251
+ CryptoConfig : cryptoConfig }
201
252
202
253
fmpsjs , _ := proto .Marshal (fmspconf )
203
254
0 commit comments