Path: blob/master/test/jdk/sun/security/ssl/DHKeyExchange/DHEKeySizing.java
41152 views
/*1* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223//24// SunJSSE does not support dynamic system properties, no way to re-use25// system properties in samevm/agentvm mode.26//2728/*29* @test30* @bug 695639831* @summary make ephemeral DH key match the length of the certificate key32* @run main/othervm -Djdk.tls.client.enableSessionTicketExtension=false33* DHEKeySizing TLS_DHE_RSA_WITH_AES_128_CBC_SHA false 1643 26734* @run main/othervm -Djsse.enableFFDHE=false35* -Djdk.tls.client.enableSessionTicketExtension=false36* DHEKeySizing SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA true 1259 7537* @run main/othervm -Djsse.enableFFDHE=false38* -Djdk.tls.ephemeralDHKeySize=matched39* -Djdk.tls.client.enableSessionTicketExtension=false40* DHEKeySizing SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA true 1259 7541* @run main/othervm -Djsse.enableFFDHE=false42* -Djdk.tls.ephemeralDHKeySize=legacy43* -Djdk.tls.client.enableSessionTicketExtension=false44* DHEKeySizing SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA true 1259 7545* @run main/othervm -Djsse.enableFFDHE=false46* -Djdk.tls.ephemeralDHKeySize=102447* -Djdk.tls.client.enableSessionTicketExtension=false48* DHEKeySizing SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA true 1259 7549*50* @run main/othervm -Djsse.enableFFDHE=false51* -Djdk.tls.client.enableSessionTicketExtension=false52* DHEKeySizing SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA true 233 7553*54* @run main/othervm -Djsse.enableFFDHE=false55* -Djdk.tls.client.enableSessionTicketExtension=false56* DHEKeySizing TLS_DHE_RSA_WITH_AES_128_CBC_SHA false 1387 13957* @run main/othervm -Djsse.enableFFDHE=false58* -Djdk.tls.ephemeralDHKeySize=legacy59* -Djdk.tls.client.enableSessionTicketExtension=false60* DHEKeySizing TLS_DHE_RSA_WITH_AES_128_CBC_SHA false 1323 10761* @run main/othervm -Djsse.enableFFDHE=false62* -Djdk.tls.ephemeralDHKeySize=matched63* -Djdk.tls.client.enableSessionTicketExtension=false64* DHEKeySizing TLS_DHE_RSA_WITH_AES_128_CBC_SHA false 1643 26765* @run main/othervm -Djsse.enableFFDHE=false66* -Djdk.tls.ephemeralDHKeySize=102467* -Djdk.tls.client.enableSessionTicketExtension=false68* DHEKeySizing TLS_DHE_RSA_WITH_AES_128_CBC_SHA false 1387 13969*70* @run main/othervm -Djsse.enableFFDHE=false71* -Djdk.tls.client.enableSessionTicketExtension=false72* DHEKeySizing SSL_DH_anon_WITH_RC4_128_MD5 false 361 13973* @run main/othervm -Djsse.enableFFDHE=false74* -Djdk.tls.client.enableSessionTicketExtension=false75* -Djdk.tls.ephemeralDHKeySize=legacy76* DHEKeySizing SSL_DH_anon_WITH_RC4_128_MD5 false 297 10777* @run main/othervm -Djsse.enableFFDHE=false78* -Djdk.tls.client.enableSessionTicketExtension=false79* -Djdk.tls.ephemeralDHKeySize=matched80* DHEKeySizing SSL_DH_anon_WITH_RC4_128_MD5 false 361 13981* @run main/othervm -Djsse.enableFFDHE=false82* -Djdk.tls.client.enableSessionTicketExtension=false83* -Djdk.tls.ephemeralDHKeySize=102484* DHEKeySizing SSL_DH_anon_WITH_RC4_128_MD5 false 361 13985*/8687/*88* This is a simple hack to test key sizes of Diffie-Hellman key exchanging89* during SSL/TLS handshaking.90*91* The record length of DH ServerKeyExchange and ClientKeyExchange.92* ServerKeyExchange message are wrapped in ServerHello series messages, which93* contains ServerHello, Certificate and ServerKeyExchange message.94*95* struct {96* opaque dh_p<1..2^16-1>;97* opaque dh_g<1..2^16-1>;98* opaque dh_Ys<1..2^16-1>;99* } ServerDHParams; // Ephemeral DH parameters100*101* struct {102* select (PublicValueEncoding) {103* case implicit: struct { };104* case explicit: opaque dh_Yc<1..2^16-1>;105* } dh_public;106* } ClientDiffieHellmanPublic;107*108* Fomr above structures, it is clear that if the DH key size increasing 128109* bits (16 bytes), the ServerHello series messages increases 48 bytes110* (becuase dh_p, dh_g and dh_Ys each increase 16 bytes) and ClientKeyExchange111* increases 16 bytes (because of the size increasing of dh_Yc).112*113* Here is a summary of the record length in the test case.114*115* | ServerHello Series | ClientKeyExchange | ServerHello Anon116* 512-bit | 1259 bytes | 75 bytes | 233 bytes117* 768-bit | 1323 bytes | 107 bytes | 297 bytes118* 1024-bit | 1387 bytes | 139 bytes | 361 bytes119* 2048-bit | 1643 bytes | 267 bytes | 361 bytes120*/121122import javax.net.ssl.*;123import javax.net.ssl.SSLEngineResult.*;124import java.io.*;125import java.nio.*;126import java.security.KeyStore;127import java.security.KeyFactory;128import java.security.Security;129import java.security.cert.Certificate;130import java.security.cert.CertificateFactory;131import java.security.spec.PKCS8EncodedKeySpec;132import java.security.interfaces.*;133import java.util.Base64;134135public class DHEKeySizing {136137private final static boolean debug = true;138139// key length bias because of the stripping of leading zero bytes of140// negotiated DH keys.141//142// This is an effort to mimum intermittent failure when we cannot143// estimate what's the exact number of leading zero bytes of144// negotiated DH keys.145private final static int KEY_LEN_BIAS = 6;146147private SSLContext sslc;148private SSLEngine ssle1; // client149private SSLEngine ssle2; // server150151private ByteBuffer appOut1; // write side of ssle1152private ByteBuffer appIn1; // read side of ssle1153private ByteBuffer appOut2; // write side of ssle2154private ByteBuffer appIn2; // read side of ssle2155156private ByteBuffer oneToTwo; // "reliable" transport ssle1->ssle2157private ByteBuffer twoToOne; // "reliable" transport ssle2->ssle1158159/*160* Where do we find the keystores?161*/162// Certificates and key used in the test.163static String trustedCertStr =164"-----BEGIN CERTIFICATE-----\n" +165"MIIC8jCCAdqgAwIBAgIEUjkuRzANBgkqhkiG9w0BAQUFADA7MR0wGwYDVQQLExRT\n" +166"dW5KU1NFIFRlc3QgU2VyaXZjZTENMAsGA1UEChMESmF2YTELMAkGA1UEBhMCVVMw\n" +167"HhcNMTMwOTE4MDQzODMxWhcNMTMxMjE3MDQzODMxWjA7MR0wGwYDVQQLExRTdW5K\n" +168"U1NFIFRlc3QgU2VyaXZjZTENMAsGA1UEChMESmF2YTELMAkGA1UEBhMCVVMwggEi\n" +169"MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCO+IGeaskJAvEcYc7pCl9neK3E\n" +170"a28fwWLtChufYNaC9hQfZlUdETWYjV7fZJVJKT/oLzdDNMWuVA0LKXArpI3thLNK\n" +171"QLXisdF9hKPlZRDazACL9kWUUtJ0FzpEySK4e8wW/z9FuU6e6iO19FbjxAfInJqk\n" +172"3EDiEhB5g73S2vtvPCxgq2DvWw9TDl/LIqdKG2JCS93koXCCaHmQ7MrIOqHPd+8r\n" +173"RbGpatXT9qyHKppUv9ATxVygO4rA794mgCFxpT+fkhz+NEB0twTkM65T1hnnOv5n\n" +174"ZIxkcjBggt85UlZtnP3b9P7SYxsWIa46Oc38Od2f3YejfVg6B+PqPgWNl3+/AgMB\n" +175"AAEwDQYJKoZIhvcNAQEFBQADggEBAAlrP6DFLRPSy0IgQhcI2i56tR/na8pezSte\n" +176"ZHcCdaCZPDy4UP8mpLJ9QCjEB5VJv8hPm4xdK7ULnKGOGHgYqDpV2ZHvQlhV1woQ\n" +177"TZGb/LM3c6kAs0j4j9KM2fq3iYUYexjIkS1KzsziflxMM6igS9BRMBR2LQyU+cYq\n" +178"YEsFzkF7Aj2ET4v/+tgot9mRr2NioJcaJkdsPDpMU3IKB1cczfu+OuLQ/GCG0Fqu\n" +179"6ijCeCqfnaAbemHbJeVZZ6Qgka3uC2YMntLBmLkhqEo1d9zGYLoh7oWL77y5ibQZ\n" +180"LK5/H/zikcu579TWjlDHcqL3arCwBcrtsjSaPrRSWMrWV/6c0qw=\n" +181"-----END CERTIFICATE-----";182183// Private key in the format of PKCS#8184static String targetPrivateKey =185"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCO+IGeaskJAvEc\n" +186"Yc7pCl9neK3Ea28fwWLtChufYNaC9hQfZlUdETWYjV7fZJVJKT/oLzdDNMWuVA0L\n" +187"KXArpI3thLNKQLXisdF9hKPlZRDazACL9kWUUtJ0FzpEySK4e8wW/z9FuU6e6iO1\n" +188"9FbjxAfInJqk3EDiEhB5g73S2vtvPCxgq2DvWw9TDl/LIqdKG2JCS93koXCCaHmQ\n" +189"7MrIOqHPd+8rRbGpatXT9qyHKppUv9ATxVygO4rA794mgCFxpT+fkhz+NEB0twTk\n" +190"M65T1hnnOv5nZIxkcjBggt85UlZtnP3b9P7SYxsWIa46Oc38Od2f3YejfVg6B+Pq\n" +191"PgWNl3+/AgMBAAECggEAPdb5Ycc4m4A9QBSCRcRpzbyiFLKPh0HDg1n65q4hOtYr\n" +192"kAVYTVFTSF/lqGS+Ob3w2YIKujQKSUQrvCc5UHdFuHXMgxKIWbymK0+DAMb9SlYw\n" +193"6lkkcWp9gx9E4dnJ/df2SAAxovvrKMuHlL1SFASHhVtPfH2URvSfUaANLDXxyYOs\n" +194"8BX0Nr6wazhWjLjXo9yIGnKSvFfB8XisYcA78kEgas43zhmIGCDPqaYyyffOfRbx\n" +195"pM1KNwGmlN86iWR1CbwA/wwhcMySWQueS+s7cHbpRqZIYJF9jEeELiwi0vxjealS\n" +196"EMuHYedIRFMWaDIq9XyjrvXamHb0Z25jlXBNZHaM0QKBgQDE9adl+zAezR/n79vw\n" +197"0XiX2Fx1UEo3ApZHuoA2Q/PcBk+rlKqqQ3IwTcy6Wo648wK7v6Nq7w5nEWcsf0dU\n" +198"QA2Ng/AJEev/IfF34x7sKGYxtk1gcE0EuSBA3R+ocEZxnNw1Ryd5nUU24s8d4jCP\n" +199"Mkothnyaim+zE2raDlEtVc0CaQKBgQC509av+02Uq5oMjzbQp5PBJfQFjATOQT15\n" +200"eefYnVYurkQ1kcVfixkrO2ORhg4SjmI2Z5hJDgGtXdwgidpzkad+R2epS5qLMyno\n" +201"lQVpY6bMpEZ7Mos0yQygxnm8uNohEcTExOe+nP5fNJVpzBsGmfeyYOhnPQlf6oqf\n" +202"0cHizedb5wKBgQC/l5LyMil6HOGHlhzmIm3jj7VI7QR0hJC5T6N+phVml8ESUDjA\n" +203"DYHbmSKouISTRtkG14FY+RiSjCxH7bvuKazFV2289PETquogTA/9e8MFYqfcQwG4\n" +204"sXi9gBxWlnj/9a2EKiYtOB5nKLR/BlNkSHA93tAA6N+FXEMZwMmYhxk42QKBgAuY\n" +205"HQgD3PZOsqDf+qKQIhbmAFCsSMx5o5VFtuJ8BpmJA/Z3ruHkMuDQpsi4nX4o5hXQ\n" +206"5t6AAjjH52kcUMXvK40kdWJJtk3DFnVNfvXxYsHX6hHbuHXFqYUKfSP6QJnZmvZP\n" +207"9smcz/4usLfWJUWHK740b6upUkFqx9Vq5/b3s9y3AoGAdM5TW7LkkOFsdMGVAUzR\n" +208"9iXmCWElHTK2Pcp/3yqDBHSfiQx6Yp5ANyPnE9NBM0yauCfOyBB2oxLO4Rdv3Rqk\n" +209"9V9kyR/YAGr7dJaPcQ7pZX0OpkzgueAOJYPrx5VUzPYUtklYV1ycFZTfKlpFCxT+\n" +210"Ei6KUo0NXSdUIcB4yib1J10=";211212static char passphrase[] = "passphrase".toCharArray();213214/*215* Majority of the test case is here, setup is done below.216*/217218private void createSSLEngines() throws Exception {219ssle1 = sslc.createSSLEngine("client", 1);220ssle1.setUseClientMode(true);221222ssle2 = sslc.createSSLEngine("server", 2);223ssle2.setUseClientMode(false);224}225226private boolean isHandshaking(SSLEngine e) {227return (e.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING);228}229230private void checkResult(ByteBuffer bbIn, ByteBuffer bbOut,231SSLEngineResult result,232Status status, HandshakeStatus hsStatus,233int consumed, int produced)234throws Exception {235236if ((status != null) && (result.getStatus() != status)) {237throw new Exception("Unexpected Status: need = " + status +238" got = " + result.getStatus());239}240241if ((hsStatus != null) && (result.getHandshakeStatus() != hsStatus)) {242throw new Exception("Unexpected hsStatus: need = " + hsStatus +243" got = " + result.getHandshakeStatus());244}245246if ((consumed != -1) && (consumed != result.bytesConsumed())) {247throw new Exception("Unexpected consumed: need = " + consumed +248" got = " + result.bytesConsumed());249}250251if ((produced != -1) && (produced != result.bytesProduced())) {252throw new Exception("Unexpected produced: need = " + produced +253" got = " + result.bytesProduced());254}255256if ((consumed != -1) && (bbIn.position() != result.bytesConsumed())) {257throw new Exception("Consumed " + bbIn.position() +258" != " + consumed);259}260261if ((produced != -1) && (bbOut.position() != result.bytesProduced())) {262throw new Exception("produced " + bbOut.position() +263" != " + produced);264}265}266267private void test(String cipherSuite, boolean exportable,268int lenServerKeyEx, int lenClientKeyEx) throws Exception {269270createSSLEngines();271createBuffers();272273SSLEngineResult result1; // ssle1's results from last operation274SSLEngineResult result2; // ssle2's results from last operation275276String[] suites = new String [] {cipherSuite};277278ssle1.setEnabledCipherSuites(suites);279ssle2.setEnabledCipherSuites(suites);280281log("======================================");282log("===================");283log("client hello");284result1 = ssle1.wrap(appOut1, oneToTwo);285checkResult(appOut1, oneToTwo, result1,286Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);287oneToTwo.flip();288289result2 = ssle2.unwrap(oneToTwo, appIn2);290checkResult(oneToTwo, appIn2, result2,291Status.OK, HandshakeStatus.NEED_TASK, result1.bytesProduced(), 0);292runDelegatedTasks(ssle2);293oneToTwo.compact();294295log("===================");296log("ServerHello");297result2 = ssle2.wrap(appOut2, twoToOne);298checkResult(appOut2, twoToOne, result2,299Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);300twoToOne.flip();301302log("Message length of ServerHello series: " + twoToOne.remaining());303if (twoToOne.remaining() < (lenServerKeyEx - KEY_LEN_BIAS) ||304twoToOne.remaining() > lenServerKeyEx) {305throw new Exception(306"Expected to generate ServerHello series messages of " +307lenServerKeyEx + " bytes, but not " + twoToOne.remaining());308}309310result1 = ssle1.unwrap(twoToOne, appIn1);311checkResult(twoToOne, appIn1, result1,312Status.OK, HandshakeStatus.NEED_TASK, result2.bytesProduced(), 0);313runDelegatedTasks(ssle1);314twoToOne.compact();315316log("===================");317log("Key Exchange");318result1 = ssle1.wrap(appOut1, oneToTwo);319checkResult(appOut1, oneToTwo, result1,320Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);321oneToTwo.flip();322323log("Message length of ClientKeyExchange: " + oneToTwo.remaining());324if (oneToTwo.remaining() < (lenClientKeyEx - KEY_LEN_BIAS) ||325oneToTwo.remaining() > lenClientKeyEx) {326throw new Exception(327"Expected to generate ClientKeyExchange message of " +328lenClientKeyEx + " bytes, but not " + oneToTwo.remaining());329}330result2 = ssle2.unwrap(oneToTwo, appIn2);331checkResult(oneToTwo, appIn2, result2,332Status.OK, HandshakeStatus.NEED_TASK, result1.bytesProduced(), 0);333runDelegatedTasks(ssle2);334oneToTwo.compact();335336log("===================");337log("Client CCS");338result1 = ssle1.wrap(appOut1, oneToTwo);339checkResult(appOut1, oneToTwo, result1,340Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);341oneToTwo.flip();342343result2 = ssle2.unwrap(oneToTwo, appIn2);344checkResult(oneToTwo, appIn2, result2,345Status.OK, HandshakeStatus.NEED_UNWRAP,346result1.bytesProduced(), 0);347oneToTwo.compact();348349log("===================");350log("Client Finished");351result1 = ssle1.wrap(appOut1, oneToTwo);352checkResult(appOut1, oneToTwo, result1,353Status.OK, HandshakeStatus.NEED_UNWRAP, 0, -1);354oneToTwo.flip();355356result2 = ssle2.unwrap(oneToTwo, appIn2);357checkResult(oneToTwo, appIn2, result2,358Status.OK, HandshakeStatus.NEED_WRAP,359result1.bytesProduced(), 0);360oneToTwo.compact();361362log("===================");363log("Server CCS");364result2 = ssle2.wrap(appOut2, twoToOne);365checkResult(appOut2, twoToOne, result2,366Status.OK, HandshakeStatus.NEED_WRAP, 0, -1);367twoToOne.flip();368369result1 = ssle1.unwrap(twoToOne, appIn1);370checkResult(twoToOne, appIn1, result1,371Status.OK, HandshakeStatus.NEED_UNWRAP, result2.bytesProduced(), 0);372twoToOne.compact();373374log("===================");375log("Server Finished");376result2 = ssle2.wrap(appOut2, twoToOne);377checkResult(appOut2, twoToOne, result2,378Status.OK, HandshakeStatus.FINISHED, 0, -1);379twoToOne.flip();380381result1 = ssle1.unwrap(twoToOne, appIn1);382checkResult(twoToOne, appIn1, result1,383Status.OK, HandshakeStatus.FINISHED, result2.bytesProduced(), 0);384twoToOne.compact();385386log("===================");387log("Check Session/Ciphers");388String cs = ssle1.getSession().getCipherSuite();389if (!cs.equals(suites[0])) {390throw new Exception("suites not equal: " + cs + "/" + suites[0]);391}392393cs = ssle2.getSession().getCipherSuite();394if (!cs.equals(suites[0])) {395throw new Exception("suites not equal: " + cs + "/" + suites[0]);396}397398log("===================");399log("Done with SSL/TLS handshaking");400}401402public static void main(String args[]) throws Exception {403// reset security properties to make sure that the algorithms404// and keys used in this test are not disabled.405Security.setProperty("jdk.tls.disabledAlgorithms", "");406Security.setProperty("jdk.certpath.disabledAlgorithms", "");407408if (args.length != 4) {409System.out.println(410"Usage: java DHEKeySizing cipher-suite " +411"exportable(true|false)\n" +412" size-of-server-hello-record size-of-client-key-exchange");413throw new Exception("Incorrect usage!");414}415416(new DHEKeySizing()).test(args[0],417Boolean.parseBoolean(args[1]),418Integer.parseInt(args[2]),419Integer.parseInt(args[3]));420System.out.println("Test Passed.");421}422423/*424* **********************************************************425* Majority of the test case is above, below is just setup stuff426* **********************************************************427*/428429public DHEKeySizing() throws Exception {430sslc = getSSLContext();431}432433/*434* Create an initialized SSLContext to use for this test.435*/436private SSLContext getSSLContext() throws Exception {437438// generate certificate from cert string439CertificateFactory cf = CertificateFactory.getInstance("X.509");440441// create a key store442KeyStore ts = KeyStore.getInstance("JKS");443KeyStore ks = KeyStore.getInstance("JKS");444ts.load(null, null);445ks.load(null, null);446447// import the trused cert448ByteArrayInputStream is =449new ByteArrayInputStream(trustedCertStr.getBytes());450Certificate trusedCert = cf.generateCertificate(is);451is.close();452ts.setCertificateEntry("rsa-trusted-2048", trusedCert);453454// generate the private key.455String keySpecStr = targetPrivateKey;456PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(457Base64.getMimeDecoder().decode(keySpecStr));458KeyFactory kf = KeyFactory.getInstance("RSA");459RSAPrivateKey priKey = (RSAPrivateKey)kf.generatePrivate(priKeySpec);460461Certificate[] chain = new Certificate[1];462chain[0] = trusedCert;463464// import the key entry.465ks.setKeyEntry("rsa-key-2048", priKey, passphrase, chain);466467// create SSL context468KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");469kmf.init(ks, passphrase);470471TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");472tmf.init(ts);473474SSLContext sslCtx = SSLContext.getInstance("TLSv1");475sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);476477return sslCtx;478}479480private void createBuffers() {481// Size the buffers as appropriate.482483SSLSession session = ssle1.getSession();484int appBufferMax = session.getApplicationBufferSize();485int netBufferMax = session.getPacketBufferSize();486487appIn1 = ByteBuffer.allocateDirect(appBufferMax + 50);488appIn2 = ByteBuffer.allocateDirect(appBufferMax + 50);489490oneToTwo = ByteBuffer.allocateDirect(netBufferMax);491twoToOne = ByteBuffer.allocateDirect(netBufferMax);492493appOut1 = ByteBuffer.wrap("Hi Engine2, I'm SSLEngine1".getBytes());494appOut2 = ByteBuffer.wrap("Hello Engine1, I'm SSLEngine2".getBytes());495496log("AppOut1 = " + appOut1);497log("AppOut2 = " + appOut2);498log("");499}500501private static void runDelegatedTasks(SSLEngine engine) throws Exception {502503Runnable runnable;504while ((runnable = engine.getDelegatedTask()) != null) {505log("running delegated task...");506runnable.run();507}508}509510private static void log(String str) {511if (debug) {512System.out.println(str);513}514}515}516517518