-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from rneatherway/windows-sup
Add support for Windows
- Loading branch information
Showing
10 changed files
with
193 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package slackclient | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/billgraziano/dpapi" | ||
) | ||
|
||
type EncryptedKey struct { | ||
EncryptedKey string `json:"encrypted_key"` | ||
} | ||
type LocalState struct { | ||
OSCrypt EncryptedKey `json:"os_crypt"` | ||
} | ||
|
||
func cookiePassword() ([]byte, error) { | ||
bs, err := os.ReadFile(path.Join(slackConfigDir(), "Local State")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var localState LocalState | ||
err = json.Unmarshal(bs, &localState) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
encryptedKey, err := base64.StdEncoding.DecodeString(localState.OSCrypt.EncryptedKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
encryptionMethod := encryptedKey[:5] | ||
if string(encryptionMethod) != "DPAPI" { | ||
return nil, fmt.Errorf("encryption method %q is not supported", encryptionMethod) | ||
} | ||
|
||
encryptedKey = encryptedKey[5:] | ||
decryptedKey, err := dpapi.DecryptBytes(encryptedKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return decryptedKey, nil | ||
} |
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,31 @@ | ||
package slackclient | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"runtime" | ||
) | ||
|
||
func slackConfigDir() string { | ||
switch runtime.GOOS { | ||
case "windows": | ||
return path.Join(os.Getenv("APPDATA"), "Slack") | ||
case "darwin": | ||
home := os.Getenv("HOME") | ||
first := path.Join(home, "Library", "Application Support", "Slack") | ||
second := path.Join(home, "Library", "Containers", "com.tinyspeck.slackmacgap", "Data", "Library", "Application Support", "Slack") | ||
|
||
if _, err := os.Stat(first); err == nil { | ||
return first | ||
} | ||
return second | ||
case "linux": | ||
if xdgConfigDir, found := os.LookupEnv("XDG_CONFIG_DIR"); found { | ||
return path.Join(xdgConfigDir, "Slack") | ||
} | ||
return path.Join(os.Getenv("HOME"), ".config", "Slack") | ||
default: | ||
panic(fmt.Sprintf("Platform %q not supported", runtime.GOOS)) | ||
} | ||
} |
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,35 @@ | ||
package slackclient | ||
|
||
import ( | ||
"crypto/aes" | ||
"crypto/cipher" | ||
"crypto/sha1" | ||
|
||
"golang.org/x/crypto/pbkdf2" | ||
) | ||
|
||
type UnixCookieDecryptor struct { | ||
rounds int | ||
} | ||
|
||
func (d UnixCookieDecryptor) Decrypt(value, key []byte) ([]byte, error) { | ||
dk := pbkdf2.Key(key, []byte("saltysalt"), d.rounds, 16, sha1.New) | ||
|
||
block, err := aes.NewCipher(dk) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
iv := make([]byte, 16) | ||
for i := range iv { | ||
iv[i] = ' ' | ||
} | ||
|
||
mode := cipher.NewCBCDecrypter(block, iv) | ||
|
||
mode.CryptBlocks(value, value) | ||
|
||
bytesToStrip := int(value[len(value)-1]) | ||
|
||
return value[:len(value)-bytesToStrip], nil | ||
} |
Oops, something went wrong.