-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from replicatedhq/laverya/sign-enterprise-req…
…uests sign enterprise requests, and use ecdsa keys instead
- Loading branch information
Showing
6 changed files
with
161 additions
and
58 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,53 @@ | ||
package enterpriseclient | ||
|
||
import ( | ||
"encoding/base64" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
func Test_sigAndFingerprint(t *testing.T) { | ||
req := require.New(t) | ||
|
||
var testData string // just needs to be of sufficient length | ||
for i := 0; i < 100; i++ { | ||
testData = testData + "abcdefghijklmnopqurstuvwxyz123456789" | ||
} | ||
|
||
// make a new private key | ||
privateKey, err := generatePrivateKey() | ||
req.NoError(err) | ||
|
||
// encode that private key to bytes | ||
privateKeyBytes := encodePrivateKeyToPEM(privateKey) | ||
// decode private key bytes | ||
privateKey, err = decodePrivateKeyPEM(privateKeyBytes) | ||
req.NoError(err) | ||
|
||
sig, fingerprint, err := sigAndFingerprint(privateKey, []byte(testData)) | ||
req.NoError(err) | ||
|
||
pubKey := encodePublicKey(&privateKey.PublicKey) | ||
|
||
// everything past this depends only on testData, sig, fingerprint, pubKey and req | ||
// NOT privateKey | ||
|
||
sigBytes, err := base64.StdEncoding.DecodeString(sig) | ||
req.NoError(err) | ||
|
||
parsedPubKey, err := ssh.ParsePublicKey(pubKey) | ||
req.NoError(err) | ||
|
||
req.True(strings.HasPrefix(parsedPubKey.Type(), "ecdsa-sha2-"), parsedPubKey.Type()) | ||
|
||
err = parsedPubKey.Verify([]byte(testData), &ssh.Signature{ | ||
Format: parsedPubKey.Type(), | ||
Blob: sigBytes, | ||
}) | ||
req.NoError(err) | ||
|
||
req.Equal(fingerprint, ssh.FingerprintSHA256(parsedPubKey)) | ||
} |
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,16 @@ | ||
package enterpriseclient | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewNilHTTPClient(t *testing.T) { | ||
req := require.New(t) | ||
client := NewHTTPClient("origin", nil) | ||
req.Equal(&HTTPClient{ | ||
privateKey: nil, | ||
apiOrigin: "origin", | ||
}, client) | ||
} |