opentrace-community / opentrace-android

OpenTrace Android app. Reference implementation of the BlueTrace protocol.
https://bluetrace.io
GNU General Public License v3.0
577 stars 223 forks source link

Invalid PIN on trying to upload data #12

Closed simonry14 closed 4 years ago

simonry14 commented 4 years ago

Thanks for the good work.

Whenever I try to upload data I get an invalid pin error message.

I have followed all the cloud functions instructions and the tests all run successfully.

Please kindly advise what I might be missing

slxe6 commented 4 years ago

Hi simonry14, the getUploadToken requires a pin that is generated on the server. You need to enter this pin in order to upload. Can you double check that you entered the correct pin?

rinekri commented 4 years ago

Yeah, you should generate a bunch of pin codes to upload data. You can use setUploadCodes function from getUploadToken.ts file. But to invoke it you should make some changes to source code, now it's just an unused function.

valr2 commented 4 years ago

I did manage to get a test pin ('1234') into Firestore, by adding a line at the beginning of getUploadToken() in getUploadToken.ts, that calls "await storeUploadCodes(['1234']);". Afterwards I could see in Cloud Firestore Database a "codes" collection, with an "uploadCode" document.

After doing this, the app still said Invalid Pin, although getUploadToken() executed successfully on the server and returned status: "SUCCESS" and the base64 encoded token to the client. The reason was an exception on the client-side related to SimpleDateFormat('YYYYMMdd') in uploadToCloudStorage() from EnterPinFragment.kt. I've changed the format string to 'yyyyMMdd' and now the whole uploading works, and I see my data inside the upload storage bucket, as unencrypted json.

rinekri commented 4 years ago

And I remembered one important thing. I added in the getUploadToken.ts function trimming logic:

valid = uploadCodes.find(x => x.trim() === data.trim()) !== undefined; It will protect you from insufficient error if you entered spaces accidentally.

rez20004 commented 4 years ago

@ValentinRadoi can you please share how the code look like that you the added the await storeUploadCodes(['1234']); thanks in advance.

simonry14 commented 4 years ago

Thanks all for the feedback. I resolved it by following @ValentinRadoi's advice.

esQmo commented 4 years ago

Hey @simonry14 , It will be better if you share your solution with others too

Biplovkumar commented 4 years ago

undefined

Can u plz share @rinekri Where it need to be add ?

Biplovkumar commented 4 years ago

Thanks all for the feedback. I resolved it by following @ValentinRadoi's advice.

Can u plz share the solution with class name. @simonry14

Hoangtho11188 commented 4 years ago

@rinekri I'm facing with the below issue when trying to upload data : _Error: 9 FAILEDPRECONDITION: The Cloud Firestore API is not available for Datastore Mode projects. Could you pls help me on this?

Biplovkumar commented 4 years ago

I did manage to get a test pin ('1234') into Firestore, by adding a line at the beginning of getUploadToken() in getUploadToken.ts, that calls "await storeUploadCodes(['1234']);". Afterwards I could see in Cloud Firestore Database a "codes" collection, with an "uploadCode" document.

After doing this, the app still said Invalid Pin, although getUploadToken() executed successfully on the server and returned status: "SUCCESS" and the base64 encoded token to the client. The reason was an exception on the client-side related to SimpleDateFormat('YYYYMMdd') in uploadToCloudStorage() from EnterPinFragment.kt. I've changed the format string to 'yyyyMMdd' and now the whole uploading works, and I see my data inside the upload storage bucket, as unencrypted json.

Not helped @valr2. i hev entered verification code in Enter pin number and changed 'yyyyMMdd' too. but still facing issue.

rinekri commented 4 years ago

@Hoangtho11188 It seems you should change Firestore Mode to Native.

lorsk commented 4 years ago

I did manage to get a test pin ('1234') into Firestore, by adding a line at the beginning of getUploadToken() in getUploadToken.ts, that calls "await storeUploadCodes(['1234']);". Afterwards I could see in Cloud Firestore Database a "codes" collection, with an "uploadCode" document.

After doing this, the app still said Invalid Pin, although getUploadToken() executed successfully on the server and returned status: "SUCCESS" and the base64 encoded token to the client. The reason was an exception on the client-side related to SimpleDateFormat('YYYYMMdd') in uploadToCloudStorage() from EnterPinFragment.kt. I've changed the format string to 'yyyyMMdd' and now the whole uploading works, and I see my data inside the upload storage bucket, as unencrypted json.

This has not worked for me. I added the await storeUploadCodes(['1234']); line to see if that helps but its giving me this Invalid key length error:

image

rinekri commented 4 years ago

I did manage to get a test pin ('1234') into Firestore, by adding a line at the beginning of getUploadToken() in getUploadToken.ts, that calls "await storeUploadCodes(['1234']);". Afterwards I could see in Cloud Firestore Database a "codes" collection, with an "uploadCode" document.

After doing this, the app still said Invalid Pin, although getUploadToken() executed successfully on the server and returned status: "SUCCESS" and the base64 encoded token to the client. The reason was an exception on the client-side related to SimpleDateFormat('YYYYMMdd') in uploadToCloudStorage() from EnterPinFragment.kt. I've changed the format string to 'yyyyMMdd' and now the whole uploading works, and I see my data inside the upload storage bucket, as unencrypted json.

This has not worked for me. I added the await storeUploadCodes(['1234']); line to see if that helps but its giving me this Invalid key length error:

image

Code should have minimum 6 symbols, try to add 123456 code number.

lorsk commented 4 years ago

Code should have minimum 6 symbols, try to add 123456 code number.

Hey @rinekri tried that and am getting the same thing unfortunately. What do you think I am missing?

image

lorsk commented 4 years ago

After some investigating, the Invalid key length is coming from the key I generated and uploaded to the Secret Manager. I have set it up correctly I believe and it passes all my tests. My default encryption algorithm is "aes-256-gcm".

Not sure where I am going wrong.

EDIT: I was able to successfully upload a key by doing this const key_in_bytes = Buffer.from("FKdDh0d0qUv4FByKxwkZtCPfR87uspUwEokBFRQll5w=", 'base64') and passing that instead of this.key

image (And similar thing with the same base64 string to the decrypt function)

This means I did something weird with how I generated the key possibly with the head -c32 /dev/urandom | base64 line

So still not sure what the issue there is.

rinekri commented 4 years ago

@LorsK You can add logging of encryption key from SecretManager in the encrypt function. Maybe problem isn't in key itself, but in the way how you added it in the Manager. You could copy key with spaces, new lines and etc.

Hoangtho11188 commented 4 years ago

@rinekri I getuploadtoken success from my side uploadtoken So how to upload data to Storage bucket? My Upload bucket still is empty now.

vishaljoseph commented 4 years ago

@Hoangtho11188 I'm having the same issue. Getting this error on checking the logs: E/StorageException: StorageException has occurred. User does not have permission to access this object. Code: -13021 HttpResult: 403 E/StorageException: The server has terminated the upload session

Were you able to fix it?

ghost commented 3 years ago

"await storeUploadCodes(['1234']);"

hello, can you please specify where did you put this "await storeUploadCodes(['1234']);" line? It will be extremely helpful. Thank you.