Skip to content

Commit 118c432

Browse files
authored
added the time shift option for the tls OSN certificate. (hyperledger#5251)
Signed-off-by: Fedor Partanskiy <fredprtnsk@gmail.com>
1 parent 3b66f3b commit 118c432

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

common/fabhttp/tls.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"crypto/tls"
1111
"crypto/x509"
1212
"os"
13+
"time"
1314

1415
"github.com/hyperledger/fabric/internal/pkg/comm"
1516
)
@@ -20,6 +21,7 @@ type TLS struct {
2021
KeyFile string
2122
ClientCertRequired bool
2223
ClientCACertFiles []string
24+
TimeShift time.Duration
2325
}
2426

2527
func (t TLS) Config() (*tls.Config, error) {
@@ -44,6 +46,12 @@ func (t TLS) Config() (*tls.Config, error) {
4446
CipherSuites: comm.DefaultTLSCipherSuites,
4547
ClientCAs: caCertPool,
4648
}
49+
if t.TimeShift > 0 {
50+
tlsConfig.Time = func() time.Time {
51+
return time.Now().Add((-1) * t.TimeShift)
52+
}
53+
}
54+
4755
if t.ClientCertRequired {
4856
tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert
4957
} else {

integration/nwo/operational_client.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ import (
1818
)
1919

2020
func OrdererOperationalClients(n *Network, o *Orderer) (authClient, unauthClient *http.Client) {
21-
return operationalClients(n, n.OrdererLocalTLSDir(o))
21+
return OrdererOperationalClientsTimeShift(n, o, 0)
22+
}
23+
24+
func OrdererOperationalClientsTimeShift(n *Network, o *Orderer, timeShift time.Duration) (authClient, unauthClient *http.Client) {
25+
return operationalClients(n, n.OrdererLocalTLSDir(o), timeShift)
2226
}
2327

2428
func PeerOperationalClients(n *Network, p *Peer) (authClient, unauthClient *http.Client) {
25-
return operationalClients(n, n.PeerLocalTLSDir(p))
29+
return operationalClients(n, n.PeerLocalTLSDir(p), 0)
2630
}
2731

28-
func operationalClients(n *Network, tlsDir string) (authClient, unauthClient *http.Client) {
32+
func operationalClients(n *Network, tlsDir string, timeShift time.Duration) (authClient, unauthClient *http.Client) {
2933
fingerprint := "http::" + tlsDir
3034
if d := n.throttleDuration(fingerprint); d > 0 {
3135
time.Sleep(d)
@@ -42,19 +46,30 @@ func operationalClients(n *Network, tlsDir string) (authClient, unauthClient *ht
4246
Expect(err).NotTo(HaveOccurred())
4347
clientCertPool.AppendCertsFromPEM(caCert)
4448

49+
authenticatedTlsConfig := &tls.Config{
50+
Certificates: []tls.Certificate{clientCert},
51+
RootCAs: clientCertPool,
52+
}
53+
unauthenticatedTlsConfig := &tls.Config{RootCAs: clientCertPool}
54+
if timeShift > 0 {
55+
authenticatedTlsConfig.Time = func() time.Time {
56+
return time.Now().Add((-1) * timeShift)
57+
}
58+
unauthenticatedTlsConfig.Time = func() time.Time {
59+
return time.Now().Add((-1) * timeShift)
60+
}
61+
}
62+
4563
authenticatedClient := &http.Client{
4664
Transport: &http.Transport{
4765
MaxIdleConnsPerHost: -1,
48-
TLSClientConfig: &tls.Config{
49-
Certificates: []tls.Certificate{clientCert},
50-
RootCAs: clientCertPool,
51-
},
66+
TLSClientConfig: authenticatedTlsConfig,
5267
},
5368
}
5469
unauthenticatedClient := &http.Client{
5570
Transport: &http.Transport{
5671
MaxIdleConnsPerHost: -1,
57-
TLSClientConfig: &tls.Config{RootCAs: clientCertPool},
72+
TLSClientConfig: unauthenticatedTlsConfig,
5873
},
5974
}
6075

orderer/common/server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ func newAdminServer(admin localconfig.Admin) *fabhttp.Server {
675675
KeyFile: admin.TLS.PrivateKey,
676676
ClientCertRequired: admin.TLS.ClientAuthRequired,
677677
ClientCACertFiles: admin.TLS.ClientRootCAs,
678+
TimeShift: admin.TLS.TLSHandshakeTimeShift,
678679
},
679680
})
680681
}

0 commit comments

Comments
 (0)