mirror of
https://github.com/minio/minio.git
synced 2025-11-09 13:39:46 -05:00
Display SSL expiry warnings (#2925)
This commit is contained in:
committed by
Harshavardhana
parent
0320a77dc0
commit
c03ce0f74a
49
cmd/certs.go
49
cmd/certs.go
@@ -17,8 +17,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// createCertsPath create certs path.
|
||||
@@ -87,3 +92,47 @@ func isSSL() bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func readCertificateChain() ([]*x509.Certificate, error) {
|
||||
certPath := filepath.Join(mustGetCertsPath(), globalMinioCertFile)
|
||||
file, err := os.Open(certPath)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not open certificate for reading")
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
bytes, err2 := ioutil.ReadAll(file)
|
||||
|
||||
if err2 != nil {
|
||||
return nil, errors.Wrapf(err2, "Could not read certificate contents")
|
||||
}
|
||||
|
||||
return parseCertificateChain(bytes)
|
||||
}
|
||||
|
||||
// Parses certificate chain
|
||||
func parseCertificateChain(bytes []byte) ([]*x509.Certificate, error) {
|
||||
var certs []*x509.Certificate
|
||||
var block *pem.Block
|
||||
current := bytes
|
||||
|
||||
for len(current) > 0 {
|
||||
block, current = pem.Decode(current)
|
||||
|
||||
if block == nil {
|
||||
return nil, errors.New("Could not PEM block")
|
||||
}
|
||||
|
||||
cert, err := x509.ParseCertificate(block.Bytes)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not parse certficiate")
|
||||
}
|
||||
|
||||
certs = append(certs, cert)
|
||||
|
||||
}
|
||||
|
||||
return certs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user