Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i send message by using phone number witch already being registered? #2849

Open
finch7 opened this issue Aug 6, 2019 · 16 comments
Open
Assignees

Comments

@finch7
Copy link

finch7 commented Aug 6, 2019

Now we cant register by yowsup,so i registered a account by ios whatsapp application,
Then i logged on and send some message by whatsapp app.
The problem is how can i use this phone number to send message by yowsup?
there is not password thing.just a phone number and Verification Code to logging.
Guys,What should i do?

@finch7
Copy link
Author

finch7 commented Aug 6, 2019

how can i get client static keypair?
please give me some help

@s-boris
Copy link

s-boris commented Sep 15, 2019

I don't think you can. It's probably encrypted in your app data folder somewhere or in the db...

@sinsinewave
Copy link

With iOS I'm not aware of a way, but if you have a rooted Android device available, you can pull the values and axolotl.db from there.

I can't remember the exact location though, you'll have to find that yourself.

@s-boris
Copy link

s-boris commented Sep 16, 2019

With iOS I'm not aware of a way, but if you have a rooted Android device available, you can pull the values and axolotl.db from there.

I can't remember the exact location though, you'll have to find that yourself.

Are you sure the client key is in there? I looked through the axolotl.db from my phone but it doesn't appear like there is anything that resembles the client static key...
(btw it's in data/com.whatsapp/databases together with the msgstore.db and other stuff)

@bryanjhv
Copy link

I'm gonna guess that you opened that file as the SQLite3 (Android variant) it is, and not as a text or binary file.

@s-boris
Copy link

s-boris commented Sep 18, 2019

I'm gonna guess that you opened that file as the SQLite3 (Android variant) it is, and not as a text or binary file.

Of course. But the only table in the db that looked somehow interesting to me were the prekeys that yowsup also downloads right after registration.

@sinsinewave
Copy link

I just checked, apparently I found client_static_keypair and server_static_public in data/com.whatsapp/shared_prefs/keystore.xml

@s-boris
Copy link

s-boris commented Sep 18, 2019

I just checked, apparently I found client_static_keypair and server_static_public in data/com.whatsapp/shared_prefs/keystore.xml

nice I somehow missed that.
I'll try to copy the preshared keys from the app axolot.db into yowsup's db and put in the correct app version,hash etc. See if I can login with yowsup that way...

@github-k8n
Copy link

@Neolysion If you manage to do it correctly can you make a short how-to for dummies?
Basically I already opened the keystore.xml previously and saw the values, however it is a bit unclear as to how to populate the yowsup config (where?) so that I can actually start and try including it in the spectrum2 config...

@bryanjhv
Copy link

bryanjhv commented Sep 22, 2019

~/.config/yowsup/[phone]/config.json reads:

{
  "__version__": 1,
  "cc": "[countrycode]",
  "client_static_keypair": "...",
  "edge_routing_info": "...",
  "expid": "...",
  "fdid": "...",
  "id": "...",
  "mcc": "[mcc]",
  "mnc": "[mnc]",
  "phone": "[phone]",
  "pushname": "[yourname]",
  "server_static_public": "...",
  "sim_mcc": "000",
  "sim_mnc": "000"
}

Alternative, keyval format:

yowsup/yowsup-cli

Lines 23 to 40 in f14a03f

############# Yowsup Configuration Sample ###########
#
# ====================
# The file contains info about your WhatsApp account. This is used during registration and login.
# You can define or override all fields in the command line args as well.
#
# Country code. See http://www.ipipi.com/help/telephone-country-codes.htm. This is now required.
cc=49
#
# Your full phone number including the country code you defined in 'cc', without preceding '+' or '00'
phone=491234567890
#
# Your pushname, this name is displayed to users when they're notified with your messages.
pushname=yowsup
#
# This keypair is generated during registration.
client_static_keypair=YJa8Vd9pG0KV2tDYi5V+DMOtSvCEFzRGCzOlGZkvBHzJvBE5C3oC2Fruniw0GBGo7HHgR4TjvjI3C9AihStsVg=="
#######################################################

Where is that saved?

NAME_CONFIG = "config.json"
@staticmethod
def constructPath(*path):
path = os.path.join(*path)
fullPath = os.path.join(user_config_dir(YowConstants.YOWSUP), path)
if not os.path.exists(os.path.dirname(fullPath)):
os.makedirs(os.path.dirname(fullPath))
return fullPath
@staticmethod
def getStorageForProfile(profile_name):
if type(profile_name) is not str:
profile_name = str(profile_name)
return StorageTools.constructPath(profile_name + '/')
@staticmethod
def writeProfileData(profile_name, name, val):
logger.debug("writeProfileData(profile_name=%s, name=%s, val=[omitted])" % (profile_name, name))
path = os.path.join(StorageTools.getStorageForProfile(profile_name), name)
logger.debug("Writing %s" % path)
with open(path, 'w' if type(val) is str else 'wb') as attrFile:
attrFile.write(val)

I'd love people reading code and/or learning at least Python before asking.

@sleek-geek
Copy link

Hi guys, sorry for reopening the topic, but I've got the keyspair from this file data/com.whatsapp/shared_prefs/keystore.xml and I tried to use convert it to BASE64 but the code complained about the length. Is there something I'm doing wrong here?

@baptx
Copy link

baptx commented Apr 16, 2020

@bryanjhv I got the same error as @SAMY-MOHSEN: ValueError: Wrong length: 86 with the command to send a message yowsup-cli demos -s CCYYYYYYYYY hello --config-phone CCXXXXXXXXX where CC is the country code, X are my phone number digits (without the unnecessary first digit "0") and Y are the phone number digits of someone else.
I tried with the JSON format in ~/.config/yowsup/CCXXXXXXXXX/config.json and the keyval format in ~/.config/yowsup/CCXXXXXXXXX/config.yo.
I converted the client_static_keypair found in the file shared_prefs/keystore.xml of the official Android WhatsApp client with the base64 Linux command like this:
echo -n "XXX" | base64
Which displayed the base64 on 2 lines. So I removed the new line character to make it fit on one line in the yowsup config file.
In the config file, I only added the fields cc, phone, pushname, client_static_keypair like in the keyval example, is that enough? (I don't have the other fields and don't know how to get them, someone asked the question here also: #2829 (comment))
By the way I think there is a bug in the keyval example because there is a quote at the end of the client_static_keypair but I did not find one before (I guess quotes are not needed in the keyval format so I did not use them).

@bryanjhv
Copy link

Please at least share the stack trace. A simple GitHub search for "wrong length" returned no code matches so it might be from some of Yowsup's dependencies, would be useful to see. Apart from that, other error that I can think of is that the "echo" command must go with single quotes instead of double to avoid shell expansion, escaping and those things. Regarding the keyval example, I don't remember it correctly but I think quotes are needed (at the start and the end of the string) because it contains an "=" sign which could be misinterpreted by the parser (note: I might be wrong).

@baptx
Copy link

baptx commented Apr 17, 2020

@bryanjhv here is the stack trace:

Traceback (most recent call last):
  File "/usr/local/bin/yowsup-cli", line 679, in <module>
    if not parser.process():
  File "/usr/local/bin/yowsup-cli", line 546, in process
    super(DemosArgParser, self).process()
  File "/usr/local/bin/yowsup-cli", line 206, in process
    self._config = self._config_manager.load(config_phone)
  File "/usr/local/lib/python2.7/dist-packages/yowsup/config/manager.py", line 52, in load
    return self.load_path(fpath)
  File "/usr/local/lib/python2.7/dist-packages/yowsup/config/manager.py", line 85, in load_path
    return self.load_data(datadict)
  File "/usr/local/lib/python2.7/dist-packages/yowsup/config/manager.py", line 93, in load_data
    return ConfigSerialize(Config).deserialize(datadict)
  File "/usr/local/lib/python2.7/dist-packages/yowsup/config/base/serialize.py", line 26, in deserialize
    data = transform.reverse(data)
  File "/usr/local/lib/python2.7/dist-packages/yowsup/config/transforms/props.py", line 34, in reverse
    key, val = target(key, val) if type(target) == types.FunctionType else (key, target)
  File "/usr/local/lib/python2.7/dist-packages/yowsup/config/v1/serialize.py", line 33, in <lambda>
    "client_static_keypair": lambda key, val: (key, KeyPair.from_bytes(base64.b64decode(val))),
  File "/home/user/.local/lib/python2.7/site-packages/consonance/structs/keypair.py", line 54, in from_bytes
    keypair = X25519KeyPair.from_bytes(data)
  File "/home/user/.local/lib/python2.7/site-packages/dissononce/dh/x25519/keypair.py", line 19, in from_bytes
    raise ValueError("Wrong length: %d" % len(data))
ValueError: Wrong length: 86

If I use single quotes instead of double quotes with echo, the base64 result is the same.
The error is also displayed if I use quotes in the keyval config file.

@bryanjhv
Copy link

Here are the links relevant to the stack trace you provided.
https://github.com/tgalal/yowsup/blob/v3.2.3/yowsup/config/v1/serialize.py#L33
https://github.com/tgalal/consonance/blob/0.1.2/consonance/structs/keypair.py#L54
https://github.com/tgalal/dissononce/blob/0.34.3/dissononce/dh/x25519/keypair.py#L18-L19

After looking at keystore.xml file from WhatsApp, looks like it's already in base64 format but missing the required padding, which means adding = until the string length is 88 (as per https://stackoverflow.com/a/32140193 and given that keypair needs to have a length of 64).

Here's a script which could help (just adds the required "=" padding):

# save as pad.py and run:
# python pad.py '[keypair]'

from sys import argv, exit
from base64 import b64decode

if len(argv) != 2:
    print('ERROR: Missing keypair.')
    exit(1)

value = argv[1]
if len(value) > 88:
    print('ERROR: Invalid keypair.')
    exit(1)

print(value + (88 - len(value)) * '=')

NOTE: This does not guarantee that it will work or even be a valid one. I'm just helping with the validation. WhatsApp is banning most accounts so be careful, I'm not held responsible for you getting banned or someting, neither I am affiliated with someone here.

@baptx
Copy link

baptx commented Apr 18, 2020

@bryanjhv thanks, since I don't use Android / iOS on my smartphone, I registered my phone number with the official WhatsApp Android app on my laptop using Anbox (it works using Android x86 in VirtualBox also). I read that they ban people who register with yowsup but anyway I don't really use WhatsApp since they don't provide a standalone web version that works without Android / iOS app.

The keypair was indeed already in base64 format, I just had to add 2 equals.
Now I get this error when trying to send a message with yowsup, do you have an idea what's wrong?

yowsup-cli  v3.2.0
yowsup      v3.2.3

Copyright (c) 2012-2019 Tarek Galal
http://www.openwhatsapp.org

This software is provided free of charge. Copying and redistribution is
encouraged.

If you appreciate this software and you would like to support future
development please consider donating:
http://openwhatsapp.org/yowsup/donate


I 2020-04-18 14:49:13,910 yowsup.layers.network.layer - Connecting to e11.whatsapp.net:443
I 2020-04-18 14:49:14,057 yowsup.axolotl.manager - Loaded 812 unsent prekeys
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/local/lib/python2.7/dist-packages/yowsup/layers/noise/workers/handshake.py", line 36, in run
    self._protocol.start(self._stream, self._client_config, self._s, self._rs)
  File "/home/user/.local/lib/python2.7/site-packages/consonance/protocol.py", line 82, in start
    result = handshake.perform(client_config, stream, s, rs)
  File "/home/user/.local/lib/python2.7/site-packages/consonance/handshake.py", line 84, in perform
    cipherstatepair = self._start_handshake_xx(stream, client_payload, dissononce_s)
  File "/home/user/.local/lib/python2.7/site-packages/consonance/handshake.py", line 107, in _start_handshake_xx
    s=s
  File "/home/user/.local/lib/python2.7/site-packages/dissononce/extras/processing/handshakestate_forwarder.py", line 13, in initialize
    return self._handshakestate.initialize(handshake_pattern, initiator, prologue, s, e, rs, re, psks)
  File "/home/user/.local/lib/python2.7/site-packages/dissononce/extras/processing/handshakestate_guarded.py", line 89, in initialize
    return self._handshakestate.initialize(handshake_pattern, initiator, prologue, s, e, rs, re, psks)
  File "/home/user/.local/lib/python2.7/site-packages/dissononce/processing/impl/handshakestate.py", line 64, in initialize
    self._symmetricstate.mix_hash(prologue)
  File "/home/user/.local/lib/python2.7/site-packages/dissononce/processing/impl/symmetricstate.py", line 74, in mix_hash
    self._h = self._hashfn.hash(self._h + data)
  File "/home/user/.local/lib/python2.7/site-packages/dissononce/hash/sha256.py", line 14, in hash
    digest.update(data)
  File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/hashes.py", line 92, in update
    raise TypeError("data must be bytes.")
TypeError: data must be bytes.

Update: @tgalal could it mean that yowsup does not work anymore because WhatsApp changed its API? I often see updates for the Android app that requires the user to download the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants