@@ -318,6 +318,8 @@ func createTBSCertificate(template *Certificate, pub interface{}, sigAlg Signatu
318318 // Create a basic ASN.1 DER encoding of the To-Be-Signed certificate
319319 // This is a simplified implementation for testing purposes
320320
321+ fmt .Printf ("DEBUG: createTBSCertificate called with signature algorithm: %d\n " , sigAlg )
322+
321323 // Determine OIDs based on signature algorithm
322324 var signatureOID asn1.ObjectIdentifier
323325 var publicKeyOID asn1.ObjectIdentifier
@@ -368,6 +370,71 @@ func createTBSCertificate(template *Certificate, pub interface{}, sigAlg Signatu
368370 return nil , fmt .Errorf ("unsupported public key type: %T" , pub )
369371 }
370372
373+ // For GOST certificates, we need to use a different approach
374+ // GOST certificates have a specific ASN.1 structure that's different from standard X.509
375+ if sigAlg == GOST256 || sigAlg == GOST512 {
376+ fmt .Printf ("DEBUG: Using GOST-specific certificate structure\n " )
377+ // Create GOST-specific certificate structure
378+ gostCert := struct {
379+ Version int `asn1:"optional,explicit,default:0,tag:0"`
380+ SerialNumber * big.Int
381+ SignatureAlgorithm pkix.AlgorithmIdentifier
382+ Issuer pkix.Name
383+ Validity struct {
384+ NotBefore time.Time
385+ NotAfter time.Time
386+ }
387+ Subject pkix.Name
388+ SubjectPublicKeyInfo struct {
389+ Algorithm pkix.AlgorithmIdentifier
390+ PublicKey asn1.BitString
391+ }
392+ IssuerUniqueID asn1.BitString `asn1:"optional,tag:1"`
393+ SubjectUniqueID asn1.BitString `asn1:"optional,tag:2"`
394+ Extensions []pkix.Extension `asn1:"optional,tag:3"`
395+ }{
396+ Version : template .Version ,
397+ SerialNumber : template .SerialNumber ,
398+ SignatureAlgorithm : pkix.AlgorithmIdentifier {
399+ Algorithm : signatureOID ,
400+ },
401+ Issuer : template .Issuer ,
402+ Validity : struct {
403+ NotBefore time.Time
404+ NotAfter time.Time
405+ }{
406+ NotBefore : template .NotBefore ,
407+ NotAfter : template .NotAfter ,
408+ },
409+ Subject : template .Subject ,
410+ SubjectPublicKeyInfo : struct {
411+ Algorithm pkix.AlgorithmIdentifier
412+ PublicKey asn1.BitString
413+ }{
414+ Algorithm : pkix.AlgorithmIdentifier {
415+ Algorithm : publicKeyOID ,
416+ },
417+ PublicKey : asn1.BitString {
418+ Bytes : publicKeyBytes ,
419+ BitLength : bitLength ,
420+ },
421+ },
422+ IssuerUniqueID : asn1.BitString {},
423+ SubjectUniqueID : asn1.BitString {},
424+ Extensions : template .Extensions ,
425+ }
426+
427+ // Encode to ASN.1 DER
428+ der , err := asn1 .Marshal (gostCert )
429+ if err != nil {
430+ return nil , fmt .Errorf ("failed to marshal GOST TBS certificate: %w" , err )
431+ }
432+
433+ fmt .Printf ("DEBUG: GOST TBS certificate marshaled successfully, length: %d\n " , len (der ))
434+ return der , nil
435+ }
436+
437+ fmt .Printf ("DEBUG: Using standard X.509 certificate structure\n " )
371438 // Create the basic certificate structure with proper ASN.1 tags
372439 tbs := struct {
373440 Version int `asn1:"optional,explicit,default:0,tag:0"`
0 commit comments