| 1 |
/* |
| 2 |
Copyright 2013-2014 Canonical Ltd. |
| 3 |
|
| 4 |
This program is free software: you can redistribute it and/or modify it |
| 5 |
under the terms of the GNU General Public License version 3, as published |
| 6 |
by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, but |
| 9 |
WITHOUT ANY WARRANTY; without even the implied warranties of |
| 10 |
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 11 |
PURPOSE. See the GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License along |
| 14 |
with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
package server |
| 18 |
|
| 19 |
import ( |
| 20 |
"crypto/tls" |
| 21 |
"fmt" |
| 22 |
|
| 23 |
"gitlab.com/ubports/development/core/lomiri-push-service/config" |
| 24 |
) |
| 25 |
|
| 26 |
// A TLSParsedConfig holds and can be used to parse a tls server config. |
| 27 |
type TLSParsedConfig struct { |
| 28 |
ParsedKeyPEMFile string `json:"key_pem_file"` |
| 29 |
ParsedCertPEMFile string `json:"cert_pem_file"` |
| 30 |
// private post-processed config |
| 31 |
cert tls.Certificate |
| 32 |
} |
| 33 |
|
| 34 |
func (cfg *TLSParsedConfig) LoadPEMs(baseDir string) error { |
| 35 |
keyPEMBlock, err := config.LoadFile(cfg.ParsedKeyPEMFile, baseDir) |
| 36 |
if err != nil { |
| 37 |
return fmt.Errorf("reading key_pem_file: %v", err) |
| 38 |
} |
| 39 |
certPEMBlock, err := config.LoadFile(cfg.ParsedCertPEMFile, baseDir) |
| 40 |
if err != nil { |
| 41 |
return fmt.Errorf("reading cert_pem_file: %v", err) |
| 42 |
} |
| 43 |
cfg.cert, err = tls.X509KeyPair(certPEMBlock, keyPEMBlock) |
| 44 |
return err |
| 45 |
} |
| 46 |
|
| 47 |
func (cfg *TLSParsedConfig) TLSServerConfig() *tls.Config { |
| 48 |
tlsCfg := &tls.Config{ |
| 49 |
Certificates: []tls.Certificate{cfg.cert}, |
| 50 |
SessionTicketsDisabled: true, |
| 51 |
// order from crypto/tls/cipher_suites.go, no RC4 |
| 52 |
CipherSuites: []uint16{ |
| 53 |
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 54 |
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 55 |
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 56 |
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 57 |
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
| 58 |
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, |
| 59 |
tls.TLS_RSA_WITH_AES_128_CBC_SHA, |
| 60 |
tls.TLS_RSA_WITH_AES_256_CBC_SHA, |
| 61 |
}, |
| 62 |
MinVersion: tls.VersionTLS10, |
| 63 |
} |
| 64 |
return tlsCfg |
| 65 |
} |