[proxy] Add tls support
Caveats: * TLS files must be present on the target server (and readable) * TLS file paths cannot contain spaces * TLS file paths must be absolute (i.e. cannot be relative) * Bash argument parsing is terrible
This commit is contained in:
1 parent
8514172e57
commit
c31358259f
9 files changed
+290
-21
No files matched your search
@@ -0,0 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/docker/machine/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
org = "vagrant"
|
||||
bits = 2048
|
||||
caKeyPath = "ca-key.pem"
|
||||
caCertPath = "ca.pem"
|
||||
clientKeyPath = "key.pem"
|
||||
clientCertPath = "cert.pem"
|
||||
serverKeyPath = "server-key.pem"
|
||||
serverCertPath = "server.pem"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if _, err := os.Stat(caCertPath); os.IsNotExist(err) {
|
||||
log.Printf("Creating CA: %s", caCertPath)
|
||||
|
||||
// check if the key path exists; if so, error
|
||||
if _, err := os.Stat(caKeyPath); err == nil {
|
||||
log.Fatalf("The CA key already exists. Please remove it or specify a different key/cert.")
|
||||
}
|
||||
|
||||
if err := utils.GenerateCACertificate(caCertPath, caKeyPath, org, bits); err != nil {
|
||||
log.Printf("Error generating CA certificate: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(clientCertPath); os.IsNotExist(err) {
|
||||
log.Printf("Creating client certificate: %s", clientCertPath)
|
||||
|
||||
// check if the key path exists; if so, error
|
||||
if _, err := os.Stat(clientKeyPath); err == nil {
|
||||
log.Fatalf("The client key already exists. Please remove it or specify a different key/cert.")
|
||||
}
|
||||
|
||||
err = utils.GenerateCert(
|
||||
[]string{""},
|
||||
clientCertPath,
|
||||
clientKeyPath,
|
||||
caCertPath,
|
||||
caKeyPath,
|
||||
org,
|
||||
bits,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("Error generating client certificate: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(os.Args) <= 1 {
|
||||
return
|
||||
}
|
||||
for _, ip := range os.Args[1:] {
|
||||
serverKeyPath := fmt.Sprintf("%s-key.pem", ip)
|
||||
serverCertPath := fmt.Sprintf("%s.pem", ip)
|
||||
|
||||
if _, err := os.Stat(serverCertPath); os.IsNotExist(err) {
|
||||
log.Printf("Creating server certificate: %s", serverCertPath)
|
||||
err = utils.GenerateCert(
|
||||
[]string{ip},
|
||||
serverCertPath,
|
||||
serverKeyPath,
|
||||
caCertPath,
|
||||
caKeyPath,
|
||||
org,
|
||||
bits,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("error generating server cert: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user