forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cipherinfotypes.go
146 lines (124 loc) · 4.23 KB
/
cipherinfotypes.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
// Copyright (c) 2017 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"encoding/hex"
"github.com/google/go-cmp/cmp"
zconfig "github.com/lf-edge/eve/api/go/config"
zcommon "github.com/lf-edge/eve/api/go/evecommon"
"github.com/lf-edge/eve/pkg/pillar/base"
)
// CipherContext : a pair of device and controller certificate
// published by controller along with some attributes
// part of EdgeDevConfig block, received from controller
type CipherContext struct {
ContextID string
HashScheme zcommon.HashAlgorithm
KeyExchangeScheme zconfig.KeyExchangeScheme
EncryptionScheme zconfig.EncryptionScheme
ControllerCertHash []byte
DeviceCertHash []byte
// ErrorAndTime provides SetErrorNow() and ClearError()
ErrorAndTime
}
// Key :
func (status *CipherContext) Key() string {
return status.ContextID
}
// ControllerCertKey :
func (status *CipherContext) ControllerCertKey() string {
return hex.EncodeToString(status.ControllerCertHash)
}
// EdgeNodeCertKey :
func (status *CipherContext) EdgeNodeCertKey() string {
return hex.EncodeToString(status.DeviceCertHash)
}
// LogCreate :
func (status CipherContext) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.CipherContextLogType, "",
nilUUID, status.LogKey())
if logObject == nil {
return
}
logObject.Noticef("Cipher block status create")
}
// LogModify :
func (status CipherContext) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.CipherContextLogType, "",
nilUUID, status.LogKey())
oldStatus, ok := old.(CipherContext)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of CipherContext type")
}
// XXX remove? XXX huge?
logObject.CloneAndAddField("diff", cmp.Diff(oldStatus, status)).
Noticef("Cipher block status modify")
}
// LogDelete :
func (status CipherContext) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.CipherContextLogType, "",
nilUUID, status.LogKey())
logObject.Noticef("Cipher block status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status CipherContext) LogKey() string {
return string(base.CipherContextLogType) + "-" + status.Key()
}
// CipherBlockStatus : Object specific encryption information
type CipherBlockStatus struct {
CipherBlockID string // constructed using individual reference
CipherContextID string // cipher context id
InitialValue []byte
CipherData []byte `json:"pubsub-large-CipherData"`
ClearTextHash []byte
IsCipher bool
// ErrorAndTime provides SetErrorNow() and ClearError()
ErrorAndTime
}
// Key :
func (status *CipherBlockStatus) Key() string {
return status.CipherBlockID
}
// LogCreate :
func (status CipherBlockStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.CipherBlockStatusLogType, "",
nilUUID, status.LogKey())
if logObject == nil {
return
}
logObject.Noticef("Cipher block status create")
}
// LogModify :
func (status CipherBlockStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.CipherBlockStatusLogType, "",
nilUUID, status.LogKey())
oldStatus, ok := old.(CipherBlockStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of CipherBlockStatus type")
}
// XXX remove? XXX huge?
logObject.CloneAndAddField("diff", cmp.Diff(oldStatus, status)).
Noticef("Cipher block status modify")
}
// LogDelete :
func (status CipherBlockStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.CipherBlockStatusLogType, "",
nilUUID, status.LogKey())
logObject.Noticef("Cipher block status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status CipherBlockStatus) LogKey() string {
return string(base.CipherBlockStatusLogType) + "-" + status.Key()
}
// EncryptionBlock - This is a Mirror of
// api/proto/config/acipherinfo.proto - EncryptionBlock
// Always need to keep these two consistent.
type EncryptionBlock struct {
DsAPIKey string
DsPassword string
WifiUserName string // If the authentication type is EAP
WifiPassword string
ProtectedUserData string
}