12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /*##############################################################################
- HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ############################################################################## */
- #include "ws_codesignService.hpp"
- #include "jutil.hpp"
- #include "codesigner.hpp"
- Cws_codesignEx::Cws_codesignEx()
- {
- }
- Cws_codesignEx::~Cws_codesignEx()
- {
- }
- void Cws_codesignEx::init(IPropertyTree *cfg, const char *process, const char *service)
- {
- if(cfg == nullptr)
- throw MakeStringException(-1, "Cannot initialize Cws_codesignEx, cfg is NULL");
- StringBuffer xpath;
- xpath.appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]", process, service);
- m_serviceCfg.setown(cfg->getPropTree(xpath.str()));
- }
- bool Cws_codesignEx::onSign(IEspContext &context, IEspSignRequest &req, IEspSignResponse &resp)
- {
- resp.setRetCode(-1);
- StringBuffer userid(req.getUserID()), signedText;
- userid.trim();
- const char* text = req.getText();
- if (userid.length() == 0 || !text || !*text)
- {
- resp.setErrMsg("Please provide both UserID and Text");
- return false;
- }
- try
- {
- queryCodeSigner().sign(text, userid.str(), req.getKeyPass(), signedText);
- }
- catch (IException *e)
- {
- StringBuffer msg;
- e->errorMessage(msg);
- resp.setRetCode(e->errorCode());
- resp.setErrMsg(msg);
- e->Release();
- return false;
- }
- resp.setRetCode(0);
- resp.setSignedText(signedText.str());
- return true;
- }
- bool Cws_codesignEx::onListUserIDs(IEspContext &context, IEspListUserIDsRequest &req, IEspListUserIDsResponse &resp)
- {
- StringArray userIds;
- try
- {
- queryCodeSigner().getUserIds(userIds);
- }
- catch (IException *e)
- {
- e->Release();
- return false;
- }
- resp.setUserIDs(userIds);
- return true;
- }
|