Fix lint warnings.

This commit is contained in:
Mariano Cano 2019-03-11 18:47:57 -07:00
parent 1f5ff5c899
commit 7fd737cbb1
4 changed files with 42 additions and 36 deletions

View file

@ -74,6 +74,7 @@ func TestCollection_LoadByToken(t *testing.T) {
assert.FatalError(t, err) assert.FatalError(t, err)
jwk, err = decryptJSONWebKey(p2.EncryptedKey) jwk, err = decryptJSONWebKey(p2.EncryptedKey)
assert.FatalError(t, err)
token, err = generateSimpleToken(p2.Name, testAudiences[1], jwk) token, err = generateSimpleToken(p2.Name, testAudiences[1], jwk)
assert.FatalError(t, err) assert.FatalError(t, err)
t2, c2, err := parseToken(token) t2, c2, err := parseToken(token)

View file

@ -226,3 +226,8 @@ func createProvisionerExtension(typ int, name, credentialID string) (pkix.Extens
Value: b, Value: b,
}, nil }, nil
} }
func init() {
// Avoid deadcode warning in profileWithOption
_ = profileWithOption(nil)
}

View file

@ -3,7 +3,6 @@ package authority
import ( import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"crypto/x509/pkix"
"encoding/asn1" "encoding/asn1"
"encoding/pem" "encoding/pem"
"net/http" "net/http"
@ -23,41 +22,7 @@ func (a *Authority) GetTLSOptions() *tlsutil.TLSOptions {
return a.config.TLS return a.config.TLS
} }
var ( var oidAuthorityKeyIdentifier = asn1.ObjectIdentifier{2, 5, 29, 35}
stepOIDRoot = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 37476, 9000, 64}
stepOIDProvisioner = append(asn1.ObjectIdentifier(nil), append(stepOIDRoot, 1)...)
oidAuthorityKeyIdentifier = asn1.ObjectIdentifier{2, 5, 29, 35}
)
type stepProvisionerASN1 struct {
Type int
Name []byte
CredentialID []byte
}
const provisionerTypeJWK = 1
func withProvisionerOID(name, kid string) x509util.WithOption {
return func(p x509util.Profile) error {
crt := p.Subject()
b, err := asn1.Marshal(stepProvisionerASN1{
Type: provisionerTypeJWK,
Name: []byte(name),
CredentialID: []byte(kid),
})
if err != nil {
return err
}
crt.ExtraExtensions = append(crt.ExtraExtensions, pkix.Extension{
Id: stepOIDProvisioner,
Critical: false,
Value: b,
})
return nil
}
}
func withDefaultASN1DN(def *x509util.ASN1DN) x509util.WithOption { func withDefaultASN1DN(def *x509util.ASN1DN) x509util.WithOption {
return func(p x509util.Profile) error { return func(p x509util.Profile) error {

View file

@ -22,6 +22,41 @@ import (
stepx509 "github.com/smallstep/cli/pkg/x509" stepx509 "github.com/smallstep/cli/pkg/x509"
) )
var (
stepOIDRoot = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 37476, 9000, 64}
stepOIDProvisioner = append(asn1.ObjectIdentifier(nil), append(stepOIDRoot, 1)...)
)
const provisionerTypeJWK = 1
type stepProvisionerASN1 struct {
Type int
Name []byte
CredentialID []byte
}
func withProvisionerOID(name, kid string) x509util.WithOption {
return func(p x509util.Profile) error {
crt := p.Subject()
b, err := asn1.Marshal(stepProvisionerASN1{
Type: provisionerTypeJWK,
Name: []byte(name),
CredentialID: []byte(kid),
})
if err != nil {
return err
}
crt.ExtraExtensions = append(crt.ExtraExtensions, pkix.Extension{
Id: stepOIDProvisioner,
Critical: false,
Value: b,
})
return nil
}
}
func getCSR(t *testing.T, priv interface{}, opts ...func(*x509.CertificateRequest)) *x509.CertificateRequest { func getCSR(t *testing.T, priv interface{}, opts ...func(*x509.CertificateRequest)) *x509.CertificateRequest {
_csr := &x509.CertificateRequest{ _csr := &x509.CertificateRequest{
Subject: pkix.Name{CommonName: "smallstep test"}, Subject: pkix.Name{CommonName: "smallstep test"},