SK-EID / smart-id-java-client

MIT License
15 stars 16 forks source link

Getting 400 Bad Request when trying to sign document #52

Closed alekseibahmatov closed 3 years ago

alekseibahmatov commented 3 years ago

I'm using smart-id v2 with Demo credentials. Right now I'm trying to set up signing service, but everytime I try to sign any document I get 400 Bad Request.

Tracelog: 2020-12-20 12:28:10.298 DEBUG 6416 --- [nio-8220-exec-1] ee.sk.smartid.rest.LoggingFilter : POST https://sid.demo.sk.ee/smart-id-rp/v2/certificatechoice/document/PNOEE-10101010005-Z1B2-Q 2020-12-20 12:28:10.301 TRACE 6416 --- [nio-8220-exec-1] ee.sk.smartid.rest.LoggingFilter : Request headers: {Accept=[application/json], Content-Type=[application/json]} 2020-12-20 12:28:10.447 TRACE 6416 --- [nio-8220-exec-1] ee.sk.smartid.rest.LoggingFilter : Message body: {"relyingPartyUUID":"00000000-0000-0000-0000-000000000000","relyingPartyName":"DEMO","certificateLevel":"QUALIFIED"} 2020-12-20 12:28:10.529 DEBUG 6416 --- [nio-8220-exec-1] ee.sk.smartid.rest.LoggingFilter : Response status: 200 - OK 2020-12-20 12:28:10.531 TRACE 6416 --- [nio-8220-exec-1] ee.sk.smartid.rest.LoggingFilter : Response body: {"sessionID":"9f7c6e98-a2fc-45f6-a396-1a6ef6e368c2"} 2020-12-20 12:28:10.568 DEBUG 6416 --- [nio-8220-exec-1] ee.sk.smartid.rest.LoggingFilter : GET https://sid.demo.sk.ee/smart-id-rp/v2/session/9f7c6e98-a2fc-45f6-a396-1a6ef6e368c2 2020-12-20 12:28:10.569 TRACE 6416 --- [nio-8220-exec-1] ee.sk.smartid.rest.LoggingFilter : Request headers: {Accept=[application/json]} 2020-12-20 12:28:10.642 DEBUG 6416 --- [nio-8220-exec-1] ee.sk.smartid.rest.LoggingFilter : Response status: 200 - OK 2020-12-20 12:28:10.643 TRACE 6416 --- [nio-8220-exec-1] ee.sk.smartid.rest.LoggingFilter : Response body: {"state":"COMPLETE","result":{"endResult":"OK","documentNumber":"PNOEE-10101010005-Z1B2-Q"},"cert":{"value":"somehash","certificateLevel":"QUALIFIED"}} 2020-12-20 12:28:10.655 INFO 6416 --- [nio-8220-exec-1] o.d.impl.asic.AsicSignatureFinalizer : Getting data to sign 2020-12-20 12:28:10.669 INFO 6416 --- [nio-8220-exec-1] e.e.e.d.v.CommonCertificateVerifier : + New CommonCertificateVerifier created. 2020-12-20 12:28:10.739 INFO 6416 --- [nio-8220-exec-1] org.digidoc4j.Configuration : Source by country <EE> not found, using default TSP source 2020-12-20 12:28:12.672 DEBUG 6416 --- [nio-8220-exec-3] ee.sk.smartid.rest.LoggingFilter : POST https://sid.demo.sk.ee/smart-id-rp/v2/signature/document/PNOEE-10101010005-Z1B2-Q 2020-12-20 12:28:12.672 TRACE 6416 --- [nio-8220-exec-3] ee.sk.smartid.rest.LoggingFilter : Request headers: {Accept=[application/json], Content-Type=[application/json]} 2020-12-20 12:28:12.693 TRACE 6416 --- [nio-8220-exec-3] ee.sk.smartid.rest.LoggingFilter : Message body: {"relyingPartyUUID":"00000000-0000-0000-0000-000000000000","relyingPartyName":"DEMO","certificateLevel":"QUALIFIED","hash":"somehash","hashType":"SHA256","allowedInteractionsOrder":[{"type":"confirmationMessage","displayText200":"Long text (up to 200 characters) goes here."},{"type":"displayTextAndPIN","displayText60":"Shorter text for less capable devices"}]} 2020-12-20 12:28:12.706 DEBUG 6416 --- [nio-8220-exec-3] ee.sk.smartid.rest.LoggingFilter : Response status: 400 - Bad Request 2020-12-20 12:28:12.706 TRACE 6416 --- [nio-8220-exec-3] ee.sk.smartid.rest.LoggingFilter : Response body: {"code":400,"message":"Bad Request"} 2020-12-20 12:28:12.713 WARN 6416 --- [nio-8220-exec-3] ee.sk.smartid.rest.SmartIdRestConnector : Request is invalid for URI https://sid.demo.sk.ee/smart-id-rp/v2/signature/document/PNOEE-10101010005-Z1B2-Q

Could this error be related to the fact that I am using the demo version of the service?

aasaru commented 3 years ago

@jalukse can you please comment.

jalukse commented 3 years ago

Used hash value is not valid - Bad Request

"hash":"somehash"

Should be - Base64 encoded hash function output to be signed (Base64 encoding according to rfc4648). More info https://github.com/SK-EID/smart-id-documentation#23104-request-parameters