-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename getAttributes to getMap * Fix getMap * Add Authenticator to Beholder * Use Authenticator in Beholder * Add Authenticator to Beholder global * Use Authenticator Headers in LOOP * Add authenticator to HTTP client * Fix config test * Add pub key getter to authenticator * Set CSA pub key on Otel resource * Add noop value to authenticator * Move auth tests to beholder package, unexport new auth * Simplify auth header approach * Remove duplicate test * Use ed25519 keys instead of signer * Remove pub key from args --------- Co-authored-by: nanchano <nicolas.anchano@smartcontract.com> Co-authored-by: Pavel <177363085+pkcll@users.noreply.github.com> Co-authored-by: Geert G <117188496+cll-gg@users.noreply.github.com>
- Loading branch information
1 parent
4ae4553
commit 914b88b
Showing
9 changed files
with
93 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package beholder | ||
|
||
import ( | ||
"crypto/ed25519" | ||
"fmt" | ||
) | ||
|
||
// authHeaderKey is the name of the header that the node authenticator will use to send the auth token | ||
var authHeaderKey = "X-Beholder-Node-Auth-Token" | ||
|
||
// authHeaderVersion is the version of the auth header format | ||
var authHeaderVersion = "1" | ||
|
||
// BuildAuthHeaders creates the auth header value to be included on requests. | ||
// The current format for the header is: | ||
// | ||
// <version>:<public_key_hex>:<signature_hex> | ||
// | ||
// where the byte value of <public_key_hex> is what's being signed | ||
func BuildAuthHeaders(privKey ed25519.PrivateKey) map[string]string { | ||
pubKey := privKey.Public().(ed25519.PublicKey) | ||
messageBytes := pubKey | ||
signature := ed25519.Sign(privKey, messageBytes) | ||
headerValue := fmt.Sprintf("%s:%x:%x", authHeaderVersion, messageBytes, signature) | ||
|
||
return map[string]string{authHeaderKey: headerValue} | ||
} |
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,22 @@ | ||
package beholder | ||
|
||
import ( | ||
"crypto/ed25519" | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBuildAuthHeaders(t *testing.T) { | ||
csaPrivKeyHex := "1ac84741fa51c633845fa65c06f37a700303619135630a01f2d22fb98eb1c54ecab39509e63cfaa81c70e2c907391f96803aacb00db5619a5ace5588b4b08159" | ||
csaPrivKeyBytes, err := hex.DecodeString(csaPrivKeyHex) | ||
assert.NoError(t, err) | ||
csaPrivKey := ed25519.PrivateKey(csaPrivKeyBytes) | ||
|
||
expectedHeaders := map[string]string{ | ||
"X-Beholder-Node-Auth-Token": "1:cab39509e63cfaa81c70e2c907391f96803aacb00db5619a5ace5588b4b08159:4403178e299e9acc5b48ae97de617d3975c5d431b794cfab1d23eda01c194119b2360f5f74cfb3e4f706237ab57a0ba88ffd3f8addbc1e5197b3d3e13a1fc409", | ||
} | ||
|
||
assert.Equal(t, expectedHeaders, BuildAuthHeaders(csaPrivKey)) | ||
} |
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
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