Skip to content

Commit 5255e95

Browse files
committed
session: add WithPrivacy to Session type
1 parent 683cdbd commit 5255e95

File tree

4 files changed

+52
-41
lines changed

4 files changed

+52
-41
lines changed

session/interface.go

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,23 @@ type FeaturesConfig map[string][]byte
4646

4747
// Session is a struct representing a long-term Terminal Connect session.
4848
type Session struct {
49-
ID ID
50-
Label string
51-
State State
52-
Type Type
53-
Expiry time.Time
54-
CreatedAt time.Time
55-
RevokedAt time.Time
56-
ServerAddr string
57-
DevServer bool
58-
MacaroonRootKey uint64
59-
MacaroonRecipe *MacaroonRecipe
60-
PairingSecret [mailbox.NumPassphraseEntropyBytes]byte
61-
LocalPrivateKey *btcec.PrivateKey
62-
LocalPublicKey *btcec.PublicKey
63-
RemotePublicKey *btcec.PublicKey
64-
FeatureConfig *FeaturesConfig
49+
ID ID
50+
Label string
51+
State State
52+
Type Type
53+
Expiry time.Time
54+
CreatedAt time.Time
55+
RevokedAt time.Time
56+
ServerAddr string
57+
DevServer bool
58+
MacaroonRootKey uint64
59+
MacaroonRecipe *MacaroonRecipe
60+
PairingSecret [mailbox.NumPassphraseEntropyBytes]byte
61+
LocalPrivateKey *btcec.PrivateKey
62+
LocalPublicKey *btcec.PublicKey
63+
RemotePublicKey *btcec.PublicKey
64+
FeatureConfig *FeaturesConfig
65+
WithPrivacyMapper bool
6566
}
6667

6768
// MacaroonBaker is a function type for baking a super macaroon.
@@ -71,7 +72,7 @@ type MacaroonBaker func(ctx context.Context, rootKeyID uint64,
7172
// NewSession creates a new session with the given user-defined parameters.
7273
func NewSession(label string, typ Type, expiry time.Time, serverAddr string,
7374
devServer bool, perms []bakery.Op, caveats []macaroon.Caveat,
74-
featureConfig FeaturesConfig) (*Session, error) {
75+
featureConfig FeaturesConfig, privacy bool) (*Session, error) {
7576

7677
_, pairingSecret, err := mailbox.NewPassphraseEntropy()
7778
if err != nil {
@@ -89,19 +90,20 @@ func NewSession(label string, typ Type, expiry time.Time, serverAddr string,
8990
macRootKey := NewSuperMacaroonRootKeyID(macRootKeyBase)
9091

9192
sess := &Session{
92-
ID: macRootKeyBase,
93-
Label: label,
94-
State: StateCreated,
95-
Type: typ,
96-
Expiry: expiry,
97-
CreatedAt: time.Now(),
98-
ServerAddr: serverAddr,
99-
DevServer: devServer,
100-
MacaroonRootKey: macRootKey,
101-
PairingSecret: pairingSecret,
102-
LocalPrivateKey: privateKey,
103-
LocalPublicKey: pubKey,
104-
RemotePublicKey: nil,
93+
ID: macRootKeyBase,
94+
Label: label,
95+
State: StateCreated,
96+
Type: typ,
97+
Expiry: expiry,
98+
CreatedAt: time.Now(),
99+
ServerAddr: serverAddr,
100+
DevServer: devServer,
101+
MacaroonRootKey: macRootKey,
102+
PairingSecret: pairingSecret,
103+
LocalPrivateKey: privateKey,
104+
LocalPublicKey: pubKey,
105+
RemotePublicKey: nil,
106+
WithPrivacyMapper: privacy,
105107
}
106108

107109
if perms != nil || caveats != nil {

session/tlv.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
typeMacaroonRecipe tlv.Type = 12
2727
typeCreatedAt tlv.Type = 13
2828
typeFeaturesConfig tlv.Type = 14
29-
typeReservedNum2 tlv.Type = 15
29+
typeWithPrivacy tlv.Type = 15
3030
typeRevokedAt tlv.Type = 16
3131

3232
// typeMacaroon is no longer used, but we leave it defined for backwards
@@ -65,12 +65,17 @@ func SerializeSession(w io.Writer, session *Session) error {
6565
privateKey = session.LocalPrivateKey.Serialize()
6666
createdAt = uint64(session.CreatedAt.Unix())
6767
revokedAt uint64
68+
withPrivacy = uint8(0)
6869
)
6970

7071
if !session.RevokedAt.IsZero() {
7172
revokedAt = uint64(session.RevokedAt.Unix())
7273
}
7374

75+
if session.WithPrivacyMapper {
76+
withPrivacy = 1
77+
}
78+
7479
if session.DevServer {
7580
devServer = 1
7681
}
@@ -130,7 +135,9 @@ func SerializeSession(w io.Writer, session *Session) error {
130135
}
131136

132137
tlvRecords = append(
133-
tlvRecords, tlv.MakePrimitiveRecord(typeRevokedAt, &revokedAt),
138+
tlvRecords,
139+
tlv.MakePrimitiveRecord(typeWithPrivacy, &withPrivacy),
140+
tlv.MakePrimitiveRecord(typeRevokedAt, &revokedAt),
134141
)
135142

136143
tlvStream, err := tlv.NewStream(tlvRecords...)
@@ -145,13 +152,13 @@ func SerializeSession(w io.Writer, session *Session) error {
145152
// the data to be encoded in the tlv format.
146153
func DeserializeSession(r io.Reader) (*Session, error) {
147154
var (
148-
session = &Session{}
149-
label, serverAddr []byte
150-
pairingSecret, privateKey []byte
151-
state, typ, devServer uint8
152-
expiry, createdAt, revokedAt uint64
153-
macRecipe MacaroonRecipe
154-
featureConfig FeaturesConfig
155+
session = &Session{}
156+
label, serverAddr []byte
157+
pairingSecret, privateKey []byte
158+
state, typ, devServer, privacy uint8
159+
expiry, createdAt, revokedAt uint64
160+
macRecipe MacaroonRecipe
161+
featureConfig FeaturesConfig
155162
)
156163
tlvStream, err := tlv.NewStream(
157164
tlv.MakePrimitiveRecord(typeLabel, &label),
@@ -177,6 +184,7 @@ func DeserializeSession(r io.Reader) (*Session, error) {
177184
typeFeaturesConfig, &featureConfig, nil,
178185
featureConfigEncoder, featureConfigDecoder,
179186
),
187+
tlv.MakePrimitiveRecord(typeWithPrivacy, &privacy),
180188
tlv.MakePrimitiveRecord(typeRevokedAt, &revokedAt),
181189
)
182190
if err != nil {
@@ -196,6 +204,7 @@ func DeserializeSession(r io.Reader) (*Session, error) {
196204
session.CreatedAt = time.Unix(int64(createdAt), 0)
197205
session.ServerAddr = string(serverAddr)
198206
session.DevServer = devServer == 1
207+
session.WithPrivacyMapper = privacy == 1
199208

200209
if revokedAt != 0 {
201210
session.RevokedAt = time.Unix(int64(revokedAt), 0)

session/tlv_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestSerializeDeserializeSession(t *testing.T) {
8787
test.name, test.sessType,
8888
time.Date(99999, 1, 1, 0, 0, 0, 0, time.UTC),
8989
"foo.bar.baz:1234", true, test.perms,
90-
test.caveats, test.featureConfig,
90+
test.caveats, test.featureConfig, true,
9191
)
9292
require.NoError(t, err)
9393

session_rpcserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (s *sessionRpcServer) AddSession(_ context.Context,
249249

250250
sess, err := session.NewSession(
251251
req.Label, typ, expiry, req.MailboxServerAddr, req.DevServer,
252-
uniquePermissions, caveats, nil,
252+
uniquePermissions, caveats, nil, false,
253253
)
254254
if err != nil {
255255
return nil, fmt.Errorf("error creating new session: %v", err)

0 commit comments

Comments
 (0)