Skip to content

Commit c7f593e

Browse files
committed
x509
1 parent ba41dbc commit c7f593e

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

common/crypto/x509/x509.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,32 @@ func createTBSCertificate(template *Certificate, sigAlg SignatureAlgorithm) ([]b
319319
publicKeyOID = asn1.ObjectIdentifier{1, 2, 643, 7, 1, 1, 1, 1}
320320
}
321321

322+
// Encode public key properly for GOST
323+
var publicKeyBytes []byte
324+
if template.PublicKey != nil {
325+
if gostPub, ok := template.PublicKey.(*gost3410.PublicKey); ok {
326+
// Encode GOST public key as X and Y coordinates
327+
xBytes := gostPub.X.Bytes()
328+
yBytes := gostPub.Y.Bytes()
329+
330+
// Create GOST public key structure
331+
gostPubKey := struct {
332+
X []byte
333+
Y []byte
334+
}{
335+
X: xBytes,
336+
Y: yBytes,
337+
}
338+
339+
// Marshal to ASN.1 DER
340+
pubKeyDER, err := asn1.Marshal(gostPubKey)
341+
if err != nil {
342+
return nil, fmt.Errorf("failed to marshal GOST public key: %w", err)
343+
}
344+
publicKeyBytes = pubKeyDER
345+
}
346+
}
347+
322348
// Create the basic certificate structure
323349
tbs := struct {
324350
Version int `asn1:"optional,explicit,default:0,tag:0"`
@@ -358,8 +384,8 @@ func createTBSCertificate(template *Certificate, sigAlg SignatureAlgorithm) ([]b
358384
Algorithm: publicKeyOID,
359385
},
360386
PublicKey: asn1.BitString{
361-
Bytes: []byte{}, // Placeholder - will be filled by actual public key
362-
BitLength: 0,
387+
Bytes: publicKeyBytes,
388+
BitLength: len(publicKeyBytes) * 8,
363389
},
364390
},
365391
Extensions: template.Extensions,

0 commit comments

Comments
 (0)