@@ -7,10 +7,8 @@ SPDX-License-Identifier: Apache-2.0
77package config
88
99import (
10- "crypto/ecdsa"
11- "crypto/x509"
12- "encoding/pem"
1310 "fmt"
11+ "net"
1412 "os"
1513 "path/filepath"
1614 "sort"
@@ -254,6 +252,7 @@ func (config *Configuration) ExtractRouterConfig(configBlock *common.Block) *nod
254252 ListenAddress : config .LocalConfig .NodeLocalConfig .GeneralConfig .ListenAddress + ":" + strconv .Itoa (int (config .LocalConfig .NodeLocalConfig .GeneralConfig .ListenPort )),
255253 ConfigStorePath : config .LocalConfig .NodeLocalConfig .FileStore .Path ,
256254 Shards : config .ExtractShards (),
255+ Consenter : config .ExtractConsenterInParty (),
257256 NumOfConnectionsForBatcher : config .LocalConfig .NodeLocalConfig .RouterParams .NumberOfConnectionsPerBatcher ,
258257 NumOfgRPCStreamsPerConnection : config .LocalConfig .NodeLocalConfig .RouterParams .NumberOfStreamsPerConnection ,
259258 UseTLS : config .LocalConfig .TLSConfig .Enabled ,
@@ -333,6 +332,7 @@ func (config *Configuration) ExtractConsenterConfig() *nodeconfig.ConsenterNodeC
333332 consenterConfig := & nodeconfig.ConsenterNodeConfig {
334333 Shards : config .ExtractShards (),
335334 Consenters : config .ExtractConsenters (),
335+ Router : config .ExtractRouterInParty (),
336336 Directory : config .LocalConfig .NodeLocalConfig .FileStore .Path ,
337337 ListenAddress : config .LocalConfig .NodeLocalConfig .GeneralConfig .ListenAddress + ":" + strconv .Itoa (int (config .LocalConfig .NodeLocalConfig .GeneralConfig .ListenPort )),
338338 PartyId : config .LocalConfig .NodeLocalConfig .PartyID ,
@@ -394,22 +394,7 @@ func (config *Configuration) ExtractShards() []nodeconfig.ShardInfo {
394394 for _ , batcher := range party .BatchersConfig {
395395 shardId := types .ShardID (batcher .ShardID )
396396
397- // Fetch public key from signing certificate
398- // NOTE: ARMA's new configuration uses certificates, which inherently contain the public key, instead of a separate public key field.
399- // To ensure backward compatibility until the full new config integration, the public key it enabled.
400- block , _ := pem .Decode (batcher .SignCert )
401- if block == nil || block .Bytes == nil {
402- panic ("Failed decoding batcher signing certificate" )
403- }
404-
405- var pemPublicKey []byte
406- if block .Type == "CERTIFICATE" {
407- pemPublicKey = blockToPublicKey (block )
408- }
409-
410- if block .Type == "PUBLIC KEY" {
411- pemPublicKey = batcher .SignCert
412- }
397+ pemPublicKey := utils .GetPublicKeyFromCertificate (batcher .SignCert )
413398
414399 batcher := nodeconfig.BatcherInfo {
415400 PartyID : types .PartyID (party .PartyID ),
@@ -447,22 +432,7 @@ func (config *Configuration) ExtractConsenters() []nodeconfig.ConsenterInfo {
447432 tlsCACertsCollection = append (tlsCACertsCollection , ca )
448433 }
449434
450- // Fetch public key from signing certificate
451- // NOTE: ARMA's new configuration now uses certificates, which inherently contain the public key, instead of a separate public key field.
452- // To ensure backward compatibility until the full new config integration, the public key it enabled.
453- block , _ := pem .Decode (party .ConsenterConfig .SignCert )
454- if block == nil || block .Bytes == nil {
455- panic ("Failed decoding consenter signing certificate" )
456- }
457-
458- var pemPublicKey []byte
459- if block .Type == "CERTIFICATE" {
460- pemPublicKey = blockToPublicKey (block )
461- }
462-
463- if block .Type == "PUBLIC KEY" {
464- pemPublicKey = party .ConsenterConfig .SignCert
465- }
435+ pemPublicKey := utils .GetPublicKeyFromCertificate (party .ConsenterConfig .SignCert )
466436
467437 consenterInfo := nodeconfig.ConsenterInfo {
468438 PartyID : types .PartyID (party .PartyID ),
@@ -476,28 +446,43 @@ func (config *Configuration) ExtractConsenters() []nodeconfig.ConsenterInfo {
476446 return consenters
477447}
478448
479- func blockToPublicKey (block * pem.Block ) []byte {
480- cert , err := x509 .ParseCertificate (block .Bytes )
481- if err != nil {
482- panic (fmt .Sprintf ("Failed parsing consenter signing certificate: %v" , err ))
449+ func (config * Configuration ) ExtractRouterInParty () nodeconfig.RouterInfo {
450+ partyID := config .LocalConfig .NodeLocalConfig .PartyID
451+ var party * protos.PartyConfig
452+ for _ , p := range config .SharedConfig .PartiesConfig {
453+ if types .PartyID (p .PartyID ) == partyID {
454+ party = p
455+ }
456+ }
457+ if party == nil {
458+ panic ("failed to extract router from config" )
483459 }
484460
485- pubKey , ok := cert .PublicKey .(* ecdsa.PublicKey )
486- if ! ok {
487- panic (fmt .Sprintf ("Failed parsing consenter public key: %v" , err ))
461+ routerConfig := party .RouterConfig
462+
463+ var tlsCACertsCollection []nodeconfig.RawBytes
464+ for _ , ca := range party .TLSCACerts {
465+ tlsCACertsCollection = append (tlsCACertsCollection , ca )
488466 }
489467
490- publicKeyBytes , err := x509 .MarshalPKIXPublicKey (pubKey )
491- if err != nil {
492- panic (fmt .Sprintf ("Failed marshaling consenter public key: %v" , err ))
468+ routerInfo := nodeconfig.RouterInfo {
469+ PartyID : partyID ,
470+ Endpoint : net .JoinHostPort (routerConfig .Host , strconv .Itoa (int (routerConfig .Port ))),
471+ TLSCACerts : tlsCACertsCollection ,
472+ TLSCert : routerConfig .TlsCert ,
493473 }
494474
495- pemPublicKey := pem .EncodeToMemory (& pem.Block {
496- Type : "PUBLIC KEY" ,
497- Bytes : publicKeyBytes ,
498- })
475+ return routerInfo
476+ }
499477
500- return pemPublicKey
478+ func (config * Configuration ) ExtractConsenterInParty () nodeconfig.ConsenterInfo {
479+ consenterInfos := config .ExtractConsenters ()
480+ for _ , consenter := range consenterInfos {
481+ if consenter .PartyID == config .LocalConfig .NodeLocalConfig .PartyID {
482+ return consenter
483+ }
484+ }
485+ panic ("failed to extract consenter from config" )
501486}
502487
503488func (config * Configuration ) extractBundleFromConfigBlock (configBlock * common.Block ) channelconfig.Resources {
0 commit comments