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

Report bugs for Synology DSM deploy hook #2727

Open
tresni opened this issue Feb 9, 2020 · 240 comments
Open

Report bugs for Synology DSM deploy hook #2727

tresni opened this issue Feb 9, 2020 · 240 comments
Assignees
Labels
3rd party api report bugs to dns api, deploy hooks and notification hooks

Comments

@tresni
Copy link
Contributor

tresni commented Feb 9, 2020

Please report bugs for the Synology DSM hook here. Remember to include debug logs

acme.sh  --deploy --deploy-hook synology_dsm .....   --debug 2
@Neilpang Neilpang added the 3rd party api report bugs to dns api, deploy hooks and notification hooks label Feb 15, 2020
@lippertmarkus
Copy link
Contributor

@tresni thank's for your work! This doesn't support automatically renewing the cert, does it?

@tresni
Copy link
Contributor Author

tresni commented Mar 5, 2020

@lippertmarkus If you mean will the Synology automatically renew the certs, no. However, renewed certificates will be updated on the synology.

If you want to do renewals on your synology, I do this using a cronjob. Control Panel -> Task Scheduler -> Create -> Scheduled Task -> User-defined Script. Under General, set User to root. Under Schedule, set a schedule you feel is appropriate (I do monthly.) Under Task Settings, put the following in the Run Command box (assuming you installed to /usr/local/share/acme.sh):

/usr/local/share/acme.sh/acme.sh --cron --home /usr/local/share/acme.sh/

@lippertmarkus
Copy link
Contributor

@tresni Thanks for the quick response. I do basically the same, see https://github.com/lippertmarkus/synology-le-dns-auto-renew
I just think searching for all the directories of all apps where the certificate is used like the script in the Wiki and my script does is a bit ugly.

When I saw that you use the web API in your deployment hook, I wondered if we could use the this API also for the renewing process?

@tresni
Copy link
Contributor Author

tresni commented Mar 7, 2020

This does both issuance and renewal. No weird directory handling, it just uses the API for everything. Maybe an example is better then trying to explain :)

ash-4.3# acme.sh --issue -d example.us --dns dns_cf
...
[Fri Mar  6 22:21:47 MST 2020] Your cert is in  /usr/local/share/acme.sh/example.us/example.us.cer
[Fri Mar  6 22:21:47 MST 2020] Your cert key is in  /usr/local/share/acme.sh/example.us/example.us.key
[Fri Mar  6 22:21:47 MST 2020] The intermediate CA cert is in  /usr/local/share/acme.sh/example.us/ca.cer
[Fri Mar  6 22:21:47 MST 2020] And the full chain certs is there:  /usr/local/share/acme.sh/example.us/fullchain.cer
ash-4.3# export SYNO_Username=... SYNO_Password=...
ash-4.3# SYNO_Create=1 SYNO_Certificate=example.us acme.sh -d example.us --deploy --deploy-hook synology_dsm
[Fri Mar  6 22:22:40 MST 2020] Logging into localhost:5000
[Fri Mar  6 22:22:47 MST 2020] Getting certificates in Synology DSM
[Fri Mar  6 22:22:47 MST 2020] Generate form POST request
[Fri Mar  6 22:22:47 MST 2020] Upload certificate to the Synology DSM
[Fri Mar  6 22:22:53 MST 2020] http services were NOT restarted
[Fri Mar  6 22:22:53 MST 2020] Success
ash-4.3# acme.sh -d example.us --renew --force
[Fri Mar  6 22:24:03 MST 2020] Renew: 'example.us'
[Fri Mar  6 22:24:04 MST 2020] Single domain='example.us'
[Fri Mar  6 22:24:04 MST 2020] Getting domain auth token for each domain
[Fri Mar  6 22:24:06 MST 2020] Getting webroot for domain='example.us'
[Fri Mar  6 22:24:06 MST 2020] example.us is already verified, skip dns-01.
[Fri Mar  6 22:24:06 MST 2020] Verify finished, start to sign.
[Fri Mar  6 22:24:06 MST 2020] Lets finalize the order, Le_OrderFinalize: https://acme-v02.api.letsencrypt.org/acme/finalize/.../...
[Fri Mar  6 22:24:07 MST 2020] Download cert, Le_LinkCert: https://acme-v02.api.letsencrypt.org/acme/cert/...
[Fri Mar  6 22:24:08 MST 2020] Cert success.
...
[Fri Mar  6 22:24:08 MST 2020] Your cert is in  /usr/local/share/acme.sh/example.us/example.us.cer
[Fri Mar  6 22:24:08 MST 2020] Your cert key is in  /usr/local/share/acme.sh/example.us/example.us.key
[Fri Mar  6 22:24:08 MST 2020] The intermediate CA cert is in  /usr/local/share/acme.sh/example.us/ca.cer
[Fri Mar  6 22:24:08 MST 2020] And the full chain certs is there:  /usr/local/share/acme.sh/example.us/fullchain.cer
[Fri Mar  6 22:24:09 MST 2020] Logging into localhost:5000
[Fri Mar  6 22:24:09 MST 2020] Getting certificates in Synology DSM
[Fri Mar  6 22:24:10 MST 2020] Generate form POST request
[Fri Mar  6 22:24:10 MST 2020] Upload certificate to the Synology DSM
[Fri Mar  6 22:24:10 MST 2020] http services were NOT restarted
[Fri Mar  6 22:24:10 MST 2020] Success
ash-4.3#

@lippertmarkus
Copy link
Contributor

@tresni great, works like a charm! I added OTP/2-factor auth support in #2782 :)

@lippertmarkus
Copy link
Contributor

lippertmarkus commented Mar 9, 2020

@tresni sorry for hijacking this issue for discussing. Please tell me if you want to discuss elsewhere :)

While implementing #2782 I found that there is a binary which allows executing API requests without requiring authentication:

sudo /usr/syno/bin/synowebapi --exec api=SYNO.Core.Certificate.CRT method=list version=1
[Line 259] Exec WebAPI:  api=SYNO.Core.Certificate.CRT, version=1, method=list, param={}, runner=
{
   "data" : {
      "certificates" : [
         {
...

Maybe this could be used to implement a second way for importing the certificates? This wouldn't require any access information, so no scheme, host, port, username, password or device id environment variables. On the other hand this can only be used with a locally installed version of acme.sh and requires root. What do you think? Did you already try that?

I just briefly looked into that but couldn't figure out how to prepare a request for sending the binary certificate data with this method, but I think it should work somehow.

@tresni
Copy link
Contributor Author

tresni commented Mar 10, 2020

This module is designed where it can be run from any system, not just the Synology device itself, in line with what I believe acme.sh is attempting to accomplish. So using the WebApi allows for that, using the binary would not. Definitely a good find though!

@tatablack
Copy link

tatablack commented Apr 28, 2020

Nice work with the hook, much cleaner than looping over folders and certs. 👍 🙂

I was trying it today, but I ran into two separate issues:

Password
The password is not escaped when hitting login.cgi in this line, and mine (aA#99B$dIix!) contained characters which broke the authentication in multiple ways (# has meaning in URLs, $ has meaning in shell scripts). I also had an exclamation mark, which however seemed fine once I exported the env variable using single instead of double quotes.

Changing the password to an alphanumeric one fixed the issue, as the script proceeded further.

Certificate upload
Here's the (edited) output of ./acme.sh -d "*.subdomain.domain.net" --deploy --deploy-hook synology_dsm --debug 3 --home $PWD.

In short, uploading fails (after quite some time) and the response has an error code of 119. I'd welcome any suggestions here... 🤔

(EDIT: trying to upload the same files through the DSM Web UI works perfectly)

DSM: 6.2.2-24922 Update 4
Wget: GNU Wget 1.19.2

[Tue Apr 28 17:37:41 IST 2020] Upload certificate to the Synology DSM
[Tue Apr 28 17:37:41 IST 2020] ./acme.sh:_post:1733                     POST
[Tue Apr 28 17:37:41 IST 2020] ./acme.sh:_post:1734                     _post_url='http://localhost:5000/webapi/entry.cgi?api=SYNO.Core.Certificate&method=import&version=1&SynoToken=MYSYNOTOKEN'
[Tue Apr 28 17:37:41 IST 2020] ./acme.sh:_post:1735                     body='----------------------------20200428163741
Content-Disposition: form-data; name="key"; filename="*.subdomain.domain.net.key"
Content-Type: application/octet-stream

-----BEGIN RSA PRIVATE KEY-----
<PRIVATE KEY REMOVED>
-----END RSA PRIVATE KEY-----

----------------------------20200428163741
Content-Disposition: form-data; name="cert"; filename="*.subdomain.domain.net.cer"
Content-Type: application/octet-stream

-----BEGIN CERTIFICATE-----
<CERTIFICATE REMOVED>
-----END CERTIFICATE-----

----------------------------20200428163741
Content-Disposition: form-data; name="inter_cert"; filename="ca.cer"
Content-Type: application/octet-stream


-----BEGIN CERTIFICATE-----
<CERTIFICATE REMOVED>
-----END CERTIFICATE-----

----------------------------20200428163741
Content-Disposition: form-data; name="id"


----------------------------20200428163741
Content-Disposition: form-data; name="desc"

Letsencrypt wildcard certificate for my internal network
----------------------------20200428163741
Content-Disposition: form-data; name="as_default"

false
----------------------------20200428163741--
'
[Tue Apr 28 17:37:41 IST 2020] ./acme.sh:_post:1736                     _postContentType='multipart/form-data; boundary=--------------------------20200428163741'
[Tue Apr 28 17:37:42 IST 2020] ./acme.sh:_exists:494                    curl exists=0
[Tue Apr 28 17:37:42 IST 2020] ./acme.sh:_exists:494                    mktemp exists=0
[Tue Apr 28 17:37:42 IST 2020] ./acme.sh:_exists:494                    wget exists=0
[Tue Apr 28 17:37:42 IST 2020] ./acme.sh:_post:1794                     _WGET='wget -q -d  --content-on-error '
[Tue Apr 28 17:40:08 IST 2020] Please refer to https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html for error code: 4
[Tue Apr 28 17:40:08 IST 2020] ./acme.sh:_sed_i:867                     options='s/^ *//g'
[Tue Apr 28 17:40:08 IST 2020] ./acme.sh:_sed_i:869                     Using sed  -i
[Tue Apr 28 17:40:09 IST 2020] ./acme.sh:_post:1843                     _ret='4'
[Tue Apr 28 17:40:09 IST 2020] deploy/synology_dsm.sh:synology_dsm_deploy:142 response='{"error":{"code":119},"success":false}'
[Tue Apr 28 17:40:09 IST 2020] Unable to update certificate, error code {"error":{"code":119},"success":false}
[Tue Apr 28 17:40:09 IST 2020] Error deploy for domain:*.subdomain.domain.net
[Tue Apr 28 17:40:09 IST 2020] Deploy error.

@tatablack
Copy link

Actually, according to the manual, Wget does not currently support multipart/form-data for transmitting POST data... 😖

I tried this again using cURL and it works.

So I guess the options are either doing the upload in a way that works with Wget, or bail out with a message if that's not possible and Wget is being used.

@tresni
Copy link
Contributor Author

tresni commented May 4, 2020

Exit code 4 is a network error which I don't think is related to the form data itself. Also, the documentation for wget is just saying that it cannot create multipart uploads itself. We construct the payload ourself and send it as data, I don't think this has any impact on wget, but I'll double check.

@JoJota
Copy link

JoJota commented May 4, 2020

I'm using default cURL for transferring the certificates, but receiving error code 119 too.

As the default synology certificate is not verified, I first got cURL error 60 with the combination of "SSL certificate problem: unable to get local issuer certificate". After resolving this problem with setting export HTTPS_INSECURE=1 I received the synology error 119, which I am stuck with now. Further investigation seemed that there is not very much known what causes this error in detail, at least I couldn't find anything helpful.

Apart from that after not getting any further, I tried importing the certificates with a different reload script which was linked here, but this broke my DSM certificate system completely (no certificates were shown and even after regenerating the nginx certificate folder all the services which use the certificates are gone and I am not able to restore them). So I will now restore the DSM system to factory settings to see if that somehow helps getting rid of the 119er.

Device: DS216j
DSM Version: DSM 6.2.2-24922 Update 4

Error 119 debug log using cURL (cleared of private data):

[Mon  4 May 10:37:42 CEST 2020] _postContentType='multipart/form-data; boundary=--------------------------20200504083742'
[Mon  4 May 10:37:42 CEST 2020] _CURL='curl -L --silent --dump-header /home/pi/.acme.sh/http.header  --trace-ascii /tmp/tmp.DOAhb8GRzk  -g  --insecure  '
[Mon  4 May 10:37:42 CEST 2020] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 92
[Mon  4 May 10:37:42 CEST 2020] Here is the curl dump log:
[Mon  4 May 10:37:42 CEST 2020] == Info: Expire in 0 ms for 6 (transfer 0x3fa880)
== Info: Expire in 1 ms for 1 (transfer 0x3fa880)
== Info: Expire in 0 ms for 1 (transfer 0x3fa880)
(...)
== Info: Expire in 0 ms for 1 (transfer 0x3fa880)
== Info:   Trying 192.168.222.21...
== Info: TCP_NODELAY set
== Info: Expire in 200 ms for 4 (transfer 0x3fa880)
== Info: Connected to example.com (192.168.222.21) port 443 (#0)
== Info: ALPN, offering h2
== Info: ALPN, offering http/1.1
== Info: successfully set certificate verify locations:
== Info:   CAfile: none
  CApath: /etc/ssl/certs
=> Send SSL data, 5 bytes (0x5)
0000: .....
== Info: TLSv1.3 (OUT), TLS handshake, Client hello (1):
=> Send SSL data, 512 bytes (0x200)
0000: ......x..*79..%.).$.J.G..}...<..&..r.# ......b..j.G>....};...-
0040: O.,.....>.......,.0.........+./...$.(.k.#.'.g.....9.....3.....=.
<= Recv SSL data, 5 bytes (0x5)
0000: ....b
== Info: TLSv1.3 (IN), TLS handshake, Server hello (2):
<= Recv SSL data, 98 bytes (0x62)
0000: ...^../*.-.....Y.J.......C3]n~........ ..1.!.$..Nz.M.}d...lH...<
0040: .pY}..../.......................h2
<= Recv SSL data, 5 bytes (0x5)
0000: ....(
== Info: TLSv1.2 (IN), TLS handshake, Certificate (11):
<= Recv SSL data, 808 bytes (0x328)
0000: ...$..!...0...0.......|..{My.0...*.H........0Q1.0...U....TW1.0..
0040: .U....Taipei1.0...U....Synology Inc.1.0...U....Synology Inc. CA0
0080: ...200503181130Z..400119181130Z0M1.0...U....TW1.0...U....Taipei1
00c0: .0...U....Synology Inc.1.0...U....synology.com0.."0...*.H.......
0100: ......0..............K.u.v..^Ht.#..:.4......4.w..;..B.d.......
0140: (.'....W.>..(.........qlD.3.'B....EO3..Y.CvT.....X)i%?GE.DE..c
0180: (.]#........RbSn.hL~....1.A.....;..#....k..F...1....]w.G0.....^.
01c0: .......4X.....*..\.^..b_....5.K..u<s...D.-.....FU....._...V..(..
0200: W=4y.......m.-#.....0...*.H..............^.........e....E..O.MiB
0240: /n.....eC!...p..v.C7G...*n...."..N.|....E.).....s..C..t6.bx;..!.
0280: .(.iy!.*...~_p},{.<.R.........Lm.=mu..Q......U.%+H.)u6...T......
02c0: ..e...........9!..6..2.c.V..o.x..-iN2:.e...`....|.*+k.b..4.nc+..
0300: =........t.....h.....X..`xD.....q....*D6
<= Recv SSL data, 5 bytes (0x5)
0000: ....M
== Info: TLSv1.2 (IN), TLS handshake, Server key exchange (12):
<= Recv SSL data, 333 bytes (0x14d)
0000: ...I...A...1...E.sNL..,8.5.....\l.ui.3. q.F..9E.3y1C.....}..3...
0040: ....... .......N$.?./.y5.......> ....e..b..}Cc....:..3.....@....
0080: ..%D.]...{.....V.......H!...#M". ...y.4.<..|.2.i^...;'J..UW..M
00c0: y......4..1..)T.dS.&...=....I..c@W....sM....N.|.$U$.B'.M........
0100: .K..@.......z.|6G...d~..Un......=.....9..Fk........W...s.r{...W.
0140: P..O.u2....MD
<= Recv SSL data, 5 bytes (0x5)
0000: .....
== Info: TLSv1.2 (IN), TLS handshake, Server finished (14):
<= Recv SSL data, 4 bytes (0x4)
0000: ....
=> Send SSL data, 5 bytes (0x5)
0000: ....F
== Info: TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
=> Send SSL data, 70 bytes (0x46)
0000: ...BA..*~b.#.}>i.....?..G..Y.*....l.3..'..T...l6.h.&../..@.I...@
0040: {}.=.E
=> Send SSL data, 5 bytes (0x5)
0000: .....
== Info: TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
=> Send SSL data, 1 bytes (0x1)
0000: .
=> Send SSL data, 5 bytes (0x5)
0000: ....(
== Info: TLSv1.2 (OUT), TLS handshake, Finished (20):
=> Send SSL data, 16 bytes (0x10)
0000: ........=.b....w
<= Recv SSL data, 5 bytes (0x5)
0000: .....
<= Recv SSL data, 5 bytes (0x5)
0000: ....(
== Info: TLSv1.2 (IN), TLS handshake, Finished (20):
<= Recv SSL data, 16 bytes (0x10)
0000: .....%..S.......
== Info: SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
== Info: ALPN, server accepted to use h2
== Info: Server certificate:
== Info:  subject: C=TW; L=Taipei; O=Synology Inc.; CN=synology.com
== Info:  start date: May  3 18:11:30 2020 GMT
== Info:  expire date: Jan 19 18:11:30 2040 GMT
== Info:  issuer: C=TW; L=Taipei; O=Synology Inc.; CN=Synology Inc. CA
== Info:  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
== Info: Using HTTP2, server supports multi-use
== Info: Connection state changed (HTTP/2 confirmed)
== Info: Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
=> Send SSL data, 5 bytes (0x5)
0000: ....0
=> Send SSL data, 5 bytes (0x5)
0000: ....3
=> Send SSL data, 5 bytes (0x5)
0000: ....%
== Info: Using Stream ID: 1 (easy handle 0x3fa880)
=> Send SSL data, 5 bytes (0x5)
0000: .....
=> Send header, 375 bytes (0x177)
0000: POST /webapi/entry.cgi?api=SYNO.Core.Certificate&method=import&v
0040: ersion=1&SynoToken=ObIUVFgjj3w66 HTTP/2
0069: Host: example.com:port
008b: User-Agent: acme.sh/2.8.6 (https://github.com/acmesh-official/ac
00cb: me.sh)
00d3: Accept: */*
00e0: Content-Type: multipart/form-data; boundary=--------------------
0120: ------20200504083742
0136: Cookie: ;
0142: X-SYNO-TOKEN: ObIUVFgjj3w66
015f: Content-Length: 6185
0175:
<= Recv SSL data, 5 bytes (0x5)
0000: ....@
== Info: Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
=> Send SSL data, 5 bytes (0x5)
0000: ....!
=> Send SSL data, 5 bytes (0x5)
0000: ....J
=> Send data, 6185 bytes (0x1829)
0000: ----------------------------20200504083742
002c: Content-Disposition: form-data; name="key"; filename="my.key"
007e: Content-Type: application/octet-stream
00a6:
00a8: -----BEGIN RSA PRIVATE KEY----------END RSA PRIVAT
0728: E KEY-----.
0735: ----------------------------20200504083742
0761: Content-Disposition: form-data; name="cert"; filename="my.cer"
07b4: Content-Type: application/octet-stream
07dc:
07de: -----BEGIN CERTIFICATE----------END C
0f9e: ERTIFICATE-----.
0fb0: ----------------------------20200504083742
0fdc: Content-Disposition: form-data; name="inter_cert"; filename="ca.
101c: cer"
1022: Content-Type: application/octet-stream
104a:
104c: .-----BEGIN CERTIFICATE----------END CERTIFICATE-----.
16be: ----------------------------20200504083742
16ea: Content-Disposition: form-data; name="id"
1715:
1717:
1719: ----------------------------20200504083742
1745: Content-Disposition: form-data; name="desc"
1772:
1774: acme.sh certificate
1793: ----------------------------20200504083742
17bf: Content-Disposition: form-data; name="as_default"
17f2:
17f4: false
17fb: ----------------------------20200504083742--
== Info: We are completely uploaded and fine
<= Recv SSL data, 5 bytes (0x5)
0000: ....!
<= Recv SSL data, 5 bytes (0x5)
0000: ....O
<= Recv header, 13 bytes (0xd)
0000: HTTP/2 200
<= Recv header, 15 bytes (0xf)
0000: server: nginx
<= Recv header, 37 bytes (0x25)
0000: date: Mon, 04 May 2020 08:37:42 GMT
<= Recv header, 43 bytes (0x2b)
0000: content-type: text/plain; charset="UTF-8"
<= Recv header, 23 bytes (0x17)
0000: vary: Accept-Encoding
<= Recv header, 25 bytes (0x19)
0000: x-request-error: unauth
<= Recv header, 33 bytes (0x21)
0000: x-content-type-options: nosniff
<= Recv header, 33 bytes (0x21)
0000: x-xss-protection: 1; mode=block
<= Recv header, 63 bytes (0x3f)
0000: cache-control: max-age=0, no-cache, no-store, must-revalidate
<= Recv header, 18 bytes (0x12)
0000: pragma: no-cache
<= Recv header, 12 bytes (0xc)
0000: expires: 0
<= Recv header, 73 bytes (0x49)
0000: strict-transport-security: max-age=15768000; includeSubdomains;
0040: preload
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 38 bytes (0x26)
0000: {"error":{"code":119},"success":false}
<= Recv SSL data, 5 bytes (0x5)
0000: ....%
== Info: HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2)
== Info: stopped the pause stream!
== Info: Connection #0 to host example.com left intact
[Mon  4 May 10:37:42 CEST 2020] _ret='92'
[Mon  4 May 10:37:42 CEST 2020] Unable to update certificate, error code {"error":{"code":119},"success":false}
[Mon  4 May 10:37:43 CEST 2020] Error deploy for domain:example.com
[Mon  4 May 10:37:43 CEST 2020] Deploy error.

@tresni
Copy link
Contributor Author

tresni commented May 16, 2020

I've fixed the URL encoding issue for passwords, I'll open a PR for that shortly. I have confirmed there appears to be an issue using wget. Comparing differences between wget and curl now.

@tresni
Copy link
Contributor Author

tresni commented May 16, 2020

@JoJota and @tatablack both of your issues should be fixed by #2935 . Thank you for the reports. @JoJota I'm not entirely sure but I believe this is actually the same issue that is causing wget to fail all the time. curl always worked for me, but looking at the code and digging through everything it looks like it should have been failing with the 119 error. (That error is not actually defined but it appears to be the id cookie is missing.) Anyway, should be resolved, please let me know if you continue to have any issues.

@ghost
Copy link

ghost commented May 22, 2020

The Synology DSM deploy hook feature is broken - on master and dev branches.

The script does not detect or read exported SYNO_Create variable/data. Only when it is added to the synology_dsm.sh script are you able to progress up to the deployment function which after authentication and reading of cert data fails to add and apply the Let's Encrypt cert.

[Fri May 22 18:49:39 +03 2020] _postContentType='multipart/form-data; boundary=--------------------------20200522154939'
[Fri May 22 18:49:39 +03 2020] _CURL='curl -L --silent --dump-header /root/.acme.sh/http.header  --trace-ascii /tmp/tmp.liqxVE82'
[Fri May 22 18:49:39 +03 2020] _ret='0'
[Fri May 22 18:49:39 +03 2020] Unable to update certificate, error code {"error":{"code":5529},"success":false}
[Fri May 22 18:49:39 +03 2020] Error deploy for domain:xxx.xxxxxxx.xxx
[Fri May 22 18:49:39 +03 2020] Deploy error.

Note: xxx.xxxxxxx.xxx replaces actual cert domain

There's also the issue of the missing sudo command which is not mentioned in the wiki - https://github.com/acmesh-official/acme.sh/wiki/Synology-NAS-Guide

No issues to report with the issuance of Let's Encrypt certs, acme.sh itself or other exported variables ie. CERT_DOMAIN

@tresni
Copy link
Contributor Author

tresni commented May 22, 2020

@atam1 Please give some additional information. Are you attempting to run this on Synology NAS device or from a remote computer? If on a Synology NAS, what device and what version of DSM? I've just tested from my personal machine to a virtualized DS3615xs running DSM 6.1.7 with no issues (only the domain has been changed.)

With latest dev:

 bash-5.0$ ./acme.sh --test -d example.com --deploy --deploy-hook synology_dsm
[Fri May 22 10:34:34 MDT 2020] Using stage ACME_DIRECTORY: https://acme-staging-v02.api.letsencrypt.org/directory
[Fri May 22 10:34:34 MDT 2020] Logging into localhost:5000
[Fri May 22 10:34:35 MDT 2020] Getting certificates in Synology DSM
[Fri May 22 10:34:35 MDT 2020] Unable to find certificate: What In The World and $SYNO_Create is not set
[Fri May 22 10:34:35 MDT 2020] Error deploy for domain:example.com
[Fri May 22 10:34:35 MDT 2020] Deploy error.
bash-5.0$ SYNO_Create=1 ./acme.sh --test -d example.com --deploy --deploy-hook synology_dsm
[Fri May 22 10:34:45 MDT 2020] Using stage ACME_DIRECTORY: https://acme-staging-v02.api.letsencrypt.org/directory
[Fri May 22 10:34:45 MDT 2020] Logging into localhost:5000
[Fri May 22 10:34:45 MDT 2020] Getting certificates in Synology DSM
[Fri May 22 10:34:46 MDT 2020] Generate form POST request
[Fri May 22 10:34:46 MDT 2020] Upload certificate to the Synology DSM
[Fri May 22 10:34:46 MDT 2020] http services were NOT restarted
[Fri May 22 10:34:46 MDT 2020] Success

With master:

bash-5.0$ ./acme.sh --test -d example.com --deploy --deploy-hook synology_dsm
[Fri May 22 10:40:56 MDT 2020] Using stage ACME_DIRECTORY: https://acme-staging-v02.api.letsencrypt.org/directory
[Fri May 22 10:40:56 MDT 2020] Logging into localhost:5000
[Fri May 22 10:40:56 MDT 2020] Getting certificates in Synology DSM
/Users/bhartvig/Projects/acme.sh/deploy/synology_dsm.sh: line 113: SYNO_Create: parameter null or not set
[Fri May 22 10:40:56 MDT 2020] Deploy error.
bash-5.0$ SYNO_Create=1 ./acme.sh --test -d example.com --deploy --deploy-hook synology_dsm
[Fri May 22 10:41:04 MDT 2020] Using stage ACME_DIRECTORY: https://acme-staging-v02.api.letsencrypt.org/directory
[Fri May 22 10:41:04 MDT 2020] Logging into localhost:5000
[Fri May 22 10:41:04 MDT 2020] Getting certificates in Synology DSM
[Fri May 22 10:41:04 MDT 2020] Generate form POST request
[Fri May 22 10:41:04 MDT 2020] Upload certificate to the Synology DSM
[Fri May 22 10:41:04 MDT 2020] http services were NOT restarted
[Fri May 22 10:41:04 MDT 2020] Success

Additionally, the hook does not use sudo, so I'm not sure what you mean by "missing sudo command" at all.

@tresni
Copy link
Contributor Author

tresni commented May 22, 2020

I just tested master on the same virtual machine (DS3615sx running DSM 6.1.7) and had no issues:

tresni@testdsm:/$ sudo -i

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

Password:
root@testdsm:~# wget https://github.com/Neilpang/acme.sh/archive/master.tar.gz
--2020-05-22 09:49:18--  https://github.com/Neilpang/acme.sh/archive/master.tar.gz
Resolving github.com... 140.82.113.4
Connecting to github.com|140.82.113.4|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://github.com/acmesh-official/acme.sh/archive/master.tar.gz [following]
--2020-05-22 09:49:18--  https://github.com/acmesh-official/acme.sh/archive/master.tar.gz
Reusing existing connection to github.com:443.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/acmesh-official/acme.sh/tar.gz/master [following]
--2020-05-22 09:49:18--  https://codeload.github.com/acmesh-official/acme.sh/tar.gz/master
Resolving codeload.github.com... 140.82.113.10
Connecting to codeload.github.com|140.82.113.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 193181 (189K) [application/x-gzip]
Saving to: 'master.tar.gz'

100%[====================================================================================================================>] 193,181      753KB/s   in 0.3s

2020-05-22 09:49:19 (753 KB/s) - 'master.tar.gz' saved [193181/193181]

root@testdsm:~# tar xvf master.tar.gz
[trimmed]
root@testdsm:~# cd acme.sh-master/
root@testdsm:~/acme.sh-master# ./acme.sh --install --nocron --home /usr/local/share/acme.sh --accountemail "brian.andrew@brianandjenny.com"
[Fri May 22 09:49:59 MST 2020] It is recommended to install socat first.
[Fri May 22 09:49:59 MST 2020] We use socat for standalone server if you use standalone mode.
[Fri May 22 09:49:59 MST 2020] If you don't use standalone mode, just ignore this warning.
[Fri May 22 09:49:59 MST 2020] Installing to /usr/local/share/acme.sh
[Fri May 22 09:49:59 MST 2020] Installed to /usr/local/share/acme.sh/acme.sh
[Fri May 22 09:49:59 MST 2020] Installing alias to '/root/.profile'
[Fri May 22 09:49:59 MST 2020] OK, Close and reopen your terminal to start using acme.sh
[Fri May 22 09:50:00 MST 2020] Good, bash is found, so change the shebang to use bash as preferred.
[Fri May 22 09:50:00 MST 2020] OK
root@testdsm:~/acme.sh-master# cd /usr/local/share/acme.sh
root@testdsm:/usr/local/share/acme.sh# export HE_Username=[USERNAME]
root@testdsm:/usr/local/share/acme.sh# export HE_Password=[PASSWORD]
root@testdsm:/usr/local/share/acme.sh# export SYNO_Username=[USERNAME]
root@testdsm:/usr/local/share/acme.sh# export SYNO_Password=[PASSWORD]
root@testdsm:/usr/local/share/acme.sh# . acme.sh.env
root@testdsm:/usr/local/share/acme.sh# acme.sh --test --issue -d example.com --dns dns_he
It seems that you are using sudo, please read this link first:
https://github.com/acmesh-official/acme.sh/wiki/sudo
root@testdsm:/usr/local/share/acme.sh# exit
logout
tresni@testdsm:/$ sudo su
ash-4.3# cd /usr/local/share/acme.sh
ash-4.3# . acme.sh.env
ash-4.3# export HE_Username=[USERNAME]
ash-4.3# export HE_Password=[PASSWORD]
ash-4.3# export SYNO_Username=[USERNAME]
ash-4.3# export SYNO_Password=[PASSWORD]
ash-4.3# export SYNO_Certificate="This is a test"
ash-4.3# acme.sh --test --issue -d example.com --dns dns_he
[Fri May 22 09:55:05 MST 2020] Using stage ACME_DIRECTORY: https://acme-staging-v02.api.letsencrypt.org/directory
[Fri May 22 09:55:06 MST 2020] Single domain='example.com'
[Fri May 22 09:55:06 MST 2020] Getting domain auth token for each domain
[Fri May 22 09:55:07 MST 2020] Getting webroot for domain='example.com'
[Fri May 22 09:55:07 MST 2020] Adding txt value: kdSTp4Gi5_88zn6WQFSUe9kxv1tlSQGpJzzkpkonbgk for domain:  _acme-challenge.example.com
[Fri May 22 09:55:07 MST 2020] Using DNS-01 Hurricane Electric hook
[Fri May 22 09:55:08 MST 2020] TXT record added successfully.
[Fri May 22 09:55:08 MST 2020] The txt record is added: Success.
[Fri May 22 09:55:08 MST 2020] Let's check each dns records now. Sleep 20 seconds first.
[Fri May 22 09:55:29 MST 2020] Checking example.com for _acme-challenge.example.com
[Fri May 22 09:55:29 MST 2020] Domain example.com '_acme-challenge.example.com' success.
[Fri May 22 09:55:29 MST 2020] All success, let's return
[Fri May 22 09:55:29 MST 2020] Verifying: example.com
[Fri May 22 09:55:32 MST 2020] Success
[Fri May 22 09:55:32 MST 2020] Removing DNS records.
[Fri May 22 09:55:32 MST 2020] Removing txt: kdSTp4Gi5_88zn6WQFSUe9kxv1tlSQGpJzzkpkonbgk for domain: _acme-challenge.example.com
[Fri May 22 09:55:32 MST 2020] Cleaning up after DNS-01 Hurricane Electric hook
[Fri May 22 09:55:33 MST 2020] Record removed successfully.
[Fri May 22 09:55:33 MST 2020] Removed: Success
[Fri May 22 09:55:33 MST 2020] Verify finished, start to sign.
[REMOVED LINKS TO CERT]
[Fri May 22 09:55:34 MST 2020] Cert success.
-----BEGIN CERTIFICATE-----
[TRIMMED]
-----END CERTIFICATE-----
[Fri May 22 09:55:34 MST 2020] Your cert is in  /usr/local/share/acme.sh/example.com/example.com.cer
[Fri May 22 09:55:34 MST 2020] Your cert key is in  /usr/local/share/acme.sh/example.com/example.com.key
[Fri May 22 09:55:34 MST 2020] The intermediate CA cert is in  /usr/local/share/acme.sh/example.com/ca.cer
[Fri May 22 09:55:34 MST 2020] And the full chain certs is there:  /usr/local/share/acme.sh/example.com/fullchain.cer
ash-4.3# acme.sh --test -d example.com --deploy --deploy-hook synology_dsm
[Fri May 22 09:56:16 MST 2020] Using stage ACME_DIRECTORY: https://acme-staging-v02.api.letsencrypt.org/directory
[Fri May 22 09:56:16 MST 2020] Logging into localhost:5000
[Fri May 22 09:56:16 MST 2020] Getting certificates in Synology DSM
/usr/local/share/acme.sh/deploy/synology_dsm.sh: line 113: SYNO_Create: parameter null or not set
[Fri May 22 09:56:16 MST 2020] Deploy error.
ash-4.3# SYNO_Create=1 acme.sh --test -d example.com --deploy --deploy-hook synology_dsm
[Fri May 22 09:56:30 MST 2020] Using stage ACME_DIRECTORY: https://acme-staging-v02.api.letsencrypt.org/directory
[Fri May 22 09:56:30 MST 2020] Logging into localhost:5000
[Fri May 22 09:56:30 MST 2020] Getting certificates in Synology DSM
[Fri May 22 09:56:31 MST 2020] Generate form POST request
[Fri May 22 09:56:31 MST 2020] Upload certificate to the Synology DSM
[Fri May 22 09:56:31 MST 2020] http services were NOT restarted
[Fri May 22 09:56:31 MST 2020] Success
ash-4.3#

@ghost
Copy link

ghost commented May 22, 2020

@tresni Hi Brian.

Yes, I am connected to the synology box via ssh from my computer (mac pro).

On sudo - if I run the command without sudo:

root@xxxx:/usr/local/share/acme.sh# ./acme.sh --deploy -d "$CERT_DOMAIN" --deploy-hook synology_dsm --ecc --debug 2
It seems that you are using sudo, please read this link first:
https://github.com/acmesh-official/acme.sh/wiki/sudo

The same goes for script installation. Once you execute 'sudo -i' and after entering password you are logged in as root. I did not try to install the script under an administrator account as 'sudo -i' was used in the instructions.

As for SYNO_Create, I just tried executing the same command line you used but with sudo and after exporting SYNO_Unsername, SYNO_Password, CERT_DOMAIN, SYNO_Certificate and the result:

root@xxxx:/usr/local/share/acme.sh# SYNO_Create=1 sudo ./acme.sh --test -d xxx.xxxxxxx.xxx --deploy --deploy-hook synology_dsm --ecc
[Fri May 22 19:59:00 +03 2020] Using stage ACME_DIRECTORY: https://acme-staging-v02.api.letsencrypt.org/directory
[Fri May 22 19:59:00 +03 2020] Logging into xxx.xxxxxxx.xxx:14080
[Fri May 22 19:59:01 +03 2020] Getting certificates in Synology DSM
[Fri May 22 19:59:01 +03 2020] Unable to find certificate:  and $SYNO_Create is not set
[Fri May 22 19:59:01 +03 2020] Error deploy for domain:xxx.xxxxxxx.xxx
[Fri May 22 19:59:01 +03 2020] Deploy error.

acme.sh created and installed the cert and its files to /root/.acme.sh/xxx.xxxxxxx.xxx_ecc/

Also, another issue I had with the master branch was SYNO_Scheme, SYNO_Hostname, SYNO_Port were not being picked up by the deployment script so I manually saved them in /root/.acme.sh/xxx.xxxxxxx.xxx_ecc/xxx.xxxxxxx.xxx.conf ... haven't tested dev yet.

@tresni
Copy link
Contributor Author

tresni commented May 22, 2020

On sudo - if I run the command without sudo:

A shell started with sudo -i is detected as using sudo. Doing sudo su is not. YMMV.

As for SYNO_Create, I just tried executing the same command line you used but with sudo and after exporting SYNO_Unsername, SYNO_Password, CERT_DOMAIN, SYNO_Certificate and the result:

The command is incorrect. By doing SYNO_Create=1 sudo you are passing SYNO_Create in the environment to sudo, but it won't (normally) be passed on to the command you are actually running (./acme.sh).

asciicast

If you are going to use sudo, the appropriate command would be sudo SYNO_Create=1 ./acme.sh. Any environmental variables you want to pass need to come after sudo and before the command you want to execute.

Just an additional note that I've update the Synology NAS guide to give steps that work with no workarounds necessary. Please let me know if you have problems after following the steps exactly as outlined there.

@ghost
Copy link

ghost commented May 22, 2020

@tresni Alright. I'm going to start fresh and install after executing sudo su instead of sudo -i and see where that takes me.

Appreciate your help!

Thanks

@ghost
Copy link

ghost commented May 22, 2020

@tresni Hello again Brian.

I gave this another try and had followed the updated wiki. While acme.sh can now be executed without sudo and the deployment script is detecting/reading the data for SYNO_xxxxxx, it's still complaining and failing when deploying the cert to DSM.

ash-4.3# SYNO_Create=1 ./acme.sh --deploy -d xxx.xxxxxxx.xxx --deploy-hook synology_dsm --ecc
[Fri May 22 23:15:37 +03 2020] Logging into xxx.xxxxxxx.xxx:14080
[Fri May 22 23:15:38 +03 2020] Getting certificates in Synology DSM
[Fri May 22 23:15:38 +03 2020] Generate form POST request
[Fri May 22 23:15:38 +03 2020] Upload certificate to the Synology DSM
[Fri May 22 23:15:39 +03 2020] Unable to update certificate, error code {"error":{"code":5529},"success":false}
[Fri May 22 23:15:39 +03 2020] Error deploy for domain:xxx.xxxxxxx.xxx
[Fri May 22 23:15:39 +03 2020] Deploy error.

What else can be causing this?

Thank you!

@ghost
Copy link

ghost commented May 22, 2020

Adding debug output:

[Sat May 23 00:13:16 +03 2020] ./acme.sh:_post:1735                     _postContentType='multipart/form-data; boundary=--------------------------20200522211316'
[Sat May 23 00:13:16 +03 2020] ./acme.sh:_exists:494                    curl exists=0
[Sat May 23 00:13:16 +03 2020] ./acme.sh:_exists:494                    mktemp exists=0
[Sat May 23 00:13:16 +03 2020] ./acme.sh:_exists:494                    wget exists=0
[Sat May 23 00:13:16 +03 2020] ./acme.sh:_post:1747                     _CURL='curl -L --silent --dump-header /root/.acme.sh/http.header  --trace-ascii /tmp/tmp.4U3Sf34XpF  -g '
[Sat May 23 00:13:16 +03 2020] ./acme.sh:_post:1842                     _ret='0'
[Sat May 23 00:13:16 +03 2020] deploy/synology_dsm.sh:synology_dsm_deploy:139 response='{"error":{"code":5529},"success":false}'
[Sat May 23 00:13:16 +03 2020] Unable to update certificate, error code {"error":{"code":5529},"success":false}
[Sat May 23 00:13:16 +03 2020] Error deploy for domain:xxx.xxxxxxx.xxx
[Sat May 23 00:13:16 +03 2020] Deploy error.

Tested with synology_dsm.sh from both master and dev branches

@tresni
Copy link
Contributor Author

tresni commented May 22, 2020

What Synology device are you using? What version of DSM are you using? I can't find error code 5529 defined. The surrounding defined errors that I could find are:

5521:_T("certificate","err_connection"),
5522:_T("certificate","err_server_not_match"),
5523:_T("certificate","err_too_many_reg"),
5524:_T("certificate","err_too_many_req"),
5525:_T("certificate","err_mail"),
5526:_T("s2s","err_invalid_param_value")

I've been able to successfully deploy an ECC certificate as follows (DS3615sx and DSM 6.1.7):

./acme.sh --test --issue -d example.com --dns dns_he --keylength ec-256
./acme.sh --test -d example.com --deploy --deploy-hook synology_dsm --ecc

With the information you've provided, I can't replicate what you are seeing.

@ghost
Copy link

ghost commented May 22, 2020

What Synology device are you using? What version of DSM are you using? I can't find error code 5529 defined. The surrounding defined errors are that I could find are:

918+ with DSM 6.2.3 rel 25426 (latest release)

5521:_T("certificate","err_connection"),
5522:_T("certificate","err_server_not_match"),
5523:_T("certificate","err_too_many_reg"),
5524:_T("certificate","err_too_many_req"),
5525:_T("certificate","err_mail"),
5526:_T("s2s","err_invalid_param_value")

I've been able to successfully deploy an ECC certificate as follows (DS3615sx and DSM 6.1.7):

./acme.sh --test --issue -d example.com --dns dns_he --keylength ec-256
./acme.sh --test -d example.com --deploy --deploy-hook synology_dsm --ecc

With the information you've provided, I can't replicate what you are seeing.

Could the form fields/options have changed between versions as it is failing when uploading the new cert? The error code 5529 is very near to the error codes you posted so I am guessing it has something to do with the cert or its fields.

@tresni
Copy link
Contributor Author

tresni commented May 22, 2020

What Synology device are you using? What version of DSM are you using? I can't find error code 5529 defined. The surrounding defined errors are that I could find are:

918+ with DSM 6.2.3 rel 25426 (latest release)

Unfortunately I am not home to test with my DSM running latest and having trouble getting xpenology to run DSM 6.2 or later on VirtualBox.

Could the form fields/options have changed between versions as it is failing when uploading the new cert? The error code 5529 is very near to the error codes you posted so I am guessing it has something to do with the cert or its fields.

You could check the synoSDSjslib/sds.js file to see if it contains the the string '5529' similar to the ones I posted. Should be available at http://[synology_host]:[synology_port]/synoSDSjslib/sds.js .

@ghost
Copy link

ghost commented May 22, 2020

You could check the synoSDSjslib/sds.js file to see if it contains the the string '5529' similar to the ones I posted. Should be available at http://[synology_host]:[synology_port]/synoSDSjslib/sds.js .

I checked and it's 5529:_T("certificate","not_support_ecc")

How does it not support ecc when with the previous acme/synology method (prior to the dsm deployhook) I was able to create and install ec-256 and ec-384 certs.

@tresni
Copy link
Contributor Author

tresni commented May 22, 2020

I can't answer that as I don't work for Synology. That's a response from their API. Can you add the certificates manually via the DSM webui?

I was able to get something setup to access my DS1515+ at home, it's running DSM 6.2.2 and supports ECC certificates. So either it's something new in 6.2.3 or something specific to the DS918. Reviewing the DS918+ Release Notes, the closest I see is "Added support for Let's Encrypt wildcard certificates for Synology DDNS."

@briped
Copy link

briped commented Feb 25, 2024

Yeah, missed these two debug outputs. Sorry about that, will do a PR to fix them.

You might take a look at --debug 3 as well while at it. There are some outputs there as well, that isn't hidden.

@Eagle3386
Copy link
Contributor

Those outputs are meant to be written.
Only those containing passwords shall be hidden, I expanded that to include the device ID - which is well enough to secure any user from any attack to succeed (at least regarding the login itself)..

@rsporsche
Copy link

rsporsche commented Feb 25, 2024

"--debug 3" outputs the username and password as a hex string

e.g. in Saxfusion's Jan 7 post, line 7 of the log output is username and line 10 is the password.

Might want to change your password @Saxfusion

@Eagle3386
Copy link
Contributor

For the password I'll add that to the list, i.e., I'll fix 3 instead of 2 debug outputs.

However, neither ACME.sh nor this deploy extension ever cared for the username & I don't regard usernames as "sensitive information".

@rsporsche
Copy link

Ok, I mistakenly thought the username was being hidden from the log output as well.

@briped
Copy link

briped commented Feb 25, 2024

As @rsporsche already pointed out, the password is also encoded as an easily decoded hex string. Beyond that the private key should also be hidden, considering that the private key should never be shared.

While I can agree that a username isn't as sensitive as a password, it still does make it easier to figure out what accounts to attack, knowing they have admin privileges to function in their given context. Yes, I've changed the usernames in the logs I've shared here. All relevant sections have been replaced with ##SOMETHING _SHOULD_BE_HIDDEN##

adminuser@dsm:~$ sudo docker exec acme.sh sh -c 'export SYNO_Create=1; acme.sh --deploy --domain sub.domain.top --domain *.sub.domain.top --deploy-hook synology_dsm --debug 3'
Password:
[Sun Feb 25 16:06:20 UTC 2024] readlink exists=0
[Sun Feb 25 16:06:20 UTC 2024] dirname exists=0
[Sun Feb 25 16:06:20 UTC 2024] Lets find script dir.
[Sun Feb 25 16:06:20 UTC 2024] _SCRIPT_='/usr/local/bin/acme.sh'
[Sun Feb 25 16:06:20 UTC 2024] _script='/root/.acme.sh/acme.sh'
[Sun Feb 25 16:06:20 UTC 2024] _script_home='/root/.acme.sh'
[Sun Feb 25 16:06:20 UTC 2024] Using default home:/root/.acme.sh
[Sun Feb 25 16:06:20 UTC 2024] Using config home:/acme.sh
[Sun Feb 25 16:06:20 UTC 2024] ACCOUNT_CONF_PATH='/acme.sh/account.conf'
[Sun Feb 25 16:06:20 UTC 2024] OK
[Sun Feb 25 16:06:20 UTC 2024] 1:AUTO_UPGRADE='1'
[Sun Feb 25 16:06:20 UTC 2024] LE_WORKING_DIR='/root/.acme.sh'
https://github.com/acmesh-official/acme.sh
v3.0.8
[Sun Feb 25 16:06:20 UTC 2024] Running cmd: deploy
[Sun Feb 25 16:06:20 UTC 2024] Using config home:/acme.sh
[Sun Feb 25 16:06:20 UTC 2024] ACCOUNT_CONF_PATH='/acme.sh/account.conf'
[Sun Feb 25 16:06:20 UTC 2024] default_acme_server
[Sun Feb 25 16:06:20 UTC 2024] ACME_DIRECTORY='https://acme.zerossl.com/v2/DV90'
[Sun Feb 25 16:06:20 UTC 2024] _ACME_SERVER_HOST='acme.zerossl.com'
[Sun Feb 25 16:06:20 UTC 2024] _ACME_SERVER_PATH='v2/DV90'
[Sun Feb 25 16:06:20 UTC 2024] CA_CONF='/acme.sh/ca/acme.zerossl.com/v2/DV90/ca.conf'
[Sun Feb 25 16:06:20 UTC 2024] The domain 'sub.domain.top' seems to have a ECC cert already, lets use ecc cert.
[Sun Feb 25 16:06:20 UTC 2024] DOMAIN_PATH='/acme.sh/sub.domain.top_ecc'
[Sun Feb 25 16:06:20 UTC 2024] DOMAIN_CONF='/acme.sh/sub.domain.top_ecc/sub.domain.top.conf'
[Sun Feb 25 16:06:20 UTC 2024] OK
[Sun Feb 25 16:06:20 UTC 2024] 16:Le_DeployHook='synology_dsm,'
[Sun Feb 25 16:06:20 UTC 2024] _deployApi='/root/.acme.sh/deploy/synology_dsm.sh'
[Sun Feb 25 16:06:20 UTC 2024] synology_dsm_deploy exists=0
[Sun Feb 25 16:06:20 UTC 2024] _cdomain='sub.domain.top'
[Sun Feb 25 16:06:20 UTC 2024] SYNO_Username='acmeadmin'
[Sun Feb 25 16:06:20 UTC 2024] SYNO_Password='[hidden](please add '--output-insecure' to see this value)'
[Sun Feb 25 16:06:20 UTC 2024] SYNO_Create='1'
[Sun Feb 25 16:06:20 UTC 2024] SYNO_Device_Name='CertRenewal'
[Sun Feb 25 16:06:20 UTC 2024] SYNO_Device_ID='[hidden](please add '--output-insecure' to see this value)'
[Sun Feb 25 16:06:20 UTC 2024] OK
[Sun Feb 25 16:06:20 UTC 2024] 17:SAVED_SYNO_Scheme='http'
[Sun Feb 25 16:06:20 UTC 2024] OK
[Sun Feb 25 16:06:20 UTC 2024] 18:SAVED_SYNO_Hostname='localhost'
[Sun Feb 25 16:06:20 UTC 2024] OK
[Sun Feb 25 16:06:20 UTC 2024] 19:SAVED_SYNO_Port='5000'
[Sun Feb 25 16:06:21 UTC 2024] SYNO_Scheme='http'
[Sun Feb 25 16:06:21 UTC 2024] SYNO_Hostname='localhost'
[Sun Feb 25 16:06:21 UTC 2024] SYNO_Port='5000'
[Sun Feb 25 16:06:21 UTC 2024] SYNO_Certificate
[Sun Feb 25 16:06:21 UTC 2024] _base_url='http://localhost:5000'
[Sun Feb 25 16:06:21 UTC 2024] Getting API version
[Sun Feb 25 16:06:21 UTC 2024] GET
[Sun Feb 25 16:06:21 UTC 2024] url='http://localhost:5000/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth'
[Sun Feb 25 16:06:21 UTC 2024] timeout=
[Sun Feb 25 16:06:21 UTC 2024] curl exists=0
[Sun Feb 25 16:06:21 UTC 2024] mktemp exists=0
[Sun Feb 25 16:06:21 UTC 2024] wget exists=0
[Sun Feb 25 16:06:21 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header  -L  --trace-ascii /tmp/tmp.YcvaZigaKy  -g '
[Sun Feb 25 16:06:21 UTC 2024] ret='0'
[Sun Feb 25 16:06:21 UTC 2024] response='{"data":{"SYNO.API.Auth":{"maxVersion":7,"minVersion":1,"path":"entry.cgi"}},"success":true}'
[Sun Feb 25 16:06:21 UTC 2024] api_path='entry.cgi'
[Sun Feb 25 16:06:21 UTC 2024] api_version='7'
[Sun Feb 25 16:06:21 UTC 2024] Logging into localhost:5000
[Sun Feb 25 16:06:21 UTC 2024] od exists=0
[Sun Feb 25 16:06:21 UTC 2024] _url_encode
[Sun Feb 25 16:06:21 UTC 2024] _hex_str=' 61 63 6d 65 61 64 6d 69 6e'
[Sun Feb 25 16:06:21 UTC 2024] od exists=0
[Sun Feb 25 16:06:21 UTC 2024] _url_encode
[Sun Feb 25 16:06:21 UTC 2024] _hex_str='##HEX_ENCODED_SYNO_PASSWORD_SHOULD_BE_HIDDEN##'
[Sun Feb 25 16:06:21 UTC 2024] GET
[Sun Feb 25 16:06:21 UTC 2024] url='http://localhost:5000/webapi/entry.cgi?api=SYNO.API.Auth&version=7&method=login&format=sid&account=acmeadmin&passwd=##SYNO_PASSWORD_SHOULD_BE_HIDDEN##&enable_syno_token=yes&device_name=CertRenewal&device_id=##SYNO_DEVICEID_SHOULD_BE_HIDDEN##'
[Sun Feb 25 16:06:21 UTC 2024] timeout=
[Sun Feb 25 16:06:21 UTC 2024] curl exists=0
[Sun Feb 25 16:06:21 UTC 2024] mktemp exists=0
[Sun Feb 25 16:06:21 UTC 2024] wget exists=0
[Sun Feb 25 16:06:21 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header  -L  --trace-ascii /tmp/tmp.6Sz2brSbto  -g '
[Sun Feb 25 16:06:23 UTC 2024] ret='0'
[Sun Feb 25 16:06:23 UTC 2024] response='{"data":{"account":"acmeadmin","device_id":"##SYNO_DEVICEID_SHOULD_BE_HIDDEN##","ik_message":"","is_portal_port":false,"sid":"##REDACTED##","synotoken":"##REDACTED##"},"success":true}'
[Sun Feb 25 16:06:23 UTC 2024] Session ID='##REDACTED##'
[Sun Feb 25 16:06:23 UTC 2024] SynoToken='##REDACTED##'
[Sun Feb 25 16:06:23 UTC 2024] H1='X-SYNO-TOKEN: ##REDACTED##'
[Sun Feb 25 16:06:23 UTC 2024] OK
[Sun Feb 25 16:06:23 UTC 2024] 20:SAVED_SYNO_Username='acmeadmin'
[Sun Feb 25 16:06:23 UTC 2024] OK
[Sun Feb 25 16:06:23 UTC 2024] 21:SAVED_SYNO_Password='##SYNO_PASSWORD_SHOULD_BE_HIDDEN##'
[Sun Feb 25 16:06:23 UTC 2024] OK
[Sun Feb 25 16:06:23 UTC 2024] 22:SAVED_SYNO_Device_Name='CertRenewal'
[Sun Feb 25 16:06:23 UTC 2024] OK
[Sun Feb 25 16:06:23 UTC 2024] 23:SAVED_SYNO_Device_ID='##SYNO_DEVICEID_SHOULD_BE_HIDDEN##'
[Sun Feb 25 16:06:23 UTC 2024] Getting certificates in Synology DSM
[Sun Feb 25 16:06:23 UTC 2024] POST
[Sun Feb 25 16:06:23 UTC 2024] _post_url='http://localhost:5000/webapi/entry.cgi'
[Sun Feb 25 16:06:23 UTC 2024] body='api=SYNO.Core.Certificate.CRT&method=list&version=1&_sid=##REDACTED##'
[Sun Feb 25 16:06:23 UTC 2024] _postContentType
[Sun Feb 25 16:06:23 UTC 2024] curl exists=0
[Sun Feb 25 16:06:23 UTC 2024] mktemp exists=0
[Sun Feb 25 16:06:23 UTC 2024] wget exists=0
[Sun Feb 25 16:06:23 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header  -L  --trace-ascii /tmp/tmp.a08s7C82R6  -g '
[Sun Feb 25 16:06:23 UTC 2024] _ret='0'
[Sun Feb 25 16:06:23 UTC 2024] response='{"error":{"code":105},"success":false}'
[Sun Feb 25 16:06:23 UTC 2024] escaped_certificate
[Sun Feb 25 16:06:23 UTC 2024] id
[Sun Feb 25 16:06:23 UTC 2024] OK
[Sun Feb 25 16:06:23 UTC 2024] 24:SAVED_SYNO_Certificate=''
[Sun Feb 25 16:06:23 UTC 2024] Generate form POST request
[Sun Feb 25 16:06:23 UTC 2024] default='This is NOT the default certificate'
[Sun Feb 25 16:06:23 UTC 2024] Upload certificate to the Synology DSM
[Sun Feb 25 16:06:23 UTC 2024] POST
[Sun Feb 25 16:06:23 UTC 2024] _post_url='http://localhost:5000/webapi/entry.cgi?api=SYNO.Core.Certificate&method=import&version=1&SynoToken=##REDACTED##&_sid=##REDACTED##'
[Sun Feb 25 16:06:24 UTC 2024] body='----------------------------20240225160623
Content-Disposition: form-data; name="key"; filename="sub.domain.top.key"
Content-Type: application/octet-stream

-----BEGIN EC PRIVATE KEY-----
##PRIVATE_KEY_SHOULD_BE_HIDDEN##
-----END EC PRIVATE KEY-----

----------------------------20240225160623
Content-Disposition: form-data; name="cert"; filename="sub.domain.top.cer"
Content-Type: application/octet-stream

-----BEGIN CERTIFICATE-----
##REDACTED##
-----END CERTIFICATE-----

----------------------------20240225160623
Content-Disposition: form-data; name="inter_cert"; filename="ca.cer"
Content-Type: application/octet-stream


-----BEGIN CERTIFICATE-----
MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMjAwOTA0MDAwMDAw
WhcNMjUwOTE1MTYwMDAwWjAyMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg
RW5jcnlwdDELMAkGA1UEAxMCUjMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
AoIBAQC7AhUozPaglNMPEuyNVZLD+ILxmaZ6QoinXSaqtSu5xUyxr45r+XXIo9cP
R5QUVTVXjJ6oojkZ9YI8QqlObvU7wy7bjcCwXPNZOOftz2nwWgsbvsCUJCWH+jdx
sxPnHKzhm+/b5DtFUkWWqcFTzjTIUu61ru2P3mBw4qVUq7ZtDpelQDRrK9O8Zutm
NHz6a4uPVymZ+DAXXbpyb/uBxa3Shlg9F8fnCbvxK/eG3MHacV3URuPMrSXBiLxg
Z3Vms/EY96Jc5lP/Ooi2R6X/ExjqmAl3P51T+c8B5fWmcBcUr2Ok/5mzk53cU6cG
/kiFHaFpriV1uxPMUgP17VGhi9sVAgMBAAGjggEIMIIBBDAOBgNVHQ8BAf8EBAMC
AYYwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMBIGA1UdEwEB/wQIMAYB
Af8CAQAwHQYDVR0OBBYEFBQusxe3WFbLrlAJQOYfr52LFMLGMB8GA1UdIwQYMBaA
FHm0WeZ7tuXkAXOACIjIGlj26ZtuMDIGCCsGAQUFBwEBBCYwJDAiBggrBgEFBQcw
AoYWaHR0cDovL3gxLmkubGVuY3Iub3JnLzAnBgNVHR8EIDAeMBygGqAYhhZodHRw
Oi8veDEuYy5sZW5jci5vcmcvMCIGA1UdIAQbMBkwCAYGZ4EMAQIBMA0GCysGAQQB
gt8TAQEBMA0GCSqGSIb3DQEBCwUAA4ICAQCFyk5HPqP3hUSFvNVneLKYY611TR6W
PTNlclQtgaDqw+34IL9fzLdwALduO/ZelN7kIJ+m74uyA+eitRY8kc607TkC53wl
ikfmZW4/RvTZ8M6UK+5UzhK8jCdLuMGYL6KvzXGRSgi3yLgjewQtCPkIVz6D2QQz
CkcheAmCJ8MqyJu5zlzyZMjAvnnAT45tRAxekrsu94sQ4egdRCnbWSDtY7kh+BIm
lJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML+Hbisq/yFOGwXD9RiX8F6sw6W4
avAuvDszue5L3sz85K+EC4Y/wFVDNvZo4TYXao6Z0f+lQKc0t8DQYzk1OXVu8rp2
yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1O
yK5GhDDX8oVfGKF5u+decIsH4YaTw7mP3GFxJSqv3+0lUFJoi5Lc5da149p90Ids
hCExroL1+7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0+L4WPlbuEjN/lxPFin+
HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6Zv
MldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqX
nLRbwHOoq7hHwg==
-----END CERTIFICATE-----

----------------------------20240225160623
Content-Disposition: form-data; name="id"


----------------------------20240225160623
Content-Disposition: form-data; name="desc"


----------------------------20240225160623--
'
[Sun Feb 25 16:06:24 UTC 2024] _postContentType='multipart/form-data; boundary=--------------------------20240225160623'
[Sun Feb 25 16:06:24 UTC 2024] curl exists=0
[Sun Feb 25 16:06:24 UTC 2024] mktemp exists=0
[Sun Feb 25 16:06:24 UTC 2024] wget exists=0
[Sun Feb 25 16:06:24 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header  -L  --trace-ascii /tmp/tmp.BkQRSW4Wi8  -g '
[Sun Feb 25 16:06:24 UTC 2024] _ret='0'
[Sun Feb 25 16:06:24 UTC 2024] response='{"error":{"code":105},"success":false}'
[Sun Feb 25 16:06:24 UTC 2024] Unable to update certificate, error code {"error":{"code":105},"success":false}
[Sun Feb 25 16:06:24 UTC 2024] GET
[Sun Feb 25 16:06:24 UTC 2024] url='http://localhost:5000/webapi/entry.cgi?api=SYNO.API.Auth&version=7&method=logout&_sid=##REDACTED##'
[Sun Feb 25 16:06:24 UTC 2024] timeout=
[Sun Feb 25 16:06:24 UTC 2024] curl exists=0
[Sun Feb 25 16:06:24 UTC 2024] mktemp exists=0
[Sun Feb 25 16:06:24 UTC 2024] wget exists=0
[Sun Feb 25 16:06:24 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header  -L  --trace-ascii /tmp/tmp.n6cLnxL7Il  -g '
[Sun Feb 25 16:06:28 UTC 2024] ret='0'
[Sun Feb 25 16:06:28 UTC 2024] response='{"success":true}'
[Sun Feb 25 16:06:28 UTC 2024] Error deploy for domain:sub.domain.top
[Sun Feb 25 16:06:28 UTC 2024] Deploy error.

@Eagle3386
Copy link
Contributor

@briped & @rsporsche:

Had a look at it & regarding:

As @rsporsche already pointed out, the password is also encoded as an easily decoded hex string. Beyond that the private key should also be hidden, considering that the private key should never be shared.

it's non of this deploy script's business - see:

encoded_username="$(printf "%s" "$SYNO_Username" | _url_encode)"
encoded_password="$(printf "%s" "$SYNO_Password" | _url_encode)"

That _url_encode function is provided by ACME.sh, hence it needs to be fixed there.
But that in turn isn't really possible, because you do want debug output of that function in general as it's used for several URL encodings elsewhere.

The same applies for the criticized debug output of both, actual login URL & saved deploy config which use ACME.sh's _get & _savedeployconf respectively - it's up to NeilPang to fix those functions in order to hide such sensitive data.

Until then, it basically remains up to the user pasting a log to properly review & occasionally redact any sensitive data that's still in the log.

However, due to lowering the debug level for api_path & ap_version from 2 to 3 as well as switching to _secure_debug3 for both, legacy & new login request's response, future debug logs can now be limited to the lower level.
This at least hinders output of the device ID while at the same time keeps providing necessary debug information.

Lastly, your aforementioned criticized log part:

body='api=SYNO.Core.Certificate.CRT&method=list&version=1&_sid=##APPARENTLY_UNHIDDEN_SYNO_DEVICE_ID_EVEN_THOUGH_OUTPUT-INSECURE_IS_NOT_ENABLED##'

simply contains no sensitive data. Especially since my initial code change introduced required usage of SynoToken for any subsequent request - which makes it impossible to hijack a user's session, hence printing the session ID in debug scenarios (!) is just fine.

It remains up to NeilPang for when he approves PR #5030 - so, don't complain to me, please. 😉

@aaplmike
Copy link

aaplmike commented Mar 2, 2024

The deploy command does not appear to honor SYNO_CREATE. I've set it via 'export SYNO_CREATE=1', but the script does not pick it up. Even if I set SYNO_CREATE before the deploy call I get:

SYNO_CREATE=1 /root/acme.sh/acme.sh --deploy -d mydomain.com --deploy-hook synology_dsm --debug 2

...
[Sat Mar 2 16:12:46 UTC 2024] Unable to find certificate: and $SYNO_Create is not set
[Sat Mar 2 16:12:46 UTC 2024] Error deploy for domain:mydomain.com
[Sat Mar 2 16:12:46 UTC 2024] Deploy error.

What does work is when I add SYNO_CREATE=1 on line 142, right before:

if [ -z "$id" ] && [ -z "${SYNO_Create:-}" ]; then

[Sat Mar 2 16:27:25 UTC 2024] http services were NOT restarted
[Sat Mar 2 16:27:25 UTC 2024] Success

@m33ts4k0z
Copy link

The deploy command does not appear to honor SYNO_CREATE. I've set it via 'export SYNO_CREATE=1', but the script does not pick it up. Even if I set SYNO_CREATE before the deploy call I get:

SYNO_CREATE=1 /root/acme.sh/acme.sh --deploy -d mydomain.com --deploy-hook synology_dsm --debug 2

... [Sat Mar 2 16:12:46 UTC 2024] Unable to find certificate: and $SYNO_Create is not set [Sat Mar 2 16:12:46 UTC 2024] Error deploy for domain:mydomain.com [Sat Mar 2 16:12:46 UTC 2024] Deploy error.

What does work is when I add SYNO_CREATE=1 on line 142, right before:

if [ -z "$id" ] && [ -z "${SYNO_Create:-}" ]; then

[Sat Mar 2 16:27:25 UTC 2024] http services were NOT restarted [Sat Mar 2 16:27:25 UTC 2024] Success

Check your case. You have a case missmatch in the variable name.

@Saxfusion
Copy link

I did trash my docker container setup and installed again locally /usr/local/share/acme.sh
Kind of contradicting the wish (and step to the acme.sh container) to become immune to problems caused by DSM Updates. But temp admin and container .. just did not work at all.
Also see #5019

Trying to use the temp admin which is created and being deleted just fine. Only the login and deploy is failing somehow.

deploy/synology_dsm.sh:synology_dsm_deploy:155 response='{"error":{"code":406,"errors":{"is_admin":true,"is_ldap":false,"token":"******"}},"success":false}'

Any ideas?

@scruel
Copy link
Contributor

scruel commented Apr 20, 2024

@Saxfusion Try to use the latest patched version, just download and replace the old synology_dsm.sh (wiki already been updated): https://github.com/acmesh-official/acme.sh/blob/6af52933155c913d236f5be7bc1c5d4eccf05887/deploy/synology_dsm.sh
If you still can't deploy successfully, paste the full debug log here, so I may know why.

@Saxfusion
Copy link

@scruel that is working. Suspecting the enforce 2FA for admin group setting, which is temporarily disabled in this patched version, did make the difference.

@Mic13710
Copy link

Mic13710 commented Apr 25, 2024

Hello,
I have a DS220+ with two domains. Certificates are renewed via acme.sh
As it happens time to time, the deployment of the certificates fails. To solve that, I have a task I run manually and the problem is solved.
My certificates were renewed few days ago, but not deployed. So I have tried to run the task but it failed again and again.
Looking at the log, I have the following for one domain (the other has similar records) :

[Thu Apr 25 10:21:13 UTC 2024] Running cmd: deploy
[Thu Apr 25 10:21:13 UTC 2024] Using config home:/acme.sh
[Thu Apr 25 10:21:13 UTC 2024] default_acme_server
[Thu Apr 25 10:21:13 UTC 2024] ACME_DIRECTORY='https://acme.zerossl.com/v2/DV90'
[Thu Apr 25 10:21:13 UTC 2024] DOMAIN_PATH='/acme.sh/myndd'
[Thu Apr 25 10:21:13 UTC 2024] _deployApi='/root/.acme.sh/deploy/synology_dsm.sh'
[Thu Apr 25 10:21:13 UTC 2024] _cdomain='myndd'
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Username has been migrated to SAVED_SYNO_USERNAME.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Password has been migrated to SAVED_SYNO_PASSWORD.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Device_ID has been migrated to SAVED_SYNO_DEVICE_ID.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Device_Name has been migrated to SAVED_SYNO_DEVICE_NAME.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Scheme has been migrated to SAVED_SYNO_SCHEME.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Hostname has been migrated to SAVED_SYNO_HOSTNAME.
[Thu Apr 25 10:21:14 UTC 2024] Domain config SAVED_SYNO_Port has been migrated to SAVED_SYNO_PORT.
[Thu Apr 25 10:21:14 UTC 2024] Domain config SAVED_SYNO_Certificate has been migrated to SAVED_SYNO_CERTIFICATE.
[Thu Apr 25 10:21:14 UTC 2024] SYNO_CERTIFICATE='name of myndd'
[Thu Apr 25 10:21:14 UTC 2024] Getting API version...
[Thu Apr 25 10:21:14 UTC 2024] _base_url='http://172.17.0.1:5000'
[Thu Apr 25 10:21:14 UTC 2024] GET
[Thu Apr 25 10:21:14 UTC 2024] url='http://172.17.0.1:5000/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth'
[Thu Apr 25 10:21:14 UTC 2024] timeout=
[Thu Apr 25 10:21:14 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header -L -g '
[Thu Apr 25 10:21:14 UTC 2024] ret='0'
[Thu Apr 25 10:21:14 UTC 2024] Logging into 172.17.0.1:5000...
[Thu Apr 25 10:21:14 UTC 2024] Session ID
[Thu Apr 25 10:21:14 UTC 2024] SynoToken
[Thu Apr 25 10:21:14 UTC 2024] Unable to authenticate to http://172.17.0.1:5000, you may report the full log to the community.
[Thu Apr 25 10:21:14 UTC 2024] Error deploy for domain:myndd
[Thu Apr 25 10:21:14 UTC 2024] Deploy error.

First difference with the previous deployment : Session ID and SynoToken are not filled up. And obviously, the deployment fails.

Looking at my NAS, the directory usr/local/share/acme.sh/ is not here anymore !

Checking on my other NAS (DS718+) with the same configuration and it is the same.

Both NAS have been updated yesterday to DSM 7.2.1-69057U5. I have also updated acme.sh docker container to the latest. I can't tell if this directory was there before the update and if yes, which update is the culpid.

Any idea what is going wrong ?

@rsporsche
Copy link

rsporsche commented Apr 25, 2024

I'm running acme.sh in docker using the neilpang/acme.sh docker container to deploy to my synology NAS.

The docker container was updated earlier this week and out of curiosity I manually forced a renew, which failed with the following message:

grep: unrecognized option: P
BusyBox v1.35.0 (2022-11-19 10:13:10 UTC) multi-call binary.

Usage: grep [-HhnlLoqvsrRiwFE] [-m N] [-A|B|C N] { PATTERN | -e PATTERN... | -f FILE... } [FILE]...

...

I guess the grep provided by the docker container is now from busybox which doesn't seem to support the '-P' parameter.

Any chance this can be adapted or should I talk to the maintainer of the docker container?

@LordDarkneo
Copy link
Contributor

@Mic13710 I did not follow the update on the deployment hook, but I had exactly the same issue. If you read the script, in my case, it was because the token and another variable were not set, blocking the script, even it they are not used for the authentication process. After many discussions, it is related to my "old" version of DSM. I proposed a modifcation that has been rejected I think in order to fix this...
So my recommendation: put the verbose mode on, try to get the adress that is built by the script to see what variable is missing (and if it is required) to see how to fix it.... That's personnaly what I did...

@scruel
Copy link
Contributor

scruel commented Apr 25, 2024

I'm running acme.sh in docker using the neilpang/acme.sh docker container to deploy to my synology NAS.

The docker container was updated earlier this week and out of curiosity I manually forced a renew, which failed with the following message:

grep: unrecognized option: P
BusyBox v1.35.0 (2022-11-19 10:13:10 UTC) multi-call binary.

Usage: grep [-HhnlLoqvsrRiwFE] [-m N] [-A|B|C N] { PATTERN | -e PATTERN... | -f FILE... } [FILE]...

...

I guess the grep provided by the docker container is now from busybox which doesn't seem to support the '-P' parameter.

Any chance this can be adapted or should I talk to the maintainer of the docker container?

Try acme.sh --upgrade -b dev

@Mic13710
Copy link

@LordDarkneo thanks for your feeback.
I have acme.sh installed via docker for ages on both of my nas and except some bugs corrected during that time, it works like a charm. The 718+ was originally in DSM6.x. I upgraded it to DSM7.x without any renewal problem. The 220+ was originally under DSM7.x and it was ok till now for the creation of the certificates as well as for the deployment (except for the bugs reported earlier).
My concern is for the acme.sh directory which is vaniched from my two NAS.
@scruel I have rerun the deployment hook with -debug2 but I don't know where the log is supposed to be found. The only records I have are in the acme.sh.log /docker/Acme directory and are the one above. Can you tell me where it is ? I will be pleased to post it.
Here is my script for the deployment with debug :

docker exec Acme sh -c "acme.sh --deploy  -d 'myndd1' --deploy-hook synology_dsm" --debug 2
docker exec Acme sh -c "acme.sh --deploy  -d 'myndd2' --deploy-hook synology_dsm" --debug 2

I feel that the problem lies on this famous acme.sh directory
In the mean time, I have search for the same in the NAS and found it in some directories under /volume1/@docker/btrfs/subvolumes.
For instance, in this one :/volume1/@docker/btrfs/subvolumes/3b7eb545e365807cf47d49b92793d6977c0526894b24ff58ce21ba490a903ed7/root
Where I have a directory .acme.sh
I can find the same in some other subvolumes directories but I have no idea why it is there and what is the link with btrfs....

@rsporsche
Copy link

Try acme.sh --upgrade -b dev

That worked

@scruel
Copy link
Contributor

scruel commented Apr 25, 2024

@LordDarkneo
Copy link
Contributor

LordDarkneo commented Apr 25, 2024

@Mic13710 You should see something "longer" in the logs with the constructed url in the variable 'url=xx', just before the "Unable to authenticate to" log line. Try to copy and paste this URL in your browser from your local network (as it is using the local ip adress I guess) and see the error you get for the logging issue (trying to fix the url to get the successful authent might also help to find which condition is making a failure)

@Mic13710
Copy link

@LordDarkneo The URL is OK. It is the one for docker.
You are right in saying that I should have something longer.
This is the log for the last successful deployment for my DS718+. It was on 11/04/2024 :

[Thu Apr 11 15:47:07 UTC 2024] _deployApi='/root/.acme.sh/deploy/synology_dsm.sh'
[Thu Apr 11 15:47:07 UTC 2024] _cdomain='myndd'
[Thu Apr 11 15:47:07 UTC 2024] SYNO_Certificate='name of myndd'
[Thu Apr 11 15:47:07 UTC 2024] _base_url='http://172.17.0.1:5000'
[Thu Apr 11 15:47:07 UTC 2024] Getting API version
[Thu Apr 11 15:47:07 UTC 2024] GET
[Thu Apr 11 15:47:07 UTC 2024] url='http://172.17.0.1:5000/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth'
[Thu Apr 11 15:47:07 UTC 2024] timeout=
[Thu Apr 11 15:47:07 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header -L -g '
[Thu Apr 11 15:47:07 UTC 2024] ret='0'
[Thu Apr 11 15:47:08 UTC 2024] Logging into 172.17.0.1:5000
[Thu Apr 11 15:47:08 UTC 2024] GET
[Thu Apr 11 15:47:08 UTC 2024] url='http://172.17.0.1:5000/webapi/entry.cgi?api=SYNO.API.Auth&version=7&method=login&format=sid&account=myaccount&passwd=mypassword&enable_syno_token=yes&device_name=CertRenewal&device_id=QtoQDntEgOpO0cHJ4Rtd49rX36O56MSjtrAFQdiOmLh78cOUZrpDmPOWvn6F4IxnuJyeg55htz1fowGxuAiVxQ'
[Thu Apr 11 15:47:08 UTC 2024] timeout=
[Thu Apr 11 15:47:08 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header -L -g '
[Thu Apr 11 15:47:09 UTC 2024] ret='0'
[Thu Apr 11 15:47:09 UTC 2024] Session ID='27_e3kXp9lHXGnNhIXmeqdTS33P5aa8LHZBt6581WwYx-VrBtWYRDJ2u0FFPSVFm80KYN0qu_Jci0eHsXglE8U'
[Thu Apr 11 15:47:09 UTC 2024] SynoToken='yU5LMGVAgdCro'
[Thu Apr 11 15:47:09 UTC 2024] Getting certificates in Synology DSM
[Thu Apr 11 15:47:09 UTC 2024] POST
[Thu Apr 11 15:47:09 UTC 2024] _post_url='http://172.17.0.1:5000/webapi/entry.cgi'
[Thu Apr 11 15:47:09 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header -L -g '
[Thu Apr 11 15:47:10 UTC 2024] _ret='0'
[Thu Apr 11 15:47:10 UTC 2024] escaped_certificate='name of myndd'
[Thu Apr 11 15:47:10 UTC 2024] Generate form POST request
[Thu Apr 11 15:47:10 UTC 2024] Upload certificate to the Synology DSM
[Thu Apr 11 15:47:10 UTC 2024] POST
[Thu Apr 11 15:47:10 UTC 2024] _post_url='http://172.17.0.1:5000/webapi/entry.cgi?api=SYNO.Core.Certificate&method=import&version=1&SynoToken=yU5LMGVAgdCro&_sid=27_e3kXp9lHXGnNhIXmeqdTS33P5aa8LHZBt6581WwYx-VrBtWYRDJ2u0FFPSVFm80KYN0qu_Jci0eHsXglE8U'
[Thu Apr 11 15:47:10 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header -L -g '
[Thu Apr 11 15:48:50 UTC 2024] _ret='0'
[Thu Apr 11 15:48:50 UTC 2024] Restarting HTTP services succeeded
[Thu Apr 11 15:48:50 UTC 2024] GET
[Thu Apr 11 15:48:50 UTC 2024] url='http://172.17.0.1:5000/webapi/entry.cgi?api=SYNO.API.Auth&version=7&method=logout&_sid=27_e3kXp9lHXGnNhIXmeqdTS33P5aa8LHZBt6581WwYx-VrBtWYRDJ2u0FFPSVFm80KYN0qu_Jci0eHsXglE8U'
[Thu Apr 11 15:48:50 UTC 2024] timeout=
[Thu Apr 11 15:48:50 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header -L -g '
[Thu Apr 11 15:48:51 UTC 2024] ret='0'
[Thu Apr 11 15:48:51 UTC 2024] Success

There are the Session ID and SynoToken correctly collected, and the process is going to the end.

Since the update of DSM and acme in docker my attempt to deploy the certificate on the same NAS (718+) fails :

[Thu Apr 25 10:21:13 UTC 2024] Running cmd: deploy
[Thu Apr 25 10:21:13 UTC 2024] Using config home:/acme.sh
[Thu Apr 25 10:21:13 UTC 2024] default_acme_server
[Thu Apr 25 10:21:13 UTC 2024] ACME_DIRECTORY='https://acme.zerossl.com/v2/DV90'
[Thu Apr 25 10:21:13 UTC 2024] DOMAIN_PATH='/acme.sh/myndd'
[Thu Apr 25 10:21:13 UTC 2024] _deployApi='/root/.acme.sh/deploy/synology_dsm.sh'
[Thu Apr 25 10:21:13 UTC 2024] _cdomain='myndd'
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Username has been migrated to SAVED_SYNO_USERNAME.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Password has been migrated to SAVED_SYNO_PASSWORD.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Device_ID has been migrated to SAVED_SYNO_DEVICE_ID.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Device_Name has been migrated to SAVED_SYNO_DEVICE_NAME.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Scheme has been migrated to SAVED_SYNO_SCHEME.
[Thu Apr 25 10:21:13 UTC 2024] Domain config SAVED_SYNO_Hostname has been migrated to SAVED_SYNO_HOSTNAME.
[Thu Apr 25 10:21:14 UTC 2024] Domain config SAVED_SYNO_Port has been migrated to SAVED_SYNO_PORT.
[Thu Apr 25 10:21:14 UTC 2024] Domain config SAVED_SYNO_Certificate has been migrated to SAVED_SYNO_CERTIFICATE.
[Thu Apr 25 10:21:14 UTC 2024] SYNO_CERTIFICATE='name of myndd'
[Thu Apr 25 10:21:14 UTC 2024] Getting API version...
[Thu Apr 25 10:21:14 UTC 2024] _base_url='http://172.17.0.1:5000'
[Thu Apr 25 10:21:14 UTC 2024] GET
[Thu Apr 25 10:21:14 UTC 2024] url='http://172.17.0.1:5000/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth'
[Thu Apr 25 10:21:14 UTC 2024] timeout=
[Thu Apr 25 10:21:14 UTC 2024] _CURL='curl --silent --dump-header /acme.sh/http.header -L -g '
[Thu Apr 25 10:21:14 UTC 2024] ret='0'
[Thu Apr 25 10:21:14 UTC 2024] Logging into 172.17.0.1:5000...
[Thu Apr 25 10:21:14 UTC 2024] Session ID
[Thu Apr 25 10:21:14 UTC 2024] SynoToken
[Thu Apr 25 10:21:14 UTC 2024] Unable to authenticate to http://172.17.0.1:5000, you may report the full log to the community.
[Thu Apr 25 10:21:14 UTC 2024] Error deploy for domain:myndd
[Thu Apr 25 10:21:14 UTC 2024] Deploy error.

Clearly Session ID and SynoToken are not there........
IMO, the problem lies in the lost of acme.sh directory. The question is why ?

Sorry @scruel, I have tried hard but could not locate any log in var/log after running with --debug 3

@LordDarkneo
Copy link
Contributor

LordDarkneo commented Apr 25, 2024

When you paste the URL http://172.17.0.1:5000/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth in a browser, it's OK? I remember I had issues here because the SYNO.API.Auth is a mthod of the entry.cgi and not query.cgi....
The issue you're having is because you get in this if condition (meaning both sessionID and SynoToken are empty):

sid=$(echo "$response" | grep "sid" | sed -n 's/."sid" : "([^"])./\1/p')
token=$(echo "$response" | grep "synotoken" | sed -n 's/.
"synotoken" : "([^"])./\1/p')
_debug "Session ID" "$sid"
_debug SynoToken "$token"
if [ -z "$sid" ] || [ -z "$token" ]; then
# Still can't get necessary info even got no errors, may Synology have API updated?
_err "Unable to authenticate to $_base_url, you may report the full log to the community."
_temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
return 1
fi

Try to set a value (no matter what) in the SynoToken to see if it fixes the issue (because the sessionID is get later in the code, at least in the version I have)

@scruel
Copy link
Contributor

scruel commented Apr 26, 2024

@Mic13710 Unfortunately, we won't be able to know why to do the fix if you can't provide debug logs, maybe we will have to wait the other people to reproduce your issue.
BTW, you may describe how to reproduce this by providing related details like OS version, container configs and step-by-step commands etc.

@Mic13710
Copy link

@LordDarkneo Thank you for your help. The IP 172.17.0.1 is private and internal to the NAS (docker). It can't be resolve in a browser. Replacing the IP by the NAS IP can be resolved but does not provide relevant info:

{"data":{"SYNO.API.Auth":{"maxVersion":7,"minVersion":1,"path":"entry.cgi"}},"success":true}

Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json; charset="UTF-8"
Date: Fri, 26 Apr 2024 08:22:12 GMT
Expires: 0
Keep-Alive: timeout=20
Pragma: no-cache
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,/;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Connection: keep-alive
Host: 192.168.54.2:5000
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0

@scruel I have search all over the NAS with WinSCP in root. Can't locate any log related to the deployment except those already given. My certs are valid till 22/05 for the 220+ and beginning of july for the 718+ so I have little time left. I am quite busy these days but I should be able to provide more information later on. At the moment :
Both NAS are under DSM7.2.1-69057U5. The acme.sh is in container manager and the image is neilpang/acme.sh at the latest.
However, all the active certificates have been renewed automatically with the previous version and deployed correctly on the 718, not on the 220 (that was the case sometime in the past).
Since the updates to the latest DSM and the latest acme.sh image, the deploy command is not working anymore on both NAS.

@LordDarkneo
Copy link
Contributor

@Mic13710 in fact in does. It confirms that the query has been sent properly and that login should be made through entry.cgi. Now we still need to find which version is used dfor the authentication (i'd say the 7 but not sure...)did you try to set a value in the Syno Token and execute the script to see how it goes (just add a variable in the flat file).

@Mic13710
Copy link

@LordDarkneo I have tried to add values for Session ID and SynoToken in ndd.conf like this:

SAVED_SYNO_Session_ID='27_e3kXp9lHXGnNhIXmeqdTS33P5aa8LHZBt6581WwYx-VrBtWYRDJ2u0FFPSVFm80KYN0qu_Jci0eHsXglE8U'
SAVED_SYNO_SynoToken='yU5LMGVAgdCro'

Without any result. Still empty in the log. Values are those from the previous successful deployment.
Maybe I should force the values somewhere else or differently but I have no idea where and how.

@LordDarkneo
Copy link
Contributor

LordDarkneo commented Apr 27, 2024 via email

@Mic13710
Copy link

Well, what can do more, can do less.
With synotoken alone, same result.
Maybe I should try to put it directly in the script. But if I can understand it, I am not confident enought to do that by myself.

@Mic13710
Copy link

Mic13710 commented May 6, 2024

Hello @scruel , @LordDarkneo ,
Back home today, I have rerun the script and both certificates have been deployed properly !
Session ID and SynoToken are now filled up in the log.
I have no idea why, in exactly the same conditions, all my previous attempts had failed. The NAS has not been restarted and no change was made during the period.
Problem seems to be solved. To be confirmed at the next renewal.
Thanks again for your support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party api report bugs to dns api, deploy hooks and notification hooks
Projects
None yet
Development

No branches or pull requests