@@ -12,14 +12,8 @@ import (
1212 "github.com/pedroalbanese/gogost/gost3410"
1313)
1414
15- // GOST signature algorithm constants
16- const (
17- GOST256 = 0x0601 // GOST R 34.10-2012 256-bit
18- GOST512 = 0x0602 // GOST R 34.10-2012 512-bit
19- )
20-
2115// GenerateGOSTSelfSignedCert создает самоподписанный X.509 сертификат GOST2012 (256 или 512)
22- func GenerateGOSTSelfSignedCert (curve * gost3410.Curve , sigAlg x509. SignatureAlgorithm , cn string , expireDays int ) ([]byte , []byte , error ) {
16+ func GenerateGOSTSelfSignedCert (curve * gost3410.Curve , cn string , expireDays int ) ([]byte , []byte , error ) {
2317 fmt .Printf ("DEBUG: Starting GenerateGOSTSelfSignedCert\n " )
2418
2519 prvRaw := make ([]byte , curve .PointSize ())
@@ -43,34 +37,26 @@ func GenerateGOSTSelfSignedCert(curve *gost3410.Curve, sigAlg x509.SignatureAlgo
4337 notAfter := notBefore .Add (time .Duration (expireDays ) * 24 * time .Hour )
4438 serial := big .NewInt (time .Now ().UnixNano ())
4539
46- // Create certificate template with proper GOST structure
40+ // Determine the correct signature algorithm based on curve size
41+ var signatureAlgorithm x509.SignatureAlgorithm
42+ if curve .PointSize () == 32 {
43+ signatureAlgorithm = x509 .GOST256
44+ } else {
45+ signatureAlgorithm = x509 .GOST512
46+ }
47+
4748 template := x509.Certificate {
4849 SerialNumber : serial ,
4950 NotBefore : notBefore ,
5051 NotAfter : notAfter ,
51- SignatureAlgorithm : sigAlg ,
52- Subject : pkix.Name {
53- Country : []string {"RU" },
54- Province : []string {"Krasnoyarsk" },
55- Locality : []string {"Krasnoyarsk" },
56- Organization : []string {"Dolboyob Research" },
57- OrganizationalUnit : []string {"testing" },
58- CommonName : cn ,
59- },
60- Issuer : pkix.Name {
61- Country : []string {"RU" },
62- Province : []string {"Krasnoyarsk" },
63- Locality : []string {"Krasnoyarsk" },
64- Organization : []string {"Dolboyob Research" },
65- OrganizationalUnit : []string {"testing" },
66- CommonName : cn ,
67- },
52+ SignatureAlgorithm : signatureAlgorithm ,
53+ Subject : pkix.Name {CommonName : cn },
6854 KeyUsage : x509 .KeyUsageDigitalSignature | x509 .KeyUsageKeyEncipherment ,
6955 BasicConstraintsValid : true ,
7056 IsCA : false ,
7157 }
7258
73- fmt .Printf ("DEBUG: About to call CreateCertificate\n " )
59+ fmt .Printf ("DEBUG: About to call CreateCertificate with signature algorithm: %d \n " , signatureAlgorithm )
7460 certDER , err := x509 .CreateCertificate (
7561 rand .Reader ,
7662 & template , & template , pub ,
@@ -111,11 +97,20 @@ func GenerateGOSTCAChildCert(curve *gost3410.Curve, sigAlg x509.SignatureAlgorit
11197 notBefore := time .Now ()
11298 notAfter := notBefore .Add (time .Duration (expireDays ) * 24 * time .Hour )
11399 serial := big .NewInt (time .Now ().UnixNano ())
100+
101+ // Determine the correct signature algorithm based on curve size
102+ var signatureAlgorithm x509.SignatureAlgorithm
103+ if curve .PointSize () == 32 {
104+ signatureAlgorithm = x509 .GOST256
105+ } else {
106+ signatureAlgorithm = x509 .GOST512
107+ }
108+
114109 template := x509.Certificate {
115110 SerialNumber : serial ,
116111 NotBefore : notBefore ,
117112 NotAfter : notAfter ,
118- SignatureAlgorithm : sigAlg ,
113+ SignatureAlgorithm : signatureAlgorithm ,
119114 Subject : pkix.Name {CommonName : cn },
120115 KeyUsage : x509 .KeyUsageDigitalSignature | x509 .KeyUsageKeyEncipherment ,
121116 BasicConstraintsValid : true ,
0 commit comments