Skip to content

Commit cd60482

Browse files
committed
chg: [parsing] correct more parsing errors
1 parent 2c1a7a6 commit cd60482

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

main.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ func processDER(fp string, p string) bool {
268268
goto I
269269
default:
270270
fmt.Println("failed to parse certificate: " + err.Error())
271+
return false
271272
}
272273
}
273274

@@ -277,21 +278,30 @@ I:
277278
h.Write(cert.Raw)
278279
c := certMapElm{Certificate: cert, CertHash: fmt.Sprintf("%x", h.Sum(nil))}
279280
// Insert Certificate
280-
err = insertLeafCertificate(fp, c)
281+
err = insertLeafCertificate(p, c)
281282
if err != nil {
282-
log.Fatal(fmt.Sprintf("Insert Certificate into DB failed: %q", err))
283+
// Not stopping on failed insertion
284+
log.Println(fmt.Sprintf("Insert Certificate into DB failed: %q", err))
283285
}
284286

285287
return true
286288
}
287289

288290
func insertLeafCertificate(fp string, c certMapElm) error {
289-
q := `INSERT INTO "certificate" (hash, "is_CA", "is_SS", issuer, subject, cert_chain, is_valid_chain, file_path) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT DO NOTHING`
290-
_, err := db.Exec(q, c.CertHash, c.Certificate.IsCA, false, c.Certificate.Issuer.String(), c.Certificate.Subject.String(), nil, false, getFullPath(fp, c.CertHash))
291+
key, err := insertPublicKey(*c.Certificate)
291292
if err != nil {
292-
return err
293+
// Not stopping on Non Fatal Errors
294+
switch err := err.(type) {
295+
case x509.NonFatalErrors:
296+
goto J
297+
default:
298+
fmt.Println("failed to Insert Key: " + err.Error())
299+
return err
300+
}
293301
}
294-
key, err := insertPublicKey(*c.Certificate)
302+
J:
303+
q := `INSERT INTO "certificate" (hash, "is_CA", "is_SS", issuer, subject, cert_chain, is_valid_chain, file_path) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT DO NOTHING`
304+
_, err = db.Exec(q, c.CertHash, c.Certificate.IsCA, false, c.Certificate.Issuer.String(), c.Certificate.Subject.String(), nil, false, getFullPath(fp, c.CertHash))
295305
if err != nil {
296306
return err
297307
}
@@ -393,7 +403,7 @@ func insertPublicKey(c x509.Certificate) (string, error) {
393403
pub, err := x509.ParsePKIXPublicKey(c.RawSubjectPublicKeyInfo)
394404
hash := fmt.Sprintf("%x", sha256.Sum256(c.RawSubjectPublicKeyInfo))
395405
if err != nil {
396-
return hash, nil
406+
return hash, err
397407
}
398408

399409
switch pub := pub.(type) {

0 commit comments

Comments
 (0)