Skip to content

Commit e78b8b0

Browse files
gengurHagarMeir
authored andcommitted
Push config update (Integration tests - reconfiguration #247)
Signed-off-by: Genady Gurevich <genadyg@il.ibm.com>
1 parent b828378 commit e78b8b0

File tree

5 files changed

+369
-11
lines changed

5 files changed

+369
-11
lines changed

common/tools/armageddon/cryptogen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ func copyFile(src, dst string) error {
552552
return err
553553
}
554554

555-
func CreateNewCertificateFromCA(caCertPath string, caPrivateKeyPath string, pathToNewTLSCert string, pathToNewTLSKey string, nodesIPs []string) ([]byte, error) {
555+
func CreateNewCertificateFromCA(caCertPath string, caPrivateKeyPath string, name string, pathToNewCert string, pathToNewPrivateKey string, nodesIPs []string) ([]byte, error) {
556556
caCertBytes, err := utils.ReadPem(caCertPath)
557557
if err != nil {
558558
return nil, err
@@ -595,20 +595,20 @@ func CreateNewCertificateFromCA(caCertPath string, caPrivateKeyPath string, path
595595
return nil, fmt.Errorf("failed marshaling private key, err: %s", err)
596596
}
597597

598-
_, err = ca.SignCertificate(pathToNewTLSCert, "tls", nil, nodesIPs, GetPublicKey(privateKey), x509.KeyUsageCertSign|x509.KeyUsageCRLSign, []x509.ExtKeyUsage{
598+
_, err = ca.SignCertificate(pathToNewCert, name, nil, nodesIPs, GetPublicKey(privateKey), x509.KeyUsageCertSign|x509.KeyUsageCRLSign|x509.KeyUsageDigitalSignature, []x509.ExtKeyUsage{
599599
x509.ExtKeyUsageClientAuth,
600600
x509.ExtKeyUsageServerAuth,
601601
})
602602
if err != nil {
603603
return nil, err
604604
}
605605

606-
err = utils.WritePEMToFile(pathToNewTLSKey, "PRIVATE KEY", privateKeyBytes)
606+
err = utils.WritePEMToFile(pathToNewPrivateKey, "PRIVATE KEY", privateKeyBytes)
607607
if err != nil {
608608
return nil, err
609609
}
610610

611-
newCertBytes, err := os.ReadFile(filepath.Join(pathToNewTLSCert, "tls-cert.pem"))
611+
newCertBytes, err := os.ReadFile(filepath.Join(pathToNewCert, fmt.Sprintf("%s-cert.pem", name)))
612612
if err != nil {
613613
return nil, err
614614
}

common/utils/net.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,47 @@ func CertificateBytesToString(cert []byte) (string, error) {
6464
return CertificateToString(x509Cert), nil
6565
}
6666

67+
func AreCertificatesEqual(cert1, cert2 []byte) bool {
68+
x509Cert1, err := Parsex509Cert(cert1)
69+
if err != nil {
70+
return false
71+
}
72+
x509Cert2, err := Parsex509Cert(cert2)
73+
if err != nil {
74+
return false
75+
}
76+
77+
if x509Cert1.SerialNumber.Cmp(x509Cert2.SerialNumber) != 0 {
78+
return false
79+
}
80+
81+
if x509Cert1.Issuer.String() != x509Cert2.Issuer.String() {
82+
return false
83+
}
84+
85+
if x509Cert1.Subject.String() != x509Cert2.Subject.String() {
86+
return false
87+
}
88+
89+
if !x509Cert1.NotBefore.Equal(x509Cert2.NotBefore) {
90+
return false
91+
}
92+
93+
if !x509Cert1.NotAfter.Equal(x509Cert2.NotAfter) {
94+
return false
95+
}
96+
97+
if x509Cert1.PublicKeyAlgorithm != x509Cert2.PublicKeyAlgorithm {
98+
return false
99+
}
100+
101+
if x509Cert1.SignatureAlgorithm != x509Cert2.SignatureAlgorithm {
102+
return false
103+
}
104+
105+
return true
106+
}
107+
67108
func CertificateToString(cert *x509.Certificate) string {
68109
var sb strings.Builder
69110
fmt.Fprintf(&sb, "Certificate:\n")

config/config.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ func (config *Configuration) CheckIfBatcherNodeExistsInSharedConfig(localSignCer
697697
return fmt.Errorf("batcher in shard%d does not exist for party%d in the shared config", localShardID, localPartyID)
698698
}
699699

700-
if !bytes.Equal(localTLSCert, sharedBatcherConfig.TlsCert) {
700+
if !utils.AreCertificatesEqual(localTLSCert, sharedBatcherConfig.TlsCert) {
701701
localTLSCertString, err := utils.CertificateBytesToString(localTLSCert)
702702
if err != nil {
703703
return err
@@ -709,7 +709,8 @@ func (config *Configuration) CheckIfBatcherNodeExistsInSharedConfig(localSignCer
709709
return fmt.Errorf("certificate mismatch: the batcher of party %d shard %d is attempting to load with TLS certificate: %v that differs from the shared configuration TLS certificate: %v", localPartyID, localShardID, localTLSCertString, sharedTLSCertString)
710710
}
711711

712-
if !bytes.Equal(localSignCert, sharedBatcherConfig.SignCert) {
712+
// if !bytes.Equal(localSignCert, sharedBatcherConfig.SignCert) {
713+
if !utils.AreCertificatesEqual(localSignCert, sharedBatcherConfig.SignCert) {
713714
localSignCertString, err := utils.CertificateBytesToString(localSignCert)
714715
if err != nil {
715716
return err
@@ -737,7 +738,7 @@ func (config *Configuration) CheckIfConsenterNodeExistsInSharedConfig(localSignC
737738
return fmt.Errorf("consenter configuration of partyID %d is missing from the shared configuration: %+v", localPartyID, sharedPartyConfig)
738739
}
739740

740-
if !bytes.Equal(localSignCert, sharedPartyConfig.ConsenterConfig.SignCert) {
741+
if !utils.AreCertificatesEqual(localSignCert, sharedPartyConfig.ConsenterConfig.SignCert) {
741742
localSignCertString, err := utils.CertificateBytesToString(localSignCert)
742743
if err != nil {
743744
return err
@@ -749,7 +750,7 @@ func (config *Configuration) CheckIfConsenterNodeExistsInSharedConfig(localSignC
749750
return fmt.Errorf("sign certificate mismatch: Consenter%d is attempting to load with sign certificate: %v that differs from the shared configuration sign certificate: %v", localPartyID, localSignCertString, sharedSignCertString)
750751
}
751752

752-
if !bytes.Equal(localTLSCert, sharedPartyConfig.ConsenterConfig.TlsCert) {
753+
if !utils.AreCertificatesEqual(localTLSCert, sharedPartyConfig.ConsenterConfig.TlsCert) {
753754
localTLSCertString, err := utils.CertificateBytesToString(localTLSCert)
754755
if err != nil {
755756
return err
@@ -775,7 +776,7 @@ func (config *Configuration) CheckIfAssemblerNodeExistsInSharedConfig() error {
775776
if sharedPartyConfig.AssemblerConfig == nil {
776777
return fmt.Errorf("assembler configuration of partyID %d is missing from the shared configuration: %+v", localPartyID, sharedPartyConfig)
777778
}
778-
if !bytes.Equal(localTLSCert, sharedPartyConfig.AssemblerConfig.TlsCert) {
779+
if !utils.AreCertificatesEqual(localTLSCert, sharedPartyConfig.AssemblerConfig.TlsCert) {
779780
localTLSCertString, err := utils.CertificateBytesToString(localTLSCert)
780781
if err != nil {
781782
return err

node/consensus/consensus_real_reconfig_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestConsensusWithRealConfigUpdate(t *testing.T) {
162162
caPrivKeyPath := filepath.Join(dir, "crypto", "ordererOrganizations", fmt.Sprintf("org%d", consenterToUpdate), "tlsca", "priv_sk")
163163
newCertPath := filepath.Join(dir, "crypto", "ordererOrganizations", fmt.Sprintf("org%d", consenterToUpdate), "orderers", fmt.Sprintf("party%d", consenterToUpdate), "consenter", "tls")
164164
newKeyPath := filepath.Join(dir, "crypto", "ordererOrganizations", fmt.Sprintf("org%d", consenterToUpdate), "orderers", fmt.Sprintf("party%d", consenterToUpdate), "consenter", "tls", "key.pem")
165-
newCert, err := armageddon.CreateNewCertificateFromCA(caCertPath, caPrivKeyPath, newCertPath, newKeyPath, nodesIPs)
165+
newCert, err := armageddon.CreateNewCertificateFromCA(caCertPath, caPrivKeyPath, "tls", newCertPath, newKeyPath, nodesIPs)
166166
require.NoError(t, err)
167167
configUpdatePbData := configUpdateBuilder.UpdateConsensusTLSCert(t, consenterToUpdate, newCert)
168168
env := configutil.CreateConfigTX(t, dir, parties, 1, configUpdatePbData)

0 commit comments

Comments
 (0)