/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Signature and hash algorithm.
*
* [RFC5246] The client uses the "signature_algorithms" extension to
* used in digital signatures. The "extension_data" field of this
* extension contains a "supported_signature_algorithms" value.
*
* enum {
* none(0), md5(1), sha1(2), sha224(3), sha256(4), sha384(5),
* sha512(6), (255)
* } HashAlgorithm;
*
* enum { anonymous(0), rsa(1), dsa(2), ecdsa(3), (255) }
* SignatureAlgorithm;
*
* struct {
* HashAlgorithm hash;
* SignatureAlgorithm signature;
* } SignatureAndHashAlgorithm;
*/
final class SignatureAndHashAlgorithm {
// minimum priority for default enabled algorithms
// performance optimization
// supported pairs of signature and hash algorithm
// the hash algorithm
// the signature algorithm
// id in 16 bit MSB format, i.e. 0x0603 for SHA512withECDSA
private int id;
// the standard algorithm name, for example "SHA512withECDSA"
// Priority for the preference order. The lower the better.
//
// If the algorithm is unsupported, its priority should be bigger
// than SUPPORTED_ALG_PRIORITY_MAX_NUM.
private int priority;
// constructor for supported algorithm
}
// constructor for unsupported algorithm
// add one more to the sequece number, in case that the number is zero
}
// Note that we do not use the sequence argument for supported algorithms,
// so please don't sort by comparing the objects read from handshake
// messages.
hash &= 0xFF;
signature &= 0xFF;
// unsupported algorithm
signAlg = new SignatureAndHashAlgorithm(
}
return signAlg;
}
int getHashValue() {
}
int getSignatureValue() {
return id & 0xFF;
}
return algorithm;
}
// return the size of a SignatureAndHashAlgorithm structure in TLS record
static int sizeInRecord() {
return 2;
}
// Get local supported algorithm collection complying to
// algorithm constraints
static Collection<SignatureAndHashAlgorithm>
synchronized (priorityMap) {
}
}
}
return supported;
}
// Get supported algorithm collection from an untrusted collection
}
}
return supported;
}
if (algorithms != null) {
}
}
}
if (algorithms != null) {
}
}
}
return algorithmNames;
}
}
throw new RuntimeException(
"Duplicate SignatureAndHashAlgorithm definition, id: " +
}
throw new RuntimeException(
"Duplicate SignatureAndHashAlgorithm definition, priority: " +
}
}
}
return sigAlg;
}
}
return null; // no supported algorithm
}
return null; // no expected algorithm, no supported algorithm
}
/*
* Need to check RSA key length to match the length of hash value
*/
if (signingKey != null &&
/*
* RSA keys of 512 bits have been shown to be practically
* breakable, it does not make much sense to use the strong
* hash algorithm for keys whose key size less than 512 bits.
* So it is not necessary to caculate the required max digest
* length exactly.
*
* If key size is greater than or equals to 768, there is no max
* digest length limitation in currect implementation.
*
* If key size is greater than or equals to 512, but less than
* 768, the digest length should be less than or equal to 32 bytes.
*
* If key size is less than 512, the digest length should be
* less than or equal to 20 bytes.
*/
if (keySize >= 768) {
} // Otherwise, cannot determine the key size, prefer the most
// perferable hash algorithm.
}
return algorithm;
}
} else if (
return algorithm;
}
}
return null;
}
static enum HashAlgorithm {
// except the UNDEFINED, other names are defined
// by TLS 1.2 protocol
final int value;
this.standardName = standardName;
}
switch (value) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
}
return algorithm;
}
}
static enum SignatureAlgorithm {
// except the UNDEFINED, other names are defined
// by TLS 1.2 protocol
final int value;
}
switch (value) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
return algorithm;
}
}
static {
synchronized (supportedMap) {
int p = SUPPORTED_ALG_PRIORITY_MAX_NUM;
"MD5withRSA", --p);
"SHA1withDSA", --p);
"SHA1withRSA", --p);
"SHA1withECDSA", --p);
"SHA224withRSA", --p);
"SHA224withECDSA", --p);
"SHA256withRSA", --p);
"SHA256withECDSA", --p);
"SHA384withRSA", --p);
"SHA384withECDSA", --p);
"SHA512withRSA", --p);
"SHA512withECDSA", --p);
}
}
}