-
Notifications
You must be signed in to change notification settings - Fork 155
/
handlecertconfig.go
640 lines (561 loc) · 19.8 KB
/
handlecertconfig.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
// Copyright (c) 2017-2018 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package zedagent
// certs API specific parser/utility routines
import (
"bytes"
"crypto/sha256"
"crypto/x509"
"encoding/hex"
"encoding/pem"
"errors"
"fmt"
"net/http"
"os"
"time"
"github.com/lf-edge/eve-api/go/attest"
zcert "github.com/lf-edge/eve-api/go/certs"
zconfig "github.com/lf-edge/eve-api/go/config"
"github.com/lf-edge/eve-api/go/evecommon"
"github.com/lf-edge/eve/pkg/pillar/agentlog"
"github.com/lf-edge/eve/pkg/pillar/flextimer"
"github.com/lf-edge/eve/pkg/pillar/types"
"github.com/lf-edge/eve/pkg/pillar/zedcloud"
"google.golang.org/protobuf/proto"
)
// Cipher Information Context
type cipherContext struct {
zedagentCtx *zedagentContext // Cross link
// post and get certs triggers
triggerEdgeNodeCerts chan struct{}
triggerControllerCerts chan struct{}
cfgControllerCertHash string // Last controllercert_confighash received from controller
iteration int
}
var controllerCertHash []byte
// parse and update controller certs
func parseControllerCerts(ctx *zedagentContext, contents []byte) (changed bool, err error) {
log.Functionf("Started parsing controller certs")
cfgConfig := &zcert.ZControllerCert{}
err = proto.Unmarshal(contents, cfgConfig)
if err != nil {
err = fmt.Errorf("parseControllerCerts(): Unmarshal error %w", err)
log.Error(err)
return false, err
}
cfgCerts := cfgConfig.GetCerts()
h := sha256.New()
for _, cfgCert := range cfgCerts {
computeConfigElementSha(h, cfgCert)
}
newHash := h.Sum(nil)
if bytes.Equal(newHash, controllerCertHash) {
return false, nil
}
log.Functionf("parseControllerCerts: Applying updated config "+
"Last Sha: % x, "+
"New Sha: % x, "+
"Num of cfgCert: %d",
controllerCertHash, newHash, len(cfgCerts))
controllerCertHash = newHash
// First look for deleted ones
items := ctx.getconfigCtx.pubControllerCert.GetAll()
for _, item := range items {
config := item.(types.ControllerCert)
configHash := config.CertHash
found := false
for _, cfgConfig := range cfgCerts {
cfgConfigHash := cfgConfig.GetCertHash()
if bytes.Equal(configHash, cfgConfigHash) {
found = true
break
}
}
if found {
continue
}
// Is the ControllerCert in use?
if lookupCipherContextByCCH(ctx.getconfigCtx, configHash) != nil {
log.Noticef("ControllerCert %s hash %s in use",
config.Key(), string(configHash))
} else {
log.Noticef("ControllerCert %s hash %s delete",
config.Key(), string(configHash))
unpublishControllerCert(ctx.getconfigCtx, config.Key())
changed = true
}
}
for _, cfgConfig := range cfgCerts {
certKey := hex.EncodeToString(cfgConfig.GetCertHash())
cert := lookupControllerCert(ctx.getconfigCtx, certKey)
if cert == nil {
log.Functionf("parseControllerCerts: not found %s", certKey)
cert = &types.ControllerCert{
HashAlgo: cfgConfig.GetHashAlgo(),
Type: cfgConfig.GetType(),
Cert: cfgConfig.GetCert(),
CertHash: cfgConfig.GetCertHash(),
}
publishControllerCert(ctx.getconfigCtx, *cert)
changed = true
}
}
log.Functionf("parsing controller certs done")
return changed, nil
}
// look up controller cert
func lookupControllerCert(ctx *getconfigContext,
key string) *types.ControllerCert {
log.Functionf("lookupControllerCert(%s)", key)
pub := ctx.pubControllerCert
item, err := pub.Get(key)
if err != nil {
log.Errorf("lookupControllerCert(%s) not found", key)
return nil
}
status := item.(types.ControllerCert)
log.Functionf("lookupControllerCert(%s) Done", key)
return &status
}
// pubsub functions
// for controller cert
func publishControllerCert(ctx *getconfigContext,
config types.ControllerCert) {
key := config.Key()
log.Tracef("publishControllerCert %s", key)
pub := ctx.pubControllerCert
pub.Publish(key, config)
log.Tracef("publishControllerCert %s Done", key)
}
func unpublishControllerCert(ctx *getconfigContext, key string) {
log.Tracef("unpublishControllerCert %s", key)
pub := ctx.pubControllerCert
c, _ := pub.Get(key)
if c == nil {
log.Errorf("unpublishControllerCert(%s) not found", key)
return
}
log.Tracef("unpublishControllerCert %s Done", key)
pub.Unpublish(key)
}
func handleEdgeNodeCertCreate(ctxArg interface{}, key string,
configArg interface{}) {
handleEdgeNodeCertImpl(ctxArg, key, configArg)
}
func handleEdgeNodeCertModify(ctxArg interface{}, key string,
configArg interface{}, oldConfigArg interface{}) {
handleEdgeNodeCertImpl(ctxArg, key, configArg)
}
func handleEdgeNodeCertImpl(ctxArg interface{}, key string,
configArg interface{}) {
ctx := ctxArg.(*zedagentContext)
status := configArg.(types.EdgeNodeCert)
log.Functionf("handleEdgeNodeCertImpl for %s", status.Key())
triggerEdgeNodeCertEvent(ctx)
}
func handleEdgeNodeCertDelete(ctxArg interface{}, key string,
configArg interface{}) {
ctx := ctxArg.(*zedagentContext)
status := configArg.(types.EdgeNodeCert)
log.Functionf("handleEdgeNodeCertDelete for %s", status.Key())
triggerEdgeNodeCertEvent(ctx)
}
// Run a task certificate post task, on change trigger
func controllerCertsTask(ctx *zedagentContext, triggerCerts <-chan struct{}) {
log.Functionln("starting controller certificate fetch task")
retry := !getCertsFromController(ctx, "initial")
wdName := agentName + "ccerts"
// Run a periodic timer so we always update StillRunning
stillRunning := time.NewTicker(25 * time.Second)
ctx.ps.StillRunning(wdName, warningTime, errorTime)
ctx.ps.RegisterFileWatchdog(wdName)
// Run a timer for extra safety to handle controller certificates updates
// If we failed with the initial we have a short timer, otherwise
// the configurable one.
const shortTime = 120 // Two minutes
certInterval := ctx.globalConfig.GlobalValueInt(types.CertInterval)
if retry {
log.Noticef("Initial getCertsFromController failed; switching to short timer")
certInterval = shortTime
}
interval := time.Duration(certInterval) * time.Second
max := float64(interval)
min := max * 0.3
periodicTicker := flextimer.NewRangeTicker(time.Duration(min),
time.Duration(max))
ctx.getconfigCtx.certTickerHandle = periodicTicker
for {
success := true
select {
case <-triggerCerts:
start := time.Now()
success = getCertsFromController(ctx, "triggered")
ctx.ps.CheckMaxTimeTopic(wdName, "publishCerts", start,
warningTime, errorTime)
case <-periodicTicker.C:
start := time.Now()
success = getCertsFromController(ctx, "periodic")
ctx.ps.CheckMaxTimeTopic(wdName, "publishCerts", start,
warningTime, errorTime)
case <-stillRunning.C:
}
ctx.ps.StillRunning(wdName, warningTime, errorTime)
if retry && success {
log.Noticef("getCertsFromController succeeded; switching to long timer %d seconds",
ctx.globalConfig.GlobalValueInt(types.CertInterval))
updateCertTimer(ctx.globalConfig.GlobalValueInt(types.CertInterval),
ctx.getconfigCtx.certTickerHandle)
retry = false
} else if !retry && !success {
log.Noticef("getCertsFromController failed; switching to short timer")
updateCertTimer(shortTime,
ctx.getconfigCtx.certTickerHandle)
retry = true
}
}
}
func verifySigningCertNewest(ctx *zedagentContext, certByte []byte) error {
block, _ := pem.Decode(certByte)
if block == nil {
err := fmt.Errorf("verifyCertNewest: pem.Decode() failed")
return err
}
newCert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
err = fmt.Errorf("verifyCertNewest: x509.ParseCertificate() failed: %w", err)
return err
}
err = zedcloud.LoadSavedServerSigningCert(zedcloudCtx)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
// Certificates were not loaded, accept
return nil
}
err = fmt.Errorf("verifyCertNewest: LoadSavedServerSigningCert() failed: %w", err)
return err
}
oldCert := zedcloudCtx.ServerSigningCert
if newCert.NotBefore.Before(oldCert.NotBefore) {
err = fmt.Errorf("verifyCertNewest: received old signing certificate, new.NotBefore '%v' < '%v' old.NotBefore",
newCert.NotBefore, oldCert.NotBefore)
return err
}
return nil
}
// Fetch and verify the controller certificates. Returns true if certificates have
// not changed or the update was successfully applied.
// False is returned if the function failed to fetch/verify/unmarshal certs.
func requestCertsByURL(ctx *zedagentContext, certURL string, desc string,
requireSigningCertNewest bool) bool {
log.Functionf("getCertsFromController started for %s", desc)
ctxWork, cancel := zedcloud.GetContextForAllIntfFunctions(zedcloudCtx)
defer cancel()
const bailOnHTTPErr = false
const withNetTracing = false
rv, err := zedcloud.SendOnAllIntf(ctxWork, zedcloudCtx, certURL, 0, nil, 0,
bailOnHTTPErr, withNetTracing)
if err != nil {
switch rv.Status {
case types.SenderStatusUpgrade:
log.Noticef("getCertsFromController: Controller upgrade in progress")
case types.SenderStatusRefused:
log.Noticef("getCertsFromController: Controller returned ECONNREFUSED")
case types.SenderStatusCertInvalid:
log.Warnf("getCertsFromController: Controller certificate invalid time")
log.Noticef("%s trigger", rv.Status.String())
triggerControllerCertEvent(ctx)
case types.SenderStatusCertMiss:
log.Noticef("getCertsFromController: Controller certificate miss")
log.Noticef("%s trigger", rv.Status.String())
triggerControllerCertEvent(ctx)
default:
log.Errorf("getCertsFromController failed: %s", err)
}
return false
}
switch rv.HTTPResp.StatusCode {
case http.StatusOK:
log.Functionf("getCertsFromController: status %d", rv.Status)
default:
log.Errorf("getCertsFromController: failed, statuscode %d %s",
rv.HTTPResp.StatusCode, http.StatusText(rv.HTTPResp.StatusCode))
switch rv.Status {
case types.SenderStatusCertMiss, types.SenderStatusCertInvalid:
// trigger to acquire new controller certs from cloud
log.Noticef("%s trigger", rv.Status.String())
triggerControllerCertEvent(ctx)
}
return false
}
if err := zedcloud.ValidateProtoContentType(certURL, rv.HTTPResp); err != nil {
log.Errorf("getCertsFromController: resp header error")
return false
}
if len(rv.RespContents) > 0 {
err = zedcloud.RemoveAndVerifyAuthContainer(zedcloudCtx, &rv, true)
if err != nil {
log.Errorf("RemoveAndVerifyAuthContainer failed: %s", err)
return false
}
}
// validate the certificate message payload
signingCertBytes, ret := zedcloud.VerifyProtoSigningCertChain(log, rv.RespContents)
if ret != nil {
log.Errorf("getCertsFromController: verify err %v", ret)
switch rv.Status {
case types.SenderStatusCertMiss, types.SenderStatusCertInvalid:
// trigger to acquire new controller certs from cloud
log.Noticef("%s trigger", rv.Status.String())
triggerControllerCertEvent(ctx)
}
return false
}
// verify if signing certificate is the newest
if requireSigningCertNewest {
err := verifySigningCertNewest(ctx, signingCertBytes)
if err != nil {
log.Error(err)
return false
}
}
// manage the certificates through pubsub
changed, err := parseControllerCerts(ctx, rv.RespContents)
if err != nil {
// Note that err is already logged.
return false
}
if !changed {
return true
}
// write the signing cert to file
if err := zedcloud.SaveServerSigningCert(zedcloudCtx, signingCertBytes); err != nil {
errStr := fmt.Sprintf("%v", err)
log.Errorf("getCertsFromController: " + errStr)
return false
}
log.Noticef("getCertsFromController: success for %s", desc)
return true
}
// Fetch and verify the controller certificates. Returns true if certificates
// have not changed or the update was successfully applied. False is returned
// if the function failed to fetch/verify/unmarshal certs.
//
// If main controller is unavailable (@false is returned), the next set of
// attempts is to fallback to retrieve certs from the LOC.
func getCertsFromController(ctx *zedagentContext, desc string) bool {
// not V2API
if !zedcloud.UseV2API() {
log.Noticef("getCertsFromController not V2API!")
return false
}
url := zedcloud.URLPathString(serverNameAndPort, zedcloudCtx.V2API,
nilUUID, "certs")
// Controller is in the power to push us outdated certs.
// Do not question the power of the controller, this is
// insubordition.
requireSigningCertNewest := false
rv := requestCertsByURL(ctx, url, desc, requireSigningCertNewest)
if !rv {
log.Warningf("getCertsFromController: fetching certs from controller failed")
}
if !rv && ctx.getconfigCtx.sideController.locConfig != nil {
locURL := ctx.getconfigCtx.sideController.locConfig.LocURL
url = zedcloud.URLPathString(locURL, zedcloudCtx.V2API,
nilUUID, "certs")
// Don't let LOC push us outdated certs
requireSigningCertNewest := true
// Request certs from LOC if previous request has failed and LOC
// configuration exists and is valid
rv = requestCertsByURL(ctx, url, desc, requireSigningCertNewest)
log.Warningf("getCertsFromController: certs were requested from the LOC with the result '%v'",
rv)
}
return rv
}
// edge node certificate post task, on change trigger
func edgeNodeCertsTask(ctx *zedagentContext, triggerEdgeNodeCerts chan struct{}) {
log.Functionln("starting edge node certificates publish task")
publishEdgeNodeCertsToController(ctx)
wdName := agentName + "ecerts"
stillRunning := time.NewTicker(25 * time.Second)
ctx.ps.StillRunning(wdName, warningTime, errorTime)
ctx.ps.RegisterFileWatchdog(wdName)
for {
select {
case <-triggerEdgeNodeCerts:
start := time.Now()
publishEdgeNodeCertsToController(ctx)
ctx.ps.CheckMaxTimeTopic(wdName,
"publishEdgeNodeCertsToController", start,
warningTime, errorTime)
case <-stillRunning.C:
}
ctx.ps.StillRunning(wdName, warningTime, errorTime)
}
}
// prepare the edge node certs list proto message
func publishEdgeNodeCertsToController(ctx *zedagentContext) {
var attestReq = &attest.ZAttestReq{}
// not V2API
if !zedcloud.UseV2API() {
ctx.publishedEdgeNodeCerts = true
return
}
attestReq = new(attest.ZAttestReq)
startPubTime := time.Now()
attestReq.ReqType = attest.ZAttestReqType_ATTEST_REQ_CERT
// no quotes
sub := ctx.subEdgeNodeCert
items := sub.GetAll()
if len(items) == 0 {
//Nothing to be sent
return
}
ecdhCertExists := false
for _, item := range items {
config := item.(types.EdgeNodeCert)
certMsg := zcert.ZCert{
HashAlgo: convertLocalToApiHashAlgo(config.HashAlgo),
Type: convertLocalToApiCertType(config.CertType),
Cert: config.Cert,
CertHash: config.CertID,
}
for _, metaData := range config.MetaDataItems {
certMetaData := new(zcert.ZCertMetaData)
certMetaData.Type = convertLocalToAPICertMetaDataType(metaData.Type)
certMetaData.MetaData = metaData.Data
certMsg.MetaDataItems = append(certMsg.MetaDataItems, certMetaData)
}
attestReq.Certs = append(attestReq.Certs, &certMsg)
if certMsg.Type == zcert.ZCertType_CERT_TYPE_DEVICE_ECDH_EXCHANGE {
ecdhCertExists = true
}
}
if !ecdhCertExists {
//we expect it to be published first
log.Warn("publishEdgeNodeCertsToController: no ecdh")
}
log.Tracef("publishEdgeNodeCertsToController, sending %s", attestReq)
sendAttestReqProtobuf(attestReq, ctx.cipherCtx.iteration)
log.Tracef("publishEdgeNodeCertsToController: after send, total elapse sec %v",
time.Since(startPubTime).Seconds())
ctx.cipherCtx.iteration++
// The getDeferredSentHandlerFunction will set ctx.publishedEdgeNodeCerts
// when the message has been sent.
}
// Try all (first free, then rest) until it gets through.
// Each iteration we try a different port for load spreading.
// For each port we try all its local IP addresses until we get a success.
func sendAttestReqProtobuf(attestReq *attest.ZAttestReq, iteration int) {
data, err := proto.Marshal(attestReq)
if err != nil {
log.Fatal("SendInfoProtobufStr proto marshaling error: ", err)
}
deferKey := "attest:" + devUUID.String()
attestURL := zedcloud.URLPathString(serverNameAndPort, zedcloudCtx.V2API,
devUUID, "attest")
buf := bytes.NewBuffer(data)
if buf == nil {
log.Fatal("malloc error")
}
size := int64(proto.Size(attestReq))
//We queue the message and then get the highest priority message to send.
//If there are no failures and defers we'll send this message,
//but if there is a queue we'll retry sending the highest priority message.
// Since attest messages can fail if there is a certificate mismatch
// we set ignoreErr to allow other messages to be sent as well.
zedcloudCtx.DeferredEventCtx.SetDeferred(deferKey, buf, size, attestURL,
false, false, true, attestReq.ReqType)
}
// initialize cipher pubsub trigger handlers and channels
func cipherModuleInitialize(ctx *zedagentContext) {
// create the trigger channels
ctx.cipherCtx.triggerEdgeNodeCerts = make(chan struct{}, 1)
ctx.cipherCtx.triggerControllerCerts = make(chan struct{}, 1)
}
// start the task threads
func cipherModuleStart(ctx *zedagentContext) {
if !zedcloud.UseV2API() {
log.Functionf("V2 APIs are still not enabled")
// we will run the tasks for watchdog
}
// start the edge node certificate push task
log.Functionf("Creating %s at %s", "edgeNodeCertsTask", agentlog.GetMyStack())
go edgeNodeCertsTask(ctx, ctx.cipherCtx.triggerEdgeNodeCerts)
// start the controller certificate fetch task
log.Functionf("Creating %s at %s", "controllerCertsTask", agentlog.GetMyStack())
go controllerCertsTask(ctx, ctx.cipherCtx.triggerControllerCerts)
}
// Controller certificate, check whether there is a Sha mismatch
// to trigger the post request
func handleControllerCertsSha(ctx *zedagentContext,
config *zconfig.EdgeDevConfig) {
certHash := config.GetControllercertConfighash()
if certHash != ctx.cipherCtx.cfgControllerCertHash {
log.Noticef("handleControllerCertsSha trigger due to controller %v vs current %v",
certHash, ctx.cipherCtx.cfgControllerCertHash)
ctx.cipherCtx.cfgControllerCertHash = certHash
triggerControllerCertEvent(ctx)
}
}
// controller certificate pull trigger function
func triggerControllerCertEvent(ctxPtr *zedagentContext) {
log.Noticef("Trigger for Controller Certs")
select {
case ctxPtr.cipherCtx.triggerControllerCerts <- struct{}{}:
// Do nothing more
default:
log.Warnf("triggerControllerCertEvent(): already triggered, still not processed")
}
}
// edge node certificate post trigger function
func triggerEdgeNodeCertEvent(ctxPtr *zedagentContext) {
log.Function("Trigger Edge Node Certs publish")
select {
case ctxPtr.cipherCtx.triggerEdgeNodeCerts <- struct{}{}:
// Do nothing more
default:
log.Warnf("triggerEdgeNodeCertEvent(): already triggered, still not processed")
}
}
func triggerEdgeNodeCertDelayedEvent(ctxPtr *zedagentContext, d time.Duration) {
go func() {
time.Sleep(d)
triggerEdgeNodeCertEvent(ctxPtr)
}()
}
func convertLocalToApiHashAlgo(algo types.CertHashType) evecommon.HashAlgorithm {
switch algo {
case types.CertHashTypeSha256First16:
return evecommon.HashAlgorithm_HASH_ALGORITHM_SHA256_16BYTES
default:
errStr := fmt.Sprintf("convertLocalToApiHashAlgo(): unknown hash algorithm: %v", algo)
log.Fatal(errStr)
return evecommon.HashAlgorithm_HASH_ALGORITHM_INVALID
}
}
func convertLocalToApiCertType(certType types.CertType) zcert.ZCertType {
switch certType {
case types.CertTypeOnboarding:
return zcert.ZCertType_CERT_TYPE_DEVICE_ONBOARDING
case types.CertTypeRestrictSigning:
return zcert.ZCertType_CERT_TYPE_DEVICE_RESTRICTED_SIGNING
case types.CertTypeEk:
return zcert.ZCertType_CERT_TYPE_DEVICE_ENDORSEMENT_RSA
case types.CertTypeEcdhXchange:
return zcert.ZCertType_CERT_TYPE_DEVICE_ECDH_EXCHANGE
default:
errStr := fmt.Sprintf("convertLocalToApiCertType(): unknown certificate type: %v", certType)
log.Fatal(errStr)
return zcert.ZCertType_CERT_TYPE_CONTROLLER_NONE
}
}
func convertLocalToAPICertMetaDataType(metaDataType types.CertMetaDataType) zcert.ZCertMetaDataType {
switch metaDataType {
case types.CertMetaDataTypeTpm2Public:
return zcert.ZCertMetaDataType_Z_CERT_META_DATA_TYPE_TPM2_PUBLIC
default:
log.Errorf("convertLocalToAPICertMetaDataType: unknown type %v", metaDataType)
return zcert.ZCertMetaDataType_Z_CERT_META_DATA_TYPE_INVALID
}
}