-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): added support of the TLS certificates along with x-token …
…authorisation token for the gRPC connection (#3954)
- Loading branch information
Showing
5 changed files
with
163 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package core | ||
|
||
import ( | ||
"crypto/tls" | ||
"encoding/json" | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/celestiaorg/celestia-node/libs/utils" | ||
) | ||
|
||
const xtokenFileName = "xtoken.json" | ||
|
||
func EmptyTLSConfig() *tls.Config { | ||
return &tls.Config{MinVersion: tls.VersionTLS12} | ||
} | ||
|
||
// XToken retrieves the authentication token from a JSON file at the specified path. | ||
func XToken(xtokenPath string) (string, error) { | ||
xtokenPath = filepath.Join(xtokenPath, xtokenFileName) | ||
exist := utils.Exists(xtokenPath) | ||
if !exist { | ||
return "", os.ErrNotExist | ||
} | ||
|
||
token, err := os.ReadFile(xtokenPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
auth := struct { | ||
Token string `json:"x-token"` | ||
}{} | ||
|
||
err = json.Unmarshal(token, &auth) | ||
if err != nil { | ||
return "", err | ||
} | ||
if auth.Token == "" { | ||
return "", errors.New("x-token is empty. Please setup a token or cleanup xtokenPath") | ||
} | ||
return auth.Token, nil | ||
} |
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