-
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
7 changed files
with
97 additions
and
3 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,69 @@ | ||
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(err.Error()+": %s", filename) | ||
} | ||
|
||
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) { | ||
|
||
// TODO: figure out how we know which key is in deployment. | ||
// It could be BP, FEGA or GDI pub key that we need to provide. | ||
publicKey, err := readPublicKeyFile("/keys/crypt4gh_sda_key.pub.pem") | ||
pub := hex.EncodeToString(publicKey[:]) | ||
if err != nil { | ||
log.Error("Failure to get public key ", err) | ||
} | ||
|
||
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----- | ||
Ma1S5JUotetl9WFIShmNgpHL40ddn6BlDzPWlMh+Zn4= | ||
-----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,3 @@ | ||
-----BEGIN CRYPT4GH PUBLIC KEY----- | ||
vP8hUVPM+S/+YXGMGdlLqalFD58iaco/zqgsZ2J85W0= | ||
-----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,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