Skip to content

Commit 2aeefc3

Browse files
drakkanFiloSottile
authored andcommitted
ssh: add support for SSH_AGENT_CONSTRAIN_EXTENSION with id 255
it was changed in the following draft https://datatracker.ietf.org/doc/html/draft-miller-ssh-agent-03 The id 3 is now used for SSH_AGENT_CONSTRAIN_MAXSIGN key constraint, an OpenSSH extension to the protocol that we do not currently support. Instead, we added a compatibility layer for SSH_AGENT_CONSTRAIN_EXTENSION with ID 3. Fixes golang/go#62311 Change-Id: I421aee92aee9e693e43f66e6a5515c055333cb9b Reviewed-on: https://go-review.googlesource.com/c/crypto/+/525355 Reviewed-by: Matthew Dempsky <[email protected]> Run-TryBot: Nicola Murino <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent e3cc52e commit 2aeefc3

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

ssh/agent/client.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,14 @@ const (
141141
agentAddSmartcardKeyConstrained = 26
142142

143143
// 3.7 Key constraint identifiers
144-
agentConstrainLifetime = 1
145-
agentConstrainConfirm = 2
146-
agentConstrainExtension = 3
144+
agentConstrainLifetime = 1
145+
agentConstrainConfirm = 2
146+
// Constraint extension identifier up to version 2 of the protocol. A
147+
// backward incompatible change will be required if we want to add support
148+
// for SSH_AGENT_CONSTRAIN_MAXSIGN which uses the same ID.
149+
agentConstrainExtensionV00 = 3
150+
// Constraint extension identifier in version 3 and later of the protocol.
151+
agentConstrainExtension = 255
147152
)
148153

149154
// maxAgentResponseBytes is the maximum agent reply size that is accepted. This
@@ -205,7 +210,7 @@ type constrainLifetimeAgentMsg struct {
205210
}
206211

207212
type constrainExtensionAgentMsg struct {
208-
ExtensionName string `sshtype:"3"`
213+
ExtensionName string `sshtype:"255|3"`
209214
ExtensionDetails []byte
210215

211216
// Rest is a field used for parsing, not part of message

ssh/agent/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func parseConstraints(constraints []byte) (lifetimeSecs uint32, confirmBeforeUse
208208
case agentConstrainConfirm:
209209
confirmBeforeUse = true
210210
constraints = constraints[1:]
211-
case agentConstrainExtension:
211+
case agentConstrainExtension, agentConstrainExtensionV00:
212212
var msg constrainExtensionAgentMsg
213213
if err = ssh.Unmarshal(constraints, &msg); err != nil {
214214
return 0, false, nil, err

ssh/agent/server_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ func TestParseConstraints(t *testing.T) {
243243
ExtensionDetails: []byte(fmt.Sprintf("details: %d", i)),
244244
}
245245
expect = append(expect, ext)
246-
data = append(data, agentConstrainExtension)
246+
if i%2 == 0 {
247+
data = append(data, agentConstrainExtension)
248+
} else {
249+
data = append(data, agentConstrainExtensionV00)
250+
}
247251
data = append(data, ssh.Marshal(ext)...)
248252
}
249253
_, _, extensions, err := parseConstraints(data)

0 commit comments

Comments
 (0)