cookbook 'esim_activation', '~> 1.0.0'
esim_activation (1) Versions 1.0.0 Follow0
Parse and validate GSMA SGP.22 eSIM activation codes (LPA:1$smdp$matchingid) before they reach an MDM, a QR generator or a device inventory
cookbook 'esim_activation', '~> 1.0.0', :supermarket
knife supermarket install esim_activation
knife supermarket download esim_activation
esim_activation
A small Chef cookbook for checking eSIM activation codes before they end up
in a device inventory, an MDM enrolment payload or a QR generator. It parses
the GSMA SGP.22 activation-code string, tells you exactly what is wrong when
a device would reject it, and can write a de-duplicated, normalised list of
good codes to disk.
What an activation code looks like
SGP.22 (section 4.1) defines the string behind every eSIM QR code and behind
the "enter details manually" screen on iOS and Android:
LPA:1$$[$[$]]
| Field | Rule enforced here |
|---|---|
LPA:1 |
Fixed prefix (case-insensitive). LPA:2 or anything else is rejected |
| SM-DP+ address | A host name with at least two labels. Schemes (https://), ports, paths, bare IPs and localhost are rejected. Lower-cased on output |
| matching ID | Up to 255 characters, no whitespace or control characters. May be empty for profiles that are pushed to the device |
| SM-DP+ OID | Optional dotted OID such as 1.3.6.1.4.1.99999.1
|
| confirmation code flag | Optional, and only the value 1 is valid. It means the user must also type a confirmation code |
The usual copy-and-paste faults it catches: a leading https://, a trailing
space or newline, a space inside the matching ID from a wrapped e-mail, and a
$ swapped for a S or 5 by OCR.
Usage
Library (recipes, custom resources, anywhere)
code = EsimActivation::Lpa.parse('LPA:1$smdp.example.com$ABCD-EFGH-1234') code.smdp # => "smdp.example.com" code.matching_id # => "ABCD-EFGH-1234" code.confirmation_code_required # => false code.to_s # => "LPA:1$smdp.example.com$ABCD-EFGH-1234" EsimActivation::Lpa.valid?('LPA:1$https://smdp.example.com$X') # => false EsimActivation::Lpa.reject_reason('LPA:1$https://smdp.example.com$X') # => "SM-DP+ address \"https://smdp.example.com\" is not a valid host name"
Inside recipes and resources the module is also available as esim_lpa.
Recipe esim_activation::default
Checks node['esim_activation']['codes'] and logs a warning for each code a
device would reject. Set strict to true to fail the run instead.
default['esim_activation']['codes'] = ['LPA:1$smdp.example.com$ABCD-EFGH-1234'] default['esim_activation']['strict'] = true
Resource esim_activation_inventory
Writes the normalised codes, one per line, to a file (mode 0600 by default,
because an activation code is a one-time credential until the profile is
installed). Invalid codes are skipped with a warning, or fail the run with
strict true.
esim_activation_inventory '/etc/fleet/esim_codes' do codes [ 'LPA:1$smdp.example.com$ABCD-EFGH-1234', 'lpa:1$SMDP.Example.com$ABCD-EFGH-1234', # duplicate after normalising 'LPA:1$rsp.example.net$K2-3F5-9X$$1' ] strict false end
Where these codes come from
Any consumer or travel eSIM store issues one per order. Stores that take
crypto at checkout, such as an
eSIM that accepts crypto
without an account, deliver the same string by e-mail or on the order page,
so the same checks apply. Disclosure: this cookbook is maintained by the team
behind that store; nothing in the cookbook talks to it.
Testing
ruby test/unit/lpa_test.rb
The tests cover valid codes, the OID and confirmation-code fields, round
tripping, and each rejection rule.
License
MIT. See LICENSE.
Dependent cookbooks
This cookbook has no specified dependencies.
Contingent cookbooks
There are no cookbooks that are contingent upon this one.
esim_activation CHANGELOG
1.0.0
- Initial release: SGP.22 activation-code parser,
esim_lpahelper, default recipe,esim_activation_inventoryresource.