<commit_before>package main

import (
	"crypto/rand"
	"crypto/rsa"
	"crypto/tls"
	"crypto/x509"
	"crypto/x509/pkix"
	"encoding/pem"
	"github.com/Sirupsen/logrus"
	"github.com/codegangsta/cli"
	"io/ioutil"
	"math/big"
	"net"
	"os"
	"time"
)

func main() {
	app := cli.NewApp()
	app.Name = "tlsgen"
	app.Usage = "Generates web server TLS certificates"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "org",
			Value: "",
			Usage: "Organization name",
		},
		cli.StringSliceFlag{
			Name:  "host",
			Value: &cli.StringSlice{},
			Usage: "Server Host",
		},
	}
	app.Action = func(c *cli.Context) {
		org := c.String("org")
		if org == "" {
			logrus.Fatal("org shoule not be empty")
		}
		host := c.StringSlice("host")
		if len(host) == 0 {
			logrus.Fatal("host shoule not be empty")
		}
		GenerateCACertificate("ca.pem", "ca-key.pem", org, 2048)
		GenerateCert(host, "cert.pem", "key.pem", "ca.pem", "ca-key.pem", org, 2048)
	}

	app.Run(os.Args)
}

func getTLSConfig(caCert, cert, key []byte, allowInsecure bool) (*tls.Config, error) {
	// TLS config
	var tlsConfig tls.Config
	tlsConfig.InsecureSkipVerify = allowInsecure
	certPool := x509.NewCertPool()

	certPool.AppendCertsFromPEM(caCert)
	tlsConfig.RootCAs = certPool
	keypair, err := tls.X509KeyPair(cert, key)
	if err != nil {
		return &tlsConfig, err
	}
	tlsConfig.Certificates = []tls.Certificate{keypair}
	if allowInsecure {
		tlsConfig.InsecureSkipVerify = true
	}

	return &tlsConfig, nil
}

func newCertificate(org string) (*x509.Certificate, error) {
	now := time.Now()
	// need to set notBefore slightly in the past to account for time<commit_msg>add client cert<commit_after>package main

import (
	"crypto/rand"
	"crypto/rsa"
	"crypto/tls"
	"crypto/x509"
	"crypto/x509/pkix"
	"encoding/pem"
	"github.com/Sirupsen/logrus"
	"github.com/codegangsta/cli"
	"io/ioutil"
	"math/big"
	"net"
	"os"
	"time"
)

func main() {
	app := cli.NewApp()
	app.Name = "tlsgen"
	app.Usage = "Generates web server TLS certificates"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "org",
			Value: "",
			Usage: "Organization name",
		},
		cli.StringSliceFlag{
			Name:  "host",
			Value: &cli.StringSlice{},
			Usage: "Server Host",
		},
	}
	app.Action = func(c *cli.Context) {
		org := c.String("org")
		if org == "" {
			logrus.Fatal("org shoule not be empty")
		}
		host := c.StringSlice("host")
		if len(host) == 0 {
			logrus.Fatal("host shoule not be empty")
		}
		GenerateCACertificate("ca.pem", "ca-key.pem", org, 2048)
		//client
		GenerateCert([]string{""}, "cert.pem", "key.pem", "ca.pem", "ca-key.pem", org, 2048)
		//server
		GenerateCert(host, "server.pem", "server-key.pem", "ca.pem", "ca-key.pem", org, 2048)
	}

	app.Run(os.Args)
}

func getTLSConfig(caCert, cert, key []byte, allowInsecure bool) (*tls.Config, error) {
	// TLS config
	var tlsConfig tls.Config
	tlsConfig.InsecureSkipVerify = allowInsecure
	certPool := x509.NewCertPool()

	certPool.AppendCertsFromPEM(caCert)
	tlsConfig.RootCAs = certPool
	keypair, err := tls.X509KeyPair(cert, key)
	if err != nil {
		return &tlsConfig, err
	}
	tlsConfig.Certificates = []tls.Certificate{keypair}
	if allowInsecure {
		tlsConfig.InsecureSkipVerify = true
	}

	return &tlsConfig, nil
}

func newCertificate(org string) (*x509.Certificate, error) {
	now := time.Now()
	// need to set notBefore slightly in the past to account for time
{'fraction_non_alphanumeric': 0.16150178784266986, 'fraction_numerical': 0.015494636471990465, 'mean_word_length': 3.879360465116279, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4382414', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1323, 'n_words': 286}