@@ -13,6 +13,7 @@ import (
1313 "time"
1414
1515 "github.com/pedroalbanese/gogost/gost3410"
16+ "github.com/pedroalbanese/gogost/gost34112012256"
1617)
1718
1819// SignatureAlgorithm represents the algorithm used to sign the certificate
@@ -319,7 +320,7 @@ func createTBSCertificate(template *Certificate, sigAlg SignatureAlgorithm) ([]b
319320 publicKeyOID = asn1.ObjectIdentifier {1 , 2 , 643 , 7 , 1 , 1 , 1 , 1 }
320321 }
321322
322- // Create the basic certificate structure
323+ // Create the basic certificate structure with proper ASN.1 tags
323324 tbs := struct {
324325 Version int `asn1:"optional,explicit,default:0,tag:0"`
325326 SerialNumber * big.Int
@@ -334,7 +335,9 @@ func createTBSCertificate(template *Certificate, sigAlg SignatureAlgorithm) ([]b
334335 Algorithm pkix.AlgorithmIdentifier
335336 PublicKey asn1.BitString
336337 }
337- Extensions []pkix.Extension `asn1:"optional,tag:3"`
338+ IssuerUniqueID asn1.BitString `asn1:"optional,tag:1"`
339+ SubjectUniqueID asn1.BitString `asn1:"optional,tag:2"`
340+ Extensions []pkix.Extension `asn1:"optional,tag:3"`
338341 }{
339342 Version : template .Version ,
340343 SerialNumber : template .SerialNumber ,
@@ -358,11 +361,13 @@ func createTBSCertificate(template *Certificate, sigAlg SignatureAlgorithm) ([]b
358361 Algorithm : publicKeyOID ,
359362 },
360363 PublicKey : asn1.BitString {
361- Bytes : []byte {}, // Placeholder - will be filled by actual public key
362- BitLength : 0 ,
364+ Bytes : []byte {0x04 , 0x20 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 }, // Placeholder GOST public key
365+ BitLength : 256 ,
363366 },
364367 },
365- Extensions : template .Extensions ,
368+ IssuerUniqueID : asn1.BitString {},
369+ SubjectUniqueID : asn1.BitString {},
370+ Extensions : template .Extensions ,
366371 }
367372
368373 // Encode to ASN.1 DER
@@ -400,7 +405,18 @@ func signWithGOST(data []byte, priv *gost3410.PrivateKey, sigAlg SignatureAlgori
400405
401406func signWithGOSTReverseDigest (data []byte , priv * gost3410.PrivateKeyReverseDigest , sigAlg SignatureAlgorithm ) ([]byte , error ) {
402407 // Use GOST signing with reverse digest
403- return priv .Sign (rand .Reader , data , nil )
408+ // First, we need to hash the data with GOST hash function
409+ hash := gost34112012256 .New ()
410+ hash .Write (data )
411+ hashed := hash .Sum (nil )
412+
413+ // Sign the hash
414+ signature , err := priv .Sign (rand .Reader , hashed , nil )
415+ if err != nil {
416+ return nil , fmt .Errorf ("failed to sign with GOST: %w" , err )
417+ }
418+
419+ return signature , nil
404420}
405421
406422func getPublicKeyAlgorithm (pub interface {}) PublicKeyAlgorithm {
0 commit comments