1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
16 // Create a root CA key and use it to make a new server
17 // certificate+key pair.
19 // In future we'll make one root CA key per host instead of one per
20 // cluster, so it only needs to be imported to a browser once for
21 // ongoing dev/test usage.
22 type createCertificates struct{}
24 func (createCertificates) String() string {
28 func (createCertificates) Run(ctx context.Context, fail func(error), super *Supervisor) error {
30 if net.ParseIP(super.ListenHost) != nil {
31 san += fmt.Sprintf(",IP:%s", super.ListenHost)
33 san += fmt.Sprintf(",DNS:%s", super.ListenHost)
35 hostname, err := os.Hostname()
37 return fmt.Errorf("hostname: %w", err)
39 san += ",DNS:" + hostname
42 err = super.RunProgram(ctx, super.tempdir, runOptions{}, "openssl", "genrsa", "-out", "rootCA.key", "4096")
46 // Generate a self-signed root certificate
47 err = super.RunProgram(ctx, super.tempdir, runOptions{}, "openssl", "req", "-x509", "-new", "-nodes", "-key", "rootCA.key", "-sha256", "-days", "3650", "-out", "rootCA.crt", "-subj", "/C=US/ST=MA/O=Example Org/CN=localhost")
51 // Generate server key
52 err = super.RunProgram(ctx, super.tempdir, runOptions{}, "openssl", "genrsa", "-out", "server.key", "2048")
56 // Build config file for signing request
57 defaultconf, err := ioutil.ReadFile("/etc/ssl/openssl.cnf")
61 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)
65 // Generate signing request
66 err = super.RunProgram(ctx, super.tempdir, runOptions{}, "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")
71 err = super.RunProgram(ctx, super.tempdir, runOptions{}, "openssl", "x509", "-req", "-in", "server.csr", "-CA", "rootCA.crt", "-CAkey", "rootCA.key", "-CAcreateserial", "-out", "server.crt", "-extfile", "server.cfg", "-extensions", "SAN", "-days", "3650", "-sha256")