1// Copyright (C) 2021 Storj Labs, Inc.
2// See LICENSE for copying information.
3
4package uplink
5
6import (
7	"context"
8	"sync"
9
10	"storj.io/common/identity"
11	"storj.io/common/peertls/tlsopts"
12)
13
14var processTLSOptions struct {
15	mu         sync.Mutex
16	tlsOptions *tlsopts.Options
17}
18
19func getProcessTLSOptions(ctx context.Context) (*tlsopts.Options, error) {
20	processTLSOptions.mu.Lock()
21	defer processTLSOptions.mu.Unlock()
22
23	if processTLSOptions.tlsOptions != nil {
24		return processTLSOptions.tlsOptions, nil
25	}
26
27	ident, err := identity.NewFullIdentity(ctx, identity.NewCAOptions{
28		Difficulty:  0,
29		Concurrency: 1,
30	})
31	if err != nil {
32		return nil, packageError.Wrap(err)
33	}
34
35	tlsConfig := tlsopts.Config{
36		UsePeerCAWhitelist: false,
37		PeerIDVersions:     "0",
38	}
39
40	tlsOptions, err := tlsopts.NewOptions(ident, tlsConfig, nil)
41	if err != nil {
42		return nil, packageError.Wrap(err)
43	}
44
45	processTLSOptions.tlsOptions = tlsOptions
46	return tlsOptions, nil
47}
48