Skip to content

Commit

Permalink
fix lint + remove unecessary pr check step
Browse files Browse the repository at this point in the history
Signed-off-by: Houssem Ben Mabrouk <[email protected]>
  • Loading branch information
orange-hbenmabrouk committed Oct 29, 2024
1 parent 591a376 commit 3498e5b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,3 @@ jobs:
packages: write
id-token: write
security-events: write

dependency-review:
name: Dependency review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Dependency Review
uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4
14 changes: 5 additions & 9 deletions connector/cert/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

type Config struct {
// ClientCAPath is the path of the CA certificate used to validate client certificates
ClientCAPath string `json:"clientCAPath"`
ClientCAPath string `json:"clientCAPath"`
// CertHeader is the name of the HTTP header containing the client certificate (if using a proxy)
CertHeader string `json:"certHeader"`
CertHeader string `json:"certHeader"`

UserIDKey string `json:"userIDKey"`
UserNameKey string `json:"userNameKey"`
Expand All @@ -35,10 +35,6 @@ type CertConnector struct {
logger *slog.Logger
}

var (
_ connector.CertificateConnector = (*CertConnector)(nil)
)

// loadCACert loads the CA certificate from the file
func loadCACert(caCertFile string) (*x509.CertPool, error) {
clientCA := x509.NewCertPool()
Expand Down Expand Up @@ -66,7 +62,7 @@ func (c *Config) Open(id string, logger *slog.Logger) (connector.Connector, erro
return nil, fmt.Errorf("failed to load CA certificate: %v", err)
}

return &CertConnector {
return &CertConnector{
clientCA: clientCA,
certHeader: c.CertHeader,
userIDKey: c.UserIDKey,
Expand Down Expand Up @@ -132,7 +128,7 @@ func (c *CertConnector) ValidateCertificate(cert *x509.Certificate) (identity co
if c.userIDKey != "" {
userID = getValueFromCertificate(cert, c.userIDKey)
} else {
defaultUserIDKey := "0.9.2342.19200300.100.1.1" // OID for UID
defaultUserIDKey := "0.9.2342.19200300.100.1.1" // OID for UID
userID = getValueFromCertificate(cert, defaultUserIDKey)
}
// safe guard
Expand Down Expand Up @@ -167,7 +163,7 @@ func (c *CertConnector) ValidateCertificate(cert *x509.Certificate) (identity co
if c.groupKey != "" {
groups = append(groups, getValueFromCertificate(cert, c.groupKey))
} else {
defaultGroupKey := "2.5.4.10" // OID for Organization
defaultGroupKey := "2.5.4.10" // OID for Organization
groups = append(groups, getValueFromCertificate(cert, defaultGroupKey))
}

Expand Down
28 changes: 14 additions & 14 deletions connector/cert/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func TestExtractValidateCertificate(t *testing.T) {
caPool.AddCert(caCert)

certConnector := &CertConnector{
clientCA: caPool,
clientCA: caPool,
certHeader: "X-Client-Cert",
logger: slog.New(slog.NewTextHandler(os.Stdout, nil)),
logger: slog.New(slog.NewTextHandler(os.Stdout, nil)),
}

// Test with valid certificate in TLS
Expand Down Expand Up @@ -118,16 +118,16 @@ func generateCACertificate() (*x509.Certificate, *rsa.PrivateKey, error) {
caTemplate := x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
Country: []string{"FR"},
Country: []string{"FR"},
Organization: []string{"Orange CA"},
CommonName: "Test CA",
CommonName: "Test CA",
},
NotBefore: time.Now(),
NotAfter: time.Now().Add(time.Hour * 24),
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
NotBefore: time.Now(),
NotAfter: time.Now().Add(time.Hour * 24),
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
IsCA: true,
IsCA: true,
}

caBytes, err := x509.CreateCertificate(rand.Reader, &caTemplate, &caTemplate, &caPrivKey.PublicKey, caPrivKey)
Expand All @@ -152,19 +152,19 @@ func generateClientCertificate(caCert *x509.Certificate, caPrivKey *rsa.PrivateK
clientTemplate := x509.Certificate{
SerialNumber: big.NewInt(2),
Subject: pkix.Name{
Country: []string{"FR"},
Country: []string{"FR"},
Organization: []string{"Orange"},
CommonName: "Test Client",
CommonName: "Test Client",
ExtraNames: []pkix.AttributeTypeAndValue{
{
Type: []int{0, 9, 2342, 19200300, 100, 1, 1}, // OID for UID
Value: "CUID2048",
},
},
},
NotBefore: time.Now(),
NotAfter: time.Now().Add(time.Hour * 24),
KeyUsage: x509.KeyUsageDigitalSignature,
NotBefore: time.Now(),
NotAfter: time.Now().Add(time.Hour * 24),
KeyUsage: x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
}

Expand Down

0 comments on commit 3498e5b

Please sign in to comment.