github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/common/enroller/hsmproxyenroller.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 enroller
    20  
    21  import (
    22  	"time"
    23  
    24  	current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
    25  	"github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/config"
    26  	"github.com/hyperledger/fabric-ca/api"
    27  	"github.com/hyperledger/fabric-ca/lib"
    28  )
    29  
    30  type HSMProxyCAClient interface {
    31  	Init() error
    32  	Enroll(*api.EnrollmentRequest) (*lib.EnrollmentResponse, error)
    33  	GetEnrollmentRequest() *current.Enrollment
    34  	GetHomeDir() string
    35  	GetTLSCert() []byte
    36  	PingCA(time.Duration) error
    37  	SetHSMLibrary(string)
    38  }
    39  
    40  type HSMProxyEnroller struct {
    41  	Client HSMProxyCAClient
    42  	Req    *current.Enrollment
    43  }
    44  
    45  func NewHSMProxyEnroller(caClient HSMProxyCAClient) *HSMProxyEnroller {
    46  	return &HSMProxyEnroller{
    47  		Client: caClient,
    48  	}
    49  }
    50  
    51  func (e *HSMProxyEnroller) GetEnrollmentRequest() *current.Enrollment {
    52  	return e.Client.GetEnrollmentRequest()
    53  }
    54  
    55  func (e *HSMProxyEnroller) PingCA(timeout time.Duration) error {
    56  	return e.Client.PingCA(timeout)
    57  }
    58  
    59  func (e *HSMProxyEnroller) Enroll() (*config.Response, error) {
    60  	e.Client.SetHSMLibrary("/usr/local/lib/libpkcs11-proxy.so")
    61  	return enroll(e.Client)
    62  }