forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expiration.go
36 lines (31 loc) · 862 Bytes
/
expiration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package crypto
import (
"crypto/x509"
"encoding/pem"
"time"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/msp"
)
// ExpiresAt returns when the given identity expires, or a zero time.Time
// in case we cannot determine that
func ExpiresAt(identityBytes []byte) time.Time {
sId := &msp.SerializedIdentity{}
// If protobuf parsing failed, we make no decisions about the expiration time
if err := proto.Unmarshal(identityBytes, sId); err != nil {
return time.Time{}
}
bl, _ := pem.Decode(sId.IdBytes)
if bl == nil {
// If the identity isn't a PEM block, we make no decisions about the expiration time
return time.Time{}
}
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
return time.Time{}
}
return cert.NotAfter
}