...
1 package mocks
2
3 import (
4 "context"
5 "crypto/x509"
6 "encoding/pem"
7 "fmt"
8 "time"
9
10 capb "github.com/letsencrypt/boulder/ca/proto"
11 corepb "github.com/letsencrypt/boulder/core/proto"
12 "google.golang.org/grpc"
13 "google.golang.org/protobuf/types/known/timestamppb"
14 )
15
16
17
18 type MockCA struct {
19 PEM []byte
20 }
21
22
23 func (ca *MockCA) IssuePrecertificate(ctx context.Context, _ *capb.IssueCertificateRequest, _ ...grpc.CallOption) (*capb.IssuePrecertificateResponse, error) {
24 if ca.PEM == nil {
25 return nil, fmt.Errorf("MockCA's PEM field must be set before calling IssueCertificate")
26 }
27 block, _ := pem.Decode(ca.PEM)
28 cert, err := x509.ParseCertificate(block.Bytes)
29 if err != nil {
30 return nil, err
31 }
32 return &capb.IssuePrecertificateResponse{
33 DER: cert.Raw,
34 }, nil
35 }
36
37
38 func (ca *MockCA) IssueCertificateForPrecertificate(ctx context.Context, req *capb.IssueCertificateForPrecertificateRequest, _ ...grpc.CallOption) (*corepb.Certificate, error) {
39 now := time.Now()
40 expires := now.Add(1 * time.Hour)
41
42 return &corepb.Certificate{
43 Der: req.DER,
44 RegistrationID: 1,
45 Serial: "mock",
46 Digest: "mock",
47 IssuedNS: now.UnixNano(),
48 Issued: timestamppb.New(now),
49 ExpiresNS: expires.UnixNano(),
50 Expires: timestamppb.New(expires),
51 }, nil
52 }
53
54 type MockOCSPGenerator struct{}
55
56
57 func (ca *MockOCSPGenerator) GenerateOCSP(ctx context.Context, req *capb.GenerateOCSPRequest, _ ...grpc.CallOption) (*capb.OCSPResponse, error) {
58 return nil, nil
59 }
60
61 type MockCRLGenerator struct{}
62
63
64 func (ca *MockCRLGenerator) GenerateCRL(ctx context.Context, opts ...grpc.CallOption) (capb.CRLGenerator_GenerateCRLClient, error) {
65 return nil, nil
66 }
67
View as plain text