Skip to content
This repository has been archived by the owner on Feb 16, 2025. It is now read-only.

Commit

Permalink
[SSH-CA] support passing keyID directly to Generate
Browse files Browse the repository at this point in the history
  • Loading branch information
b1naryth1ef committed Jul 10, 2017
1 parent 19a0044 commit 3c0f113
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bowser

import (
"crypto/rand"
"fmt"
"golang.org/x/crypto/ed25519"
"golang.org/x/crypto/ssh"
"io/ioutil"
Expand Down Expand Up @@ -35,7 +34,7 @@ func NewCertificateAuthority(keyPath string) (ca *CertificateAuthority, err erro
}

// Generate a new ed25519 keypair and SSH user certificate, then sign with our CA private key
func (ca *CertificateAuthority) Generate(sessionID, username, command string, sourceAddresses []string) (*ssh.Certificate, *ed25519.PrivateKey, error) {
func (ca *CertificateAuthority) Generate(keyID, username, command string, sourceAddresses []string) (*ssh.Certificate, *ed25519.PrivateKey, error) {
edPublicKey, edPrivateKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, nil, err
Expand All @@ -49,7 +48,7 @@ func (ca *CertificateAuthority) Generate(sessionID, username, command string, so
cert := ssh.Certificate{
Key: publicKey,
CertType: ssh.UserCert,
KeyId: fmt.Sprintf("%s_%s", username, sessionID),
KeyId: keyID,
ValidPrincipals: []string{username},
ValidAfter: uint64(time.Now().UTC().Add(-15 * time.Second).Unix()),
ValidBefore: uint64(time.Now().UTC().Add(1 * time.Minute).Unix()),
Expand Down
3 changes: 2 additions & 1 deletion lib/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ func (s *SSHSession) handleChannelForward(newChannel ssh.NewChannel) {
username = s.Account.Username
}

keyID := fmt.Sprintf("user[%s] / session[%s]", s.Account.Username, s.UUID)
cert, privateKey, err := s.State.ca.Generate(
s.UUID,
keyID,
username,
s.State.Config.ForceCommand,
s.State.Config.PermittedSourceAddresses,
Expand Down

0 comments on commit 3c0f113

Please sign in to comment.