@ -8,6 +8,7 @@ from common.android import get_imei, get_serial, get_subscriber_info
from common . api import api_get
from common . api import api_get
from common . params import Params
from common . params import Params
from common . file_helpers import mkdirs_exists_ok
from common . file_helpers import mkdirs_exists_ok
from common . basedir import PERSIST
def register ( ) :
def register ( ) :
params = Params ( )
params = Params ( )
@ -22,24 +23,24 @@ def register():
# create a key for auth
# create a key for auth
# your private key is kept on your device persist partition and never sent to our servers
# your private key is kept on your device persist partition and never sent to our servers
# do not erase your persist partition
# do not erase your persist partition
if not os . path . isfile ( " /persist /comma/id_rsa.pub" ) :
if not os . path . isfile ( PERSIST + " /comma/id_rsa.pub " ) :
cloudlog . warning ( " generating your personal RSA key " )
cloudlog . warning ( " generating your personal RSA key " )
mkdirs_exists_ok ( " /persist /comma" )
mkdirs_exists_ok ( PERSIST + " /comma " )
assert os . system ( " openssl genrsa -out /persist /comma/id_rsa.tmp 2048 " ) == 0
assert os . system ( " openssl genrsa -out " + PERSIST + " /comma/id_rsa.tmp 2048" ) == 0
assert os . system ( " openssl rsa -in /persist/comma/id_rsa.tmp -pubout -out /persist /comma/id_rsa.tmp.pub " ) == 0
assert os . system ( " openssl rsa -in " + PERSIST + " /comma/id_rsa.tmp -pubout -out " + PERSIST + " /comma/id_rsa.tmp.pub" ) == 0
os . rename ( " /persist /comma/id_rsa.tmp" , " /persist /comma/id_rsa" )
os . rename ( PERSIST + " /comma/id_rsa.tmp " , PERSIST + " /comma/id_rsa " )
os . rename ( " /persist /comma/id_rsa.tmp.pub" , " /persist /comma/id_rsa.pub" )
os . rename ( PERSIST + " /comma/id_rsa.tmp.pub " , PERSIST + " /comma/id_rsa.pub " )
# make key readable by app users (ai.comma.plus.offroad)
# make key readable by app users (ai.comma.plus.offroad)
os . chmod ( ' /persist /comma/' , 0o755 )
os . chmod ( PERSIST + ' /comma/ ' , 0o755 )
os . chmod ( ' /persist /comma/id_rsa' , 0o744 )
os . chmod ( PERSIST + ' /comma/id_rsa ' , 0o744 )
dongle_id , access_token = params . get ( " DongleId " , encoding = ' utf8 ' ) , params . get ( " AccessToken " , encoding = ' utf8 ' )
dongle_id , access_token = params . get ( " DongleId " , encoding = ' utf8 ' ) , params . get ( " AccessToken " , encoding = ' utf8 ' )
public_key = open ( " /persist /comma/id_rsa.pub" ) . read ( )
public_key = open ( PERSIST + " /comma/id_rsa.pub " ) . read ( )
# create registration token
# create registration token
# in the future, this key will make JWTs directly
# in the future, this key will make JWTs directly
private_key = open ( " /persist /comma/id_rsa" ) . read ( )
private_key = open ( PERSIST + " /comma/id_rsa " ) . read ( )
# late import
# late import
import jwt
import jwt