-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#200: Provide endpoint with info for sda-cli login
- Loading branch information
Showing
10 changed files
with
119 additions
and
5 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
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,75 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/kataras/iris/v12" | ||
"github.com/neicnordic/crypt4gh/keys" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type Info struct { | ||
ClientID string `json:"client_id"` | ||
OidcURI string `json:"oidc_uri"` | ||
PublicKey string `json:"public_key"` | ||
InboxURI string `json:"inbox_uri"` | ||
} | ||
|
||
func readPublicKeyFile(filename string) (key *[32]byte, err error) { | ||
log.Info("Reading Public key file") | ||
file, err := os.Open(filepath.Clean(filename)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
publicKey, err := readPublicKey(file) | ||
if err != nil { | ||
return nil, fmt.Errorf("error while reading public key file %s: %v", filename, err) | ||
} | ||
|
||
return &publicKey, err | ||
} | ||
|
||
// Wrapper for the respective crypt4gh function. Since this function panics if the key is | ||
// malformed, so we handle that as well as errors. | ||
func readPublicKey(reader io.Reader) (key [32]byte, err error) { | ||
|
||
defer func() { | ||
if recover() != nil { | ||
err = fmt.Errorf("malformed key file") | ||
} | ||
}() | ||
|
||
publicKey, err := keys.ReadPublicKey(reader) | ||
|
||
return publicKey, err | ||
} | ||
|
||
func (auth AuthHandler) getInfo(ctx iris.Context) { | ||
|
||
// Read the c4gh pub key from file. This is the same across | ||
// different deployments and set in the config | ||
// | ||
publicKey, err := readPublicKeyFile(auth.Config.C4ghPubKey) | ||
pub := hex.EncodeToString(publicKey[:]) | ||
if err != nil { | ||
log.Error("Failure to get public key: ", err) | ||
} | ||
|
||
// TODO: remove. hardcoding for testing | ||
auth.OAuth2Config.ClientID = "8b7b0168-6b16-4fd2-baec-b0a28b0d5cb0" | ||
auth.Config.JwtIssuer = "https://login.elixir-czech.org/oidc/" | ||
auth.Config.S3Inbox = "https://login.elixir-czech.org/oidc" | ||
|
||
info := Info{ClientID: auth.OAuth2Config.ClientID, OidcURI: auth.Config.JwtIssuer, PublicKey: pub, InboxURI: auth.Config.S3Inbox} | ||
err = ctx.JSON(info) | ||
if err != nil { | ||
log.Error("Failure to get Info ", err) | ||
|
||
return | ||
} | ||
} |
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,3 @@ | ||
-----BEGIN CRYPT4GH PUBLIC KEY----- | ||
J75CRF/Z45yb455rNqVeYeOAH8hF9jeBqBPT/pl34Xo= | ||
-----END CRYPT4GH PUBLIC KEY----- |
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,5 @@ | ||
-----BEGIN CRYPT4GH ENCRYPTED PRIVATE KEY----- | ||
YzRnaC12MQAGc2NyeXB0ABQAAAAAq5Zoea6wEWm2lT5gad3aZQARY2hhY2hhMjBf | ||
cG9seTEzMDUAPBfY7N9POe/m4L+x1Z1QYEhv7x3HOU47G+wqRFVXq2WBHfrrQNHp | ||
1YIpd3rGNnXI8O5WoB+qZ8ynAIn2tA== | ||
-----END CRYPT4GH ENCRYPTED PRIVATE KEY----- |
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