
From sickmind@lavabit.com  Fri May 10 05:39:49 2013
Return-Path: <sickmind@lavabit.com>
X-Original-To: dtn-users@ietfa.amsl.com
Delivered-To: dtn-users@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id AEE6121F8FDC for <dtn-users@ietfa.amsl.com>; Fri, 10 May 2013 05:39:49 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: 0.461
X-Spam-Level: 
X-Spam-Status: No, score=0.461 tagged_above=-999 required=5 tests=[BAYES_20=-0.74, J_CHICKENPOX_33=0.6, J_CHICKENPOX_63=0.6, WEIRD_PORT=0.001]
Received: from mail.ietf.org ([12.22.58.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hSN9uxHyNtD1 for <dtn-users@ietfa.amsl.com>; Fri, 10 May 2013 05:39:45 -0700 (PDT)
Received: from karen.lavabit.com (karen.lavabit.com [72.249.41.33]) by ietfa.amsl.com (Postfix) with ESMTP id 6C00521F8FA5 for <dtn-users@irtf.org>; Fri, 10 May 2013 05:39:42 -0700 (PDT)
Received: from d.earth.lavabit.com (d.earth.lavabit.com [192.168.111.13]) by karen.lavabit.com (Postfix) with ESMTP id 6A06411B9A4 for <dtn-users@irtf.org>; Fri, 10 May 2013 07:39:41 -0500 (CDT)
Received: from localhost (pppoe.178-66-171-99.dynamic.avangarddsl.ru [178.66.171.99]) by lavabit.com with ESMTP id CS8HH117S4UH for <dtn-users@irtf.org>; Fri, 10 May 2013 07:39:41 -0500
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=lavabit; d=lavabit.com; b=vp/1SfggWOhy1uklzXbmVSfOphSHNMYi433TbmNqQdXoUEdjgHNqbH0aJx8Go1eKD3uDTHYCSctSvapv2YHul7UBL9+Kq3rmBtx0pNEOHCYXbkern4XYmF/S+gHbx+7XOXPRxlu3RRWqqfXeyMuXzlnvPRtgl1BfT4WmiFKRk38=; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent;
Date: Fri, 10 May 2013 12:39:42 +0000
From: Lana Black <sickmind@lavabit.com>
To: dtn-users maillist <dtn-users@irtf.org>
Message-ID: <20130510123942.GA10712@glow>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="SUOF0GtieIMvvwua"
Content-Disposition: inline
User-Agent: Mutt/1.5.21 (2010-09-15)
Subject: [dtn-users] Ciphersuite compilation error
X-BeenThere: dtn-users@irtf.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id: "The Delay-Tolerant Networking Research Group \(DTNRG\) - Users." <dtn-users.irtf.org>
List-Unsubscribe: <https://www.irtf.org/mailman/options/dtn-users>, <mailto:dtn-users-request@irtf.org?subject=unsubscribe>
List-Archive: <http://www.irtf.org/mail-archive/web/dtn-users>
List-Post: <mailto:dtn-users@irtf.org>
List-Help: <mailto:dtn-users-request@irtf.org?subject=help>
List-Subscribe: <https://www.irtf.org/mailman/listinfo/dtn-users>, <mailto:dtn-users-request@irtf.org?subject=subscribe>
X-List-Received-Date: Fri, 10 May 2013 12:39:49 -0000

--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

The new ciphersuite code contains a error, which might result in DTN crash.
GCC does not detect it and produces incorrect code. Clang throws the following
error:

security/ECDH.cc:558:9: error: goto into protected scope
        goto err;
        ^
security/ECDH.cc:624:19: note: jump bypasses initialization of variable length array
    unsigned char cek[cek_len];
                  ^
security/ECDH.cc:623:19: note: jump bypasses initialization of variable length array
    unsigned char shared_data[shared_data_len];

Please see this page for more information:
http://clang.llvm.org/compatibility.html#blocks-in-protected-scope

The patch attached resolves the problem.

With best regards.

--SUOF0GtieIMvvwua
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="ecdh-scope.patch"

diff --git a/servlib/security/ECDH.cc b/servlib/security/ECDH.cc
index c632651..191da15 100644
--- a/servlib/security/ECDH.cc
+++ b/servlib/security/ECDH.cc
@@ -620,51 +620,53 @@ int ECDH::decrypt(LocalBuffer &out,
         shared_key_len = 256/8;
         cek_len = 256/8;
     }
-    unsigned char shared_data[shared_data_len];
-    unsigned char cek[cek_len];
-    memset(shared_data, 0xffff, shared_data_len);
-    memset(cek, 0xffff, cek_len);
-
-    // Retrieve the User Keying Material
-    ukm = ASN1_STRING_data(ri->d.kari->ukm);
-    log_debug_p(log, "ECDH::decrypt: User Keying Material (ukm) :  %s", Ciphersuite::buf2str(ukm, 16).c_str());
-
-    // Compute the ECDH shared value from the public key and my private key
-    if(!ECDH_compute_key(shared_data, shared_data_len, ephemeral, myKey_ec, NULL)) {
-    	log_err_p(log, "ECDH::decrypt: Error computing ECDH shared value");
-        goto err;
-    }
-
-    // Derive the shared key from the shared data and the ukm
-    shared_key = derive_key(ukm, shared_data, shared_data_len*4);
-    if(AES_set_decrypt_key(shared_key, shared_key_len*8, &shared_key_aes)<0) {
-    	log_err_p(log, "ECDH::decrypt: Error setting AES decryption key");
-        goto err;
-    }
-
-    // iv is the parameter of env->encryptedContentInfo->contentEncryptionAlgorithm
-    void *ivcopy;
-    int len;
-    X509_ALGOR_get0(NULL, &len, &ivcopy,
-    		cms->d.envelopedData->encryptedContentInfo->contentEncryptionAlgorithm);
-    if(!ivcopy) {
-    	log_err_p(log, "ECDH::decrypt: Error extracting IV");
-        goto err;
-    }
-    iv_cbc = ASN1_STRING_data((ASN1_STRING *)ivcopy);
-
-    for(int i=0;i<16;i++) {
-        cek[i] = i;
-    }
-    if(!AES_unwrap_key(&shared_key_aes, NULL, cek, ASN1_STRING_data(rek->encryptedKey),
-    		ASN1_STRING_length(rek->encryptedKey))) {
-    	log_err_p(log, "ECDH::decrypt: Error in AES_unwrap_key");
-        goto err;
-    }
-
-    if(AES_set_decrypt_key(cek, cek_len*8, &cek_aes)<0) {
-    	log_err_p(log, "ECDH::decrypt: Error setting AES decryption key");
-        goto err;
+    {
+        unsigned char shared_data[shared_data_len];
+        unsigned char cek[cek_len];
+        memset(shared_data, 0xffff, shared_data_len);
+        memset(cek, 0xffff, cek_len);
+
+        // Retrieve the User Keying Material
+        ukm = ASN1_STRING_data(ri->d.kari->ukm);
+        log_debug_p(log, "ECDH::decrypt: User Keying Material (ukm) :  %s", Ciphersuite::buf2str(ukm, 16).c_str());
+
+        // Compute the ECDH shared value from the public key and my private key
+        if(!ECDH_compute_key(shared_data, shared_data_len, ephemeral, myKey_ec, NULL)) {
+            log_err_p(log, "ECDH::decrypt: Error computing ECDH shared value");
+            goto err;
+        }
+
+        // Derive the shared key from the shared data and the ukm
+        shared_key = derive_key(ukm, shared_data, shared_data_len*4);
+        if(AES_set_decrypt_key(shared_key, shared_key_len*8, &shared_key_aes)<0) {
+            log_err_p(log, "ECDH::decrypt: Error setting AES decryption key");
+            goto err;
+        }
+
+        // iv is the parameter of env->encryptedContentInfo->contentEncryptionAlgorithm
+        void *ivcopy;
+        int len;
+        X509_ALGOR_get0(NULL, &len, &ivcopy,
+                cms->d.envelopedData->encryptedContentInfo->contentEncryptionAlgorithm);
+        if(!ivcopy) {
+            log_err_p(log, "ECDH::decrypt: Error extracting IV");
+            goto err;
+        }
+        iv_cbc = ASN1_STRING_data((ASN1_STRING *)ivcopy);
+
+        for(int i=0;i<16;i++) {
+            cek[i] = i;
+        }
+        if(!AES_unwrap_key(&shared_key_aes, NULL, cek, ASN1_STRING_data(rek->encryptedKey),
+                    ASN1_STRING_length(rek->encryptedKey))) {
+            log_err_p(log, "ECDH::decrypt: Error in AES_unwrap_key");
+            goto err;
+        }
+
+        if(AES_set_decrypt_key(cek, cek_len*8, &cek_aes)<0) {
+            log_err_p(log, "ECDH::decrypt: Error setting AES decryption key");
+            goto err;
+        }
     }
     out.reserve(ASN1_STRING_length(cms->d.envelopedData->encryptedContentInfo->encryptedContent));
     out.set_len(ASN1_STRING_length(cms->d.envelopedData->encryptedContentInfo->encryptedContent));

--SUOF0GtieIMvvwua--

