Skip to content

Commit

Permalink
feat: Introduce windows-specific client (#83)
Browse files Browse the repository at this point in the history
Also consolidates 3 config utils into a single common util.
  • Loading branch information
andyrzhao committed Jun 16, 2023
1 parent ff40aa5 commit 5b63ef5
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 237 deletions.
2 changes: 1 addition & 1 deletion build/scripts/windows_amd64.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If (Test-Path $OutputFolder) {
# Build the signer binary
Set-Location .\internal\signer\windows
go build
Move-Item .\signer.exe ..\..\..\build\bin\windows_amd64\ecp.exe
Move-Item .\windows.exe ..\..\..\build\bin\windows_amd64\ecp.exe
Set-Location ..\..\..\

# Build the signer library
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ module github.com/googleapis/enterprise-certificate-proxy

go 1.19

require github.com/google/go-pkcs11 v0.2.0
require (
github.com/google/go-pkcs11 v0.2.0
golang.org/x/crypto v0.10.0
golang.org/x/sys v0.9.0
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
github.com/google/go-pkcs11 v0.2.0 h1:5meDPB26aJ98f+K9G21f0AqZwo/S5BJMJh8nuhMbdsI=
github.com/google/go-pkcs11 v0.2.0/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY=
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2 changes: 1 addition & 1 deletion internal/signer/darwin/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"time"

"github.com/googleapis/enterprise-certificate-proxy/internal/signer/darwin/keychain"
"github.com/googleapis/enterprise-certificate-proxy/internal/signer/darwin/util"
"github.com/googleapis/enterprise-certificate-proxy/internal/signer/util"
)

// If ECP Logging is enabled return true
Expand Down
8 changes: 0 additions & 8 deletions internal/signer/darwin/util/test_data/certificate_config.json

This file was deleted.

55 changes: 0 additions & 55 deletions internal/signer/darwin/util/util.go

This file was deleted.

29 changes: 0 additions & 29 deletions internal/signer/darwin/util/util_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/signer/linux/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"time"

"github.com/googleapis/enterprise-certificate-proxy/internal/signer/linux/pkcs11"
"github.com/googleapis/enterprise-certificate-proxy/internal/signer/linux/util"
"github.com/googleapis/enterprise-certificate-proxy/internal/signer/util"
)

// If ECP Logging is enabled return true
Expand Down
10 changes: 0 additions & 10 deletions internal/signer/linux/util/test_data/certificate_config.json

This file was deleted.

19 changes: 19 additions & 0 deletions internal/signer/util/test_data/certificate_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"cert_configs": {
"macos_keychain": {
"issuer": "Google Endpoint Verification"
},
"windows_store": {
"issuer": "enterprise_v1_corp_client",
"store": "MY",
"provider": "current_user"
},
"pkcs11": {
"slot": "0x1739427",
"label": "gecc",
"user_pin": "0000",
"module": "pkcs11_module.so"
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,26 @@ type EnterpriseCertificateConfig struct {
CertConfigs CertConfigs `json:"cert_configs"`
}

// CertConfigs is a container for various ECP Configs.
// CertConfigs is a container for various OS-specific ECP Configs.
type CertConfigs struct {
PKCS11 PKCS11 `json:"pkcs11"`
MacOSKeychain MacOSKeychain `json:"macos_keychain"`
WindowsStore WindowsStore `json:"windows_store"`
PKCS11 PKCS11 `json:"pkcs11"`
}

// PKCS11 contains parameters describing the certificate to use.
// MacOSKeychain contains keychain parameters describing the certificate to use.
type MacOSKeychain struct {
Issuer string `json:"issuer"`
}

// WindowsStore contains Windows key store parameters describing the certificate to use.
type WindowsStore struct {
Issuer string `json:"issuer"`
Store string `json:"store"`
Provider string `json:"provider"`
}

// PKCS11 contains PKCS#11 parameters describing the certificate to use.
type PKCS11 struct {
Slot string `json:"slot"` // The hexadecimal representation of the uint36 slot ID. (ex:0x1739427)
Label string `json:"label"` // The token label (ex: gecc)
Expand All @@ -54,5 +68,4 @@ func LoadConfig(configFilePath string) (config EnterpriseCertificateConfig, err
return EnterpriseCertificateConfig{}, err
}
return config, nil

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,31 @@ import (

func TestLoadConfig(t *testing.T) {
config, err := LoadConfig("./test_data/certificate_config.json")
// darwin
if err != nil {
t.Fatalf("LoadConfig error: %v", err)
t.Fatalf("LoadConfig error: %q", err)
}
want := "0x1739427"
want := "Google Endpoint Verification"
if config.CertConfigs.MacOSKeychain.Issuer != want {
t.Errorf("Expected issuer is %q, got: %q", want, config.CertConfigs.MacOSKeychain.Issuer)
}

// windows
want = "enterprise_v1_corp_client"
if config.CertConfigs.WindowsStore.Issuer != want {
t.Errorf("Expected issuer is %q, got: %q", want, config.CertConfigs.WindowsStore.Issuer)
}
want = "MY"
if config.CertConfigs.WindowsStore.Store != want {
t.Errorf("Expected store is %q, got: %q", want, config.CertConfigs.WindowsStore.Store)
}
want = "current_user"
if config.CertConfigs.WindowsStore.Provider != want {
t.Errorf("Expected provider is %q, got: %q", want, config.CertConfigs.WindowsStore.Provider)
}

// pkcs11
want = "0x1739427"
if config.CertConfigs.PKCS11.Slot != want {
t.Errorf("Expected slot is %v, got: %v", want, config.CertConfigs.PKCS11.Slot)
}
Expand Down
8 changes: 0 additions & 8 deletions internal/signer/windows/go.mod

This file was deleted.

11 changes: 0 additions & 11 deletions internal/signer/windows/go.sum

This file was deleted.

5 changes: 3 additions & 2 deletions internal/signer/windows/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (
"log"
"net/rpc"
"os"
"signer/ncrypt"
"signer/util"

"github.com/googleapis/enterprise-certificate-proxy/internal/signer/util"
"github.com/googleapis/enterprise-certificate-proxy/internal/signer/windows/ncrypt"
)

// If ECP Logging is enabled return true
Expand Down

This file was deleted.

57 changes: 0 additions & 57 deletions internal/signer/windows/util/util.go

This file was deleted.

37 changes: 0 additions & 37 deletions internal/signer/windows/util/util_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion linux/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// limitations under the License.

// Package linux contains a linux-specific client for accessing the PKCS#11 APIs directly,
// bypassing the RPC-mechanims of the universal client.
// bypassing the RPC-mechanism of the universal client.
package linux

import (
Expand Down

0 comments on commit 5b63ef5

Please sign in to comment.