API login request fails

Discussions about ideaMaker and other printing software.
Fiesel
Posts: 21
Joined: Wed Jan 24, 2018 3:42 pm

API login request fails

Postby Fiesel » Tue Jan 22, 2019 4:18 pm

I want to play with the camera and try to call my printers API via the following script:

Code: Select all

#!/bin/bash

password=$1
echo "      pwd: $password"

timestamp=`date +%s%N | cut -b1-13`
echo "timestamp: $timestamp"

sha1=($(echo "password=$password&timestamp=$timestamp" | sha1sum))
echo "     sha1: [${sha1}]"

md5=($(echo $sha1 | md5sum))
echo "      md5: [${md5}]"
echo ""

curl -s "http://192.168.178.61:10800/v1/login?sign=$md5&timestamp=$timestamp" | jq


sadly the api does not let me log in:

Code: Select all

[fk@linux ~]$ ./cam.sh testpassword
      pwd: testpassword
timestamp: 1548173780240
     sha1: [a355c64d15f31dea5a89b30a5e96592d3252afb9]
      md5: [fe557cee8d1867ded3276af345d98bca]

{
  "error": {
    "code": 10000,
    "msg": "sign error or password error"
  },
  "status": 0
}


Does anyone have an idea what is wrong? I rechecked that correct api password is set in printer for sure.
Can someone verify that im generating correct sha1 and md5 for password "testpassword" and timestamp 1548173780240?

User avatar
Vicky@Raise3D
Posts: 4815
Joined: Fri Mar 25, 2016 3:54 am

Re: API login request fails

Postby Vicky@Raise3D » Wed Jan 23, 2019 5:06 am

Please check whether you are using the correct API password. When setting API password, the first screen is requesting SSH password not API password. The two password are not the same.
Or check out the following steps to see whether it helps.
1.png

User avatar
jetdillo
Posts: 169
Joined: Mon Jun 12, 2017 5:10 am

Re: API login request fails

Postby jetdillo » Wed Jan 23, 2019 7:39 am

I'm also experiencing the same error when trying to login to the API.
I did set my ssh password via the touchpanel instead of on the Linux CLI.
I also set the API password via the API password menu under the Developer Settings sub-menu.
What am I missing here ? How accurate does the timestamp have to be ?

User avatar
jetdillo
Posts: 169
Joined: Mon Jun 12, 2017 5:10 am

Re: API login request fails

Postby jetdillo » Wed Jan 23, 2019 4:47 pm

Fiesel wrote:I want to play with the camera and try to call my printers API via the following script:

Code: Select all

#!/bin/bash

password=$1
echo "      pwd: $password"

timestamp=`date +%s%N | cut -b1-13`
echo "timestamp: $timestamp"

sha1=($(echo "password=$password&timestamp=$timestamp" | sha1sum))



One possible problem here is that you are getting a trailing newline being piped from your echo into sha1sum.
To wit:

Code: Select all

osprey-4:Documents dillo$ echo "password=testpassword&timestamp=1548222352"|shasum
3be9ee804450c55e9411992147578ba056e8ea39  -


vs

Code: Select all

osprey-4:Documents dillo$ echo -n "password=testpassword&timestamp=1548222352"|shasum
0a147205c22a3e2effe7ec33e6c03ea20dbc4724  -


Also, note that there are trailing characters at the end of the shasum and md5sum output. This needs to be trimmed before being pasted into the string that makes up the URL.
Here's my version of the sha1/md5sum lines in your script:

Code: Select all

sha1=($(echo "password=$password&timestamp=$timestamp" | shasum|awk ' { printf("%s",$1)}'))

and

Code: Select all

md5=($(echo $sha1 | md5sum|awk ' { printf("%s",$1) }'))


So that's one obvious problem, although as I noted in another post, even with fixing the newline and trailing char issues, I'm still not able to authenticate against the API.

User avatar
Vicky@Raise3D
Posts: 4815
Joined: Fri Mar 25, 2016 3:54 am

Re: API login request fails

Postby Vicky@Raise3D » Wed Jan 23, 2019 6:52 pm

jetdillo wrote:I'm also experiencing the same error when trying to login to the API.
I did set my ssh password via the touchpanel instead of on the Linux CLI.
I also set the API password via the API password menu under the Developer Settings sub-menu.
What am I missing here ? How accurate does the timestamp have to be ?


Do you meet the same failure when following the steps in the picture I attached before?

User avatar
jetdillo
Posts: 169
Joined: Mon Jun 12, 2017 5:10 am

Re: API login request fails

Postby jetdillo » Thu Jan 24, 2019 7:51 am

Vicky@Raise3D wrote:
jetdillo wrote:I'm also experiencing the same error when trying to login to the API.
I did set my ssh password via the touchpanel instead of on the Linux CLI.
I also set the API password via the API password menu under the Developer Settings sub-menu.
What am I missing here ? How accurate does the timestamp have to be ?


Do you meet the same failure when following the steps in the picture I attached before?


Yes.
I set the ssh password on the touchscreen under Settings.
I went into the Developer sub-menu, set the API password there.
I followed the instructions in the screenshot you posted, which are the same instructions you see when just accessing http://<PrinterIP>:10800

I take the string

Code: Select all

 "password=mypasswd&timestamp=1548222352"
, get the SHA1 hash, pipe that into md5sum, get the md5sum

Code: Select all

osprey-4:Documents dillo$ echo -n "password=testpassword&timestamp=1548222352"|shasum|awk '{ print($1) }'
0a147205c22a3e2effe7ec33e6c03ea20dbc4724


Take the MD5sum of the SHA1:

Code: Select all

osprey-4:Documents dillo$ echo -n "0a147205c22a3e2effe7ec33e6c03ea20dbc4724"|md5sum|awk '{ print($1) }'
6fa7378bc12334e330e6491ba3c612e8


string it intro a URL:

Code: Select all

osprey-4:Documents dillo$ curl "http://192.168.16.108:10800/v1/login?sign=6fa7378bc12334e330e6491ba3c612e8&timestamp=1548222352"
{"error":{"code":10000,"msg":"sign error or password error"},"status":0}
osprey-4:Documents dillo$


That's what the browser docs and what your screenshot say to do right ? Or should we do the timestamp for the URL again right before we send the message vs. when we are doing the SHA1 and MD5SUM ?

Fiesel
Posts: 21
Joined: Wed Jan 24, 2018 3:42 pm

Re: API login request fails

Postby Fiesel » Thu Jan 24, 2019 11:39 am

jetdillo wrote:One possible problem here is that you are getting a trailing newline being piped from your echo into sha1sum.
To wit:

Code: Select all

osprey-4:Documents dillo$ echo "password=testpassword&timestamp=1548222352"|shasum
3be9ee804450c55e9411992147578ba056e8ea39  -



What I'm doing is parsing the result into an array splitting by space and accessing the first element:

Code: Select all

var=($(echo "some array values"))
echo "<start>${var}<end>"


results in:

Code: Select all

./test.sh
<start>some<end>


so basically the same result you achieve with awk formatting.
However, this still does not help with our login problem :lol:


@Vicky@Raise3D:
Could you please ask the API's devs to generate correct sha1 and md5 hashes for password "testpassword" and timestamp 1548173780240 so we can see if the gnu md5sum and sha1sum commands do not generate expected results?
Thanks a lot :)

User avatar
jetdillo
Posts: 169
Joined: Mon Jun 12, 2017 5:10 am

Re: API login request fails

Postby jetdillo » Thu Jan 24, 2019 2:10 pm

Fiesel wrote:
jetdillo wrote:One possible problem here is that you are getting a trailing newline being piped from your echo into sha1sum.
To wit:

Code: Select all

osprey-4:Documents dillo$ echo "password=testpassword&timestamp=1548222352"|shasum
3be9ee804450c55e9411992147578ba056e8ea39  -



What I'm doing is parsing the result into an array splitting by space and accessing the first element:

Code: Select all

var=($(echo "some array values"))
echo "<start>${var}<end>"


results in:

Code: Select all

./test.sh
<start>some<end>


so basically the same result you achieve with awk formatting.
However, this still does not help with our login problem :lol:


:lol:
@Vicky@Raise3D:
Could you please ask the API's devs to generate correct sha1 and md5 hashes for password "testpassword" and timestamp 1548173780240 so we can see if the gnu md5sum and sha1sum commands do not generate expected results?
Thanks a lot :)


Agreed. There's either some step we're missing or the docs are not fully explaining.

User avatar
Vicky@Raise3D
Posts: 4815
Joined: Fri Mar 25, 2016 3:54 am

Re: API login request fails

Postby Vicky@Raise3D » Fri Jan 25, 2019 3:46 am

Fiesel wrote:
jetdillo wrote:One possible problem here is that you are getting a trailing newline being piped from your echo into sha1sum.
To wit:

Code: Select all

osprey-4:Documents dillo$ echo "password=testpassword&timestamp=1548222352"|shasum
3be9ee804450c55e9411992147578ba056e8ea39  -



What I'm doing is parsing the result into an array splitting by space and accessing the first element:

Code: Select all

var=($(echo "some array values"))
echo "<start>${var}<end>"


results in:

Code: Select all

./test.sh
<start>some<end>


so basically the same result you achieve with awk formatting.
However, this still does not help with our login problem :lol:


@Vicky@Raise3D:
Could you please ask the API's devs to generate correct sha1 and md5 hashes for password "testpassword" and timestamp 1548173780240 so we can see if the gnu md5sum and sha1sum commands do not generate expected results?
Thanks a lot :)


Should be something wrong with your md5. Here is the result we got.
pwd: testpassword
timestamp: 1548173780240
sha1: 74e01bbe64263454c59977bb6da974f46cd5265f
md5: 334f9363095cec4dadfa54a929371562

User avatar
jetdillo
Posts: 169
Joined: Mon Jun 12, 2017 5:10 am

Re: API login request fails

Postby jetdillo » Fri Jan 25, 2019 7:55 am

Vicky@Raise3D wrote:Should be something wrong with your md5. Here is the result we got.
pwd: testpassword
timestamp: 1548173780240
sha1: 74e01bbe64263454c59977bb6da974f46cd5265f
md5: 334f9363095cec4dadfa54a929371562


Hmmm...so I'm noticing that the timestamp is 20 chars long.
I'm on a Mac which doesn't have support for nanoseconds in date(1) output, only seconds, so my timestamps are only 11 chars long
Is it required to supply a 20-digit integer for the timestamp ?

Could you show us what commands you are using to generate the SHA1 and MD5SUM and timestamp ?
Thanks!

User avatar
jetdillo
Posts: 169
Joined: Mon Jun 12, 2017 5:10 am

Re: API login request fails

Postby jetdillo » Fri Jan 25, 2019 9:27 am

I installed gdate on my Mac, which supports the "%s%N" date format and generates a 20-char long timestamp but am still not getting in.
This shouldn't be that hard. Are you using OAuth for the login request ?

User avatar
Vicky@Raise3D
Posts: 4815
Joined: Fri Mar 25, 2016 3:54 am

Re: API login request fails

Postby Vicky@Raise3D » Sat Jan 26, 2019 1:16 am

jetdillo wrote:
Vicky@Raise3D wrote:Should be something wrong with your md5. Here is the result we got.
pwd: testpassword
timestamp: 1548173780240
sha1: 74e01bbe64263454c59977bb6da974f46cd5265f
md5: 334f9363095cec4dadfa54a929371562


Hmmm...so I'm noticing that the timestamp is 20 chars long.
I'm on a Mac which doesn't have support for nanoseconds in date(1) output, only seconds, so my timestamps are only 11 chars long
Is it required to supply a 20-digit integer for the timestamp ?

Could you show us what commands you are using to generate the SHA1 and MD5SUM and timestamp ?
Thanks!


There is no necessary to make it to be 20 characters long.
We just search online how to generate SHA1 and MD5. http://sha1-online.com.testednet.com/

Fiesel
Posts: 21
Joined: Wed Jan 24, 2018 3:42 pm

Re: API login request fails

Postby Fiesel » Sat Jan 26, 2019 10:11 am

got it working :)

echo command appended a newline to the piped strings :oops:
Adding -n to echo fixed everything.

With this script I get a valid auth token from the printer:

Code: Select all

#!/bin/bash

password=$1
echo "      pwd: $password"

timestamp=`date +%s%N | cut -b1-13`
echo "timestamp: $timestamp"

sha1=($(echo -n "password=$password&timestamp=$timestamp" | sha1sum))
echo "     sha1: [${sha1}]"

md5=($(echo -n $sha1 | md5sum))
echo "      md5: [${md5}]"
echo ""

curl -s "http://192.168.178.61:10800/v1/login?sign=${md5}&timestamp=${timestamp}" | jq

User avatar
jetdillo
Posts: 169
Joined: Mon Jun 12, 2017 5:10 am

Re: API login request fails

Postby jetdillo » Tue Jan 29, 2019 3:43 am

Fiesel wrote:got it working :)

echo command appended a newline to the piped strings :oops:
Adding -n to echo fixed everything.

I thought I mentioned that a few posts back, but I'm glad you got it sorted out.
Mine's working too now.


Return to “Software”

Who is online

Users browsing this forum: No registered users and 5 guests