Skip to content

Commit

Permalink
Fix issue 2168 (hyperledger-archives#2205)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Geng authored and srderson committed Jul 14, 2016
1 parent 7a0ddfd commit f4b71fe
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions core/chaincode/exectransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func initMemSrvc() (net.Listener, error) {
finitMemSrvc(nil)

ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
ca.CacheConfiguration() // Cache configuration

aca := ca.NewACA()
eca := ca.NewECA()
Expand Down
1 change: 1 addition & 0 deletions core/crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ func setup() {

func initPKI() {
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
ca.CacheConfiguration() // Need cache the configuration first
aca = ca.NewACA()
eca = ca.NewECA()
tca = ca.NewTCA(eca)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func setup() {

func initMembershipSrvc() {
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)

ca.CacheConfiguration() // Cache configuration
aca = ca.NewACA()
eca = ca.NewECA()
tca = ca.NewTCA(eca)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func setup() {

func initMembershipSrvc() {
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)

ca.CacheConfiguration() // Cache configuration
aca = ca.NewACA()
eca = ca.NewECA()
tca = ca.NewTCA(eca)
Expand Down
2 changes: 1 addition & 1 deletion examples/chaincode/go/rbac_tcerts_no_attrs/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func setup() {

func initMemershipServices() {
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)

ca.CacheConfiguration() // Cache configuration
eca = ca.NewECA()
tca = ca.NewTCA(eca)
tlsca = ca.NewTLSCA(eca)
Expand Down
20 changes: 16 additions & 4 deletions membersrvc/ca/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"io/ioutil"
"math/big"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -73,7 +74,11 @@ type AffiliationGroup struct {
}

var (
mutex = &sync.Mutex{}
mutex = &sync.Mutex{}
caOrganization string
caCountry string
rootPath string
caDir string
)

// NewCertificateSpec creates a new certificate spec
Expand Down Expand Up @@ -118,6 +123,13 @@ func NewDefaultCertificateSpecWithCommonName(id string, commonName string, pub i
return NewDefaultPeriodCertificateSpecWithCommonName(id, commonName, serialNumber, pub, usage, opt...)
}

func CacheConfiguration() {
caOrganization = viper.GetString("pki.ca.subject.organization")
caCountry = viper.GetString("pki.ca.subject.country")
rootPath = viper.GetString("server.rootpath")
caDir = viper.GetString("server.cadir")
}

// GetID returns the spec's ID field/value
//
func (spec *CertificateSpec) GetID() string {
Expand Down Expand Up @@ -163,13 +175,13 @@ func (spec *CertificateSpec) GetNotAfter() *time.Time {
// GetOrganization returns the spec's Organization field/value
//
func (spec *CertificateSpec) GetOrganization() string {
return viper.GetString("pki.ca.subject.organization")
return caOrganization
}

// GetCountry returns the spec's Country field/value
//
func (spec *CertificateSpec) GetCountry() string {
return viper.GetString("pki.ca.subject.country")
return caCountry
}

// GetSubjectKeyID returns the spec's subject KeyID
Expand Down Expand Up @@ -209,7 +221,7 @@ func initializeCommonTables(db *sql.DB) error {
// NewCA sets up a new CA.
func NewCA(name string, initTables TableInitializer) *CA {
ca := new(CA)
ca.path = viper.GetString("server.rootpath") + "/" + viper.GetString("server.cadir")
ca.path = filepath.Join(rootPath, caDir)

if _, err := os.Stat(ca.path); err != nil {
Info.Println("Fresh start; creating databases, key pairs, and certificates.")
Expand Down
2 changes: 1 addition & 1 deletion membersrvc/ca/ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestNewCA(t *testing.T) {

//initialize logging to avoid panics in the current code
LogInit(os.Stdout, os.Stdout, os.Stdout, os.Stderr, os.Stdout)

CacheConfiguration() // Cache configuration
//Create new CA
ca := NewCA(name, initializeTables)
if ca == nil {
Expand Down
1 change: 1 addition & 0 deletions membersrvc/ca/membersrvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func setupTestConfig() {

func initPKI() {
LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
CacheConfiguration() // Cache configuration
aca = NewACA()
eca = NewECA()
tca = NewTCA(eca)
Expand Down
2 changes: 1 addition & 1 deletion membersrvc/ca/tca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func initTCA() (*TCA, error) {

//initialize logging to avoid panics in the current code
LogInit(os.Stdout, os.Stdout, os.Stdout, os.Stderr, os.Stdout)

CacheConfiguration() // Cache configuration
eca := NewECA()
if eca == nil {
return nil, fmt.Errorf("Could not create a new ECA")
Expand Down
2 changes: 1 addition & 1 deletion membersrvc/ca/tlsca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestTLS(t *testing.T) {

func startTLSCA(t *testing.T) {
LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)

CacheConfiguration() // Cache configuration
ecaS = NewECA()
tlscaS = NewTLSCA(ecaS)

Expand Down
3 changes: 3 additions & 0 deletions membersrvc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func main() {
}

ca.LogInit(iotrace, ioinfo, iowarning, ioerror, iopanic)
// cache configure
ca.CacheConfiguration()

ca.Info.Println("CA Server (" + viper.GetString("server.version") + ")")

aca := ca.NewACA()
Expand Down

0 comments on commit f4b71fe

Please sign in to comment.