@@ -31,6 +31,7 @@ import (
31
31
"github.com/google/uuid"
32
32
"github.com/interlynk-io/sbomqs/pkg/cpe"
33
33
"github.com/interlynk-io/sbomqs/pkg/licenses"
34
+ "github.com/interlynk-io/sbomqs/pkg/logger"
34
35
"github.com/interlynk-io/sbomqs/pkg/omniborid"
35
36
"github.com/interlynk-io/sbomqs/pkg/purl"
36
37
"github.com/interlynk-io/sbomqs/pkg/swhid"
@@ -170,7 +171,7 @@ func (c *CdxDoc) parse() {
170
171
c .parsePrimaryCompAndRelationships ()
171
172
c .parseVulnerabilities ()
172
173
if c .Signature ().GetSigValue () == "" && c .Signature ().GetPublicKey () == "" {
173
- fmt . Println ( "Extract public key and signature from SBOM " )
174
+ c . addToLogs ( "extract public key and signature from cylonedx sbom itself " )
174
175
c .parseSignature ()
175
176
}
176
177
c .parseComps ()
@@ -255,6 +256,8 @@ func (c *CdxDoc) parseVulnerabilities() {
255
256
// until and unless cyclondx-go library supports signature, this part is useless
256
257
// So, we are using tech hack to parse signature directly from JSON sbom file
257
258
func (c * CdxDoc ) parseSignature () {
259
+ log := logger .FromContext (c .ctx )
260
+ log .Debug ("parseSignature()" )
258
261
c .SignatureDetail = & Signature {}
259
262
if c .doc .Declarations != nil {
260
263
if c .doc .Declarations .Signature != nil {
@@ -265,27 +268,27 @@ func (c *CdxDoc) parseSignature() {
265
268
// decode the signature
266
269
signatureValue , err := base64 .StdEncoding .DecodeString (sigValue )
267
270
if err != nil {
268
- fmt . Println ("Error decoding signature:" , err )
271
+ log . Debug ("Error decoding signature:" , err )
269
272
return
270
273
}
271
274
272
275
// write the signature to a file
273
276
if err := os .WriteFile ("extracted_signature.bin" , signatureValue , 0o600 ); err != nil {
274
- fmt . Println ("Error writing signature to file:" , err )
277
+ log . Debug ("Error writing signature to file: %s " , err )
275
278
return
276
279
}
277
280
c .addToLogs ("Signature written to file: extracted_signature.bin" )
278
281
279
282
// extract the public key modulus and exponent
280
283
modulus , err := base64 .StdEncoding .DecodeString (pubKeyModulus )
281
284
if err != nil {
282
- fmt . Println ("Error decoding public key modulus:" , err )
285
+ log . Debug ("Error decoding public key modulus:" , err )
283
286
return
284
287
}
285
288
286
289
exponent := decodeBase64URLEncodingToInt (pubKeyExponent )
287
290
if exponent == 0 {
288
- fmt . Println ("Invalid public key exponent." )
291
+ c . addToLogs ("Invalid public key exponent." )
289
292
return
290
293
}
291
294
@@ -298,7 +301,7 @@ func (c *CdxDoc) parseSignature() {
298
301
// write the public key to a PEM file
299
302
pubKeyPEM := publicKeyToPEM (pubKey )
300
303
if err := os .WriteFile ("extracted_public_key.pem" , pubKeyPEM , 0o600 ); err != nil {
301
- fmt . Println ("Error writing public key to file:" , err )
304
+ log . Debug ("Error writing public key to file:" , err )
302
305
return
303
306
}
304
307
0 commit comments