예제 #1
0
//Create base 64 encoded digital signature of given data
bool digiSign(StringBuffer &b64Signature, size32_t dataSz, const void *data, const CLoadedKey &signingKey)
{
    OwnedEVPMdCtx signingCtx(EVP_MD_CTX_create());
    //initialize context for SHA-256 hashing function
    int rc = EVP_DigestSignInit(signingCtx, nullptr, EVP_sha256(), nullptr, signingKey);
    if (rc <= 0)
        throwEVPException(-1, "digiSign:EVP_DigestSignInit");

    //add string to the context
    if (EVP_DigestSignUpdate(signingCtx, data, dataSz) <= 0)
        throwEVPException(-1, "digiSign:EVP_DigestSignUpdate");

    //compute length of signature
    size_t encMsgLen;
    if (EVP_DigestSignFinal(signingCtx, nullptr, &encMsgLen) <= 0)
        throwEVPException(-1, "digiSign:EVP_DigestSignFinal1");

    if (encMsgLen == 0)
        throwEVPException(-1, "digiSign:EVP_DigestSignFinal length returned 0");

    //compute signature (signed digest)
    OwnedEVPMemory encMsg = OPENSSL_malloc(encMsgLen);
    if (encMsg == nullptr)
        throw MakeStringException(-1, "digiSign:OPENSSL_malloc(%u) returned NULL", (unsigned)encMsgLen);

    if (EVP_DigestSignFinal(signingCtx, (unsigned char *)encMsg.get(), &encMsgLen) <= 0)
        throwEVPException(-1, "digiSign:EVP_DigestSignFinal2");

    //convert to base64
    JBASE64_Encode(encMsg, encMsgLen, b64Signature, false);

    return true;
}
예제 #2
0
 CMultiMailPart(CMailPart const & _inlined, CMailPart const & _attachment) : CMailPart("multipart/mixed", NULL), inlined(_inlined), attachment(_attachment)
 {
     unsigned char rndm[12];
     for(unsigned i=0; i<12; ++i)
         rndm[i] = getRandom() % 256;
     JBASE64_Encode(rndm, 12, boundary);
     mime.append("; boundary=\"").append(boundary).append("\"");
 }
예제 #3
0
static StringBuffer &buildAuthToken(IUserDescriptor *userDesc, StringBuffer &authToken)
{
    StringBuffer uidpair;
    userDesc->getUserName(uidpair);
    uidpair.append(":");
    userDesc->getPassword(uidpair);
    JBASE64_Encode(uidpair.str(), uidpair.length(), authToken);
    return authToken;
}
예제 #4
0
int HttpClient::getUrl(const char* url)
{
    if(!url || !*url || !m_times)
        return 0;

    StringBuffer protocol, user, passwd, port, path;
    m_host.clear();
    SplitURL(url, protocol, user, passwd, m_host, port, path);

    if(port.length() > 0)
        m_port = atoi(port.str());
    else
    {
        if(protocol.length() > 0 && stricmp(protocol.str(), "https") == 0)
            m_port = 443;
        else
            m_port = 80;
    }

    if(stricmp(protocol.str(), "HTTPS") == 0)
        m_use_ssl = true;

    if(m_use_ssl)
    {
#if USE_OPENSSL
        if(m_ssctx.get() == NULL)
            m_ssctx.setown(createSecureSocketContext(ClientSocket));
#else
        throw MakeStringException(-1, "HttpClient: failure to create SSL socket - OpenSSL not enabled in build");
#endif
    }

    StringBuffer request;
    request.appendf("GET %s HTTP/1.0\r\n", path.str());
    request.append("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*\r\n");
    request.append("Accept-Language: en-us\r\n");
    //request.append("Accept-Encoding: gzip, deflate\r\n");
    request.append("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n");
    request.append("Host: ").append(m_host.str());
    if(m_port != 80)
        request.appendf(":%d", m_port);
    request.append("\r\n");
    if(user.length() > 0)
    {
        StringBuffer auth, abuf;
        abuf.appendf("%s:%s", user.str(), passwd.str());
        JBASE64_Encode(abuf.str(), abuf.length(), auth);
        request.appendf("Authorization: Basic %s\r\n", auth.str());
    }
    request.append("\r\n");

    return sendRequest(request);
}
예제 #5
0
void CLogThread::addLogInfo(IArrayOf<IEspLogInfo>& valueArray,IPropertyTree& logInfo)
{

    StringBuffer dataStr,nameStr,valueStr;
    Owned<IPropertyTreeIterator> itr =  logInfo.getElements("*");
    itr->first();
    while(itr->isValid())
    {
        IPropertyTree &node = itr->query();
        const char* name = node.queryName();
        if (getTreeFlattening()==true && node.hasChildren() == true)
        {

            if(IsArray(node)==true)
            {
                FlattenArray(valueArray,node,nameStr);
            }
            else
            {
                FlattenTree(valueArray,node,nameStr);
            }
        //  logElement.setName(node.queryName());
        //  dataStr.clear();
            /*toXML(&node,dataStr);
            //DOM temporary work about for the lack of XML decoding in esp arrays
            StringBuffer encodedData;
            JBASE64_Encode(dataStr.str(), dataStr.length() , encodedData);
            logElement.setData(encodedData.str());
        */

        }
        else if (getTreeFlattening()==false && node.hasChildren() == true)
        {
            IClientLogInfo& logElement = addLogInfoElement(valueArray);
            logElement.setName(node.queryName());
            dataStr.clear();
            toXML(&node,dataStr);
            //DOM temporary work about for the lack of XML decoding in esp arrays
            StringBuffer encodedData;
            JBASE64_Encode(dataStr.str(), dataStr.length() , encodedData);
            logElement.setData(encodedData.str());
        }
        else if (node.queryProp("") != 0 && ( strcmp(node.queryProp(""),"0") != 0 ))
        {
            IClientLogInfo& logElement = addLogInfoElement(valueArray);
            logElement.setName(node.queryName());
            logElement.setValue(node.queryProp(""));
        }
        itr->next();
    }

}
예제 #6
0
 virtual void endNode(const char *tag, unsigned length, const void *value, bool binary, offset_t endOffset)
 {
     if (datasetLevel)
     {
         if (length)
         {
             if (binary)
                 JBASE64_Encode(value, length, buffer);
             else
                 encodeUtf8XML((const char *)value, buffer);
         }
         buffer.append("</").append(tag).append('>');
         if (streq("Dataset", tag) || streq("Exception", tag))
             datasetLevel--;
     }
 }
예제 #7
0
 virtual void endNode(const char *tag, unsigned length, const void *value, bool binary, offset_t endOffset)
 {
     if (resultlevel)
     {
         if (length)
         {
             if (binary)
                 JBASE64_Encode(value, length, buffer);
             else
                 encodeUtf8XML((const char *)value, buffer);
         }
         buffer.append("</").append(tag).append('>');
         bool *pIsResultTag = resultChildTags.getValue(tag);
         if (pIsResultTag && *pIsResultTag)
             resultlevel--;
     }
 }
예제 #8
0
unsigned CLoggingManager::serializeLogRequestContent(IEspUpdateLogRequestWrap* request, const char* GUID, StringBuffer& logData)
{
    appendXMLTag(logData, LOGREQUEST_GUID, GUID);

    const char* option = request->getOption();
    if (!isEmptyString(option))
        appendXMLTag(logData, LOGREQUEST_OPTION, option);

    appendXMLOpenTag(logData, LOGREQUEST);

    const char* logRequest = request->getUpdateLogRequest();
    MemoryBuffer memBuf;
    LZWCompress(logRequest, strlen(logRequest), memBuf, 0x100);
    JBASE64_Encode(memBuf.toByteArray(), memBuf.length(), logData);

    appendXMLCloseTag(logData, LOGREQUEST);

    return logData.length();
}
예제 #9
0
 CDataMailPart(size32_t len, const void * data, char const * mimeType, char const * filename) : CMailPart(mimeType, filename)
 {
     JBASE64_Encode(data, len, buff);
     encoding = "base64";
 }
예제 #10
0
int HttpClient::sendSoapRequest(const char* url, const char* soapaction, const char* infile)
{
    if(!url || !*url || !infile || !*infile)
        return 0;

    StringBuffer protocol, user, passwd, port, path;
    m_host.clear();
    SplitURL(url, protocol, user, passwd, m_host, port, path);

    if(port.length() > 0)
        m_port = atoi(port.str());
    else
    {
        if(protocol.length() > 0 && stricmp(protocol.str(), "https") == 0)
            m_port = 443;
        else
            m_port = 80;
    }

    if(stricmp(protocol.str(), "HTTPS") == 0)
        m_use_ssl = true;

    if(m_use_ssl)
    {
#ifdef USE_OPENSSL
        if(m_ssctx.get() == NULL)
            m_ssctx.setown(createSecureSocketContext(ClientSocket));
#else
        throw MakeStringException(-1, "HttpClient: failure to create SSL socket - OpenSSL not enabled in build");
#endif
    }

    StringBuffer request;

    try
    {
        request.loadFile(infile, true);
    }
    catch(IException* e)
    {
        StringBuffer errmsg;
        printf("\nerror loading file %s - %s", infile, e->errorMessage(errmsg).str());
        return -1;
    }
    catch(...)
    {
        printf("\nerror loading file %s", infile);
        return -1;
    }

    if(request.length() == 0)
    {
        printf("input is empty\n");
        return -1;
    }


    const char* ptr = request.str();
    while(*ptr == ' ')
        ptr++;
    if(*ptr != '<')
    {
        printf("the input should be xml\n");
        return -1;
    }

    if(strncmp(ptr, "<?xml", 5) != 0 && strncmp(ptr, "<soap:Envelope", 14) != 0)
    {
        request.insert(0, "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/04/secext\"><soap:Body>");
        request.append("</soap:Body></soap:Envelope>");
    }

    StringBuffer headers;

    headers.appendf("POST %s HTTP/1.1\r\n", path.str());
    headers.append("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*\r\n");
    headers.append("Accept-Language: en-us\r\n");
    headers.append("Content-Type: text/xml\r\n");
    if(soapaction && *soapaction)
        headers.appendf("SOAPAction: \"%s\"\r\n", soapaction);
    //headers.append("Accept-Encoding: gzip, deflate\r\n");
    headers.append("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n");
    headers.appendf("Content-Length: %d\r\n", request.length());
    headers.append("Host: ").append(m_host.str());
    if(m_port != 80)
        headers.appendf(":%d", m_port);
    headers.append("\r\n");

    if(user.length() > 0)
    {
        StringBuffer auth, abuf;
        abuf.appendf("%s:%s", user.str(), passwd.str());
        JBASE64_Encode(abuf.str(), abuf.length(), auth);
        headers.appendf("Authorization: Basic %s\r\n", auth.str());
    }

    headers.append("\r\n");


    request.insert(0, headers.str());

    return sendRequest(request);
}