]> src.bluestatic.org Git - mailpopbox.git/blob - config.go
Add small program to help debug TLS issues using a non-Go stack.
[mailpopbox.git] / config.go
1 package main
2
3 import (
4 "crypto/tls"
5 )
6
7 type Config struct {
8 SMTPPort int
9 POP3Port int
10
11 // Hostname is the name of the MX server that is running.
12 Hostname string
13
14 Servers []Server
15 }
16
17 type Server struct {
18 // Domain is the second component of a mail address: <local-part@domain.com>.
19 Domain string
20
21 TLSKeyPath string
22 TLSCertPath string
23
24 // Password for the POP3 mailbox user, mailbox@domain.com.
25 MailboxPassword string
26
27 // Location to store the mail messages.
28 MaildropPath string
29
30 // Blacklisted addresses that should not accept mail.
31 BlacklistedAddresses []string
32 }
33
34 func (c Config) GetTLSConfig() (*tls.Config, error) {
35 certs := make([]tls.Certificate, 0, len(c.Servers))
36 for _, server := range c.Servers {
37 if server.TLSCertPath == "" {
38 continue
39 }
40
41 cert, err := tls.LoadX509KeyPair(server.TLSCertPath, server.TLSKeyPath)
42 if err != nil {
43 return nil, err
44 }
45 certs = append(certs, cert)
46 }
47
48 if len(certs) == 0 {
49 return nil, nil
50 }
51
52 config := &tls.Config{
53 Certificates: certs,
54 }
55 config.BuildNameToCertificate()
56 return config, nil
57 }