168 * method is called with {@code "setIdentityPublicKey"}
169 * as its argument to see if it's ok to set the public key.
170 *
171 * @param key the public key for this identity.
172 *
173 * @exception KeyManagementException if another identity in the
174 * identity's scope has the same public key, or if another exception occurs.
175 *
176 * @exception SecurityException if a security manager exists and its
177 * {@code checkSecurityAccess} method doesn't allow
178 * setting the public key.
179 *
180 * @see #getPublicKey
181 * @see SecurityManager#checkSecurityAccess
182 */
183 /* Should we throw an exception if this is already set? */
184 public void setPublicKey(PublicKey key) throws KeyManagementException {
185
186 check("setIdentityPublicKey");
187 this.publicKey = key;
188 certificates = new Vector<Certificate>();
189 }
190
191 /**
192 * Specifies a general information string for this identity.
193 *
194 * <p>First, if there is a security manager, its {@code checkSecurityAccess}
195 * method is called with {@code "setIdentityInfo"}
196 * as its argument to see if it's ok to specify the information string.
197 *
198 * @param info the information string.
199 *
200 * @exception SecurityException if a security manager exists and its
201 * {@code checkSecurityAccess} method doesn't allow
202 * setting the information string.
203 *
204 * @see #getInfo
205 * @see SecurityManager#checkSecurityAccess
206 */
207 public void setInfo(String info) {
208 check("setIdentityInfo");
231 * as its argument to see if it's ok to add a certificate.
232 *
233 * @param certificate the certificate to be added.
234 *
235 * @exception KeyManagementException if the certificate is not valid,
236 * if the public key in the certificate being added conflicts with
237 * this identity's public key, or if another exception occurs.
238 *
239 * @exception SecurityException if a security manager exists and its
240 * {@code checkSecurityAccess} method doesn't allow
241 * adding a certificate.
242 *
243 * @see SecurityManager#checkSecurityAccess
244 */
245 public void addCertificate(Certificate certificate)
246 throws KeyManagementException {
247
248 check("addIdentityCertificate");
249
250 if (certificates == null) {
251 certificates = new Vector<Certificate>();
252 }
253 if (publicKey != null) {
254 if (!keyEquals(publicKey, certificate.getPublicKey())) {
255 throw new KeyManagementException(
256 "public key different from cert public key");
257 }
258 } else {
259 publicKey = certificate.getPublicKey();
260 }
261 certificates.addElement(certificate);
262 }
263
264 private boolean keyEquals(Key aKey, Key anotherKey) {
265 String aKeyFormat = aKey.getFormat();
266 String anotherKeyFormat = anotherKey.getFormat();
267 if ((aKeyFormat == null) ^ (anotherKeyFormat == null))
268 return false;
269 if (aKeyFormat != null && anotherKeyFormat != null)
270 if (!aKeyFormat.equalsIgnoreCase(anotherKeyFormat))
271 return false;
|
168 * method is called with {@code "setIdentityPublicKey"}
169 * as its argument to see if it's ok to set the public key.
170 *
171 * @param key the public key for this identity.
172 *
173 * @exception KeyManagementException if another identity in the
174 * identity's scope has the same public key, or if another exception occurs.
175 *
176 * @exception SecurityException if a security manager exists and its
177 * {@code checkSecurityAccess} method doesn't allow
178 * setting the public key.
179 *
180 * @see #getPublicKey
181 * @see SecurityManager#checkSecurityAccess
182 */
183 /* Should we throw an exception if this is already set? */
184 public void setPublicKey(PublicKey key) throws KeyManagementException {
185
186 check("setIdentityPublicKey");
187 this.publicKey = key;
188 certificates = new Vector<>();
189 }
190
191 /**
192 * Specifies a general information string for this identity.
193 *
194 * <p>First, if there is a security manager, its {@code checkSecurityAccess}
195 * method is called with {@code "setIdentityInfo"}
196 * as its argument to see if it's ok to specify the information string.
197 *
198 * @param info the information string.
199 *
200 * @exception SecurityException if a security manager exists and its
201 * {@code checkSecurityAccess} method doesn't allow
202 * setting the information string.
203 *
204 * @see #getInfo
205 * @see SecurityManager#checkSecurityAccess
206 */
207 public void setInfo(String info) {
208 check("setIdentityInfo");
231 * as its argument to see if it's ok to add a certificate.
232 *
233 * @param certificate the certificate to be added.
234 *
235 * @exception KeyManagementException if the certificate is not valid,
236 * if the public key in the certificate being added conflicts with
237 * this identity's public key, or if another exception occurs.
238 *
239 * @exception SecurityException if a security manager exists and its
240 * {@code checkSecurityAccess} method doesn't allow
241 * adding a certificate.
242 *
243 * @see SecurityManager#checkSecurityAccess
244 */
245 public void addCertificate(Certificate certificate)
246 throws KeyManagementException {
247
248 check("addIdentityCertificate");
249
250 if (certificates == null) {
251 certificates = new Vector<>();
252 }
253 if (publicKey != null) {
254 if (!keyEquals(publicKey, certificate.getPublicKey())) {
255 throw new KeyManagementException(
256 "public key different from cert public key");
257 }
258 } else {
259 publicKey = certificate.getPublicKey();
260 }
261 certificates.addElement(certificate);
262 }
263
264 private boolean keyEquals(Key aKey, Key anotherKey) {
265 String aKeyFormat = aKey.getFormat();
266 String anotherKeyFormat = anotherKey.getFormat();
267 if ((aKeyFormat == null) ^ (anotherKeyFormat == null))
268 return false;
269 if (aKeyFormat != null && anotherKeyFormat != null)
270 if (!aKeyFormat.equalsIgnoreCase(anotherKeyFormat))
271 return false;
|