Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/tools/armageddon/armageddon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func checkCryptoDir(outputDir string) error {
return fmt.Errorf("error reading directory %s\n", usersDir)
}
for _, file := range files {
if !strings.HasSuffix(file.Name(), ".pem") {
if !strings.HasSuffix(file.Name(), ".pem") && !strings.Contains(file.Name(), "priv_sk") {
return fmt.Errorf("error reading %s files, suffix file is not pem\n", filepath.Join(orgDir, usersDir))
}
}
Expand Down
25 changes: 25 additions & 0 deletions common/tools/armageddon/cryptogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ func createNetworkCryptoMaterial(dir string, network *genconfig.Network) error {
if err != nil {
return err
}

// signing crypto to user
err = createUserSignCertAndPrivateKey(signCA, dir, party.ID, nil)
if err != nil {
return err
}
}
return nil
}
Expand Down Expand Up @@ -276,6 +282,25 @@ func createSignCertAndPrivateKeyForNode(ca *ca.CA, dir string, endpoint string,
return nil
}

// createUserSignCertAndPrivateKey creates for user a signed certificate with a corresponding private key used for signing and write them into files.
func createUserSignCertAndPrivateKey(ca *ca.CA, dir string, partyID types.PartyID, nodesIPs []string) error {
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return fmt.Errorf("err: %s, failed creating private key for user of party %d", err, partyID)
}
privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
if err != nil {
return fmt.Errorf("err: %s, failed marshaling private key for user of party %d", err, partyID)
}

ca.SignCertificate(filepath.Join(dir, "crypto", "ordererOrganizations", fmt.Sprintf("org%d", partyID), "users"), "sign", nil, nodesIPs, getPublicKey(privateKey), x509.KeyUsageDigitalSignature, []x509.ExtKeyUsage{})
err = writePEMToFile(filepath.Join(dir, "crypto", "ordererOrganizations", fmt.Sprintf("org%d", partyID), "users", "priv_sk"), "PRIVATE KEY", privateKeyBytes)
if err != nil {
return err
}
return nil
}

// generateNetworkCryptoConfigFolderStructure creates folders where the crypto material is written to.
func generateNetworkCryptoConfigFolderStructure(dir string, network *genconfig.Network) error {
var folders []string
Expand Down