mirror of
https://github.com/libp2p/go-openssl.git
synced 2024-12-28 23:50:14 +08:00
add support for chains in ListenAndServeTLS
This commit is contained in:
parent
9bed092d70
commit
111569c406
18
ctx.go
18
ctx.go
@ -184,7 +184,12 @@ func NewCtxFromFiles(cert_file string, key_file string) (*Ctx, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, err := LoadCertificateFromPEM(cert_bytes)
|
certs := SplitPEM(cert_bytes)
|
||||||
|
if len(certs) == 0 {
|
||||||
|
return nil, fmt.Errorf("No PEM certificate found in '%s'", cert_file)
|
||||||
|
}
|
||||||
|
first, certs := certs[0], certs[1:]
|
||||||
|
cert, err := LoadCertificateFromPEM(first)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -194,6 +199,17 @@ func NewCtxFromFiles(cert_file string, key_file string) (*Ctx, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, pem := range certs {
|
||||||
|
cert, err := LoadCertificateFromPEM(pem)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = ctx.AddChainCertificate(cert)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
key_bytes, err := ioutil.ReadFile(key_file)
|
key_bytes, err := ioutil.ReadFile(key_file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user