@@ -12,8 +12,7 @@ import (
12
12
13
13
"github.com/pkg/errors"
14
14
kmsapi "github.com/smallstep/certificates/kms/apiv1"
15
- pb "google.golang.org/genproto/googleapis/cloud/security/privateca/v1beta1"
16
- wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
15
+ pb "google.golang.org/genproto/googleapis/cloud/security/privateca/v1"
17
16
)
18
17
19
18
var (
@@ -67,11 +66,10 @@ func createCertificateConfig(tpl *x509.Certificate) (*pb.Certificate_Config, err
67
66
config := & pb.CertificateConfig {
68
67
SubjectConfig : & pb.CertificateConfig_SubjectConfig {
69
68
Subject : createSubject (tpl ),
70
- CommonName : tpl .Subject .CommonName ,
71
69
SubjectAltName : createSubjectAlternativeNames (tpl ),
72
70
},
73
- ReusableConfig : createReusableConfig (tpl ),
74
- PublicKey : pk ,
71
+ X509Config : createX509Parameters (tpl ),
72
+ PublicKey : pk ,
75
73
}
76
74
return & pb.Certificate_Config {
77
75
Config : config ,
@@ -86,15 +84,15 @@ func createPublicKey(key crypto.PublicKey) (*pb.PublicKey, error) {
86
84
return nil , errors .Wrap (err , "error marshaling public key" )
87
85
}
88
86
return & pb.PublicKey {
89
- Type : pb .PublicKey_PEM_EC_KEY ,
87
+ Format : pb .PublicKey_PEM ,
90
88
Key : pem .EncodeToMemory (& pem.Block {
91
89
Type : "PUBLIC KEY" ,
92
90
Bytes : asn1Bytes ,
93
91
}),
94
92
}, nil
95
93
case * rsa.PublicKey :
96
94
return & pb.PublicKey {
97
- Type : pb .PublicKey_PEM_RSA_KEY ,
95
+ Format : pb .PublicKey_PEM ,
98
96
Key : pem .EncodeToMemory (& pem.Block {
99
97
Type : "RSA PUBLIC KEY" ,
100
98
Bytes : x509 .MarshalPKCS1PublicKey (key ),
@@ -107,7 +105,9 @@ func createPublicKey(key crypto.PublicKey) (*pb.PublicKey, error) {
107
105
108
106
func createSubject (cert * x509.Certificate ) * pb.Subject {
109
107
sub := cert .Subject
110
- ret := new (pb.Subject )
108
+ ret := & pb.Subject {
109
+ CommonName : sub .CommonName ,
110
+ }
111
111
if len (sub .Country ) > 0 {
112
112
ret .CountryCode = sub .Country [0 ]
113
113
}
@@ -196,7 +196,7 @@ func createSubjectAlternativeNames(cert *x509.Certificate) *pb.SubjectAltNames {
196
196
return ret
197
197
}
198
198
199
- func createReusableConfig (cert * x509.Certificate ) * pb.ReusableConfigWrapper {
199
+ func createX509Parameters (cert * x509.Certificate ) * pb.X509Parameters {
200
200
var unknownEKUs []* pb.ObjectId
201
201
var ekuOptions = & pb.KeyUsage_ExtendedKeyUsageOptions {}
202
202
for _ , eku := range cert .ExtKeyUsage {
@@ -241,22 +241,19 @@ func createReusableConfig(cert *x509.Certificate) *pb.ReusableConfigWrapper {
241
241
policyIDs = append (policyIDs , createObjectID (oid ))
242
242
}
243
243
244
- var caOptions * pb.ReusableConfigValues_CaOptions
244
+ var caOptions * pb.X509Parameters_CaOptions
245
245
if cert .BasicConstraintsValid {
246
- var maxPathLength * wrapperspb.Int32Value
246
+ caOptions = new (pb.X509Parameters_CaOptions )
247
+ var maxPathLength int32
247
248
switch {
248
249
case cert .MaxPathLenZero :
249
- maxPathLength = wrapperspb .Int32 (0 )
250
+ maxPathLength = 0
251
+ caOptions .MaxIssuerPathLength = & maxPathLength
250
252
case cert .MaxPathLen > 0 :
251
- maxPathLength = wrapperspb .Int32 (int32 (cert .MaxPathLen ))
252
- default :
253
- maxPathLength = nil
254
- }
255
-
256
- caOptions = & pb.ReusableConfigValues_CaOptions {
257
- IsCa : wrapperspb .Bool (cert .IsCA ),
258
- MaxIssuerPathLength : maxPathLength ,
253
+ maxPathLength = int32 (cert .MaxPathLen )
254
+ caOptions .MaxIssuerPathLength = & maxPathLength
259
255
}
256
+ caOptions .IsCa = & cert .IsCA
260
257
}
261
258
262
259
var extraExtensions []* pb.X509Extension
@@ -270,7 +267,7 @@ func createReusableConfig(cert *x509.Certificate) *pb.ReusableConfigWrapper {
270
267
}
271
268
}
272
269
273
- values := & pb.ReusableConfigValues {
270
+ return & pb.X509Parameters {
274
271
KeyUsage : & pb.KeyUsage {
275
272
BaseKeyUsage : & pb.KeyUsage_KeyUsageOptions {
276
273
DigitalSignature : cert .KeyUsage & x509 .KeyUsageDigitalSignature > 0 ,
@@ -291,12 +288,6 @@ func createReusableConfig(cert *x509.Certificate) *pb.ReusableConfigWrapper {
291
288
AiaOcspServers : cert .OCSPServer ,
292
289
AdditionalExtensions : extraExtensions ,
293
290
}
294
-
295
- return & pb.ReusableConfigWrapper {
296
- ConfigValues : & pb.ReusableConfigWrapper_ReusableConfigValues {
297
- ReusableConfigValues : values ,
298
- },
299
- }
300
291
}
301
292
302
293
// isExtraExtension returns true if the extension oid is not managed in a
0 commit comments