src/java.base/share/classes/sun/security/ssl/SSLCipher.java
changeset 53734 cb1642ccc732
parent 52690 cecba555360c
child 55072 d0f73fccf5f3
equal deleted inserted replaced
53733:b5d45c2fe8a0 53734:cb1642ccc732
     1 /*
     1 /*
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   849             StreamReadCipher(Authenticator authenticator,
   849             StreamReadCipher(Authenticator authenticator,
   850                     ProtocolVersion protocolVersion, String algorithm,
   850                     ProtocolVersion protocolVersion, String algorithm,
   851                     Key key, AlgorithmParameterSpec params,
   851                     Key key, AlgorithmParameterSpec params,
   852                     SecureRandom random) throws GeneralSecurityException {
   852                     SecureRandom random) throws GeneralSecurityException {
   853                 super(authenticator, protocolVersion);
   853                 super(authenticator, protocolVersion);
   854                 this.cipher = JsseJce.getCipher(algorithm);
   854                 this.cipher = Cipher.getInstance(algorithm);
   855                 cipher.init(Cipher.DECRYPT_MODE, key, params, random);
   855                 cipher.init(Cipher.DECRYPT_MODE, key, params, random);
   856             }
   856             }
   857 
   857 
   858             @Override
   858             @Override
   859             public Plaintext decrypt(byte contentType, ByteBuffer bb,
   859             public Plaintext decrypt(byte contentType, ByteBuffer bb,
   931             StreamWriteCipher(Authenticator authenticator,
   931             StreamWriteCipher(Authenticator authenticator,
   932                     ProtocolVersion protocolVersion, String algorithm,
   932                     ProtocolVersion protocolVersion, String algorithm,
   933                     Key key, AlgorithmParameterSpec params,
   933                     Key key, AlgorithmParameterSpec params,
   934                     SecureRandom random) throws GeneralSecurityException {
   934                     SecureRandom random) throws GeneralSecurityException {
   935                 super(authenticator, protocolVersion);
   935                 super(authenticator, protocolVersion);
   936                 this.cipher = JsseJce.getCipher(algorithm);
   936                 this.cipher = Cipher.getInstance(algorithm);
   937                 cipher.init(Cipher.ENCRYPT_MODE, key, params, random);
   937                 cipher.init(Cipher.ENCRYPT_MODE, key, params, random);
   938             }
   938             }
   939 
   939 
   940             @Override
   940             @Override
   941             public int encrypt(byte contentType, ByteBuffer bb) {
   941             public int encrypt(byte contentType, ByteBuffer bb) {
  1021             BlockReadCipher(Authenticator authenticator,
  1021             BlockReadCipher(Authenticator authenticator,
  1022                     ProtocolVersion protocolVersion, String algorithm,
  1022                     ProtocolVersion protocolVersion, String algorithm,
  1023                     Key key, AlgorithmParameterSpec params,
  1023                     Key key, AlgorithmParameterSpec params,
  1024                     SecureRandom random) throws GeneralSecurityException {
  1024                     SecureRandom random) throws GeneralSecurityException {
  1025                 super(authenticator, protocolVersion);
  1025                 super(authenticator, protocolVersion);
  1026                 this.cipher = JsseJce.getCipher(algorithm);
  1026                 this.cipher = Cipher.getInstance(algorithm);
  1027                 cipher.init(Cipher.DECRYPT_MODE, key, params, random);
  1027                 cipher.init(Cipher.DECRYPT_MODE, key, params, random);
  1028             }
  1028             }
  1029 
  1029 
  1030             @Override
  1030             @Override
  1031             public Plaintext decrypt(byte contentType, ByteBuffer bb,
  1031             public Plaintext decrypt(byte contentType, ByteBuffer bb,
  1173             BlockWriteCipher(Authenticator authenticator,
  1173             BlockWriteCipher(Authenticator authenticator,
  1174                     ProtocolVersion protocolVersion, String algorithm,
  1174                     ProtocolVersion protocolVersion, String algorithm,
  1175                     Key key, AlgorithmParameterSpec params,
  1175                     Key key, AlgorithmParameterSpec params,
  1176                     SecureRandom random) throws GeneralSecurityException {
  1176                     SecureRandom random) throws GeneralSecurityException {
  1177                 super(authenticator, protocolVersion);
  1177                 super(authenticator, protocolVersion);
  1178                 this.cipher = JsseJce.getCipher(algorithm);
  1178                 this.cipher = Cipher.getInstance(algorithm);
  1179                 cipher.init(Cipher.ENCRYPT_MODE, key, params, random);
  1179                 cipher.init(Cipher.ENCRYPT_MODE, key, params, random);
  1180             }
  1180             }
  1181 
  1181 
  1182             @Override
  1182             @Override
  1183             public int encrypt(byte contentType, ByteBuffer bb) {
  1183             public int encrypt(byte contentType, ByteBuffer bb) {
  1289                     ProtocolVersion protocolVersion,
  1289                     ProtocolVersion protocolVersion,
  1290                     SSLCipher sslCipher, String algorithm,
  1290                     SSLCipher sslCipher, String algorithm,
  1291                     Key key, AlgorithmParameterSpec params,
  1291                     Key key, AlgorithmParameterSpec params,
  1292                     SecureRandom random) throws GeneralSecurityException {
  1292                     SecureRandom random) throws GeneralSecurityException {
  1293                 super(authenticator, protocolVersion);
  1293                 super(authenticator, protocolVersion);
  1294                 this.cipher = JsseJce.getCipher(algorithm);
  1294                 this.cipher = Cipher.getInstance(algorithm);
  1295                 if (params == null) {
  1295                 if (params == null) {
  1296                     params = new IvParameterSpec(new byte[sslCipher.ivSize]);
  1296                     params = new IvParameterSpec(new byte[sslCipher.ivSize]);
  1297                 }
  1297                 }
  1298                 cipher.init(Cipher.DECRYPT_MODE, key, params, random);
  1298                 cipher.init(Cipher.DECRYPT_MODE, key, params, random);
  1299             }
  1299             }
  1453                     ProtocolVersion protocolVersion,
  1453                     ProtocolVersion protocolVersion,
  1454                     SSLCipher sslCipher, String algorithm,
  1454                     SSLCipher sslCipher, String algorithm,
  1455                     Key key, AlgorithmParameterSpec params,
  1455                     Key key, AlgorithmParameterSpec params,
  1456                     SecureRandom random) throws GeneralSecurityException {
  1456                     SecureRandom random) throws GeneralSecurityException {
  1457                 super(authenticator, protocolVersion);
  1457                 super(authenticator, protocolVersion);
  1458                 this.cipher = JsseJce.getCipher(algorithm);
  1458                 this.cipher = Cipher.getInstance(algorithm);
  1459                 this.random = random;
  1459                 this.random = random;
  1460                 if (params == null) {
  1460                 if (params == null) {
  1461                     params = new IvParameterSpec(new byte[sslCipher.ivSize]);
  1461                     params = new IvParameterSpec(new byte[sslCipher.ivSize]);
  1462                 }
  1462                 }
  1463                 cipher.init(Cipher.ENCRYPT_MODE, key, params, random);
  1463                 cipher.init(Cipher.ENCRYPT_MODE, key, params, random);
  1588                     ProtocolVersion protocolVersion,
  1588                     ProtocolVersion protocolVersion,
  1589                     SSLCipher sslCipher, String algorithm,
  1589                     SSLCipher sslCipher, String algorithm,
  1590                     Key key, AlgorithmParameterSpec params,
  1590                     Key key, AlgorithmParameterSpec params,
  1591                     SecureRandom random) throws GeneralSecurityException {
  1591                     SecureRandom random) throws GeneralSecurityException {
  1592                 super(authenticator, protocolVersion);
  1592                 super(authenticator, protocolVersion);
  1593                 this.cipher = JsseJce.getCipher(algorithm);
  1593                 this.cipher = Cipher.getInstance(algorithm);
  1594                 this.tagSize = sslCipher.tagSize;
  1594                 this.tagSize = sslCipher.tagSize;
  1595                 this.key = key;
  1595                 this.key = key;
  1596                 this.fixedIv = ((IvParameterSpec)params).getIV();
  1596                 this.fixedIv = ((IvParameterSpec)params).getIV();
  1597                 this.recordIvSize = sslCipher.ivSize - sslCipher.fixedIvSize;
  1597                 this.recordIvSize = sslCipher.ivSize - sslCipher.fixedIvSize;
  1598                 this.random = random;
  1598                 this.random = random;
  1703                     ProtocolVersion protocolVersion,
  1703                     ProtocolVersion protocolVersion,
  1704                     SSLCipher sslCipher, String algorithm,
  1704                     SSLCipher sslCipher, String algorithm,
  1705                     Key key, AlgorithmParameterSpec params,
  1705                     Key key, AlgorithmParameterSpec params,
  1706                     SecureRandom random) throws GeneralSecurityException {
  1706                     SecureRandom random) throws GeneralSecurityException {
  1707                 super(authenticator, protocolVersion);
  1707                 super(authenticator, protocolVersion);
  1708                 this.cipher = JsseJce.getCipher(algorithm);
  1708                 this.cipher = Cipher.getInstance(algorithm);
  1709                 this.tagSize = sslCipher.tagSize;
  1709                 this.tagSize = sslCipher.tagSize;
  1710                 this.key = key;
  1710                 this.key = key;
  1711                 this.fixedIv = ((IvParameterSpec)params).getIV();
  1711                 this.fixedIv = ((IvParameterSpec)params).getIV();
  1712                 this.recordIvSize = sslCipher.ivSize - sslCipher.fixedIvSize;
  1712                 this.recordIvSize = sslCipher.ivSize - sslCipher.fixedIvSize;
  1713                 this.random = random;
  1713                 this.random = random;
  1836                     ProtocolVersion protocolVersion,
  1836                     ProtocolVersion protocolVersion,
  1837                     SSLCipher sslCipher, String algorithm,
  1837                     SSLCipher sslCipher, String algorithm,
  1838                     Key key, AlgorithmParameterSpec params,
  1838                     Key key, AlgorithmParameterSpec params,
  1839                     SecureRandom random) throws GeneralSecurityException {
  1839                     SecureRandom random) throws GeneralSecurityException {
  1840                 super(authenticator, protocolVersion);
  1840                 super(authenticator, protocolVersion);
  1841                 this.cipher = JsseJce.getCipher(algorithm);
  1841                 this.cipher = Cipher.getInstance(algorithm);
  1842                 this.tagSize = sslCipher.tagSize;
  1842                 this.tagSize = sslCipher.tagSize;
  1843                 this.key = key;
  1843                 this.key = key;
  1844                 this.iv = ((IvParameterSpec)params).getIV();
  1844                 this.iv = ((IvParameterSpec)params).getIV();
  1845                 this.random = random;
  1845                 this.random = random;
  1846 
  1846 
  1990                     ProtocolVersion protocolVersion,
  1990                     ProtocolVersion protocolVersion,
  1991                     SSLCipher sslCipher, String algorithm,
  1991                     SSLCipher sslCipher, String algorithm,
  1992                     Key key, AlgorithmParameterSpec params,
  1992                     Key key, AlgorithmParameterSpec params,
  1993                     SecureRandom random) throws GeneralSecurityException {
  1993                     SecureRandom random) throws GeneralSecurityException {
  1994                 super(authenticator, protocolVersion);
  1994                 super(authenticator, protocolVersion);
  1995                 this.cipher = JsseJce.getCipher(algorithm);
  1995                 this.cipher = Cipher.getInstance(algorithm);
  1996                 this.tagSize = sslCipher.tagSize;
  1996                 this.tagSize = sslCipher.tagSize;
  1997                 this.key = key;
  1997                 this.key = key;
  1998                 this.iv = ((IvParameterSpec)params).getIV();
  1998                 this.iv = ((IvParameterSpec)params).getIV();
  1999                 this.random = random;
  1999                 this.random = random;
  2000 
  2000 
  2131                     ProtocolVersion protocolVersion,
  2131                     ProtocolVersion protocolVersion,
  2132                     SSLCipher sslCipher, String algorithm,
  2132                     SSLCipher sslCipher, String algorithm,
  2133                     Key key, AlgorithmParameterSpec params,
  2133                     Key key, AlgorithmParameterSpec params,
  2134                     SecureRandom random) throws GeneralSecurityException {
  2134                     SecureRandom random) throws GeneralSecurityException {
  2135                 super(authenticator, protocolVersion);
  2135                 super(authenticator, protocolVersion);
  2136                 this.cipher = JsseJce.getCipher(algorithm);
  2136                 this.cipher = Cipher.getInstance(algorithm);
  2137                 this.tagSize = sslCipher.tagSize;
  2137                 this.tagSize = sslCipher.tagSize;
  2138                 this.key = key;
  2138                 this.key = key;
  2139                 this.iv = ((IvParameterSpec)params).getIV();
  2139                 this.iv = ((IvParameterSpec)params).getIV();
  2140                 this.random = random;
  2140                 this.random = random;
  2141 
  2141 
  2250                     ProtocolVersion protocolVersion,
  2250                     ProtocolVersion protocolVersion,
  2251                     SSLCipher sslCipher, String algorithm,
  2251                     SSLCipher sslCipher, String algorithm,
  2252                     Key key, AlgorithmParameterSpec params,
  2252                     Key key, AlgorithmParameterSpec params,
  2253                     SecureRandom random) throws GeneralSecurityException {
  2253                     SecureRandom random) throws GeneralSecurityException {
  2254                 super(authenticator, protocolVersion);
  2254                 super(authenticator, protocolVersion);
  2255                 this.cipher = JsseJce.getCipher(algorithm);
  2255                 this.cipher = Cipher.getInstance(algorithm);
  2256                 this.tagSize = sslCipher.tagSize;
  2256                 this.tagSize = sslCipher.tagSize;
  2257                 this.key = key;
  2257                 this.key = key;
  2258                 this.iv = ((IvParameterSpec)params).getIV();
  2258                 this.iv = ((IvParameterSpec)params).getIV();
  2259                 this.random = random;
  2259                 this.random = random;
  2260 
  2260 
  2390                     ProtocolVersion protocolVersion,
  2390                     ProtocolVersion protocolVersion,
  2391                     SSLCipher sslCipher, String algorithm,
  2391                     SSLCipher sslCipher, String algorithm,
  2392                     Key key, AlgorithmParameterSpec params,
  2392                     Key key, AlgorithmParameterSpec params,
  2393                     SecureRandom random) throws GeneralSecurityException {
  2393                     SecureRandom random) throws GeneralSecurityException {
  2394                 super(authenticator, protocolVersion);
  2394                 super(authenticator, protocolVersion);
  2395                 this.cipher = JsseJce.getCipher(algorithm);
  2395                 this.cipher = Cipher.getInstance(algorithm);
  2396                 this.tagSize = sslCipher.tagSize;
  2396                 this.tagSize = sslCipher.tagSize;
  2397                 this.key = key;
  2397                 this.key = key;
  2398                 this.iv = ((IvParameterSpec)params).getIV();
  2398                 this.iv = ((IvParameterSpec)params).getIV();
  2399                 this.random = random;
  2399                 this.random = random;
  2400 
  2400 
  2532                     ProtocolVersion protocolVersion,
  2532                     ProtocolVersion protocolVersion,
  2533                     SSLCipher sslCipher, String algorithm,
  2533                     SSLCipher sslCipher, String algorithm,
  2534                     Key key, AlgorithmParameterSpec params,
  2534                     Key key, AlgorithmParameterSpec params,
  2535                     SecureRandom random) throws GeneralSecurityException {
  2535                     SecureRandom random) throws GeneralSecurityException {
  2536                 super(authenticator, protocolVersion);
  2536                 super(authenticator, protocolVersion);
  2537                 this.cipher = JsseJce.getCipher(algorithm);
  2537                 this.cipher = Cipher.getInstance(algorithm);
  2538                 this.tagSize = sslCipher.tagSize;
  2538                 this.tagSize = sslCipher.tagSize;
  2539                 this.key = key;
  2539                 this.key = key;
  2540                 this.iv = ((IvParameterSpec)params).getIV();
  2540                 this.iv = ((IvParameterSpec)params).getIV();
  2541                 this.random = random;
  2541                 this.random = random;
  2542 
  2542