| | |
| | | config.addChangeListener(this); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isConfigurationChangeAcceptable( |
| | | CryptoManagerCfg cfg, |
| | |
| | | return isAcceptable; |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationChange(CryptoManagerCfg cfg) |
| | | { |
| | |
| | | .addAttribute(requestedAttribute); |
| | | InternalSearchOperation searchOp = icc.processSearch(request); |
| | | for (Entry e : searchOp.getSearchEntries()) { |
| | | /* attribute ds-cfg-public-key-certificate is a MUST in |
| | | the schema */ |
| | | // attribute ds-cfg-public-key-certificate is a MUST in the schema |
| | | certificate = e.parseAttribute( |
| | | ATTR_CRYPTO_PUBLIC_KEY_CERTIFICATE).asByteString().toByteArray(); |
| | | } |
| | | break; |
| | | } |
| | | catch (DirectoryException ex) { |
| | | if (0 == i |
| | | && ResultCode.NO_SUCH_OBJECT == ex.getResultCode()){ |
| | | final Entry entry = new Entry(entryDN, null, null, null); |
| | | entry.addObjectClass(DirectoryServer.getTopObjectClass()); |
| | | entry.addObjectClass(ocCertRequest); |
| | | AddOperation addOperation = icc.processAdd(entry); |
| | | if (ResultCode.SUCCESS != addOperation.getResultCode()) { |
| | | throw new DirectoryException( |
| | | addOperation.getResultCode(), |
| | | ERR_CRYPTOMGR_FAILED_TO_INITIATE_INSTANCE_KEY_GENERATION.get(entry.getName())); |
| | | } |
| | | } |
| | | else { |
| | | if (0 != i || ex.getResultCode() != ResultCode.NO_SUCH_OBJECT) { |
| | | throw ex; |
| | | } |
| | | |
| | | final Entry entry = new Entry(entryDN, null, null, null); |
| | | entry.addObjectClass(DirectoryServer.getTopObjectClass()); |
| | | entry.addObjectClass(ocCertRequest); |
| | | AddOperation addOperation = icc.processAdd(entry); |
| | | if (ResultCode.SUCCESS != addOperation.getResultCode()) { |
| | | throw new DirectoryException( |
| | | addOperation.getResultCode(), |
| | | ERR_CRYPTOMGR_FAILED_TO_INITIATE_INSTANCE_KEY_GENERATION.get(entry.getName())); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | md.digest(instanceKeyCertificate)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | Publishes the instance key entry in ADS, if it does not already |
| | | exist. |
| | | Publishes the instance key entry in ADS, if it does not already exist. |
| | | |
| | | @throws CryptoManagerException In case there is a problem |
| | | searching for the entry, or, if necessary, adding it. |
| | |
| | | Set<String> symmetricKeys = |
| | | entry.parseAttribute(ATTR_CRYPTO_SYMMETRIC_KEY).asSetOfString(); |
| | | |
| | | // Find the symmetric key value that was wrapped using |
| | | // our instance key. |
| | | SecretKey secretKey = null; |
| | | for (String symmetricKey : symmetricKeys) |
| | | { |
| | | secretKey = decodeSymmetricKeyAttribute(symmetricKey); |
| | | if (secretKey != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // Find the symmetric key value that was wrapped using our instance key. |
| | | SecretKey secretKey = decodeSymmetricKeyAttribute(symmetricKeys); |
| | | if (null != secretKey) { |
| | | CipherKeyEntry.importCipherKeyEntry(this, keyID, transformation, |
| | | secretKey, keyLengthBits, ivLengthBits, isCompromised); |
| | |
| | | CipherKeyEntry.importCipherKeyEntry(this, keyID, transformation, |
| | | secretKey, keyLengthBits, ivLengthBits, isCompromised); |
| | | |
| | | // Write the value to the entry. |
| | | InternalClientConnection internalConnection = getRootConnection(); |
| | | Attribute attribute = Attributes.create(ATTR_CRYPTO_SYMMETRIC_KEY, symmetricKey); |
| | | List<Modification> modifications = newArrayList(new Modification(ModificationType.ADD, attribute, false)); |
| | | ModifyOperation internalModify = internalConnection.processModify(entry.getName(), modifications); |
| | | if (internalModify.getResultCode() != ResultCode.SUCCESS) |
| | | { |
| | | throw new CryptoManagerException( |
| | | ERR_CRYPTOMGR_IMPORT_KEY_ENTRY_FAILED_TO_ADD_KEY.get(entry.getName())); |
| | | } |
| | | writeValueToEntry(entry, symmetricKey); |
| | | } |
| | | catch (CryptoManagerException e) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private SecretKey decodeSymmetricKeyAttribute(Set<String> symmetricKeys) throws CryptoManagerException |
| | | { |
| | | for (String symmetricKey : symmetricKeys) |
| | | { |
| | | SecretKey secretKey = decodeSymmetricKeyAttribute(symmetricKey); |
| | | if (secretKey != null) |
| | | { |
| | | return secretKey; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Imports a mac key entry from an entry in ADS. |
| | |
| | | Set<String> symmetricKeys = |
| | | entry.parseAttribute(ATTR_CRYPTO_SYMMETRIC_KEY).asSetOfString(); |
| | | |
| | | // Find the symmetric key value that was wrapped using our |
| | | // instance key. |
| | | SecretKey secretKey = null; |
| | | for (String symmetricKey : symmetricKeys) |
| | | SecretKey secretKey = decodeSymmetricKeyAttribute(symmetricKeys); |
| | | if (secretKey != null) |
| | | { |
| | | secretKey = decodeSymmetricKeyAttribute(symmetricKey); |
| | | if (secretKey != null) |
| | | { |
| | | break; |
| | | } |
| | | MacKeyEntry.importMacKeyEntry(this, keyID, algorithm, secretKey, keyLengthBits, isCompromised); |
| | | return; |
| | | } |
| | | |
| | | if (secretKey == null) |
| | | // Request the value from another server. |
| | | String symmetricKey = getSymmetricKey(symmetricKeys); |
| | | if (symmetricKey == null) |
| | | { |
| | | // Request the value from another server. |
| | | String symmetricKey = getSymmetricKey(symmetricKeys); |
| | | if (symmetricKey == null) |
| | | { |
| | | throw new CryptoManagerException( |
| | | ERR_CRYPTOMGR_IMPORT_KEY_ENTRY_FAILED_TO_DECODE.get(entry.getName())); |
| | | } |
| | | secretKey = decodeSymmetricKeyAttribute(symmetricKey); |
| | | MacKeyEntry.importMacKeyEntry(this, keyID, algorithm, |
| | | secretKey, keyLengthBits, |
| | | isCompromised); |
| | | throw new CryptoManagerException( |
| | | ERR_CRYPTOMGR_IMPORT_KEY_ENTRY_FAILED_TO_DECODE.get(entry.getName())); |
| | | } |
| | | secretKey = decodeSymmetricKeyAttribute(symmetricKey); |
| | | MacKeyEntry.importMacKeyEntry(this, keyID, algorithm, secretKey, keyLengthBits, isCompromised); |
| | | |
| | | // Write the value to the entry. |
| | | Attribute attribute = Attributes.create(ATTR_CRYPTO_SYMMETRIC_KEY, symmetricKey); |
| | | List<Modification> modifications = newArrayList( |
| | | new Modification(ModificationType.ADD, attribute, false)); |
| | | ModifyOperation internalModify = |
| | | getRootConnection().processModify(entry.getName(), modifications); |
| | | if (internalModify.getResultCode() != ResultCode.SUCCESS) |
| | | { |
| | | throw new CryptoManagerException( |
| | | ERR_CRYPTOMGR_IMPORT_KEY_ENTRY_FAILED_TO_ADD_KEY.get(entry.getName())); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | MacKeyEntry.importMacKeyEntry(this, keyID, algorithm, |
| | | secretKey, keyLengthBits, |
| | | isCompromised); |
| | | } |
| | | writeValueToEntry(entry, symmetricKey); |
| | | } |
| | | catch (CryptoManagerException e) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private void writeValueToEntry(Entry entry, String symmetricKey) throws CryptoManagerException |
| | | { |
| | | Attribute attribute = Attributes.create(ATTR_CRYPTO_SYMMETRIC_KEY, symmetricKey); |
| | | List<Modification> modifications = newArrayList(new Modification(ModificationType.ADD, attribute)); |
| | | ModifyOperation internalModify = getRootConnection().processModify(entry.getName(), modifications); |
| | | if (internalModify.getResultCode() != ResultCode.SUCCESS) |
| | | { |
| | | throw new CryptoManagerException(ERR_CRYPTOMGR_IMPORT_KEY_ENTRY_FAILED_TO_ADD_KEY.get(entry.getName())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * This class implements a utility interface to the unique |
| | |
| | | */ |
| | | private static class KeyEntryID |
| | | { |
| | | /** |
| | | * Constructs a KeyEntryID using a new unique identifier. |
| | | */ |
| | | /** Constructs a KeyEntryID using a new unique identifier. */ |
| | | public KeyEntryID() { |
| | | fValue = UUID.randomUUID(); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * Constructs a {@code KeyEntryID} from its {@code String} |
| | | * representation. |
| | | * Constructs a {@code KeyEntryID} from its {@code String} representation. |
| | | * |
| | | * @param keyEntryID The {@code String} reprentation of a |
| | | * {@code KeyEntryID}. |
| | | * @param keyEntryID The {@code String} representation of a {@code KeyEntryID}. |
| | | * |
| | | * @throws CryptoManagerException If the argument does |
| | | * not conform to the {@code KeyEntryID} string syntax. |
| | |
| | | /** |
| | | Construct an instance of {@code SecretKeyEntry} using the specified |
| | | parameters. This constructor would typically be used for key entries |
| | | imported from ADS, for which the full set of paramters is known. |
| | | imported from ADS, for which the full set of parameters is known. |
| | | <p> |
| | | Note the relationship between the secret key data array length and the |
| | | secret key length parameter described in {@link SecretKeyEntry} |
| | |
| | | ocMap.put(DirectoryServer.getTopObjectClass(), OC_TOP); |
| | | ocMap.put(ocCipherKey, OC_CRYPTO_CIPHER_KEY); |
| | | |
| | | // Create the operational and user attributes. |
| | | LinkedHashMap<AttributeType,List<Attribute>> opAttrs = new LinkedHashMap<>(0); |
| | | LinkedHashMap<AttributeType,List<Attribute>> userAttrs = new LinkedHashMap<>(); |
| | | |
| | | // Add the key ID attribute. |
| | | // Create the user attributes. |
| | | LinkedHashMap<AttributeType, List<Attribute>> userAttrs = new LinkedHashMap<>(); |
| | | userAttrs.put(attrKeyID, Attributes.createAsList(attrKeyID, distinguishedValue)); |
| | | |
| | | // Add the transformation name attribute. |
| | | putSingleValueAttribute(userAttrs, attrTransformation, keyEntry.getType()); |
| | | |
| | | // Add the init vector length attribute. |
| | | putSingleValueAttribute(userAttrs, attrInitVectorLength, |
| | | String.valueOf(keyEntry.getIVLengthBits())); |
| | | |
| | | // Add the key length attribute. |
| | | putSingleValueAttribute(userAttrs, attrKeyLength, |
| | | String.valueOf(keyEntry.getKeyLengthBits())); |
| | | |
| | | |
| | | // Get the trusted certificates. |
| | | Map<String, byte[]> trustedCerts = |
| | | cryptoManager.getTrustedCertificates(); |
| | | |
| | | // Need to add our own instance certificate. |
| | | byte[] instanceKeyCertificate = |
| | | CryptoManagerImpl.getInstanceKeyCertificateFromLocalTruststore(); |
| | | trustedCerts.put(getInstanceKeyID(instanceKeyCertificate), |
| | | instanceKeyCertificate); |
| | | |
| | | // Add the symmetric key attribute. |
| | | AttributeBuilder builder = new AttributeBuilder(attrSymmetricKey); |
| | | for (Map.Entry<String, byte[]> mapEntry : trustedCerts.entrySet()) |
| | | { |
| | | String symmetricKey = cryptoManager.encodeSymmetricKeyAttribute( |
| | | mapEntry.getKey(), mapEntry.getValue(), keyEntry.getSecretKey()); |
| | | |
| | | builder.add(symmetricKey); |
| | | } |
| | | userAttrs.put(attrSymmetricKey, builder.toAttributeList()); |
| | | userAttrs.put(attrSymmetricKey, buildSymetricKeyAttributes(cryptoManager, keyEntry.getSecretKey())); |
| | | |
| | | // Create the entry. |
| | | LinkedHashMap<AttributeType, List<Attribute>> opAttrs = new LinkedHashMap<>(0); |
| | | Entry entry = new Entry(entryDN, ocMap, userAttrs, opAttrs); |
| | | |
| | | AddOperation addOperation = getRootConnection().processAdd(entry); |
| | | if (addOperation.getResultCode() != ResultCode.SUCCESS) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Initializes a secret key entry from the supplied parameters, |
| | | * validates it, and registers it in the supplied map. The |
| | | * anticipated use of this method is to import a key entry from |
| | | * ADS. |
| | | * validates it, and registers it in the supplied map. |
| | | * The anticipated use of this method is to import a key entry from ADS. |
| | | * |
| | | * @param cryptoManager The CryptoManager instance. |
| | | * |
| | | * @param keyIDString The key identifier. |
| | | * |
| | | * @param transformation The cipher transformation for which the |
| | | * key entry was produced. |
| | | * |
| | | * @param transformation The cipher transformation for which the key entry was produced. |
| | | * @param secretKey The cipher key. |
| | | * |
| | | * @param secretKeyLengthBits The length of the cipher key in |
| | | * bits. |
| | | * |
| | | * @param secretKeyLengthBits The length of the cipher key in bits. |
| | | * @param ivLengthBits The length of the initialization vector, |
| | | * which will be zero in the case of any stream cipher algorithm, |
| | | * any block cipher algorithm for which the transformation mode |
| | | * does not use an initialization vector, and any HMAC algorithm. |
| | | * |
| | | * @param isCompromised Mark the key as compromised, so that it |
| | | * will not subsequently be used for encryption. The key entry |
| | | * must be maintained in order to decrypt existing ciphertext. |
| | | * |
| | | * @return The key entry, if one was successfully produced. |
| | | * |
| | | * @throws CryptoManagerException In case of an error in the |
| | | * parameters used to initialize or validate the key entry. |
| | | */ |
| | |
| | | CipherKeyEntry keyEntry = getKeyEntry(cryptoManager, keyID); |
| | | if (null != keyEntry) { |
| | | // Paranoiac check to ensure exact type match. |
| | | if (! (keyEntry.getType().equals(transformation) |
| | | && keyEntry.getKeyLengthBits() == secretKeyLengthBits |
| | | && keyEntry.getIVLengthBits() == ivLengthBits)) { |
| | | throw new CryptoManagerException( |
| | | ERR_CRYPTOMGR_IMPORT_KEY_ENTRY_FIELD_MISMATCH.get( |
| | | keyIDString)); |
| | | if (!keyEntry.getType().equals(transformation) |
| | | || keyEntry.getKeyLengthBits() != secretKeyLengthBits |
| | | || keyEntry.getIVLengthBits() != ivLengthBits) { |
| | | throw new CryptoManagerException( |
| | | ERR_CRYPTOMGR_IMPORT_KEY_ENTRY_FIELD_MISMATCH.get(keyIDString)); |
| | | } |
| | | // Allow transition to compromised. |
| | | if (isCompromised && !keyEntry.isCompromised()) { |
| | |
| | | getCipher(keyEntry, Cipher.DECRYPT_MODE, iv); |
| | | |
| | | // Cache new entry. |
| | | cryptoManager.cipherKeyEntryCache.put(keyEntry.getKeyID(), |
| | | keyEntry); |
| | | cryptoManager.cipherKeyEntryCache.put(keyEntry.getKeyID(), keyEntry); |
| | | |
| | | return keyEntry; |
| | | } |
| | |
| | | * |
| | | * @param cryptoManager The CryptoManager instance with which the |
| | | * key entry is associated. |
| | | * |
| | | * @param transformation The cipher transformation for which the |
| | | * key was produced. |
| | | * |
| | | * @param keyLengthBits The cipher key length in bits. |
| | | * |
| | | * @return The key entry corresponding to the parameters, or |
| | |
| | | Reject.ifNull(cryptoManager, transformation); |
| | | Reject.ifFalse(0 < keyLengthBits); |
| | | |
| | | CipherKeyEntry keyEntry = null; |
| | | // search for an existing key that satisfies the request |
| | | for (Map.Entry<KeyEntryID, CipherKeyEntry> i |
| | | : cryptoManager.cipherKeyEntryCache.entrySet()) { |
| | |
| | | if (! entry.isCompromised() |
| | | && entry.getType().equals(transformation) |
| | | && entry.getKeyLengthBits() == keyLengthBits) { |
| | | keyEntry = entry; |
| | | break; |
| | | return entry; |
| | | } |
| | | } |
| | | |
| | | return keyEntry; |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @param cryptoManager The CryptoManager instance with which the |
| | | * key entry is associated. |
| | | * |
| | | * @param keyID The key identifier. |
| | | * |
| | | * @return The key entry associated with the key identifier, or |
| | |
| | | /** |
| | | * Construct an instance of CipherKeyEntry using the specified |
| | | * parameters. This constructor would typically be used for key |
| | | * entries imported from ADS, for which the full set of paramters |
| | | * entries imported from ADS, for which the full set of parameters |
| | | * is known, and for a newly generated key entry, for which the |
| | | * initialization vector length might not yet be known, but which |
| | | * must be set prior to using the key. |
| | |
| | | * |
| | | * @param secretKey The cipher key. |
| | | * |
| | | * @param secretKeyLengthBits The length of the secret key in |
| | | * bits. |
| | | * @param secretKeyLengthBits The length of the secret key in bits. |
| | | * |
| | | * @param ivLengthBits The length in bits of a mandatory |
| | | * initialization vector or 0 if none is required. Set this |
| | |
| | | * size, or 0 for a stream cipher or a block cipher mode that does |
| | | * not use an initialization vector (e.g., ECB). |
| | | * |
| | | * @param ivLengthBits The initiazliation vector length in bits. |
| | | * @param ivLengthBits The initialization vector length in bits. |
| | | */ |
| | | private void setIVLengthBits(int ivLengthBits) { |
| | | Reject.ifFalse(-1 == fIVLengthBits && 0 <= ivLengthBits); |
| | |
| | | * @param mode Either Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE. |
| | | * |
| | | * @param initializationVector For Cipher.DECRYPT_MODE, supply |
| | | * the initialzation vector used in the corresponding encryption |
| | | * the initialization vector used in the corresponding encryption |
| | | * cipher, or {@code null} if none. |
| | | * |
| | | * @return The initialized cipher object. |
| | |
| | | ocMap.put(DirectoryServer.getTopObjectClass(), OC_TOP); |
| | | ocMap.put(ocMacKey, OC_CRYPTO_MAC_KEY); |
| | | |
| | | // Create the operational and user attributes. |
| | | LinkedHashMap<AttributeType,List<Attribute>> opAttrs = new LinkedHashMap<>(0); |
| | | LinkedHashMap<AttributeType,List<Attribute>> userAttrs = new LinkedHashMap<>(); |
| | | |
| | | // Add the key ID attribute. |
| | | // Create the user attributes. |
| | | LinkedHashMap<AttributeType, List<Attribute>> userAttrs = new LinkedHashMap<>(); |
| | | userAttrs.put(attrKeyID, Attributes.createAsList(attrKeyID, distinguishedValue)); |
| | | |
| | | // Add the mac algorithm name attribute. |
| | | putSingleValueAttribute(userAttrs, attrMacAlgorithm, keyEntry.getType()); |
| | | |
| | | // Add the key length attribute. |
| | | putSingleValueAttribute(userAttrs, attrKeyLength, String.valueOf(keyEntry.getKeyLengthBits())); |
| | | |
| | | // Get the trusted certificates. |
| | | Map<String, byte[]> trustedCerts = cryptoManager.getTrustedCertificates(); |
| | | |
| | | // Need to add our own instance certificate. |
| | | byte[] instanceKeyCertificate = |
| | | CryptoManagerImpl.getInstanceKeyCertificateFromLocalTruststore(); |
| | | trustedCerts.put(getInstanceKeyID(instanceKeyCertificate), |
| | | instanceKeyCertificate); |
| | | |
| | | // Add the symmetric key attribute. |
| | | AttributeBuilder builder = new AttributeBuilder(attrSymmetricKey); |
| | | for (Map.Entry<String, byte[]> mapEntry : |
| | | trustedCerts.entrySet()) |
| | | { |
| | | String symmetricKey = |
| | | cryptoManager.encodeSymmetricKeyAttribute( |
| | | mapEntry.getKey(), |
| | | mapEntry.getValue(), |
| | | keyEntry.getSecretKey()); |
| | | builder.add(symmetricKey); |
| | | } |
| | | |
| | | userAttrs.put(attrSymmetricKey, builder.toAttributeList()); |
| | | userAttrs.put(attrSymmetricKey, buildSymetricKeyAttributes(cryptoManager, keyEntry.getSecretKey())); |
| | | |
| | | // Create the entry. |
| | | LinkedHashMap<AttributeType, List<Attribute>> opAttrs = new LinkedHashMap<>(0); |
| | | Entry entry = new Entry(entryDN, ocMap, userAttrs, opAttrs); |
| | | |
| | | AddOperation addOperation = getRootConnection().processAdd(entry); |
| | | if (addOperation.getResultCode() != ResultCode.SUCCESS) |
| | | { |
| | |
| | | |
| | | /** |
| | | * Initializes a secret key entry from the supplied parameters, |
| | | * validates it, and registers it in the supplied map. The |
| | | * anticipated use of this method is to import a key entry from |
| | | * ADS. |
| | | * validates it, and registers it in the supplied map. |
| | | * The anticipated use of this method is to import a key entry from ADS. |
| | | * |
| | | * @param cryptoManager The CryptoManager instance. |
| | | * |
| | | * @param keyIDString The key identifier. |
| | | * |
| | | * @param algorithm The name of the MAC algorithm for which the |
| | | * key entry is to be produced. |
| | | * |
| | | * @param secretKey The MAC key. |
| | | * |
| | | * @param secretKeyLengthBits The length of the secret key in |
| | | * bits. |
| | | * |
| | | * @param isCompromised Mark the key as compromised, so that it |
| | | * @param secretKeyLengthBits The length of the secret key in bits. |
| | | * @param isCompromised Mark the key as compromised, so that it |
| | | * will not subsequently be used for new data. The key entry |
| | | * must be maintained in order to verify existing signatures. |
| | | * |
| | | * @return The key entry, if one was successfully produced. |
| | | * |
| | | * @return The key entry, if one was successfully produced. |
| | | * @throws CryptoManagerException In case of an error in the |
| | | * parameters used to initialize or validate the key entry. |
| | | */ |
| | |
| | | * |
| | | * @param cryptoManager The CryptoManager instance with which the |
| | | * key entry is associated. |
| | | * |
| | | * @param algorithm The MAC algorithm for which the key was |
| | | * produced. |
| | | * |
| | | * @param algorithm The MAC algorithm for which the key was produced. |
| | | * @param keyLengthBits The MAC key length in bits. |
| | | * |
| | | * @return The key entry corresponding to the parameters, or |
| | |
| | | Reject.ifNull(cryptoManager, algorithm); |
| | | Reject.ifFalse(0 < keyLengthBits); |
| | | |
| | | MacKeyEntry keyEntry = null; |
| | | // search for an existing key that satisfies the request |
| | | for (Map.Entry<KeyEntryID, MacKeyEntry> i |
| | | : cryptoManager.macKeyEntryCache.entrySet()) { |
| | |
| | | if (! entry.isCompromised() |
| | | && entry.getType().equals(algorithm) |
| | | && entry.getKeyLengthBits() == keyLengthBits) { |
| | | keyEntry = entry; |
| | | break; |
| | | return entry; |
| | | } |
| | | } |
| | | |
| | | return keyEntry; |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @param cryptoManager The CryptoManager instance with which the |
| | | * key entry is associated. |
| | | * |
| | | * @param keyID The key identifier. |
| | | * |
| | | * @return The key entry associated with the key identifier, or |
| | |
| | | /** |
| | | * Construct an instance of MacKeyEntry using the specified |
| | | * parameters. This constructor would typically be used for key |
| | | * entries imported from ADS, for which the full set of paramters |
| | | * is known. |
| | | * entries imported from ADS, for which the full set of parameters is known. |
| | | * |
| | | * @param keyID The unique identifier of this MAC algorithm/key |
| | | * pair. |
| | | * |
| | | * @param keyID The unique identifier of this MAC algorithm/key pair. |
| | | * @param algorithm The name of the MAC algorithm for which the |
| | | * key entry is to be produced. |
| | | * |
| | | * @param secretKey The MAC key. |
| | | * |
| | | * @param secretKeyLengthBits The length of the secret key in |
| | | * bits. |
| | | * @param secretKeyLengthBits The length of the secret key in bits. |
| | | * |
| | | * @param isCompromised {@code false} if the key may be used |
| | | * for signing, or {@code true} if the key is being retained only |
| | |
| | | private final String fType; |
| | | } |
| | | |
| | | private static List<Attribute> buildSymetricKeyAttributes(CryptoManagerImpl cryptoManager, SecretKey secretKey) |
| | | throws CryptoManagerException |
| | | { |
| | | Map<String, byte[]> trustedCerts = cryptoManager.getTrustedCertificates(); |
| | | |
| | | // Need to add our own instance certificate. |
| | | byte[] instanceKeyCertificate = CryptoManagerImpl.getInstanceKeyCertificateFromLocalTruststore(); |
| | | trustedCerts.put(getInstanceKeyID(instanceKeyCertificate), instanceKeyCertificate); |
| | | |
| | | AttributeBuilder builder = new AttributeBuilder(attrSymmetricKey); |
| | | for (Map.Entry<String, byte[]> mapEntry : trustedCerts.entrySet()) |
| | | { |
| | | String symmetricKey = |
| | | cryptoManager.encodeSymmetricKeyAttribute(mapEntry.getKey(), mapEntry.getValue(), secretKey); |
| | | builder.add(symmetricKey); |
| | | } |
| | | return builder.toAttributeList(); |
| | | } |
| | | |
| | | /** |
| | | * This method produces an initialized MAC engine based on the |
| | |
| | | return mac; |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getPreferredMessageDigestAlgorithm() |
| | | { |
| | | return preferredDigestAlgorithm; |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public MessageDigest getPreferredMessageDigest() |
| | | throws NoSuchAlgorithmException |
| | |
| | | return MessageDigest.getInstance(preferredDigestAlgorithm); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public MessageDigest getMessageDigest(String digestAlgorithm) |
| | | throws NoSuchAlgorithmException |
| | |
| | | return MessageDigest.getInstance(digestAlgorithm); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public byte[] digest(byte[] data) |
| | | throws NoSuchAlgorithmException |
| | |
| | | digest(data); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public byte[] digest(String digestAlgorithm, byte[] data) |
| | | throws NoSuchAlgorithmException |
| | |
| | | return MessageDigest.getInstance(digestAlgorithm).digest(data); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public byte[] digest(InputStream inputStream) |
| | | throws IOException, NoSuchAlgorithmException |
| | |
| | | return digest.digest(); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public byte[] digest(String digestAlgorithm, |
| | | InputStream inputStream) |
| | |
| | | return digest.digest(); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getMacEngineKeyEntryID() |
| | | throws CryptoManagerException |
| | |
| | | preferredMACAlgorithmKeyLengthBits); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getMacEngineKeyEntryID(final String macAlgorithm, |
| | | final int keyLengthBits) |
| | |
| | | return keyEntry.getKeyID().getStringValue(); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Mac getMacEngine(String keyEntryID) |
| | | throws CryptoManagerException |
| | |
| | | return keyEntry != null ? getMacEngine(keyEntry) : null; |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public byte[] encrypt(byte[] data) |
| | | throws GeneralSecurityException, CryptoManagerException |
| | |
| | | preferredCipherTransformationKeyLengthBits, data); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public byte[] encrypt(String cipherTransformation, |
| | | int keyLengthBits, |
| | |
| | | return cipherText; |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CipherOutputStream getCipherOutputStream( |
| | | OutputStream outputStream) throws CryptoManagerException |
| | |
| | | preferredCipherTransformationKeyLengthBits, outputStream); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CipherOutputStream getCipherOutputStream( |
| | | String cipherTransformation, int keyLengthBits, |
| | |
| | | return new CipherOutputStream(outputStream, cipher); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public byte[] decrypt(byte[] data) |
| | | throws GeneralSecurityException, |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CipherInputStream getCipherInputStream( |
| | | InputStream inputStream) throws CryptoManagerException |
| | |
| | | ERR_CRYPTOMGR_DECRYPT_FAILED_TO_READ_KEY_IDENTIFIER.get( |
| | | "stream underflow")); |
| | | } |
| | | keyEntry = CipherKeyEntry.getKeyEntry(this, |
| | | new KeyEntryID(keyID)); |
| | | keyEntry = CipherKeyEntry.getKeyEntry(this, new KeyEntryID(keyID)); |
| | | if (null == keyEntry) { |
| | | throw new CryptoManagerException( |
| | | ERR_CRYPTOMGR_DECRYPT_UNKNOWN_KEY_IDENTIFIER.get()); |
| | |
| | | getCipher(keyEntry, Cipher.DECRYPT_MODE, iv)); |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int compress(byte[] src, int srcOff, int srcLen, |
| | | byte[] dst, int dstOff, int dstLen) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int uncompress(byte[] src, int srcOff, int srcLen, |
| | | byte[] dst, int dstOff, int dstLen) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public SSLContext getSslContext(String componentName, SortedSet<String> sslCertNicknames) throws ConfigException |
| | | { |
| | |
| | | return sslContext; |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public SortedSet<String> getSslCertNicknames() |
| | | { |
| | | return sslCertNicknames; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isSslEncryption() |
| | | { |
| | | return sslEncryption; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public SortedSet<String> getSslProtocols() |
| | | { |
| | | return sslProtocols; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public SortedSet<String> getSslCipherSuites() |
| | | { |