Skip to content

Commit e153b09

Browse files
committed
Initial public release.
1 parent f3146db commit e153b09

17 files changed

+1678
-2
lines changed

LICENSE.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# IONIC SOFTWARE LICENSE
2+
## 1. DEFINITIONS.
3+
(a) “Derivative Work” shall mean a work that is based on one or more preexisting works, such as a revision, enhancement, modification, translation, abridgement, condensation, expansion, or any other form in which such preexisting works may be recast, transformed, or adapted, and that, if prepared without authorization of the owner in the copyright in such preexisting work, would constitute a copyright infringement, and specifically shall include any compilation that incorporates such a preexisting work.
4+
5+
(b) “Services” shall mean Ionic’s data protection and access control platform and related services provided by Ionic in the ordinary business course.
6+
7+
(c) “Software” means the application programming interfaces that enable You or Your applications to interface, interoperate or interconnect with the Services, or other original works of authorship, whether in source or object code form, that are made available under this License by including in or with such work either (i) a copyright notice referencing the applicability of this License, or (ii) a copy of this License.
8+
9+
(d) “You” means any individual or corporation, partnership, limited liability company, trust, association or other entity or organization, including any governmental or political subdivision or any agency or instrumentality thereof, exercising rights or permissions granted by this License.
10+
11+
## 2. GRANT OF LICENSE.
12+
(a) Subject to the terms and conditions of this License, Ionic grants to You a perpetual, worldwide, non-exclusive, royalty-free, copyright license to prepare Derivative Works of, reproduce, publicly display, publicly perform, sublicense and distribute the Software and any resulting Derivative Works in any form.
13+
14+
(b) Subject to the terms and conditions of this License, Ionic grants to You a perpetual, worldwide, non-exclusive, royalty-free patent license to make, have made, use, sell, offer for sale, import, and otherwise transfer its Software licensed under this License, in whole or in part. The foregoing license applies only to the patent claims that would be infringed by Ionic’s Software individually and expressly excludes any combinations with any other materials or technology.
15+
16+
(c) There is no license fee for the Software.
17+
18+
## 3. LIMITATIONS.
19+
(a) Redistribution. You may reproduce or distribute the Software only if You (i) do so pursuant to this License, (b) include a complete copy of this License with Your distribution, and (c) retain without modification any copyright, patent, trademark, or other notices that are present in the Software.
20+
21+
(b) Derivative Works. You may specify that additional or different license or othere terms apply to the use, reproduction, and distribution of your Derivative Works provided that (i) Your terms provide do not supersede, replace or modify the redistribution rights set forth in Section 3(a) above, (ii) Your terms provide that the use limitation in Section 3(c) below applies, and (iii) You identify the specific Derivative Works that are subject to Your terms.
22+
23+
(c) Use Limitation. The Software and any Derivative Works may be used or intended for use only with the Services, platforms applications provided by Ionic or its affiliates.
24+
25+
(d) Trademarks. This License does not grant any rights to use any of Ionic’s or its affiliates’ names, logos, or trademarks, except as necessary to reproduce the notices and legends as set forth in this License.
26+
27+
(e) Termination. If You violate any term of this License, then Your rights under this License will terminate immediately. In addition, if You bring or threaten to bring a patent claim against Ionic to enforce any patents that you allege are infringed by the Software, then your rights under this License may be terminated immediately by Ionic.
28+
29+
## 4. DISCLAIMER OF WARRANTIES.
30+
THE SOFTWARE IS PROVIDED “AS IS,” WITHOUT ANY WARRANTY WHAT¬SO¬EVER, AND THIS LICENSE EXCLUDES, AND IONIC SPECIFICALLY DISCLAIMS, ALL EXPRESS, IMPLIED OR STATUTORY REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT¬ABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. YOU BEAR THE RISK OF UNDERTAKING ANY ACTIVITIES UNDER THIS LICENSE.
31+
32+
## 5. LIMITATION OF LIABILITY
33+
EXCEPT WHERE PROHIBITED BY LAW, IN NO EVENT SHALL IONIC BE LIABLE UNDER ANY CONTRACT, WARRANTY, NEGLIGENCE, STRICT LIABILITY OR OTHER LEGAL OR EQUITABLE THEORY FOR LOSS OR CORRUP¬TION OF DATA, LOSS OF BUSINESS PROFITS, BUSINESS INTERRUP¬TION, LOSSES RESULTING FROM SYSTEM SHUTDOWN, FAILURE TO ACCURATELY TRANSFER, READ OR TRANSMIT INFORMA¬TION, SYSTEM INCOMPATIBILITY OR PROVIDING INCORRECT COMPATIBILITY INFORMATION, OR SPECIAL, PUNITIVE, INCIDENTAL, CONSEQUENTIAL OR INDIRECT DAMAGES RESULTING FROM THE LICENSING, FURNISHING, PERFOR¬MANCE OR USE OF THE LICENSED TECHNOLOGY, EVEN IF IONIC HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE, AND NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF ANY REMEDY ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT.
34+
35+
## 6. COMPLETE AGREEMENT.
36+
This License constitutes the complete and exclusive statement of the agreement among the parties hereto concerning the subject matter hereof. It supersedes all prior written and oral statements, including any prior representation, statement, condition or warranty.
37+
38+
## 7. APPLICABLE LAW.
39+
This Agreement will be governed by, and construed in accordance with the laws of the State of Georgia, U.S.A.
40+
41+
Effective Date: November 3, 2017
42+

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# ionic-devreq-api-python
2-
Example Python Code for Interacting with Ionic's Device Request API
1+
# ionic-devreq-api-python: Example Code for Interacting with Ionic's Device Request API
2+
3+
## Explanation
4+
5+
This example code shows how to use the advanced Device Request APIs available from the Ionic Platform.
6+
It is meant to serve as sample code for developers learning about those APIs to use as reference.
7+
8+
Most developers will instead prefer to use Ionic's supported SDKs, which include a Python SDK which has the same
9+
functionality shown in these examples, as well as significant additional features.
10+
11+
## Setting up Environment
12+
13+
You may want to use Python's virtualenv toolkit to manage your environment.
14+
15+
Once loaded, install the pre-requisites:
16+
```bash
17+
pip install -r requirements.txt
18+
```
19+
20+
## Running Examples
21+
22+
### Create and Fetch Keys:
23+
24+
The `example.py` tool shows how to create keys, and then request them again.
25+
These two operations are usually done independently.
26+
27+
Using this example requires a Secure Enrollment Profile (SEP), which it expects via the plaintext profile persistor in a file `profiles.pt`.
28+
Read [Enrollment Overview](https://dev.ionic.com/registration.html) to learn more.
29+
See the Enrollment Example for obtaining one if you don't have one via another mechanism.
30+
31+
### Enrolling:
32+
33+
The `example_enroll.py` tool shows enrolling a device and obtaining a SEP, and then storing it using the plaintext profile persistor.
34+
35+
Using this example requires first editing the code to define the correct values for the variables.
36+
After setting those values, it can be run and will produce `profiles.pt` which is the SEP stored in plaintext.
37+
38+
There are two options for setting the values:
39+
40+
#### Provide Username/Password for Ionic IdP-linked Enrollment Servers
41+
42+
If, and only if, your enrollment server is linked to Ionic's IdP (which is only for development/demo environments), then
43+
you can enter your Ionic username and password in the file (for demonstration purposes only) and it will obtain the
44+
stoken/uidauth values for you.
45+
46+
#### Provide stoken/uidauth Obtained from Any Enrollment Method
47+
48+
These values are typically obtained from doing the workflows described in [Enrollment Overview](https://dev.ionic.com/registration.html),
49+
such as SAML, Oauth, email token, or generated SAML assertions.
50+
You will need to perform the communication with the enrollment server, following the process for your selected
51+
enrollment type, to obtain these values before entering them and then running this script.
52+
See `registration/get_ionic_token.py` for an example of doing this for a SAML enrollment against the demonstration Ionic IdP.

__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
############################################################
2+
# This is a code sample for the Ionic Security Inc. API, #
3+
# and this packages it so it is usable by other examples. #
4+
# The intention is to show how to interact with the API #
5+
# using builtin and 3rd-party libraries instead of the #
6+
# Ionic SDK. #
7+
# #
8+
# (c) 2017 Ionic Security Inc. #
9+
# Confidential and Proprietary #
10+
# By using this code, I agree to the Terms & Conditions #
11+
# (https://www.ionic.com/terms-of-use/) and the Privacy #
12+
# Policy (https://www.ionic.com/privacy-notice/) #
13+
############################################################
14+
15+
from registration.registration import create_device
16+
from keys.keys import create_keys, fetch_keys
17+
import persistors.persistors

example.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
###########################################################
2+
# This is a code sample for the Ionic Security Inc. API, #
3+
# It assumes a SEP and usage v2.3 of the API #
4+
# The intention is to show how to interact with the API #
5+
# using built-in and 3rd-party libraries instead of the #
6+
# Ionic SDK. #
7+
# #
8+
# This example uses Python 3.4.3 #
9+
# This example is best read with syntax highlighting on. #
10+
# #
11+
# (c) 2017 Ionic Security Inc. #
12+
# Confidential and Proprietary #
13+
# By using this code, I agree to the Terms & Conditions #
14+
# (https://www.ionic.com/terms-of-use/) and the Privacy #
15+
# Policy (https://www.ionic.com/privacy-notice/) #
16+
# Author = rmspeers, QA = #
17+
###########################################################
18+
19+
from keys import create_keys, fetch_keys
20+
from persistors import ProfilePersistorPlaintext
21+
22+
####################################################
23+
### Requires a Device Secure Enrollment Profile ###
24+
####################################################
25+
# Assume a SEP saved to a file named `profiles.pt` #
26+
# which contains a plaintext SEP for demo purposes #
27+
# only. Use a different persistor type in real use.#
28+
####################################################
29+
30+
31+
if __name__ == "__main__":
32+
persistor = ProfilePersistorPlaintext('profiles.pt')
33+
ionic_sep = persistor.get_active_profile()
34+
35+
# Best practice is to include key attributes to describe the type of data you will be using this key to protect:
36+
## These can either be `ionic-protected-*` prefixed so Ionic.com can't see them, and only other requestors who
37+
## access the key can; or they can be unencrypted so that Ionic.com can use their values in policy decisions.
38+
dictKeyAttrs = {
39+
'classification': 'Public',
40+
'ionic-protected-test': ['encrypted_value_1']
41+
}
42+
created_keys = create_keys(ionic_sep, dictKeyAttrs)
43+
print('Created keys: {}'.format(created_keys))
44+
45+
# Now we show fetching one of these keys back:
46+
# NOTE: We may or may not be able to get it depending on the current data policy.
47+
print('Requesting the following keys by ID: {}'.format(', '.join(created_keys.keys())))
48+
49+
# The value is a JSON object with a field "protection-keys" containing
50+
# an array of keytag strings. An example of the protection_keys array:
51+
# protection_keys = ["ABcdGadsg23", "ABcdGP34erq"]
52+
# See `example_external_ids.py` for another way to retrieve keys.
53+
fetched_keys = fetch_keys(ionic_sep, list(created_keys.keys()))
54+
print('Retrieved keys: {}'.format(fetched_keys))

example_enroll.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
###########################################################
2+
# This is a code sample for the Ionic Security Inc. API, #
3+
# It assumes a SEP and usage v2.3 of the API #
4+
# The intention is to show how to interact with the API #
5+
# using built-in and 3rd-party libraries instead of the #
6+
# Ionic SDK. #
7+
# #
8+
# This example uses Python 3.4.3 #
9+
# This example is best read with syntax highlighting on. #
10+
# #
11+
# (c) 2017 Ionic Security Inc. #
12+
# Confidential and Proprietary #
13+
# By using this code, I agree to the Terms & Conditions #
14+
# (https://www.ionic.com/terms-of-use/) and the Privacy #
15+
# Policy (https://www.ionic.com/privacy-notice/) #
16+
# Author = rmspeers, QA = jmassey #
17+
###########################################################
18+
19+
import sys
20+
21+
from registration import create_device
22+
from registration import get_ionic_token
23+
from persistors import ProfilePersistorPlaintext
24+
25+
####################################################
26+
### Creates a Device Secure Enrollment Profile ###
27+
####################################################
28+
# It will output SEP to a file named `profiles.pt` #
29+
# which contains a plaintext SEP for demo purposes #
30+
# only. Use a different persistor type in real use.#
31+
####################################################
32+
33+
# TODO:
34+
# If you are using Ionic's IdP, you can enter your username
35+
# and password below. If not, you must obtain a UIDAUTH
36+
# and STOKEN before registering. These must be unique to each
37+
# registration to prevent replay attacks.
38+
39+
user = ""
40+
password = r""
41+
42+
stoken = ""
43+
uidauth = ""
44+
45+
api_url = "https://dev-api.ionic.com"
46+
enrollment_server_url = "https://dev-enrollment.ionic.com"
47+
keyspace = "ABcd"
48+
49+
50+
if __name__ == "__main__":
51+
# Validate the user provided input:
52+
if api_url == "" or enrollment_server_url == "" or keyspace == "":
53+
print("ERROR: api_url, enrollment_server_url, and keyspace must all be defined.")
54+
sys.exit(1)
55+
if user != "" and password != "":
56+
enrollment_url = "{}/keyspace/{}/register".format(enrollment_server_url, keyspace)
57+
stoken, uidauth = get_ionic_token(enrollment_url, user, password)
58+
if stoken == "" or uidauth == "":
59+
print("ERROR: Username and Password or STOKEN and UIDAUTH must be defined")
60+
sys.exit(2)
61+
62+
# Generate the request body, make the request, and decrypt the responses from the key server and Ionic.com
63+
sep = create_device(api_url, keyspace, enrollment_server_url, stoken, uidauth)
64+
# Display the profile received
65+
print(sep)
66+
67+
# Save the profile to a file
68+
# NOTE: This will overwrite any existing content at that path.
69+
persistor = ProfilePersistorPlaintext()
70+
persistor.add_sep(sep, set_as_active=True)
71+
persistor.set_file_path("profiles.pt")
72+
print(persistor)
73+
persistor.save_to_json()

example_external_ids.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
###########################################################
2+
# This is a code sample for the Ionic Security Inc. API, #
3+
# It assumes a SEP and usage v2.3 of the API #
4+
# The intention is to show how to interact with the API #
5+
# using built-in and 3rd-party libraries instead of the #
6+
# Ionic SDK. #
7+
# #
8+
# This example uses Python 3.4.3 #
9+
# This example is best read with syntax highlighting on. #
10+
# #
11+
# (c) 2017 Ionic Security Inc. #
12+
# Confidential and Proprietary #
13+
# By using this code, I agree to the Terms & Conditions #
14+
# (https://www.ionic.com/terms-of-use/) and the Privacy #
15+
# Policy (https://www.ionic.com/privacy-notice/) #
16+
# Author = rmspeers, QA = #
17+
###########################################################
18+
19+
from uuid import uuid4
20+
21+
from keys import create_keys, fetch_keys
22+
from persistors import ProfilePersistorPlaintext
23+
24+
####################################################
25+
### Requires a Device Secure Enrollment Profile ###
26+
####################################################
27+
# Assume a SEP saved to a file named `profiles.pt` #
28+
# which contains a plaintext SEP for demo purposes #
29+
# only. Use a different persistor type in real use.#
30+
####################################################
31+
32+
if __name__ == "__main__":
33+
persistor = ProfilePersistorPlaintext('profiles.pt')
34+
ionic_sep = persistor.get_active_profile()
35+
36+
# We generate, via whatever method, an external ID which allows us an alternate way to query for the key.
37+
external_id = uuid4().hex
38+
print('We will be referencing: {}'.format(external_id))
39+
40+
# Best practice is to include key attributes to describe the type of data you will be using it to protect:
41+
# See `example.py` for other options, including using encrypted attributes.
42+
dictKeyAttrs = {'classification': 'Public'}
43+
dictKeyAttrs["ionic-external-id"] = [external_id]
44+
45+
created_keys = create_keys(ionic_sep, dictKeyAttrs)
46+
print('Created keys: {}'.format(created_keys))
47+
48+
# Now we show fetching these keys back, using the external ID _instead of the key ID_:
49+
# NOTE: We may or may not be able to get it depending on the current data policy.
50+
print('We could request these keys by ID: {}'.format(', '.join(created_keys.keys())))
51+
52+
# The value is a JSON object with a field "protection-keys" containing
53+
# an array of keytag strings. An example of the protection_keys array:
54+
# protection_keys = ["ABcdGadsg23", "ABcdGP34erq"]
55+
print('However instead we will query for the key by the external ID we gave it: {}'.format(external_id))
56+
protection_keys = [] # Can define to an empty array if only want to query by external_ids.
57+
external_ids = [external_id] # Can define to None if only want to query by key IDs (as is typical).
58+
decrypted_keys, query_results = fetch_keys(ionic_sep, protection_keys, external_ids=external_ids)
59+
print('Fetch keys: {}'.format(decrypted_keys))
60+
if query_results is not None:
61+
print('Query results: {}'.format(query_results))

keys/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
############################################################
2+
# This is a code sample for the Ionic Security Inc. API, #
3+
# and this packages it so it is usable by other examples. #
4+
# The intention is to show how to interact with the API #
5+
# using builtin and 3rd-party libraries instead of the #
6+
# Ionic SDK. #
7+
# #
8+
# (c) 2017 Ionic Security Inc. #
9+
# Confidential and Proprietary #
10+
# By using this code, I agree to the Terms & Conditions #
11+
# (https://www.ionic.com/terms-of-use/) and the Privacy #
12+
# Policy (https://www.ionic.com/privacy-notice/) #
13+
############################################################
14+
15+
from keys.key_create import create_keys
16+
from keys.key_fetch import fetch_keys

0 commit comments

Comments
 (0)