Module: cryptoUtil

Methods

(static) checkPasswordAll(length, password) → {Promise}

Checks the generated password against common regexes.

Parameters:
Name Type Description
length Number

Number of characters in the password string.

password String

Password string.

Returns:

A promise which is resolved when the password passes both checks.

Type
Promise

(static) checkPasswordCrack(password) → {Promise}

Checks the generated password against the cracklib library.

Parameters:
Name Type Description
password String

Password string.

Returns:

A promise which is resolved with the password or rejected if an error occurs

Type
Promise

(static) checkPasswordStrength(length, password) → {Promise}

Checks the generated password against common regexes.

Parameters:
Name Type Description
length Number

Number of characters in the password string.

password String

Password string.

Returns:

A promise which is resolved with the password or rejected if an error occurs

Type
Promise

(static) createRandomUser() → {Promise}

Creates a random on BIG-IP/BIG-IQ.

Only works if running on the device, not remotely.

Returns:

A promise which is resolved with user credentials or rejected if an error occurs. Credentials are in the form:

{
    user: user,
    password: password
}
Type
Promise

(static) decrypt(privateKeyInFile, data, optionsopt) → {Promise}

Decrypts data with a private key

If there is an encrypted passphrase, this only works when running on the BIG-IP on which the private key was installed.

Parameters:
Name Type Attributes Description
privateKeyInFile String

Full path to private key

data String

Base64 encoded version of the data to decrypt

options Object <optional>

Optional arguments

Properties
Name Type Attributes Description
passphrase String <optional>

Passphrase for private key. Default no passphrase.

passphraseEncrypted Boolean <optional>

If there is a passphrase, whether or not it is encrypted (by MCP). Default false.

Returns:

A promise which is resolve with a string version of the decrypted data, or rejected if an error occurs.

Type
Promise

(static) encrypt(publicKeyDataOrFile, data) → {Promise}

Encrypts data with a public key

Parameters:
Name Type Description
publicKeyDataOrFile String

Either the public key, or the full path to a file containing the public key

data String

String version of the data to encrypt

Returns:

A promise which is resolved with a base64 encoded version of the encrypted data, or rejected if an error occurs.

Type
Promise

(static) generateKeyPair(privateKeyOutFile, optionsopt) → {Promise}

Generates a public/private key pair.

Parameters:
Name Type Attributes Description
privateKeyOutFile String

Full path where private key will be written

options Object <optional>

Optional arguments

Properties
Name Type Attributes Description
keyLength String <optional>

Key length. Default is 2048.

publicKeyOutFile String <optional>

Full path where public key certificate will be written. Default is to resolve with the public key.

passphrase String <optional>

Passphrase for private key. Default no passphrase.

Returns:

A promise which will be resolved when the data is written or rejected if an error occurs. If options.publicKeyOutFile is not provided, promise is resolved with the public key.

Type
Promise

(static) generateRandomBytes(length, encoding) → {Promise}

Generates random bytes of a certain length and encoding

Note: If encoding is 'base64' and length is not a multiple of 6, the returned bytes will always end in '=' or '==', which decreases randomness.

Parameters:
Name Type Description
length Number

Number of random bytes to generate.

encoding String

Encoding to use ('ascii', 'base64', 'hex', etc)

Returns:

A promise which is resolved with the random bytes or rejected if an error occurs

Type
Promise

(static) generateRandomIntInRange(minimum, maximum) → {Number}

Generate a random integer in a range

This code courtesy of https://stackoverflow.com/a/33627342

Parameters:
Name Type Description
minimum Number

Lowest number to generate

maximum Number

Highest number to generate

Returns:
  • A random number in the specified range
Type
Number

(static) nextRandomUser() → {Promise}

Runs the create random user function on BIG-IP/BIG-IQ until valid credentials are returned.

Returns:

A promise which is resolved with user credentials or re-runs createRandomUser if an error occurs. Credentials are in the form:

{
    user: user,
    password: password
}
Type
Promise

(static) symmetricDecrypt(privateKeyFile, encryptedKey, iv, data, optionsopt)

Decrypts data that was encrypted with symmetric encryption

Parameters:
Name Type Attributes Description
privateKeyFile String

The private key file matching the public key that was used to encrypte the symmetric key.

encryptedKey String

The encrypted symmetric key.

iv String | Buffer

The initialization vector that was used for encryption.

data String

Data to decrypt.

options Object <optional>

Optional arguments

Properties
Name Type Attributes Description
inputEncoding String <optional>

Encoding of the encrypted output. Default is base64.

passphrase String <optional>

Passphrase for private key. Default no passphrase.

passphraseEncrypted Boolean <optional>

If there is a passphrase, whether or not it

(static) symmetricEncrypt(publicKeyDataOrFile, data, optionsopt) → {Promise}

Encrypts data using symmetric encryption

A random symmetric key will be generated and encrypted using the public key. The data will then be encrypted using the symmetric key. Encrypted symmetric key will be returned with the data.

Parameters:
Name Type Attributes Description
publicKeyDataOrFile String

Either the public key, or the full path to a file containing the public key. The symmetric key will be encrypted with this key.

data String | Buffer

String version of the data to encrypt

options Object <optional>

Optional parameters

Properties
Name Type Attributes Description
encoding String <optional>

Encoding for encrypted output. Default is base64.

Returns:

A promise which is resolved with a base64 encoded version of the encrypted data, the encrypted symmetric key, and then initialization vector, or rejected if an error occurs. Resolved data is:

{
    encryptedKey: <encryptedKey>,
    iv: <initializationVector>,
    encryptedData: <base64_encoded_encryptedData>
}
Type
Promise