You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by bu...@apache.org on 2006/09/21 01:31:28 UTC

DO NOT REPLY [Bug 40560] New: - RSA Decrytion doesn't Work

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40560>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40560

           Summary: RSA Decrytion doesn't Work
           Product: Security
           Version: unspecified
          Platform: All
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Encryption
        AssignedTo: security-dev@xml.apache.org
        ReportedBy: samlai@amazon.com


This problem exist in both xml-security-c-1.2.1 and xml-security-c-1.3.0.

I'm trying to decrypt an XML directly with a RSA private key.  The XML looks
like the following:

      <SSN>
        <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
Type="http://www.w3.org/2001/04/xmlenc#Content">
          <xenc:EncryptionMethod
Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
          <xenc:CipherData>
           
<xenc:CipherValue>M3AF/xZbwfGn65c0eAUUdorBVUrLEUBnd1O2sZlt5FE4dFqKgtwIbRlV0hRBAarVyynLSo8r34rR
HigemlQwaM6+jAGKB6ALO5U8Qpghgq3ry/fnjvb0utlXpT1F0AsEwisHsMi03h1amzmsQch6uC/B
8B+27JBMp75iIXgmtdQ=</xenc:CipherValue>
          </xenc:CipherData>
        </xenc:EncryptedData>
      </SSN>

But I'm getting the following error when calling decryptElement:
Error: Errors occured during de-serialisation of decrypted element content

The problem is the function
"XENCAlgorithmHandlerDefault::doRSADecryptToSafeBuffer" in 
"xenc/impl/XENCAlgorithmHandlerDefault.cpp" treats the decrypted value as binary
data.  The following is the end of the function.

        // Copy to output
        result.sbMemcpyIn(decBuf, decryptLen+1);

        memset(decBuf, 0, decryptLen);

As a side note, compare it to "XENCAlgorithmHandlerDefault::decryptToSafeBuffer"
in the same file, this function treats the decrypted value as null-terminated
string:

        cipherText->appendTxfm(tcipher);

        // Do the decrypt to the safeBuffer

        result.sbStrcpyIn("");
        unsigned int offset = 0;
        XMLByte buf[1024];
        TXFMBase * b = cipherText->getLastTxfm();

        int bytesRead = b->readBytes(buf, 1024);
        while (bytesRead > 0) {
                result.sbMemcpyIn(offset, buf, bytesRead);
                offset += bytesRead;
                bytesRead = b->readBytes(buf, 1024);
        }

        result[offset] = '\0';


But "XENCCipherImpl::deSerialise" in "xenc/impl/XENCCipherImpl.cpp" treats the
decrypted data saved in safeBuffer as a null-terminated string.

        const char * crcb = content.rawCharBuffer();
        ...
        sbt.sbStrcatIn(&crcb[offset]);

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

DO NOT REPLY [Bug 40560] - RSA Decrytion doesn't Work

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40560>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40560





------- Additional Comments From blautenb@apache.org  2006-09-28 21:04 -------
Fixed in SVN.  I will do a 1.3.1 sometime soon that will have this in it.

In the interim - you can try the following (or just take XMLCipherImpl.cpp from
svn - this is the only change in there since 1.3.0).

Index: XENCCipherImpl.cpp
===================================================================
--- XENCCipherImpl.cpp  (revision 450386)
+++ XENCCipherImpl.cpp  (working copy)
@@ -552,10 +552,11 @@
        }

        safeBuffer sb("");
+       unsigned int decryptLen;

        if (handler != NULL) {

-               handler->decryptToSafeBuffer(c,
+               decryptLen = handler->decryptToSafeBuffer(c,
                        mp_encryptedData->getEncryptionMethod(),
                        mp_key,
                        mp_env->getParentDocument(),
@@ -570,7 +571,9 @@
                        "XENCCipherImpl::decryptElement - Error retrieving a han
dler for algorithm");

        }
-
+
+       sb[decryptLen] = '\0';
+
        // Now de-serialise
        DOMElement * element = mp_encryptedData->getElement();
        DOMDocumentFragment * frag = deSerialise(sb, element);


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

DO NOT REPLY [Bug 40560] - RSA Decrytion doesn't Work

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40560>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40560


blautenb@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.