Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB0CF103FC for ; Tue, 14 Jan 2014 16:41:13 +0000 (UTC) Received: (qmail 22150 invoked by uid 500); 14 Jan 2014 16:41:13 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 22095 invoked by uid 500); 14 Jan 2014 16:41:13 -0000 Mailing-List: contact dev-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list dev@cordova.apache.org Received: (qmail 22087 invoked by uid 99); 14 Jan 2014 16:41:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Jan 2014 16:41:12 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of cmarcelk@gmail.com designates 209.85.213.52 as permitted sender) Received: from [209.85.213.52] (HELO mail-yh0-f52.google.com) (209.85.213.52) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Jan 2014 16:41:07 +0000 Received: by mail-yh0-f52.google.com with SMTP id v1so184034yhn.11 for ; Tue, 14 Jan 2014 08:40:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=wj0xdh/LT7TQ+9LffD4Cx/rYQDHgpkdi90D9fYo3XLc=; b=IAwpv5M4Z7/pkJMjBbkBi/SMSI0yXPK3/YFlDJ6eYG2NXI4/aV70NNvqb2fMxGiKRu ZawWBsnwOO8WCiE51Pk82fWFNCfM2wo/mfMCGd2tERr1NX+EFNRHSDV33vqEoZnVe2wE Yd3wJ2+SAuVfivmSsiyfeupG81lgwj6ElFcTOgb9qSX7i5hvRGC66P3xTi/vLO06rQ/m 3mOnJEImyXwt8AU0jvmxxwtCKzGMIcFGPiXdJpa1XwiU1Jw1CmP5ebvltpn8BH/uB/RW RCfQiGeYPftOYZlVj693RPXtfG8eIQej4LkD+/xJdvoxEWljxOiyRQ2mQL23mmAGUEWQ YKtw== X-Received: by 10.236.87.1 with SMTP id x1mr34234943yhe.51.1389717647167; Tue, 14 Jan 2014 08:40:47 -0800 (PST) Received: from marcelk-macbook.raleigh.ibm.com (bi-03pt1.bluebird.ibm.com. [129.42.208.172]) by mx.google.com with ESMTPSA id k3sm1738681yhc.13.2014.01.14.08.40.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 14 Jan 2014 08:40:46 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: Adding SSL Certificate Pinning to Cordova From: Marcel Kinard In-Reply-To: <466D534D-C4C2-4242-8E15-ECC08F3DFD2B@gmail.com> Date: Tue, 14 Jan 2014 11:40:45 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: References: <4C3AE595-7B77-4240-A364-2D1D8C3F4487@devgeeks.org> <466D534D-C4C2-4242-8E15-ECC08F3DFD2B@gmail.com> To: dev@cordova.apache.org X-Mailer: Apple Mail (2.1510) X-Virus-Checked: Checked by ClamAV on apache.org And onReceivedSslError would cover the self-signed scenario, but it = wouldn't cover the real pinning scenario with a properly signed cert, = because it gets invoked only on a handshake failure, not a handshake = success. On Jan 14, 2014, at 11:38 AM, Marcel Kinard wrote: > I've played with that recently, and it may do most of what you want.=20= >=20 > The method CordovaWebViewClient.onReceivedSslError does get called = when attempting an SSL handshake with a server that has a self-signed = cert. I tested this using and window.open(_self). >=20 > When setting the app to debuggable=3Dtrue in AndroidManifest.xml, the = onReceivedSslError() method will treat this as a special case, and = basically ignore the SSL error by always calling = SslErrorHandler.proceed(). Once proceed() has been called, subsequent = SSL connections to that server will not result in onReceivedSslError() = getting called - once that self-signed cert has been accepted, = subsequent requests are considered accepted also. This "acceptance" is = persistent only for the duration of a single application execution - if = the application is restarted, it forgets the acceptance. According to = the docs, WebView.clearSslPreferences() might reset that. >=20 > When using debuggable=3Dfalse, it takes a different path in = onReceivedSslError() and it doesn't eat the error, and the connection = fails. I think at this point what you'd want to do is inspect the cert = to see if it matches what you want, and then call proceed() if it is = good. However, I think the last sticking point (from what I see in the = javadocs) is that although you are handed an SslCertificate object in = onReceivedSslError, the methods on SslCertificate will get you only the = human-readable info (self DN, issuer DN, valid date) and not the actual = public key. So all you can check is the DN, which I don't think is good = enough. I don't see a way to work around that by getting the raw pem or = similar. >=20 > On Jan 14, 2014, at 10:42 AM, Andrew Grieve = wrote: >=20 >> Actually, looking again, there's a custom API just for SSL certs that >> will provide you the cert to check: onReceivedSslError(). >=20