Skip to content

Commit 61d52a8

Browse files
committed
Small fixes associated with PR review
* additions and grammar edits to documentation * clarification of error msgs
1 parent 10e7b81 commit 61d52a8

File tree

6 files changed

+34
-31
lines changed

6 files changed

+34
-31
lines changed

api/api_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,8 @@ type mockAuthority struct {
502502
getTLSOptions func() *tlsutil.TLSOptions
503503
root func(shasum string) (*x509.Certificate, error)
504504
sign func(cr *x509.CertificateRequest, opts provisioner.Options, signOpts ...provisioner.SignOption) (*x509.Certificate, *x509.Certificate, error)
505-
singSSH func(key ssh.PublicKey, opts provisioner.SSHOptions, signOpts ...provisioner.SignOption) (*ssh.Certificate, error)
506-
singSSHAddUser func(key ssh.PublicKey, cert *ssh.Certificate) (*ssh.Certificate, error)
505+
signSSH func(key ssh.PublicKey, opts provisioner.SSHOptions, signOpts ...provisioner.SignOption) (*ssh.Certificate, error)
506+
signSSHAddUser func(key ssh.PublicKey, cert *ssh.Certificate) (*ssh.Certificate, error)
507507
renew func(cert *x509.Certificate) (*x509.Certificate, *x509.Certificate, error)
508508
loadProvisionerByCertificate func(cert *x509.Certificate) (provisioner.Interface, error)
509509
getProvisioners func(nextCursor string, limit int) (provisioner.List, string, error)
@@ -547,15 +547,15 @@ func (m *mockAuthority) Sign(cr *x509.CertificateRequest, opts provisioner.Optio
547547
}
548548

549549
func (m *mockAuthority) SignSSH(key ssh.PublicKey, opts provisioner.SSHOptions, signOpts ...provisioner.SignOption) (*ssh.Certificate, error) {
550-
if m.singSSH != nil {
551-
return m.singSSH(key, opts, signOpts...)
550+
if m.signSSH != nil {
551+
return m.signSSH(key, opts, signOpts...)
552552
}
553553
return m.ret1.(*ssh.Certificate), m.err
554554
}
555555

556556
func (m *mockAuthority) SignSSHAddUser(key ssh.PublicKey, cert *ssh.Certificate) (*ssh.Certificate, error) {
557-
if m.singSSHAddUser != nil {
558-
return m.singSSHAddUser(key, cert)
557+
if m.signSSHAddUser != nil {
558+
return m.signSSHAddUser(key, cert)
559559
}
560560
return m.ret1.(*ssh.Certificate), m.err
561561
}

api/ssh.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ type SSHCertificate struct {
3939
*ssh.Certificate `json:"omitempty"`
4040
}
4141

42-
// MarshalJSON implements the json.Marshaler interface. The certificate is
43-
// quoted string using the PEM encoding.
42+
// MarshalJSON implements the json.Marshaler interface. Returns a quoted,
43+
// base64 encoded, openssh wire format version of the certificate.
4444
func (c SSHCertificate) MarshalJSON() ([]byte, error) {
4545
if c.Certificate == nil {
4646
return []byte("null"), nil
@@ -50,7 +50,7 @@ func (c SSHCertificate) MarshalJSON() ([]byte, error) {
5050
}
5151

5252
// UnmarshalJSON implements the json.Unmarshaler interface. The certificate is
53-
// expected to be a quoted string using the PEM encoding.
53+
// expected to be a quoted, base64 encoded, openssh wire formatted block of bytes.
5454
func (c *SSHCertificate) UnmarshalJSON(data []byte) error {
5555
var s string
5656
if err := json.Unmarshal(data, &s); err != nil {
@@ -62,15 +62,15 @@ func (c *SSHCertificate) UnmarshalJSON(data []byte) error {
6262
}
6363
certData, err := base64.StdEncoding.DecodeString(s)
6464
if err != nil {
65-
return errors.Wrap(err, "error decoding certificate")
65+
return errors.Wrap(err, "error decoding ssh certificate")
6666
}
6767
pub, err := ssh.ParsePublicKey(certData)
6868
if err != nil {
69-
return errors.Wrap(err, "error decoding certificate")
69+
return errors.Wrap(err, "error parsing ssh certificate")
7070
}
7171
cert, ok := pub.(*ssh.Certificate)
7272
if !ok {
73-
return errors.Errorf("error decoding certificate: %T is not an *ssh.Certificate", pub)
73+
return errors.Errorf("error decoding ssh certificate: %T is not an *ssh.Certificate", pub)
7474
}
7575
c.Certificate = cert
7676
return nil

api/ssh_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ func Test_caHandler_SignSSH(t *testing.T) {
295295
authorizeSign: func(ott string) ([]provisioner.SignOption, error) {
296296
return []provisioner.SignOption{}, tt.authErr
297297
},
298-
singSSH: func(key ssh.PublicKey, opts provisioner.SSHOptions, signOpts ...provisioner.SignOption) (*ssh.Certificate, error) {
298+
signSSH: func(key ssh.PublicKey, opts provisioner.SSHOptions, signOpts ...provisioner.SignOption) (*ssh.Certificate, error) {
299299
return tt.signCert, tt.signErr
300300
},
301-
singSSHAddUser: func(key ssh.PublicKey, cert *ssh.Certificate) (*ssh.Certificate, error) {
301+
signSSHAddUser: func(key ssh.PublicKey, cert *ssh.Certificate) (*ssh.Certificate, error) {
302302
return tt.addUserCert, tt.addUserErr
303303
},
304304
}).(*caHandler)

authority/authorize.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (a *Authority) Authorize(ctx context.Context, ott string) ([]provisioner.Si
9393
}
9494

9595
// authorizeSign loads the provisioner from the token, checks that it has not
96-
// been used again and calls the provisioner AuthorizeSign method. returns a
96+
// been used again and calls the provisioner AuthorizeSign method. Returns a
9797
// list of methods to apply to the signing flow.
9898
func (a *Authority) authorizeSign(ctx context.Context, ott string) ([]provisioner.SignOption, error) {
9999
var errContext = apiCtx{"ott": ott}
@@ -110,6 +110,9 @@ func (a *Authority) authorizeSign(ctx context.Context, ott string) ([]provisione
110110

111111
// AuthorizeSign authorizes a signature request by validating and authenticating
112112
// a OTT that must be sent w/ the request.
113+
//
114+
// NOTE: This method is deprecated and should not be used. We make it available
115+
// in the short term os as not to break existing clients.
113116
func (a *Authority) AuthorizeSign(ott string) ([]provisioner.SignOption, error) {
114117
ctx := provisioner.NewContextWithMethod(context.Background(), provisioner.SignMethod)
115118
return a.Authorize(ctx, ott)

authority/provisioner/sign_ssh_options.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type SSHCertificateOptionModifier interface {
3232
// SSHCertificateValidator is the interface used to validate an SSH certificate.
3333
type SSHCertificateValidator interface {
3434
SignOption
35-
Valid(crt *ssh.Certificate) error
35+
Valid(cert *ssh.Certificate) error
3636
}
3737

3838
// SSHCertificateOptionsValidator is the interface used to validate the custom
@@ -169,7 +169,7 @@ type sshDefaultExtensionModifier struct{}
169169

170170
func (m *sshDefaultExtensionModifier) Modify(cert *ssh.Certificate) error {
171171
switch cert.CertType {
172-
// Default to no extensions to HostCert
172+
// Default to no extensions for HostCert.
173173
case ssh.HostCert:
174174
return nil
175175
case ssh.UserCert:
@@ -246,29 +246,29 @@ func (v sshCertificateOptionsValidator) Valid(got SSHOptions) error {
246246
type sshCertificateDefaultValidator struct{}
247247

248248
// Valid returns an error if the given certificate does not contain the necessary fields.
249-
func (v *sshCertificateDefaultValidator) Valid(crt *ssh.Certificate) error {
249+
func (v *sshCertificateDefaultValidator) Valid(cert *ssh.Certificate) error {
250250
switch {
251-
case len(crt.Nonce) == 0:
251+
case len(cert.Nonce) == 0:
252252
return errors.New("ssh certificate nonce cannot be empty")
253-
case crt.Key == nil:
253+
case cert.Key == nil:
254254
return errors.New("ssh certificate key cannot be nil")
255-
case crt.Serial == 0:
255+
case cert.Serial == 0:
256256
return errors.New("ssh certificate serial cannot be 0")
257-
case crt.CertType != ssh.UserCert && crt.CertType != ssh.HostCert:
258-
return errors.Errorf("ssh certificate has an unknown type: %d", crt.CertType)
259-
case crt.KeyId == "":
257+
case cert.CertType != ssh.UserCert && cert.CertType != ssh.HostCert:
258+
return errors.Errorf("ssh certificate has an unknown type: %d", cert.CertType)
259+
case cert.KeyId == "":
260260
return errors.New("ssh certificate key id cannot be empty")
261-
case len(crt.ValidPrincipals) == 0:
261+
case len(cert.ValidPrincipals) == 0:
262262
return errors.New("ssh certificate valid principals cannot be empty")
263-
case crt.ValidAfter == 0:
263+
case cert.ValidAfter == 0:
264264
return errors.New("ssh certificate valid after cannot be 0")
265-
case crt.ValidBefore == 0:
265+
case cert.ValidBefore == 0:
266266
return errors.New("ssh certificate valid before cannot be 0")
267-
case crt.CertType == ssh.UserCert && len(crt.Extensions) == 0:
267+
case cert.CertType == ssh.UserCert && len(cert.Extensions) == 0:
268268
return errors.New("ssh certificate extensions cannot be empty")
269-
case crt.SignatureKey == nil:
269+
case cert.SignatureKey == nil:
270270
return errors.New("ssh certificate signature key cannot be nil")
271-
case crt.Signature == nil:
271+
case cert.Signature == nil:
272272
return errors.New("ssh certificate signature cannot be nil")
273273
default:
274274
return nil

authority/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (a *Authority) SignSSH(key ssh.PublicKey, opts provisioner.SSHOptions, sign
150150
func (a *Authority) SignSSHAddUser(key ssh.PublicKey, subject *ssh.Certificate) (*ssh.Certificate, error) {
151151
if a.sshCAUserCertSignKey == nil {
152152
return nil, &apiError{
153-
err: errors.New("signSSHProxy: user certificate signing is not enabled"),
153+
err: errors.New("signSSHAddUser: user certificate signing is not enabled"),
154154
code: http.StatusNotImplemented,
155155
}
156156
}

0 commit comments

Comments
 (0)