Skip to content

Commit 217f65c

Browse files
committed
cert.go
1 parent e6fc257 commit 217f65c

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

common/protocol/tls/cert/cert.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,27 +232,42 @@ func GenerateGOST2012_256(parent *Certificate, opts ...SM2Option) (*Certificate,
232232

233233
// GenerateGOST2012_512 generates a certificate using GOST 2012-512 algorithm
234234
func GenerateGOST2012_512(parent *Certificate, opts ...SM2Option) (*Certificate, error) {
235+
// Extract parameters from options
235236
var (
236237
commonName string
238+
organization string
239+
dnsNames []string
237240
expireDays int = 365
238241
)
242+
239243
for _, opt := range opts {
240-
optFunc := opt
244+
// Create a temporary certificate to extract options
241245
tmp := &sm2x509.Certificate{}
242-
optFunc(tmp)
246+
opt(tmp)
247+
243248
if tmp.Subject.CommonName != "" {
244249
commonName = tmp.Subject.CommonName
245250
}
251+
if len(tmp.Subject.Organization) > 0 {
252+
organization = tmp.Subject.Organization[0]
253+
}
254+
if len(tmp.DNSNames) > 0 {
255+
dnsNames = tmp.DNSNames
256+
}
246257
if !tmp.NotAfter.IsZero() {
247258
days := int(tmp.NotAfter.Sub(time.Now()).Hours() / 24)
248259
if days > 0 {
249260
expireDays = days
250261
}
251262
}
252263
}
264+
253265
if commonName == "" {
254266
commonName = "GOST2012-512"
255267
}
268+
if organization == "" {
269+
organization = "Test Organization"
270+
}
256271

257272
certPEM, keyPEM, err := gost.GenerateGOSTSelfSignedCert(
258273
gost3410.CurveIdtc26gost34102012512paramSetA(),

0 commit comments

Comments
 (0)