11package certinfo
22
33import (
4- //nolint:all yes, we must detect/analyze legecy
4+ //lint:ignore SA41019 we need to analyse old and broken certs as well
55 "crypto/dsa"
66 "crypto/ecdsa"
77 "crypto/ed25519"
@@ -27,6 +27,7 @@ import (
2727// INTERNAL LEGACY BACKEND
2828//
2929
30+ // certSummary ...
3031func certSummary (cert * x509.Certificate , e * reportstyle.Style ) string {
3132 var s strings.Builder
3233 s .WriteString (e .L1 + "X509 Cert Subject " + e .L2 + shortMsg (cert .Subject .String ()) + e .LE )
@@ -73,6 +74,7 @@ func certSummary(cert *x509.Certificate, e *reportstyle.Style) string {
7374 return s .String ()
7475}
7576
77+ // certOpenSSL ...
7678func certOpenSSL (cert * x509.Certificate , e * reportstyle.Style ) string {
7779 ossl := x509UT .CertificateToString (cert2CT (cert ))
7880 if e .SaniFunc != nil {
@@ -85,23 +87,27 @@ func certOpenSSL(cert *x509.Certificate, e *reportstyle.Style) string {
8587 return s .String ()
8688}
8789
90+ // certPem ...
8891func certPem (cert * x509.Certificate , e * reportstyle.Style ) string {
8992 if e .SaniFunc != nil {
9093 return e .PS + e .SaniFunc (string (cert2pem (cert ))) + e .PE
9194 }
9295 return string (cert2pem (cert ))
9396}
9497
98+ // cert2pem ...
9599func cert2pem (cert * x509.Certificate ) []byte {
96100 return pem .EncodeToMemory (& pem.Block {Type : "CERTIFICATE" , Bytes : cert .Raw })
97101}
98102
103+ // cert2CT ...
99104func cert2CT (cert * x509.Certificate ) * x509CT.Certificate {
100105 pct , _ := pem .Decode (cert2pem (cert ))
101106 crt , _ := x509CT .ParseCertificate (pct .Bytes )
102107 return crt
103108}
104109
110+ // decodePemBlock ...
105111func decodePemBlock (block * pem.Block , r * Report ) string {
106112 defer func () {
107113 if err := recover (); err != nil {
@@ -138,6 +144,7 @@ func decodePemBlock(block *pem.Block, r *Report) string {
138144 return errString (errors .New ("no decoder for pem type: " + block .Type ))
139145}
140146
147+ // sigAlgo ...
141148func sigAlgo (in string , e * reportstyle.Style ) string {
142149 switch in {
143150 case "MD2-RSA" , "MD5-RSA" , "SHA1-RSA" , "DSA-SHA1" , "ECDSA-SHA1" , "DSA-SHA256" :
@@ -150,6 +157,7 @@ func sigAlgo(in string, e *reportstyle.Style) string {
150157 return e .Fail + _unknown + shortMsg (in )
151158}
152159
160+ // pubKey ...
153161func pubKey (pub any , e * reportstyle.Style ) string {
154162 switch pub := pub .(type ) {
155163 case * rsa.PublicKey :
@@ -172,11 +180,13 @@ func pubKey(pub any, e *reportstyle.Style) string {
172180 return e .Fail + "[UNKNOWN]"
173181}
174182
183+ // keyPin ...
175184func keyPin (cert * x509.Certificate ) []byte {
176185 digest := sha256 .Sum256 (cert .RawSubjectPublicKeyInfo )
177186 return digest [:]
178187}
179188
189+ // isSelfSigned ...
180190func isSelfSigned (cert * x509.Certificate , e * reportstyle.Style ) (string , bool ) {
181191 selfsigned , status := _no , false
182192 if cert .IsCA && cert .Issuer .String () == cert .Subject .String () {
@@ -188,6 +198,7 @@ func isSelfSigned(cert *x509.Certificate, e *reportstyle.Style) (string, bool) {
188198 return selfsigned , status
189199}
190200
201+ // subCA ..
191202func subCA (cert * x509.Certificate , e * reportstyle.Style ) string {
192203 if cert .IsCA {
193204 if cert .MaxPathLen > 0 {
@@ -201,6 +212,7 @@ func subCA(cert *x509.Certificate, e *reportstyle.Style) string {
201212 return _no
202213}
203214
215+ // isCA ...
204216func isCA (cert * x509.Certificate , e * reportstyle.Style ) string {
205217 state , alert := "" , ""
206218 if cert .IsCA {
@@ -217,6 +229,7 @@ func isCA(cert *x509.Certificate, e *reportstyle.Style) string {
217229 return state + alert
218230}
219231
232+ // signatureState ...
220233func signatureState (cert * x509.Certificate , e * reportstyle.Style ) string {
221234 _ , err := cert .Verify (x509.VerifyOptions {})
222235 if err != nil {
@@ -225,6 +238,7 @@ func signatureState(cert *x509.Certificate, e *reportstyle.Style) string {
225238 return e .Valid + " [trusted via system trust store]"
226239}
227240
241+ // validFor ...
228242func validFor (cert * x509.Certificate , e * reportstyle.Style ) string {
229243 // result, t := e.Fail, cert.NotAfter.Sub(time.Now())
230244 t := time .Until (cert .NotAfter )
@@ -252,10 +266,12 @@ func validFor(cert *x509.Certificate, e *reportstyle.Style) string {
252266 return result
253267}
254268
269+ // encryptedBlock ...
255270func encryptedBlock (block * pem.Block ) bool {
256271 return strings .Contains (block .Headers ["Proc-Type" ], "ENCRYPTED" )
257272}
258273
274+ // certRequestSummary ...
259275func certRequestSummary (csr * x509.CertificateRequest , e * reportstyle.Style ) string {
260276 err := csr .CheckSignature ()
261277 if err != nil {
@@ -264,6 +280,7 @@ func certRequestSummary(csr *x509.CertificateRequest, e *reportstyle.Style) stri
264280 return e .Valid
265281}
266282
283+ // keyUsage ...
267284func keyUsage (cert * x509.Certificate , e * reportstyle.Style ) string {
268285 var s strings.Builder
269286 caAlert := false
@@ -285,6 +302,7 @@ func keyUsage(cert *x509.Certificate, e *reportstyle.Style) string {
285302 return s .String ()
286303}
287304
305+ // exgtendedKeyUsage ...
288306func extendedKeyUsage (cert * x509.Certificate , e * reportstyle.Style ) string {
289307 var s strings.Builder
290308 count , critical := oidInExtensions (oidExtensionExtendedKeyUsage , cert .Extensions )
@@ -303,6 +321,7 @@ func extendedKeyUsage(cert *x509.Certificate, e *reportstyle.Style) string {
303321 return s .String ()
304322}
305323
324+ // sct ...
306325func sct (cert * x509.Certificate , _ * reportstyle.Style ) string {
307326 var s strings.Builder
308327 count , critical := oidInExtensions (oidExtensionCTPoison , cert .Extensions )
@@ -354,6 +373,7 @@ var (
354373 oidExtensionCTSCT = asn1.ObjectIdentifier {1 , 3 , 6 , 1 , 4 , 1 , 11129 , 2 , 4 , 2 }
355374)
356375
376+ // oidInExtensions ...
357377func oidInExtensions (oid asn1.ObjectIdentifier , extensions []pkix.Extension ) (int , bool ) {
358378 count := 0
359379 critical := false
@@ -368,6 +388,7 @@ func oidInExtensions(oid asn1.ObjectIdentifier, extensions []pkix.Extension) (in
368388 return count , critical
369389}
370390
391+ // keyUsageToString ...
371392func keyUsageToString (k x509.KeyUsage ) (string , bool ) {
372393 var s strings.Builder
373394 caAlert := false
@@ -402,6 +423,7 @@ func keyUsageToString(k x509.KeyUsage) (string, bool) {
402423 return s .String (), caAlert
403424}
404425
426+ // extKeyUsageToString ...
405427func extKeyUsageToString (u x509.ExtKeyUsage , e * reportstyle.Style ) string {
406428 var s strings.Builder
407429 switch u {
@@ -442,6 +464,7 @@ func extKeyUsageToString(u x509.ExtKeyUsage, e *reportstyle.Style) string {
442464 return s .String ()
443465}
444466
467+ // isCurveValid ...
445468func isCurveValid (curve elliptic.Curve ) (string , bool ) {
446469 switch curve {
447470 case elliptic .P256 ():
0 commit comments