Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Gate ECP logs behind ENABLE_ENTERPRISE_CERTIFICATE_LOGS environment variable. #57

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ ECP relies on the `certificate_config.json` file to read all the metadata inform
}
```

### Logging

To enable logging set the "ENABLE_ENTERPRISE_CERTIFICATE_LOGS" environment
variable.

#### Example

```
export ENABLE_ENTERPRISE_CERTIFICATE_LOGS=1 # Now the
enterprise-certificate-proxy will output logs to stdout.
```

## Build binaries

For amd64 MacOS, run `./build/scripts/darwin_amd64.sh`. The binaries will be placed in `build/bin/darwin_amd64` folder.
Expand Down
14 changes: 14 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"encoding/gob"
"fmt"
"io"
"io/ioutil"
"log"
"net/rpc"
"os"
"os/exec"
Expand Down Expand Up @@ -42,6 +44,17 @@ func (c *Connection) Close() error {
return werr
}

// If ECP Logging is enabled return true
// Otherwise return false
func enableECPLogging() bool {
if os.Getenv("ENABLE_ENTERPRISE_CERTIFICATE_LOGS") != "" {
return true
}

log.SetOutput(ioutil.Discard)
return false
}

func init() {
gob.Register(crypto.SHA256)
gob.Register(&rsa.PSSOptions{})
Expand Down Expand Up @@ -105,6 +118,7 @@ func (k *Key) Sign(_ io.Reader, digest []byte, opts crypto.SignerOpts) (signed [
//
// The config file also specifies which certificate the signer should use.
func Cred(configFilePath string) (*Key, error) {
enableECPLogging()
if configFilePath == "" {
configFilePath = util.GetDefaultConfigFilePath()
}
Expand Down
15 changes: 15 additions & 0 deletions cshared/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,25 @@ import (
"crypto/ecdsa"
"crypto/rsa"
"encoding/pem"
"io/ioutil"
"log"
"os"
"unsafe"

"github.com/googleapis/enterprise-certificate-proxy/client"
)

// If ECP Logging is enabled return true
// Otherwise return false
func enableECPLogging() bool {
if os.Getenv("ENABLE_ENTERPRISE_CERTIFICATE_LOGS") != "" {
return true
}

log.SetOutput(ioutil.Discard)
return false
}

func getCertPem(configFilePath string) []byte {
key, err := client.Cred(configFilePath)
if err != nil {
Expand Down Expand Up @@ -54,6 +67,7 @@ func getCertPem(configFilePath string) []byte {
//
//export GetCertPemForPython
func GetCertPemForPython(configFilePath *C.char, certHolder *byte, certHolderLen int) int {
enableECPLogging()
pemBytes := getCertPem(C.GoString(configFilePath))
if certHolder != nil {
cert := unsafe.Slice(certHolder, certHolderLen)
Expand All @@ -68,6 +82,7 @@ func GetCertPemForPython(configFilePath *C.char, certHolder *byte, certHolderLen
//export SignForPython
func SignForPython(configFilePath *C.char, digest *byte, digestLen int, sigHolder *byte, sigHolderLen int) int {
// First create a handle around the specified certificate and private key.
enableECPLogging()
key, err := client.Cred(C.GoString(configFilePath))
if err != nil {
log.Printf("Could not create client using config %s: %v", C.GoString(configFilePath), err)
Expand Down
13 changes: 13 additions & 0 deletions internal/signer/darwin/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"crypto/x509"
"encoding/gob"
"io"
"io/ioutil"
"log"
"net/rpc"
"os"
Expand All @@ -22,6 +23,17 @@ import (
"time"
)

// If ECP Logging is enabled return true
// Otherwise return false
func enableECPLogging() bool {
if os.Getenv("ENABLE_ENTERPRISE_CERTIFICATE_LOGS") != "" {
return true
}

log.SetOutput(ioutil.Discard)
return false
}

func init() {
gob.Register(crypto.SHA256)
gob.Register(crypto.SHA384)
Expand Down Expand Up @@ -76,6 +88,7 @@ func (k *EnterpriseCertSigner) Sign(args SignArgs, resp *[]byte) (err error) {
}

func main() {
enableECPLogging()
if len(os.Args) != 2 {
log.Fatalln("Signer is not meant to be invoked manually, exiting...")
}
Expand Down
13 changes: 13 additions & 0 deletions internal/signer/linux/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@ import (
"crypto/x509"
"encoding/gob"
"io"
"io/ioutil"
"log"
"net/rpc"
"os"
"signer/util"
"time"
)

// If ECP Logging is enabled return true
// Otherwise return false
func enableECPLogging() bool {
if os.Getenv("ENABLE_ENTERPRISE_CERTIFICATE_LOGS") != "" {
return true
}

log.SetOutput(ioutil.Discard)
return false
}

func init() {
gob.Register(crypto.SHA256)
gob.Register(crypto.SHA384)
Expand Down Expand Up @@ -76,6 +88,7 @@ func (k *EnterpriseCertSigner) Sign(args SignArgs, resp *[]byte) (err error) {
}

func main() {
enableECPLogging()
if len(os.Args) != 2 {
log.Fatalln("Signer is not meant to be invoked manually, exiting...")
}
Expand Down
13 changes: 13 additions & 0 deletions internal/signer/windows/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"crypto/x509"
"encoding/gob"
"io"
"io/ioutil"
"log"
"net/rpc"
"os"
Expand All @@ -22,6 +23,17 @@ import (
"time"
)

// If ECP Logging is enabled return true
// Otherwise return false
func enableECPLogging() bool {
if os.Getenv("ENABLE_ENTERPRISE_CERTIFICATE_LOGS") != "" {
return true
}

log.SetOutput(ioutil.Discard)
return false
}

func init() {
gob.Register(crypto.SHA256)
gob.Register(crypto.SHA384)
Expand Down Expand Up @@ -76,6 +88,7 @@ func (k *EnterpriseCertSigner) Sign(args SignArgs, resp *[]byte) (err error) {
}

func main() {
enableECPLogging()
if len(os.Args) != 2 {
log.Fatalln("Signer is not meant to be invoked manually, exiting...")
}
Expand Down