class CredentialManagerImpl implements CredentialManager,
		Observable<KeystoreChangedEvent> {

	@Override
	public String addKeyPair(Key privateKey, Certificate[] certs)
			throws CMException {
		// Need to make sure we are initialized before we do anything else
		// as Credential Manager can be created but not initialized
		initialize();

		String alias = null;

		synchronized (keystore) {
			// Create an alias for the new key pair entry in the Keystore as
			// "keypair#"<CERT_SUBJECT_COMMON_NAME>"#"<CERT_ISSUER_COMMON_NAME>"#"<CERT_SERIAL_NUMBER>
			String ownerDN = ((X509Certificate) certs[0])
					.getSubjectX500Principal().getName(RFC2253);
			ParsedDistinguishedName parsedDN = dnParser.parseDN(ownerDN);
			String ownerCN = parsedDN.getCN(); // owner's common name

			// Get the hexadecimal representation of the certificate's serial
			// number
			String serialNumber = new BigInteger(1,
					((X509Certificate) certs[0]).getSerialNumber()
							.toByteArray()).toString(16).toUpperCase();

			String issuerDN = ((X509Certificate) certs[0])
					.getIssuerX500Principal().getName(RFC2253);
			parsedDN = dnParser.parseDN(issuerDN);
			String issuerCN = parsedDN.getCN(); // issuer's common name

			alias = "keypair#" + ownerCN + "#" + issuerCN + "#" + serialNumber;

			try {
				keystore.setKeyEntry(alias, privateKey,
						masterPassword.toCharArray(), certs);
				saveKeystore(KEYSTORE);
				multiCaster.notify(new KeystoreChangedEvent(KEYSTORE));

				/*
				 * This is now done from the KeystoresChangedObserver's notify
				 * method. Update the default SSLSocketFactory used by the
				 * HttpsURLConnectionS
				 */
				// HttpsURLConnection.setDefaultSSLSocketFactory(createTavernaSSLSocketFactory());
				logger.debug("updating SSLSocketFactory after inserting a key pair");
			} catch (Exception ex) {
				throw new CMException("failed to insert "
						+ "the key pair entry in the Keystore", ex);
			}
		}
		return alias;
	}

	public  CredentialManagerImpl();

}