refactor: hardcode secret key in crypto package
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ArlCookie string `mapstructure:"arl_cookie"`
|
ArlCookie string `mapstructure:"arl_cookie"`
|
||||||
SecretKey string `mapstructure:"secret_key"`
|
|
||||||
OutputDir string `mapstructure:"output_dir"`
|
OutputDir string `mapstructure:"output_dir"`
|
||||||
HomeDir string
|
HomeDir string
|
||||||
}
|
}
|
||||||
@@ -33,7 +32,7 @@ func New(cfgPath string) (*Config, error) {
|
|||||||
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
|
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
|
||||||
fmt.Printf("Config file not found, creating one at %s\n", cfgPath)
|
fmt.Printf("Config file not found, creating one at %s\n", cfgPath)
|
||||||
|
|
||||||
content := []byte("arl_cookie = ''\nsecret_key = ''\noutput_dir = ''\n")
|
content := []byte("arl_cookie = ''\noutput_dir = ''\n")
|
||||||
if err := os.WriteFile(cfgPath, content, 0644); err != nil {
|
if err := os.WriteFile(cfgPath, content, 0644); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create config file: %w", err)
|
return nil, fmt.Errorf("failed to create config file: %w", err)
|
||||||
}
|
}
|
||||||
@@ -68,12 +67,6 @@ func (c *Config) Validate() error {
|
|||||||
if c.ArlCookie == "" {
|
if c.ArlCookie == "" {
|
||||||
return fmt.Errorf("arl_cookie is not set")
|
return fmt.Errorf("arl_cookie is not set")
|
||||||
}
|
}
|
||||||
if c.SecretKey == "" {
|
|
||||||
return fmt.Errorf("secret_key is not set")
|
|
||||||
}
|
|
||||||
if len(c.SecretKey) != 16 {
|
|
||||||
return fmt.Errorf("secret_key must be 16 bytes long")
|
|
||||||
}
|
|
||||||
if c.OutputDir == "" {
|
if c.OutputDir == "" {
|
||||||
c.OutputDir = filepath.Join(c.HomeDir, "Music", "GoDeez")
|
c.OutputDir = filepath.Join(c.HomeDir, "Music", "GoDeez")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,17 @@ import (
|
|||||||
"golang.org/x/crypto/blowfish"
|
"golang.org/x/crypto/blowfish"
|
||||||
)
|
)
|
||||||
|
|
||||||
var iv = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}
|
var (
|
||||||
|
iv = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}
|
||||||
|
secretKey = []byte("g4el58wc0zvf9na1")
|
||||||
|
)
|
||||||
|
|
||||||
func GetKey(secretKey, songID string) []byte {
|
func GetKey(songID string) []byte {
|
||||||
hash := md5.Sum([]byte(songID))
|
hash := md5.Sum([]byte(songID))
|
||||||
hashHex := hex.EncodeToString(hash[:])
|
hashHex := hex.EncodeToString(hash[:])
|
||||||
|
|
||||||
key := []byte(secretKey)
|
key := make([]byte, len(secretKey))
|
||||||
|
copy(key, secretKey)
|
||||||
for i := 0; i < len(hash); i++ {
|
for i := 0; i < len(hash); i++ {
|
||||||
key[i] = key[i] ^ hashHex[i] ^ hashHex[i+16]
|
key[i] = key[i] ^ hashHex[i] ^ hashHex[i+16]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ func (c *Client) downloadSong(ctx context.Context, resource deezer.Resource, son
|
|||||||
fileName := song.GetFileName(c.resourceType, mediaFormat)
|
fileName := song.GetFileName(c.resourceType, mediaFormat)
|
||||||
outputPath := path.Join(outputDir, fileName)
|
outputPath := path.Join(outputDir, fileName)
|
||||||
|
|
||||||
key := crypto.GetKey(c.appConfig.SecretKey, song.ID)
|
key := crypto.GetKey(song.ID)
|
||||||
if err := c.streamToFile(dlCtx, stream, outputPath, key); err != nil {
|
if err := c.streamToFile(dlCtx, stream, outputPath, key); err != nil {
|
||||||
fileutil.DeleteFile(outputPath)
|
fileutil.DeleteFile(outputPath)
|
||||||
return downloadResult{err: fmt.Errorf("failed to stream to file: %w", err)}
|
return downloadResult{err: fmt.Errorf("failed to stream to file: %w", err)}
|
||||||
|
|||||||
Reference in New Issue
Block a user