コード例 #1
0
ファイル: genkeys.go プロジェクト: TheThingsNetwork/ttn
func genCertCmd(component string) *cobra.Command {
	return &cobra.Command{
		Use:   "gen-cert",
		Short: "Generate a TLS certificate",
		Long:  `ttn gen-cert generates a TLS Certificate`,
		Run: func(cmd *cobra.Command, args []string) {
			var names []string
			if announcedName := viper.GetString(component + ".server-address-announce"); announcedName != "" {
				names = append(names, announcedName)
			}
			names = append(names, args...)
			if err := security.GenerateCert(viper.GetString("key-dir"), names...); err != nil {
				ctx.WithError(err).Fatal("Could not generate certificate")
			}
			ctx.WithField("TLSDir", viper.GetString("key-dir")).Info("Done")
		},
	}
}
コード例 #2
0
ファイル: auth_test.go プロジェクト: TheThingsNetwork/ttn
func TestInitTLS(t *testing.T) {
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	tmpDir := fmt.Sprintf("%s/%d", os.TempDir(), r.Int63())
	os.Mkdir(tmpDir, 755)
	defer os.Remove(tmpDir)

	a := assertions.New(t)
	c := new(Component)
	c.Identity = new(discovery.Announcement)
	c.Config.KeyDir = tmpDir

	security.GenerateKeypair(tmpDir)
	c.initKeyPair()

	a.So(c.initTLS(), assertions.ShouldNotBeNil)

	security.GenerateCert(tmpDir)

	a.So(c.initTLS(), assertions.ShouldBeNil)

	a.So(c.Identity.Certificate, assertions.ShouldNotBeEmpty)
	a.So(c.tlsConfig, assertions.ShouldNotBeNil)
}