-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce darwin-specific client (#80)
Introduces a darwin-specific client under the package name "darwin" for accessing the keychain APIs directly, bypassing the RPC mechanism of the universal client. Usage: import "github.com/googleapis/enterprise-certificate-proxy/darwin"
- Loading branch information
Showing
6 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2023 Google LLC. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build darwin && cgo | ||
// +build darwin,cgo | ||
|
||
// Package darwin contains a darwin-specific client for accessing the keychain APIs directly, | ||
// bypassing the RPC mechanism of the universal client. | ||
package darwin | ||
|
||
import ( | ||
"crypto" | ||
"io" | ||
|
||
"github.com/googleapis/enterprise-certificate-proxy/internal/signer/darwin/keychain" | ||
) | ||
|
||
// SecureKey is a public wrapper for the internal keychain implementation. | ||
type SecureKey struct { | ||
key *keychain.Key | ||
} | ||
|
||
// CertificateChain returns the SecureKey's raw X509 cert chain. This contains the public key. | ||
func (sk *SecureKey) CertificateChain() [][]byte { | ||
return sk.key.CertificateChain() | ||
} | ||
|
||
// Public returns the public key for this SecureKey. | ||
func (sk *SecureKey) Public() crypto.PublicKey { | ||
return sk.key.Public() | ||
} | ||
|
||
// Sign signs a message digest, using the specified signer options. | ||
func (sk *SecureKey) Sign(_ io.Reader, digest []byte, opts crypto.SignerOpts) (signed []byte, err error) { | ||
return sk.key.Sign(nil, digest, opts) | ||
} | ||
|
||
// Close frees up resources associated with the underlying key. | ||
func (sk *SecureKey) Close() { | ||
sk.key.Close() | ||
} | ||
|
||
// NewSecureKey returns a handle to the first available certificate and private key pair in | ||
// the MacOS Keychain matching the issuer CN filter. This includes both the current login keychain | ||
// for the user as well as the system keychain. | ||
func NewSecureKey(issuerCN string) (*SecureKey, error) { | ||
k, err := keychain.Cred(issuerCN) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &SecureKey{key: k}, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters