Files
teleport/lib/darwin/pub_key_test.go
T
Alan Parra d218fd2625 Implement macOS device enrollment methods (#19079)
Implement native macOS methods required by device enrollment, namely methods to
Create/Get the device key, Sign challenges with it, and to collect device data
(aka serial number).

The implementation is rather similar to lib/auth/touchid, but simpler in a few
aspects:

1. Device keys don't require user interaction (as in they don't cause a touch ID
   prompt); and
2. There exists, at most, a single device key at all times.

I've added a tiny refactor to reuse Apple public key parsing from touchid, plus
some changes so touchid doesn't break in the face of unexpected keys (which the
device key didn't cause, per se, but my experiments getting to it did).

gravitational/teleport.e#514
2022-12-07 18:11:21 +00:00

45 lines
1.3 KiB
Go

// Copyright 2022 Gravitational, Inc
//
// 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
//
// http://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.
package darwin_test
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gravitational/teleport/lib/darwin"
)
func TestECDSAPublicKeyFromRaw(t *testing.T) {
privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
require.NoError(t, err, "GenerateKey failed")
pubKey := privKey.PublicKey
// Marshal key into the raw Apple format.
rawAppleKey := make([]byte, 1+32+32)
rawAppleKey[0] = 0x04
pubKey.X.FillBytes(rawAppleKey[1:33])
pubKey.Y.FillBytes(rawAppleKey[33:])
got, err := darwin.ECDSAPublicKeyFromRaw(rawAppleKey)
require.NoError(t, err, "ECDSAPublicKeyFromRaw failed")
assert.Equal(t, pubKey, *got, "ECDSAPublicKeyFromRaw mismatch")
}