Drm (drm v0.2.1) View Source
A Digital Rights Management System for Elixir Applications/Modules.
Drm loads valid license files into genservers and then dispatches incoming requests to them for validation.
In this model we give each different otp application a fingerprint/hash, and associate it with a license key.
Here we are creating a new license for an otp app which we reference as "umbrella-app-hash-id", (this creates the license file, and loads it into the licensing server), then we check to see if the license is still valid
## Examples
iex> license = %{hash: "license-key12", meta: %{email: "demo@example.com", name: "licensee name"}, policy: %{name: "policy name", type: "free", expiration: nil, validation_type: "strict", checkin: false, checkin_interval: nil, max_fingerprints: nil, fingerprint: "umbrella-app-hash-id"}}
iex> License.create(license)
iex> License.fingerprint_valid?(license.policy.fingerprint)
true
Link to this section Summary
Functions
Remove all licenses
Create a new license
Decode a license
Delete a license by filename
Encode a license
Export the license file
Export license keys
check if the appid "fingerprint" exists
Generate a license key based on a hash
Validate that a license struct is valid
Validate that a license struct is valid and matches the fingerprint
Validate an encrypted license string
Validate that an encrypted license is valid and matches the fingerprint
Link to this section Functions
Specs
clear() :: String.t()
Remove all licenses
Examples
iex> License.clear()
:ok
Specs
create(Map.t()) :: String.t()
Create a new license
Parameters
hash
: the license key stringmeta
: a map of meta data to enclude in the licensepolicy
: a map of the main policy for the license ### Parametersname
: the name of the policytype
: the type of policy "free | commercial"expiration
: the license experation date this is a Datetime.t -> int ie. DateTime.utc_now() |> to_unixvalidation_type
: the validation type "strict | floating | concurrent"checkin
: when to checkin "true | false"checkin_interval
: when to checkin "nil | daily | weekly | monthly"max_fingerprints
: the number of max fingerprints for this licensefingerprint
: the fingerprint for this licenseValidation Types
strict
: a license that implements the policy will be considered invalid if its machine limit is surpassedfloating
: a license that implements the policy will be valid across multiple machinesconcurrent
: a licensing model, where you allow a set number of machines to be activated at one time, and exceeding that limit may invalidate all current sessions.Types
free
: a free licensecommercial
: a free license
Examples
iex> license = %{hash: "license-key12", meta: %{email: "demo@example.com", name: "licensee name"}, policy: %{name: "policy name", type: "free", expiration: nil, validation_type: "strict", checkin: false, checkin_interval: nil, max_fingerprints: nil, fingerprint: "main-app-name-umbrella-app-hash-id"}}
iex> License.create(license)
true
Specs
decode(String.t()) :: Map.t()
Decode a license
Examples
license_string = "1ASHD7P87VKlA1iC8Q3tdPFCthdeHxSOWS6BQfUv8gsC8yzNg6OeccIErfuKGvRWzzsRyZ7n/0RwE7ZuQCBL4eHPL5zhGCW5JunAKlsorpKdbMWACiv64q/JO3TOCBJSasd0grljX8z2OzKDeEyk7f0xfIleeL0jXfe+rF9/JC4o7vRHTwJS5va6r19fcWWB5u4AxQUw5tsJmcWBVX5TDwTH8WSJr8HK9xto8V6M1DNzNUKf3dLHBr32dVUjM+uNW2W2uy5Cl3LKIPxv+rmwZmTBZ/1kX8VrqE1BXCM7HttiwzmBEmbQJrvcnY5CAiO562HJTAM6C7RFsHGOtrwWINRzCkMxOffAeuHYy6G9S+ngasJBR/0a39HcA2Ic4mz5"
License.decode(license_string)
Specs
Delete a license by filename
Examples
iex> License.delete("3454453444")
{:error, :enoent}
Specs
encode(Map.t()) :: String.t()
Encode a license
Parameters
hash
: the license key stringmeta
: a map of meta data to enclude in the licensepolicy
: a map of the main policy for the license ### Parametersname
: the name of the policytype
: the type of policy "free | commercial"expiration
: the license experation date this is a Datetime.t -> int ie. DateTime.utc_now() |> to_unixvalidation_type
: the validation type "strict | floating | concurrent"checkin
: when to checkin "true | false"checkin_interval
: when to checkin "nil | daily | weekly | monthly"max_fingerprints
: the number of max fingerprints for this licensefingerprint
: the fingerprint for this licenseValidation Types
strict
: a license that implements the policy will be considered invalid if its machine limit is surpassedfloating
: a license that implements the policy will be valid across multiple machinesconcurrent
: a licensing model, where you allow a set number of machines to be activated at one time, and exceeding that limit may invalidate all current sessions.Types
free
: a free licensecommercial
: a free license
Examples
license = %{hash: "license-key", meta: %{email: "demo@example.com", name: "licensee name"}, policy: %{name: "policy name", type: "free", expiration: 55, validation_type: "strict", checkin: false, checkin_interval: nil, max_fingerprints: nil, fingerprint: "main-app-name-umbrella-app-hash-id"}}
License.encode(license)
Export the license file
Examples
iex> fingerprint = "umbrella-app-id"
iex> License.export(fingerprint)
{:error, "fingerprint not found"}
Specs
export_keys() :: Map.t()
Export license keys
Examples
License.export_keys()
check if the appid "fingerprint" exists
Examples
iex> fingerprint = "umbrella-app-id"
iex> License.fingerprint_valid?(fingerprint)
false
Specs
Generate a license key based on a hash
Examples
hash = "4424552325453453"
License.generate_key(hash, 2)
Specs
Validate that a license struct is valid
Examples
license = %{hash: "license-key", meta: %{email: "demo@example.com", name: "licensee name"}, policy: %{name: "policy name", type: "free", expiration: 55, validation_type: "strict", checkin: false, checkin_interval: nil, max_fingerprints: nil, fingerprint: "main-app-name-umbrella-app-hash-id"}}
License.is_valid?(license)
Validate that a license struct is valid and matches the fingerprint
Examples
license = %{hash: "license-key", meta: %{email: "demo@example.com", name: "licensee name"}, policy: %{name: "policy name", type: "free", expiration: 55, validation_type: "strict", checkin: false, checkin_interval: nil, max_fingerprints: nil, fingerprint: "main-app-name-umbrella-app-hash-id"}}
fingerprint = "main-app-name-umbrella-app-hash-id"
License.is_valid?(license, fingerprint)
Specs
Validate an encrypted license string
Examples
iex> license_string = "3454453444"
iex> License.valid?(license_string)
false
Specs
Validate that an encrypted license is valid and matches the fingerprint
Examples
iex> license_string = "3454453444"
iex> fingerprint = "umbrella-app-id"
iex> License.valid?(license_string, fingerprint)
false