ws_codesignService.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "ws_codesignService.hpp"
  14. #include "jutil.hpp"
  15. #include "codesigner.hpp"
  16. Cws_codesignEx::Cws_codesignEx()
  17. {
  18. }
  19. Cws_codesignEx::~Cws_codesignEx()
  20. {
  21. }
  22. void Cws_codesignEx::init(IPropertyTree *cfg, const char *process, const char *service)
  23. {
  24. if(cfg == nullptr)
  25. throw MakeStringException(-1, "Cannot initialize Cws_codesignEx, cfg is NULL");
  26. StringBuffer xpath;
  27. xpath.appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]", process, service);
  28. m_serviceCfg.setown(cfg->getPropTree(xpath.str()));
  29. }
  30. bool Cws_codesignEx::onSign(IEspContext &context, IEspSignRequest &req, IEspSignResponse &resp)
  31. {
  32. resp.setRetCode(-1);
  33. StringBuffer userid(req.getUserID()), signedText;
  34. userid.trim();
  35. const char* text = req.getText();
  36. if (userid.length() == 0 || !text || !*text)
  37. {
  38. resp.setErrMsg("Please provide both UserID and Text");
  39. return false;
  40. }
  41. try
  42. {
  43. queryCodeSigner().sign(text, userid.str(), req.getKeyPass(), signedText);
  44. }
  45. catch (IException *e)
  46. {
  47. StringBuffer msg;
  48. e->errorMessage(msg);
  49. resp.setRetCode(e->errorCode());
  50. resp.setErrMsg(msg);
  51. e->Release();
  52. return false;
  53. }
  54. resp.setRetCode(0);
  55. resp.setSignedText(signedText.str());
  56. return true;
  57. }
  58. bool Cws_codesignEx::onListUserIDs(IEspContext &context, IEspListUserIDsRequest &req, IEspListUserIDsResponse &resp)
  59. {
  60. StringArray userIds;
  61. try
  62. {
  63. queryCodeSigner().getUserIds(userIds);
  64. }
  65. catch (IException *e)
  66. {
  67. e->Release();
  68. return false;
  69. }
  70. resp.setUserIDs(userIds);
  71. return true;
  72. }