equal
deleted
inserted
replaced
35 import javax.crypto.spec.*; |
35 import javax.crypto.spec.*; |
36 |
36 |
37 import static sun.security.pkcs11.TemplateManager.*; |
37 import static sun.security.pkcs11.TemplateManager.*; |
38 import sun.security.pkcs11.wrapper.*; |
38 import sun.security.pkcs11.wrapper.*; |
39 import static sun.security.pkcs11.wrapper.PKCS11Constants.*; |
39 import static sun.security.pkcs11.wrapper.PKCS11Constants.*; |
|
40 import sun.security.util.KeyUtil; |
40 |
41 |
41 /** |
42 /** |
42 * KeyAgreement implementation class. This class currently supports |
43 * KeyAgreement implementation class. This class currently supports |
43 * DH. |
44 * DH. |
44 * |
45 * |
132 ("Key must be a PublicKey with algorithm DH"); |
133 ("Key must be a PublicKey with algorithm DH"); |
133 } |
134 } |
134 BigInteger p, g, y; |
135 BigInteger p, g, y; |
135 if (key instanceof DHPublicKey) { |
136 if (key instanceof DHPublicKey) { |
136 DHPublicKey dhKey = (DHPublicKey)key; |
137 DHPublicKey dhKey = (DHPublicKey)key; |
|
138 |
|
139 // validate the Diffie-Hellman public key |
|
140 KeyUtil.validate(dhKey); |
|
141 |
137 y = dhKey.getY(); |
142 y = dhKey.getY(); |
138 DHParameterSpec params = dhKey.getParams(); |
143 DHParameterSpec params = dhKey.getParams(); |
139 p = params.getP(); |
144 p = params.getP(); |
140 g = params.getG(); |
145 g = params.getG(); |
141 } else { |
146 } else { |
143 // just in case not, attempt conversion |
148 // just in case not, attempt conversion |
144 P11DHKeyFactory kf = new P11DHKeyFactory(token, "DH"); |
149 P11DHKeyFactory kf = new P11DHKeyFactory(token, "DH"); |
145 try { |
150 try { |
146 DHPublicKeySpec spec = kf.engineGetKeySpec( |
151 DHPublicKeySpec spec = kf.engineGetKeySpec( |
147 key, DHPublicKeySpec.class); |
152 key, DHPublicKeySpec.class); |
|
153 |
|
154 // validate the Diffie-Hellman public key |
|
155 KeyUtil.validate(spec); |
|
156 |
148 y = spec.getY(); |
157 y = spec.getY(); |
149 p = spec.getP(); |
158 p = spec.getP(); |
150 g = spec.getG(); |
159 g = spec.getG(); |
151 } catch (InvalidKeySpecException e) { |
160 } catch (InvalidKeySpecException e) { |
152 throw new InvalidKeyException("Could not obtain key values", e); |
161 throw new InvalidKeyException("Could not obtain key values", e); |