github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/ca/config/intermediate.go (about)

     1  /*
     2   * Copyright contributors to the Hyperledger Fabric Operator project
     3   *
     4   * SPDX-License-Identifier: Apache-2.0
     5   *
     6   * Licensed under the Apache License, Version 2.0 (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at:
     9   *
    10   * 	  http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  package config
    20  
    21  import (
    22  	"fmt"
    23  	"path/filepath"
    24  )
    25  
    26  func (c *Config) ParseIntermediateBlock() (map[string][]byte, error) {
    27  	if c.intermediateCrypto == nil {
    28  		c.intermediateCrypto = map[string][]byte{}
    29  	}
    30  
    31  	log.Info("Parsing Intermediate block")
    32  	certFiles := c.ServerConfig.CAConfig.Intermediate.TLS.CertFiles
    33  	for index, certFile := range certFiles {
    34  		err := c.HandleCertInput(certFile, fmt.Sprintf("parent-certfile%d.pem", index), c.intermediateCrypto)
    35  		if err != nil {
    36  			return nil, err
    37  		}
    38  		certFiles[index] = filepath.Join(c.HomeDir, fmt.Sprintf("parent-certfile%d.pem", index))
    39  	}
    40  	c.ServerConfig.CAConfig.Intermediate.TLS.CertFiles = certFiles
    41  
    42  	certFile := c.ServerConfig.CAConfig.Intermediate.TLS.Client.CertFile
    43  	keyFile := c.ServerConfig.CAConfig.Intermediate.TLS.Client.KeyFile
    44  	if certFile != "" && keyFile != "" {
    45  		log.Info("Client authentication information provided for intermediate CA connection")
    46  		err := c.HandleCertInput(certFile, "parent-cert.pem", c.intermediateCrypto)
    47  		if err != nil {
    48  			return nil, err
    49  		}
    50  		c.ServerConfig.CAConfig.Intermediate.TLS.Client.CertFile = filepath.Join(c.HomeDir, "parent-cert.pem")
    51  
    52  		err = c.HandleKeyInput(keyFile, "parent-key.pem", c.intermediateCrypto)
    53  		if err != nil {
    54  			return nil, err
    55  		}
    56  		c.ServerConfig.CAConfig.Intermediate.TLS.Client.KeyFile = filepath.Join(c.HomeDir, "parent-key.pem")
    57  	}
    58  
    59  	return c.intermediateCrypto, nil
    60  }
    61  
    62  func (c *Config) IntermediateMountPath() {
    63  	certFile := c.ServerConfig.CAConfig.Intermediate.TLS.Client.CertFile
    64  	keyFile := c.ServerConfig.CAConfig.Intermediate.TLS.Client.KeyFile
    65  
    66  	if certFile != "" && keyFile != "" {
    67  		c.ServerConfig.CAConfig.Intermediate.TLS.Client.CertFile = filepath.Join(c.MountPath, "parent-cert.pem")
    68  		c.ServerConfig.CAConfig.Intermediate.TLS.Client.KeyFile = filepath.Join(c.MountPath, "parent-key.pem")
    69  	}
    70  
    71  	certFiles := c.ServerConfig.CAConfig.Intermediate.TLS.CertFiles
    72  	for index, _ := range certFiles {
    73  		certFiles[index] = filepath.Join(c.MountPath, fmt.Sprintf("parent-certfile%d.pem", index))
    74  	}
    75  	c.ServerConfig.CAConfig.Intermediate.TLS.CertFiles = certFiles
    76  }