singular-labs / Singular-SKAdNetwork-App

Sample apps demonstrating the logic needed to implement SKAdNetwork as an ad network, publisher and advertiser.
https://www.singular.net
MIT License
79 stars 19 forks source link

How to generate a valid key.pem to test the workflow? #6

Closed liuxuan30 closed 4 years ago

liuxuan30 commented 4 years ago

I tried to create key.pem following https://github.com/starkbank/ecdsa-python:

openssl ecparam -name secp256k1 -genkey -out privateKey.pem
openssl ec -in privateKey.pem -pubout -out publicKey.pem

and then rename privateKey.pem to key.pem next to the server py file.

however when running showing ads, it throws:

[2020-07-13 20:57:53,093] ERROR in app: Exception on /get-ad-impression [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "skadnetwork_server.py", line 58, in get_skadnetwork_parameters
    ecdsa = ECDSA(ECDSA_PRIVATE)
  File "/Users/xuanliu/Downloads/Singular-SKAdNetwork-App-master/skadnetwork-server/ecdsa_wrapper.py", line 28, in __init__
    self._pubkey = fe_keys.get_public_key(self._key, self.CURVE)
  File "/usr/local/lib/python3.7/site-packages/fastecdsa/keys.py", line 81, in get_public_key
    return d * curve.G
  File "/usr/local/lib/python3.7/site-packages/fastecdsa/point.py", line 163, in __rmul__
    return self.__mul__(scalar)
  File "/usr/local/lib/python3.7/site-packages/fastecdsa/point.py", line 135, in __mul__
    validate_type(scalar, int)
  File "/usr/local/lib/python3.7/site-packages/fastecdsa/util.py", line 170, in validate_type
    expected_type, type(instance)))
TypeError: Expected a value of type <class 'int'>, got a value of type <class 'NoneType'>
127.0.0.1 - - [13/Jul/2020 20:57:53] "GET /get-ad-impression?skadnetwork_version=2.0&source_app_id=654321 HTTP/1.1" 500 -

it seems it failed to read public key? please fix and maybe add a doc about this. thank you

Treagzhao commented 4 years ago

你找到什么办法了吗?我也在苦苦探索同样的问题·······

danielxt7 commented 4 years ago

Hey @liuxuan30 & @Treagzhao - we wrote skadnetwork_server to work with keys compatible with what Apple is issuing for adnetworks registering for SKAdNetwork - Apple are using a different ecdsa curve: prime256v1. so please generate the key this way:

openssl ecparam -name prime256v1 -genkey -out privateKey.pem

Treagzhao commented 4 years ago

Hey @liuxuan30 & @Treagzhao - we wrote skadnetwork_server to work with keys compatible with what Apple is issuing for adnetworks registering for SKAdNetwork - Apple are using a different ecdsa curve: prime256v1. so please generate the key this way:

openssl ecparam -name prime256v1 -genkey -out privateKey.pem

we have tried ,but the prime256v1 has a param head like this

-----BEGIN EC PARAMETERS----- BgUrgQQACg== -----END EC PARAMETERS-----

and the python server could not read this ,it occurs an error. How can I fix this?

liuxuan30 commented 4 years ago

actually, you can workaround by not passing the key so it will generate the key pair for you

mervit93 commented 1 month ago

I tried to create key.pem following https://github.com/starkbank/ecdsa-python:

openssl ecparam -name secp256k1 -genkey -out privateKey.pem
openssl ec -in privateKey.pem -pubout -out publicKey.pem

and then rename privateKey.pem to key.pem next to the server py file.

however when running showing ads, it throws:

[2020-07-13 20:57:53,093] ERROR in app: Exception on /get-ad-impression [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "skadnetwork_server.py", line 58, in get_skadnetwork_parameters
    ecdsa = ECDSA(ECDSA_PRIVATE)
  File "/Users/xuanliu/Downloads/Singular-SKAdNetwork-App-master/skadnetwork-server/ecdsa_wrapper.py", line 28, in __init__
    self._pubkey = fe_keys.get_public_key(self._key, self.CURVE)
  File "/usr/local/lib/python3.7/site-packages/fastecdsa/keys.py", line 81, in get_public_key
    return d * curve.G
  File "/usr/local/lib/python3.7/site-packages/fastecdsa/point.py", line 163, in __rmul__
    return self.__mul__(scalar)
  File "/usr/local/lib/python3.7/site-packages/fastecdsa/point.py", line 135, in __mul__
    validate_type(scalar, int)
  File "/usr/local/lib/python3.7/site-packages/fastecdsa/util.py", line 170, in validate_type
    expected_type, type(instance)))
TypeError: Expected a value of type <class 'int'>, got a value of type <class 'NoneType'>
127.0.0.1 - - [13/Jul/2020 20:57:53] "GET /get-ad-impression?skadnetwork_version=2.0&source_app_id=654321 HTTP/1.1" 500 -

it seems it failed to read public key? please fix and maybe add a doc about this. thank you