mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Switch to sqscreds param for passing in SQS credentials
This commit is contained in:
parent
fe56eaddf4
commit
9fe2ca58a0
7 changed files with 89 additions and 18 deletions
36
common/sqscreds/generate_creds.go
Normal file
36
common/sqscreds/generate_creds.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sqscreds "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/sqscreds/lib"
|
||||
)
|
||||
|
||||
// This script can be run to generate the encoded SQS credentials to pass as a CLI param or SOCKS option to the client
|
||||
func main() {
|
||||
var accessKey, secretKey string
|
||||
|
||||
fmt.Print("Enter Access Key: ")
|
||||
_, err := fmt.Scanln(&accessKey)
|
||||
if err != nil {
|
||||
fmt.Println("Error reading access key:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Print("Enter Secret Key: ")
|
||||
_, err = fmt.Scanln(&secretKey)
|
||||
if err != nil {
|
||||
fmt.Println("Error reading access key:", err)
|
||||
return
|
||||
}
|
||||
|
||||
awsCreds := sqscreds.AwsCreds{AwsAccessKeyId: accessKey, AwsSecretKey: secretKey}
|
||||
println()
|
||||
println("Encoded Credentials:")
|
||||
res, err := awsCreds.Base64()
|
||||
if err != nil {
|
||||
fmt.Println("Error encoding credentials:", err)
|
||||
return
|
||||
}
|
||||
println(res)
|
||||
}
|
35
common/sqscreds/lib/sqs_creds.go
Normal file
35
common/sqscreds/lib/sqs_creds.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package sqscreds
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type AwsCreds struct {
|
||||
AwsAccessKeyId string `json:"aws-access-key-id"`
|
||||
AwsSecretKey string `json:"aws-secret-key"`
|
||||
}
|
||||
|
||||
func (awsCreds AwsCreds) Base64() (string, error) {
|
||||
jsonData, err := json.Marshal(awsCreds)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString(jsonData), nil
|
||||
}
|
||||
|
||||
func AwsCredsFromBase64(base64Str string) (AwsCreds, error) {
|
||||
var awsCreds AwsCreds
|
||||
|
||||
jsonData, err := base64.StdEncoding.DecodeString(base64Str)
|
||||
if err != nil {
|
||||
return awsCreds, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(jsonData, &awsCreds)
|
||||
if err != nil {
|
||||
return awsCreds, err
|
||||
}
|
||||
|
||||
return awsCreds, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue