ssl - Using setWebhook from Qt for a Telegram bot -
im developing telegram bot using qt c++, , i'm having problems trying set webhook.
ssl server
first of all, i've created ssl server using qtcpserver , qsslsocket. explanations can found in qsslsocket doc. also, generated self-signed certificate telegram doc explains here, using command:
openssl req -newkey rsa:2048 -sha256 -nodes -keyout yourprivate.key -x509 -days 365 -out yourpublic.pem -subj "/c=us/st=new york/l=brooklyn/o=example brooklyn company/cn=yourdomain.example"
the result pair of files, private.key file , public.pem file. so, used them in qsslsockets secure connection.
the result of ssl server capable of listen , accept connections. when use browser connect ssl server, obtain warning using self-signed certificate (which think normal), can connect server. server, i'm able of read data browser sent. so, think server side good.
request setwebhook
in order perform request setwebhook api method, use qhttpmultipart class create mime multipart request. api method needs url contacted , public certificate. so, use code generate url parameter:
qlist<qhttppart> parameters; qhttppart urlpart; urlpart.setheader(qnetworkrequest::contenttypeheader, qvariant("text/plain")); urlpart.setheader(qnetworkrequest::contentdispositionheader, qvariant("form-data; name=\"url\"")); urlpart.setbody(_url.tolatin1()); parameters.append(urlpart);
and code generate certificate parameter:
qhttppart filepath; filepath.setheader(qnetworkrequest::contentdispositionheader, qvariant("form-data; name=\"certificate\"")); qfile *file = new qfile(_filepath); file->open(qiodevice::readonly); filepath.setbodydevice(file); file->setparent(this); parameters.append(filepath);
i receive correct response, message "the webhook set". but, when telegram connects ssl server, ssl handshake doesn't finish in right way (neither encrypted() nor sslerror() signals emitted). think problem way upload public certificate. can see, file qhttppart, doesn't set content-type header because don't know value use. don't know if can problem. use "text/plain" url, don't know use certificate file.
so, don't know problem. even, i'm not sure if file upload or not. using self signed certificate not problem, since documentation indicates valid way. appreciated.
thanks in advance.
i found problem, , content-type. removed content-type of first param, urlpart. , added content-type filepath, using value "application/x-x509-ca-cert". works charm now.
Comments
Post a Comment