1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 // Create a root CA key and use it to make a new server
16 // certificate+key pair.
18 // In future we'll make one root CA key per host instead of one per
19 // cluster, so it only needs to be imported to a browser once for
20 // ongoing dev/test usage.
21 type createCertificates struct{}
23 func (createCertificates) String() string {
27 func (createCertificates) Run(ctx context.Context, fail func(error), super *Supervisor) error {
29 if net.ParseIP(super.ListenHost) != nil {
30 san = fmt.Sprintf("IP:%s", super.ListenHost)
32 san = fmt.Sprintf("DNS:%s", super.ListenHost)
36 err := super.RunProgram(ctx, super.tempdir, nil, nil, "openssl", "genrsa", "-out", "rootCA.key", "4096")
40 // Generate a self-signed root certificate
41 err = super.RunProgram(ctx, super.tempdir, nil, nil, "openssl", "req", "-x509", "-new", "-nodes", "-key", "rootCA.key", "-sha256", "-days", "3650", "-out", "rootCA.crt", "-subj", "/C=US/ST=MA/O=Example Org/CN=localhost")
45 // Generate server key
46 err = super.RunProgram(ctx, super.tempdir, nil, nil, "openssl", "genrsa", "-out", "server.key", "2048")
50 // Build config file for signing request
51 defaultconf, err := ioutil.ReadFile("/etc/ssl/openssl.cnf")
55 err = ioutil.WriteFile(filepath.Join(super.tempdir, "server.cfg"), append(defaultconf, []byte(fmt.Sprintf("\n[SAN]\nsubjectAltName=DNS:localhost,DNS:localhost.localdomain,%s\n", san))...), 0644)
59 // Generate signing request
60 err = super.RunProgram(ctx, super.tempdir, nil, nil, "openssl", "req", "-new", "-sha256", "-key", "server.key", "-subj", "/C=US/ST=MA/O=Example Org/CN=localhost", "-reqexts", "SAN", "-config", "server.cfg", "-out", "server.csr")
65 err = super.RunProgram(ctx, super.tempdir, nil, nil, "openssl", "x509", "-req", "-in", "server.csr", "-CA", "rootCA.crt", "-CAkey", "rootCA.key", "-CAcreateserial", "-out", "server.crt", "-extfile", "server.cfg", "-extensions", "SAN", "-days", "3650", "-sha256")