-
Notifications
You must be signed in to change notification settings - Fork 1
/
cert_id.go
41 lines (35 loc) · 1.05 KB
/
cert_id.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package certutil
import (
"crypto/x509"
"encoding/hex"
)
// GetThumbprintStr returns hex-encoded SHA1 of the certificate
func GetThumbprintStr(c *x509.Certificate) string {
return SHA1Hex(c.Raw)
}
// GetSubjectKeyID returns Subject Key Identifier
func GetSubjectKeyID(c *x509.Certificate) string {
return hex.EncodeToString(c.SubjectKeyId)
}
// GetAuthorityKeyID returns Authority Key Identifier
func GetAuthorityKeyID(c *x509.Certificate) string {
return hex.EncodeToString(c.AuthorityKeyId)
}
// GetSubjectID returns ID of the cert.
// If present, it uses Subject Key Identifier,
// otherwise SHA1 of the Subject name
func GetSubjectID(c *x509.Certificate) string {
if len(c.SubjectKeyId) > 0 {
return hex.EncodeToString(c.SubjectKeyId)
}
return SHA1Hex(c.RawSubject)
}
// GetIssuerID returns ID of the issuer.
// If present, it uses Authority Key Identifier,
// otherwise SHA1 of the Issuer name
func GetIssuerID(c *x509.Certificate) string {
if len(c.AuthorityKeyId) > 0 {
return hex.EncodeToString(c.AuthorityKeyId)
}
return SHA1Hex(c.RawIssuer)
}