refactor: hardcode secret key in crypto package
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
type Config struct {
|
||||
ArlCookie string `mapstructure:"arl_cookie"`
|
||||
SecretKey string `mapstructure:"secret_key"`
|
||||
OutputDir string `mapstructure:"output_dir"`
|
||||
HomeDir string
|
||||
}
|
||||
@@ -33,7 +32,7 @@ func New(cfgPath string) (*Config, error) {
|
||||
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
|
||||
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 {
|
||||
return nil, fmt.Errorf("failed to create config file: %w", err)
|
||||
}
|
||||
@@ -68,12 +67,6 @@ func (c *Config) Validate() error {
|
||||
if c.ArlCookie == "" {
|
||||
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 == "" {
|
||||
c.OutputDir = filepath.Join(c.HomeDir, "Music", "GoDeez")
|
||||
}
|
||||
|
||||
@@ -8,13 +8,17 @@ import (
|
||||
"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))
|
||||
hashHex := hex.EncodeToString(hash[:])
|
||||
|
||||
key := []byte(secretKey)
|
||||
key := make([]byte, len(secretKey))
|
||||
copy(key, secretKey)
|
||||
for i := 0; i < len(hash); i++ {
|
||||
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)
|
||||
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 {
|
||||
fileutil.DeleteFile(outputPath)
|
||||
return downloadResult{err: fmt.Errorf("failed to stream to file: %w", err)}
|
||||
|
||||
Reference in New Issue
Block a user