gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/x509ca/x509ca_test.go (about) 1 package x509ca 2 3 import ( 4 "crypto/rand" 5 "crypto/x509/pkix" 6 "encoding/base64" 7 "fmt" 8 "gitee.com/ks-custle/core-gm/sm2" 9 "gitee.com/ks-custle/core-gm/x509" 10 "testing" 11 ) 12 13 func TestGetRootCaCert(t *testing.T) { 14 cert := GetRootCaCert() 15 16 fmt.Println("cert : " + cert) 17 } 18 19 func TestGetIntermediateCaCert(t *testing.T) { 20 cert := GetIntermediateCaCert() 21 22 fmt.Println("cert : " + cert) 23 } 24 25 func TestApplySignCert(t *testing.T) { 26 27 random := rand.Reader 28 sm2Priv, err := sm2.GenerateKey(random) 29 if err != nil { 30 t.Fatalf("Failed to generate SM2 key: %s", err) 31 } 32 template := x509.CertificateRequest{ 33 Subject: pkix.Name{ 34 CommonName: "test.example.com", 35 Organization: []string{"ooo"}, 36 }, 37 SignatureAlgorithm: x509.SM2WithSM3, 38 DNSNames: []string{"test.example.com"}, 39 EmailAddresses: []string{"test@custle.org"}, 40 } 41 42 csr, _ := x509.CreateCertificateRequest(random, &template, sm2Priv) 43 fmt.Println("csr : " + base64.StdEncoding.EncodeToString(csr)) 44 cert := ApplySignCert(base64.StdEncoding.EncodeToString(csr), "sign") 45 46 fmt.Println("cert : " + cert) 47 }