示例#1
0
func TestNewRSACA(t *testing.T) {
	var si = &csr.SubjectInfo{
		CommonName: "localhost",
		OrgName:    "test certificate authority",
	}
	key, csr, err := csr.GenerateKeyAndCSR(csr.RSA, 2048, si)
	if err != nil {
		t.Fatalf("%v", err)
	}

	serial := big.NewInt(0)
	ct := NewTemplate(csr, serial, nil)
	ct.Allow(x509.KeyUsageKeyEncipherment)
	ct.Allow(x509.KeyUsageDigitalSignature)
	ct.Allow(x509.KeyUsageCertSign)
	ct.SetExpiresAfter(1 * time.Hour)
	_, err = ct.Certificate(key)
	if err != nil {
		t.Fatalf("%v", err)
	}
}
示例#2
0
func TestNewECDSACA(t *testing.T) {
	var si = &csr.SubjectInfo{
		CommonName: "localhost",
		OrgName:    "test certificate authority",
	}
	key, csr, err := csr.GenerateKeyAndCSR(csr.ECDSA, 256, si)
	if err != nil {
		t.Fatalf("%v", err)
	}

	serial := RandomSerial()
	if serial == nil {
		t.Fatal("cautil: failed to generate a random serial number")
	}
	ct := NewTemplate(csr, serial, nil)
	ct.Allow(x509.KeyUsageKeyEncipherment)
	ct.Allow(x509.KeyUsageDigitalSignature)
	ct.Allow(x509.KeyUsageCertSign)
	ct.SetExpiresAfter(1 * time.Hour)
	_, err = ct.Certificate(key)
	if err != nil {
		t.Fatalf("%v", err)
	}
}