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

secure enclave keys init follow up #1647

Closed
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
2 changes: 2 additions & 0 deletions ee/secureenclavesigner/secureenclavesigner_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func New(ctx context.Context, slogger *slog.Logger, store types.GetterSetterDele
opt(ses)
}

// this is here to facilitate testing, since go builds a special test binary,
// if we look for os.Executable in a test and try to exec it, it will error
if ses.pathToLauncherBinary == "" {
p, err := os.Executable()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions ee/secureenclavesigner/secureenclavesigner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func TestSecureEnclaveSigner(t *testing.T) {

// put the root dir somewhere else if you want to persist the signed macos app bundle
// should build this into make at some point
rootDir := "/tmp/secure_enclave_test"
// rootDir := "/tmp/secure_enclave_test"

// rootDir := t.TempDir()
rootDir := t.TempDir()
appRoot := filepath.Join(rootDir, "launcher_test.app")

// make required dirs krypto_test.app/Contents/MacOS and add files
Expand Down
2 changes: 1 addition & 1 deletion ee/secureenclavesigner/test_app_resources/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>CFBundleExecutable</key>
<string>launcher_test</string>
<key>CFBundleIdentifier</key>
<string>com.kolide.agent</string>
<string>com.launcher.test</string>
<key>CFBundleName</key>
<string>launcher_test</string>
<key>LSUIElement</key>
Expand Down
31 changes: 26 additions & 5 deletions pkg/osquery/table/launcher_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,37 @@ func generateLauncherInfoTable(store types.GetterSetter) table.GenerateFunc {
if err != nil {
return nil, fmt.Errorf("marshalling hardware keys: %w", err)
}
results[0]["hardware_key"] = string(jsonBytes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to drop this, but we'll need to update k2 to stop querying it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully grok what needs to happen server side. We could just leave the name as hardware_key, but it feels weird since it will now be a json array. I reached out on slack

results[0]["hardware_key_source"] = agent.HardwareKeys().Type()

// for darwin we'll have an array of uid / key pairs looking this
// [{"uid":"501","pub_key":"PUB_KEY_B64_DER"}, {"uid":"502","pub_key":"PUB_KEY_B64_DER"}]
results[0]["hardware_keys"] = string(jsonBytes)
results[0]["hardware_keys_source"] = agent.HardwareKeys().Type()

return results, nil
}

if hardwareKeyDer, err := x509.MarshalPKIXPublicKey(agent.HardwareKeys().Public()); err == nil {
// der is a binary format, so convert to b64
results[0]["hardware_key"] = base64.StdEncoding.EncodeToString(hardwareKeyDer)
results[0]["hardware_key_source"] = agent.HardwareKeys().Type()
// for windows and linux we just have a single key, but we want data to be in a consistent format, so update it to look like
// the darwin format
keys := []struct {
Uid string `json:"uid"`
PubKey string `json:"pub_key"`
}{
{
// the uid is irrelevant for windows and linux, so just use -1
// since hardware keys are not tied to user
Uid: "-1",
PubKey: base64.StdEncoding.EncodeToString(hardwareKeyDer),
},
}

jsonBytes, err := json.Marshal(keys)
if err != nil {
return nil, fmt.Errorf("marshalling hardware keys: %w", err)
}

results[0]["hardware_keys"] = string(jsonBytes)
results[0]["hardware_keys_source"] = agent.HardwareKeys().Type()
}

return results, nil
Expand Down
Loading