]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
use detached signatures for http post (more compatible to PHP)
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 25 Nov 2010 20:30:46 +0000 (20:30 +0000)
committerRudolf Polzer <divVerent@xonotic.org>
Fri, 26 Nov 2010 12:00:03 +0000 (13:00 +0100)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10634 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=1cbbacc96c0f13697949730d84c638941af07519

prvm_cmds.c

index ba955780bbf6ae2c08933470b2b1f7dc13e05ee5..4fe665f5816f40ae479f3e6921a62a45ef8541f3 100644 (file)
@@ -5803,6 +5803,8 @@ typedef struct
        char buffer[MAX_INPUTLINE];
        unsigned char *postdata; // free when uri_to_prog_t is freed
        size_t postlen;
+       char *sigdata; // free when uri_to_prog_t is freed
+       size_t siglen;
 }
 uri_to_prog_t;
 
@@ -5815,6 +5817,8 @@ static void uri_to_string_callback(int status, size_t length_received, unsigned
                // curl reply came too late... so just drop it
                if(handle->postdata)
                        Z_Free(handle->postdata);
+               if(handle->sigdata)
+                       Z_Free(handle->sigdata);
                Z_Free(handle);
                return;
        }
@@ -5836,6 +5840,8 @@ static void uri_to_string_callback(int status, size_t length_received, unsigned
        
        if(handle->postdata)
                Z_Free(handle->postdata);
+       if(handle->sigdata)
+               Z_Free(handle->sigdata);
        Z_Free(handle);
 }
 
@@ -5922,17 +5928,30 @@ void VM_uri_get (void)
                }
                if(postkeyid >= 0)
                {
-                       unsigned char *signed_data = (unsigned char *)Z_Malloc(handle->postlen + 8192);
-                       size_t signed_size = Crypto_SignData(handle->postdata, handle->postlen, postkeyid, signed_data, handle->postlen + 8192);
-                       if(!signed_size)
+                       size_t ll;
+                       handle->sigdata = (char *)Z_Malloc(8192);
+                       strlcpy(handle->sigdata, "X-D0-Blind-ID-Detached-Signature: ", sizeof(handle->sigdata));
+                       l = strlen(handle->sigdata);
+                       handle->siglen = Crypto_SignDataDetached(handle->postdata, handle->postlen, postkeyid, handle->sigdata + l, 8192 - l);
+                       if(!handle->siglen)
                        {
-                               VM_Warning("uri_get: could not sign with key id %i\n", postkeyid);
+                               Z_Free(handle->sigdata);
+                               Z_Free(handle->postdata);
+                               Z_Free(handle);
                                return;
                        }
-                       handle->postdata = signed_data;
-                       handle->postlen = signed_size;
+                       ll = base64_encode((unsigned char *) (handle->sigdata + l), handle->siglen, 8192 - l - 1);
+                       if(!ll)
+                       {
+                               Z_Free(handle->sigdata);
+                               Z_Free(handle->postdata);
+                               Z_Free(handle);
+                               return;
+                       }
+                       handle->siglen = l + ll;
+                       handle->sigdata[handle->siglen] = 0;
                }
-               ret = Curl_Begin_ToMemory_POST(url, NULL, 0, posttype, handle->postdata, handle->postlen, (unsigned char *) handle->buffer, sizeof(handle->buffer), uri_to_string_callback, handle);
+               ret = Curl_Begin_ToMemory_POST(url, handle->sigdata, 0, posttype, handle->postdata, handle->postlen, (unsigned char *) handle->buffer, sizeof(handle->buffer), uri_to_string_callback, handle);
        }
        else
        {
@@ -5948,6 +5967,8 @@ void VM_uri_get (void)
        {
                if(handle->postdata)
                        Z_Free(handle->postdata);
+               if(handle->sigdata)
+                       Z_Free(handle->sigdata);
                Z_Free(handle);
                PRVM_G_INT(OFS_RETURN) = 0;
        }