author | xuelei |
Wed, 09 Apr 2014 12:49:51 +0000 | |
changeset 23733 | b9b80421cfa7 |
parent 16100 | 379f48d34516 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
16080 | 2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
||
27 |
package sun.security.ssl; |
|
28 |
||
29 |
import java.io.IOException; |
|
30 |
import java.io.PrintStream; |
|
31 |
import java.math.BigInteger; |
|
16080 | 32 |
import javax.net.ssl.SSLHandshakeException; |
2 | 33 |
|
34 |
/* |
|
35 |
* Message used by clients to send their Diffie-Hellman public |
|
36 |
* keys to servers. |
|
37 |
* |
|
38 |
* @author David Brownell |
|
39 |
*/ |
|
40 |
final class DHClientKeyExchange extends HandshakeMessage { |
|
41 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
5506
diff
changeset
|
42 |
@Override |
2 | 43 |
int messageType() { |
44 |
return ht_client_key_exchange; |
|
45 |
} |
|
46 |
||
47 |
/* |
|
48 |
* This value may be empty if it was included in the |
|
49 |
* client's certificate ... |
|
50 |
*/ |
|
51 |
private byte dh_Yc[]; // 1 to 2^16 -1 bytes |
|
52 |
||
53 |
BigInteger getClientPublicKey() { |
|
16080 | 54 |
return dh_Yc == null ? null : new BigInteger(1, dh_Yc); |
2 | 55 |
} |
56 |
||
57 |
/* |
|
58 |
* Either pass the client's public key explicitly (because it's |
|
59 |
* using DHE or DH_anon), or implicitly (the public key was in the |
|
60 |
* certificate). |
|
61 |
*/ |
|
62 |
DHClientKeyExchange(BigInteger publicKey) { |
|
63 |
dh_Yc = toByteArray(publicKey); |
|
64 |
} |
|
65 |
||
66 |
DHClientKeyExchange() { |
|
67 |
dh_Yc = null; |
|
68 |
} |
|
69 |
||
70 |
/* |
|
71 |
* Get the client's public key either explicitly or implicitly. |
|
72 |
* (It's ugly to have an empty record be sent in the latter case, |
|
73 |
* but that's what the protocol spec requires.) |
|
74 |
*/ |
|
75 |
DHClientKeyExchange(HandshakeInStream input) throws IOException { |
|
16080 | 76 |
if (input.available() >= 2) { |
77 |
dh_Yc = input.getBytes16(); |
|
78 |
} else { |
|
79 |
// currently, we don't support cipher suites that requires |
|
80 |
// implicit public key of client. |
|
81 |
throw new SSLHandshakeException( |
|
82 |
"Unsupported implicit client DiffieHellman public key"); |
|
83 |
} |
|
2 | 84 |
} |
85 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
5506
diff
changeset
|
86 |
@Override |
2 | 87 |
int messageLength() { |
88 |
if (dh_Yc == null) { |
|
89 |
return 0; |
|
90 |
} else { |
|
91 |
return dh_Yc.length + 2; |
|
92 |
} |
|
93 |
} |
|
94 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
5506
diff
changeset
|
95 |
@Override |
2 | 96 |
void send(HandshakeOutStream s) throws IOException { |
16080 | 97 |
if (dh_Yc != null && dh_Yc.length != 0) { |
98 |
s.putBytes16(dh_Yc); |
|
99 |
} |
|
2 | 100 |
} |
101 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
5506
diff
changeset
|
102 |
@Override |
2 | 103 |
void print(PrintStream s) throws IOException { |
104 |
s.println("*** ClientKeyExchange, DH"); |
|
105 |
||
106 |
if (debug != null && Debug.isOn("verbose")) { |
|
107 |
Debug.println(s, "DH Public key", dh_Yc); |
|
108 |
} |
|
109 |
} |
|
110 |
} |