Exemplo n.º 1
0
func Generate(hosts []string) (*Cert, error) {
	data := &Cert{}
	ca, err := certgen.Generate(certgen.Params{IsCA: true})
	if err != nil {
		return nil, err
	}
	cert, err := certgen.Generate(certgen.Params{Hosts: hosts, CA: ca})
	if err != nil {
		return nil, err
	}
	data.CACert = ca.PEM
	data.Cert = cert.PEM
	data.Pin = cert.Pin
	data.PrivateKey = cert.KeyPEM

	return data, err
}
Exemplo n.º 2
0
func (a *GenTLSCertAction) Run(s *State) (err error) {
	data := &TLSCert{}
	s.StepData[a.ID] = data

	for i, h := range a.Hosts {
		a.Hosts[i] = interpolate(s, h)
	}
	ca, err := certgen.Generate(certgen.Params{IsCA: true})
	if err != nil {
		return err
	}
	cert, err := certgen.Generate(certgen.Params{Hosts: a.Hosts, CA: ca})
	if err != nil {
		return err
	}
	data.CACert = ca.PEM
	data.Cert = cert.PEM
	data.Pin = cert.Pin
	data.PrivateKey = cert.KeyPEM

	return err
}
Exemplo n.º 3
0
func (s *S) SetUpSuite(c *C) {
	dbname := "controllertest"
	db := setupTestDB(c, dbname)
	if err := migrateDB(db); err != nil {
		c.Fatal(err)
	}

	// reconnect with que statements prepared now that schema is migrated

	pgxpool, err := pgx.NewConnPool(pgx.ConnPoolConfig{
		ConnConfig: pgx.ConnConfig{
			Host:     "/var/run/postgresql",
			Database: dbname,
		},
		AfterConnect: schema.PrepareStatements,
	})
	if err != nil {
		c.Fatal(err)
	}
	db = postgres.New(pgxpool, nil)

	ca, err := certgen.Generate(certgen.Params{IsCA: true})
	if err != nil {
		c.Fatal(err)
	}
	s.caCert = []byte(ca.PEM)

	s.flac = newFakeLogAggregatorClient()
	s.cc = tu.NewFakeCluster()
	s.hc = handlerConfig{
		db:     db,
		cc:     s.cc,
		lc:     s.flac,
		rc:     newFakeRouter(),
		keys:   []string{authKey},
		caCert: s.caCert,
	}
	handler := appHandler(s.hc)
	s.srv = httptest.NewServer(handler)
	client, err := controller.NewClient(s.srv.URL, authKey)
	c.Assert(err, IsNil)
	s.c = client
}
Exemplo n.º 4
0
func writeCert(externalIP, dir string) error {
	fmt.Println("EXTERNAL_IP is", net.ParseIP(externalIP))

	cert, err := certgen.Generate(certgen.Params{Hosts: []string{externalIP}})
	if err != nil {
		return err
	}

	certOut, err := os.Create(filepath.Join(dir, "server.crt"))
	if err != nil {
		return err
	}
	certOut.Write([]byte(cert.PEM))
	certOut.Close()

	keyOut, err := os.OpenFile(filepath.Join(dir, "server.key"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		return err
	}
	keyOut.Write([]byte(cert.KeyPEM))
	keyOut.Close()

	return nil
}