This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
model.go
52 lines (45 loc) · 1.53 KB
/
model.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
42
43
44
45
46
47
48
49
50
51
52
package pki
import (
"context"
"crypto"
"crypto/x509"
"encoding/hex"
"time"
)
type CertificateInfo struct {
Certificate *x509.Certificate `json:"-"`
SerialBytes []byte `json:"-"`
CertType CertType `json:"type"`
Serial string `json:"serial"`
KeyId string `json:"keyId"`
Subject string `json:"subject"`
NotBefore time.Time `json:"notBefore"`
NotAfter time.Time `json:"notAfter"`
Revoked *time.Time `json:"revoked,omitempty"`
}
func CertInfoFromX509Cert(cert *x509.Certificate) *CertificateInfo {
return &CertificateInfo{
Certificate: cert,
SerialBytes: cert.SerialNumber.Bytes(),
CertType: GetCertType(cert),
Serial: hex.EncodeToString(cert.SerialNumber.Bytes()),
KeyId: hex.EncodeToString(cert.SubjectKeyId),
Subject: cert.Subject.CommonName,
NotBefore: cert.NotBefore,
NotAfter: cert.NotAfter,
Revoked: nil,
}
}
type PKIStorage interface {
GetCACert(ctx context.Context) *x509.Certificate
GetPrevCACert(ctx context.Context) *x509.Certificate
GetCrossCert(ctx context.Context) *x509.Certificate
GetPrivateKey(ctx context.Context) crypto.PrivateKey
GetPublicKey(ctx context.Context) crypto.PublicKey
GetStaticKey(ctx context.Context) StaticKey
AddCert(ctx context.Context, cert *x509.Certificate) error
ListAllCerts(ctx context.Context) ([]*CertificateInfo, error)
ListCertsBySubject(context.Context, string) ([]*CertificateInfo, error)
GetCertBySerial(context.Context, []byte) (*CertificateInfo, error)
RevokeCert(context.Context, []byte) (*CertificateInfo, error)
}