storj.io/uplink@v1.13.0/edge/config.go (about)

     1  // Copyright (C) 2021 Storj Labs, Inc.
     2  // See LICENSE for copying information.
     3  
     4  package edge
     5  
     6  import (
     7  	"crypto/tls"
     8  	"crypto/x509"
     9  
    10  	"storj.io/common/rpc"
    11  )
    12  
    13  // Config contains configuration on how to access edge services.
    14  type Config struct {
    15  	// AuthServiceAddress sets a fixed DRPC server including port.
    16  	// Valid is auth.storjshare.io:7777 or a third party hosted alternative.
    17  	AuthServiceAddress string
    18  
    19  	// CertificatePEM contains the root certificate(s) or chain(s) against which
    20  	// Uplink checks the auth service.
    21  	// In PEM format.
    22  	// Intended to test against a self-hosted auth service or to improve security.
    23  	CertificatePEM []byte
    24  
    25  	// InsecureSkipVerify makes possible to connect to Authservice without TLS. Don't use in production.
    26  	//
    27  	// Deprecated: Use InsecureUnencryptedConnection instead.
    28  	InsecureSkipVerify bool
    29  
    30  	// InsecureUnencryptedConnection makes possible to connect to Authservice without TLS,
    31  	// sending plaintext requests over the network and receiving plaintext responses.
    32  	// Don't use in production.
    33  	InsecureUnencryptedConnection bool
    34  }
    35  
    36  func (config *Config) createDialer() rpc.Dialer {
    37  	//lint:ignore SA1019 deprecated okay,
    38  	//nolint:staticcheck // deprecated okay.
    39  	connector := rpc.NewDefaultTCPConnector(nil)
    40  	connector.SetSendDRPCMuxHeader(false)
    41  
    42  	dialer := rpc.NewDefaultDialer(nil)
    43  	dialer.Connector = connector
    44  	dialer.HostnameTLSConfig = &tls.Config{}
    45  
    46  	if len(config.CertificatePEM) > 0 {
    47  		certPool := x509.NewCertPool()
    48  		certPool.AppendCertsFromPEM(config.CertificatePEM)
    49  
    50  		dialer.HostnameTLSConfig.RootCAs = certPool
    51  	}
    52  
    53  	return dialer
    54  }