feat: import IMVU products into a catalog
The importer from t5de-hub's docs/imports.md: says hello to the hub with its key pair, follows the console's config (paused, rate, jobs at a time, IMVU accounts, whose sealed passwords it keeps), claims jobs, finds each product's newest revision on IMVU's CDN, converts it (originals for placeholders, no _contents.json, ProductRating from IMVU's rating), checks it by t5de-api's pack rules and uploads it to the catalog with an import token. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2b0d27831e
commit
e8578e4a71
26 files changed
+2345
-1
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/sha256"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// seal seals as the console does in the browser: RSA-OAEP with SHA-256 over {"imvuId", "password"}.
|
||||
func seal(t *testing.T, k *Key, plain string) string {
|
||||
t.Helper()
|
||||
der, _ := base64.StdEncoding.DecodeString(k.PublicKey)
|
||||
pub, err := x509.ParsePKIXPublicKey(der)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ct, err := rsa.EncryptOAEP(sha256.New(), rand.Reader, pub.(*rsa.PublicKey), []byte(plain), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString(ct)
|
||||
}
|
||||
|
||||
func TestLoadAndOpen(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
k, made, err := Load(dir)
|
||||
if err != nil || !made {
|
||||
t.Fatalf("made %v, %v", made, err)
|
||||
}
|
||||
if k.private.N.BitLen() != Bits || len(k.Fingerprint) != 64 {
|
||||
t.Errorf("bits %d, fingerprint %q", k.private.N.BitLen(), k.Fingerprint)
|
||||
}
|
||||
again, made, err := Load(dir)
|
||||
if err != nil || made || again.Fingerprint != k.Fingerprint || again.PublicKey != k.PublicKey {
|
||||
t.Fatalf("reloaded: made %v, %v", made, err)
|
||||
}
|
||||
if fi, err := os.Stat(filepath.Join(dir, FileName)); err != nil || (fi.Mode().Perm()&0o077 != 0 && os.PathSeparator == '/') {
|
||||
t.Errorf("key file: %v, %v", fi, err)
|
||||
}
|
||||
|
||||
sealed := seal(t, k, `{"imvuId":4242,"password":"hunter2"}`)
|
||||
if pw, err := again.Open(sealed, 4242); err != nil || pw != "hunter2" {
|
||||
t.Errorf("open: %q, %v", pw, err)
|
||||
}
|
||||
if _, err := k.Open(sealed, 4243); err == nil {
|
||||
t.Error("another account's password: no error")
|
||||
}
|
||||
if _, err := k.Open(seal(t, k, `{"imvuId":4242,"password":""}`), 4242); err == nil {
|
||||
t.Error("empty password: no error")
|
||||
}
|
||||
if _, err := k.Open("not base64!", 4242); err == nil {
|
||||
t.Error("not base64: no error")
|
||||
}
|
||||
other, _, _ := Load(t.TempDir())
|
||||
if _, err := other.Open(sealed, 4242); err == nil {
|
||||
t.Error("another importer's key: no error")
|
||||
}
|
||||
|
||||
if err := os.WriteFile(filepath.Join(dir, FileName), []byte("junk"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := Load(dir); err == nil {
|
||||
t.Error("junk key file: no error")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user