e3db 2.0.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/LICENSE.md +255 -0
- data/README.md +44 -23
- data/examples/registration.rb +79 -0
- data/examples/simple.rb +2 -25
- data/lib/e3db.rb +1 -1
- data/lib/e3db/client.rb +440 -57
- data/lib/e3db/config.rb +2 -0
- data/lib/e3db/crypto.rb +32 -108
- data/lib/e3db/version.rb +1 -1
- data/travis-install-configfile.sh +18 -0
- metadata +5 -4
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd02fa9da7066c7c8de9049f56669116450e33f7
|
4
|
+
data.tar.gz: e72007bf75159c71428f7da2f39665f007649551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b4b44c6d5f1e2b13bcd2d87eee8123dd7283b7db2fdb2adf05ea268b958d86adb1755ebfac334fccff32e585570e60ae68b5deb94f1375bd1631e8565953d0b
|
7
|
+
data.tar.gz: b4ccc70e9e0ae565f64473d065555f486498484aa8a75c654de99955a13f190efba9dae21fa073fce90699b0a94c6b69ceb96fb7248bc1321e83dad29ce57f12
|
data/.gitignore
CHANGED
data/LICENSE.md
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
TOZNY NON-COMMERCIAL LICENSE
|
2
|
+
|
3
|
+
|
4
|
+
THIS TOZNY NON-COMMERCIAL LICENSE PERMITS USE OF THE SOFTWARE ONLY BY
|
5
|
+
GOVERNMENT AGENCIES, SCHOOLS, UNIVERSITIES, NON-PROFIT ORGANIZATIONS
|
6
|
+
OR INDIVIDUALS ON PROJECTS THAT DO NOT RECEIVE EXTERNAL FUNDING OTHER
|
7
|
+
THAN GOVERNMENT RESEARCH GRANTS AND CONTRACTS. FOR THE SPECIFIC
|
8
|
+
LIMITATIONS, SEE SECTION 1.12. ANY OTHER USE REQUIRES A COMMERCIAL
|
9
|
+
LICENSE. PLEASE CONTACT US FOR DETAILS AT
|
10
|
+
_info@tozny.com_.
|
11
|
+
|
12
|
+
1. DEFINITIONS
|
13
|
+
|
14
|
+
1.1. "Community" means the Initial Developer and each and every
|
15
|
+
one of You.
|
16
|
+
|
17
|
+
1.2. "Contributor" means each individual or legal entity that
|
18
|
+
creates or contributes to the creation of Modifications.
|
19
|
+
|
20
|
+
1.3. "Distribute" means to transfer, publish, or otherwise provide
|
21
|
+
or make available a copy of software to any third party.
|
22
|
+
|
23
|
+
1.4. "Distributor" means each individual or legal entity
|
24
|
+
exercising a right to Distribute Licensed Software under this
|
25
|
+
License.
|
26
|
+
|
27
|
+
1.5. "Distributor Code" means, collectively, (a) the Original
|
28
|
+
Source Code and (b) the Licensed Software that is Distributed by a
|
29
|
+
particular Distributor.
|
30
|
+
|
31
|
+
1.6. "Distributor IP" means all patent claims, copyright, and
|
32
|
+
trade secrets owned or licensable by a Distributor that are
|
33
|
+
embodied in or necessarily practiced by the Distributor Code of
|
34
|
+
that particular Distributor.
|
35
|
+
|
36
|
+
1.7. "Electronic Distribution Mechanism" means a mechanism
|
37
|
+
generally accepted in the software development community for the
|
38
|
+
electronic transfer of data.
|
39
|
+
|
40
|
+
1.8. "Executable" means software in any form other than Source
|
41
|
+
Code.
|
42
|
+
|
43
|
+
1.9. "Initial Developer" means TOZNY LLC ("TOZNY"), an Oregon
|
44
|
+
limited liability company with offices in Portland, Oregon.
|
45
|
+
|
46
|
+
1.10. "Initial Developer IP" means all patent claims, copyright,
|
47
|
+
and trade secrets owned or licensable by the Initial Developer
|
48
|
+
which are embodied in or necessarily practiced by the unmodified
|
49
|
+
Original Source Code.
|
50
|
+
|
51
|
+
1.11. "License" means this TOZNY NON-COMMERCIAL LICENSE.
|
52
|
+
|
53
|
+
1.12. "Licensed Purpose" means the exercise of rights under this
|
54
|
+
License: (a) by an official governmental agency, strictly for
|
55
|
+
non-commercial, public benefit purposes; or (b) by a school,
|
56
|
+
university, non-profit organization, or individual solely for
|
57
|
+
non-commercial teaching or research purposes in exchange for which
|
58
|
+
no financially valuable consideration (including but not limited
|
59
|
+
to sales or license revenue, service revenue, and advertising
|
60
|
+
revenue, and further including but not limited to monetary,
|
61
|
+
equity, and in-kind forms of consideration) is received, except
|
62
|
+
for tuition, or research funding received from an official
|
63
|
+
government agency sponsor.
|
64
|
+
|
65
|
+
1.13. "Licensed Software" means any copy of the Original Source
|
66
|
+
Code, the Modifications, and/or Executable versions thereof, as to
|
67
|
+
which You are exercising any rights under this License.
|
68
|
+
|
69
|
+
1.14. "Modifications" means any derivative work of either the
|
70
|
+
Original Source Code or of existing Modifications, including
|
71
|
+
header files or calls to Licensed Software library functions or
|
72
|
+
Executable programs in an application program shall not in and of
|
73
|
+
itself cause that application program to be deemed a Modification,
|
74
|
+
provided that the Licensed Software so included shall in any case
|
75
|
+
remain subject to the terms of this License.
|
76
|
+
|
77
|
+
1.15. "Original Source Code" means the Source Code for the
|
78
|
+
_E3DB Ruby SDK_ as made available for
|
79
|
+
download by TOZNY from [https://github.com/tozny/e3db-ruby](https://github.com/tozny/e3db-ruby).
|
80
|
+
|
81
|
+
1.16. "Source Code" means the preferred form of software for
|
82
|
+
making modifications to it, including all modules it contains,
|
83
|
+
plus any associated interface definition files, scripts used to
|
84
|
+
control compilation and installation of an Executable, or a list
|
85
|
+
of source code differential comparisons against either the
|
86
|
+
Original Source Code or another well known, available Modification
|
87
|
+
of the Contributor's choice. The Source Code can be in a
|
88
|
+
compressed or archival form, provided the appropriate
|
89
|
+
decompression or de-archiving software is widely available for no
|
90
|
+
charge.
|
91
|
+
|
92
|
+
1.17. "You" means an individual or a legal entity exercising
|
93
|
+
rights under this License. For legal entities, "You" includes any
|
94
|
+
entity that controls, is controlled by, or is under common control
|
95
|
+
with You. For purposes of this definition, "control" means (a) the
|
96
|
+
power, direct or indirect, to cause the direction or management of
|
97
|
+
such entity, whether by contract or otherwise, or (b) ownership of
|
98
|
+
fifty percent (50%) or more of the outstanding shares or
|
99
|
+
beneficial ownership of such entity.
|
100
|
+
|
101
|
+
2. SOFTWARE LICENSE GRANTS
|
102
|
+
|
103
|
+
2.1. The Initial Developer Grant. The Initial Developer hereby
|
104
|
+
grants You a worldwide, royalty-free, non-exclusive, solely for
|
105
|
+
the Licensed Purpose and subject to the terms and conditions of
|
106
|
+
this License (including without limitation the Contributor and
|
107
|
+
Distributor grants set forth in Section 2 and the Distribution
|
108
|
+
Obligations set forth in Section 3), as follows:
|
109
|
+
|
110
|
+
(a) A license under the Initial Developer IP to modify, copy, use,
|
111
|
+
and Distribute the Original Source Code and Modifications. (b) A
|
112
|
+
license to copy, use and Distribute Executable versions of the
|
113
|
+
Original Source Code and Modifications.
|
114
|
+
|
115
|
+
2.2. Distributor Grant. If You are a Distributor, You hereby grant
|
116
|
+
TOZNY a worldwide, royalty-free, non-exclusive license under the
|
117
|
+
Distributor IP, solely for the Licensed Purpose and subject to the
|
118
|
+
terms and conditions of this License, to modify, copy, use, and
|
119
|
+
Distribute the Distributor Code and Modifications.
|
120
|
+
|
121
|
+
2.3. Sublicenses. The license rights that are granted under this
|
122
|
+
Section 2 may be sublicensed only by Distributing Licensed
|
123
|
+
Software in compliance with all applicable terms and conditions of
|
124
|
+
this License. No other sublicensing of intellectual property
|
125
|
+
rights granted under this License is permitted.
|
126
|
+
|
127
|
+
2.4. No Other Rights. Except as expressly set forth in this
|
128
|
+
section 2, no other license rights are implied or otherwise
|
129
|
+
granted under this License.
|
130
|
+
|
131
|
+
3. DISTRIBUTION OBLIGATIONS
|
132
|
+
|
133
|
+
The right to Distribute Licensed Software set forth above, whether to
|
134
|
+
a government sponsor or to any other recipient, is subject to the
|
135
|
+
following obligations:
|
136
|
+
|
137
|
+
3.1. Notice of License to Recipients. Any publication or other
|
138
|
+
Distribution of Licensed Software must be made expressly subject
|
139
|
+
to this License. You must include a prominent copy of the notice
|
140
|
+
set forth in Exhibit A with all Licensed Software that you
|
141
|
+
Distribute: (a) in all notices or documentation in which You
|
142
|
+
describe the origin or ownership of the software or the
|
143
|
+
recipient's rights thereto, and (b) in each Source Code file. You
|
144
|
+
hereby agree to indemnify the Initial Developer and every
|
145
|
+
Contributor to the Licensed Software for any and all liability or
|
146
|
+
damages they may incur if caused by Your violation of this
|
147
|
+
Section. Except as expressly authorized by this License, no right
|
148
|
+
is granted to use the name of Tozny in any advertising, news
|
149
|
+
release, other publication, or product documentation, without the
|
150
|
+
prior express written consent of Tozny.
|
151
|
+
|
152
|
+
3.2. Required Availability of Source Code. If You Distribute
|
153
|
+
Licensed Software for which you are a Contributor, You must make
|
154
|
+
the Source Code for all Modifications to which you contribute
|
155
|
+
publicly available to TOZNY or the Community, under the terms of
|
156
|
+
this License and at no additional restriction or cost, via an
|
157
|
+
accepted Electronic Distribution Mechanism for a period of at
|
158
|
+
least twelve (12) months following the date You first Distribute
|
159
|
+
the Licensed Software. You must also include with the Source Code
|
160
|
+
a file documenting any changes You made to create each
|
161
|
+
Modification, and the dates of such changes.
|
162
|
+
|
163
|
+
3.3. Licensee Registration. Before You Distribute any Licensed
|
164
|
+
Software under this License, You must first register by sending
|
165
|
+
email to the Initial Developer addressed to _info@tozny.com_,
|
166
|
+
including a statement confirming that you accept the terms and
|
167
|
+
conditions of this License and describing the specific Electronic
|
168
|
+
Distribution Mechanism you are using (e.g., identify the URL) to
|
169
|
+
make Source Code available under Section 3.2 where applicable.
|
170
|
+
|
171
|
+
4. DISCLAIMER OF WARRANTY
|
172
|
+
|
173
|
+
LICENSED SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
174
|
+
EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
|
175
|
+
THAT THE LICENSED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A
|
176
|
+
PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE
|
177
|
+
QUALITY AND PERFORMANCE OF THE LICENSED SOFTWARE IS WITH YOU. SHOULD
|
178
|
+
ANY LICENSED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
|
179
|
+
INITIAL DEVELOPER OR ANY CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
|
180
|
+
SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY
|
181
|
+
CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY LICENSED
|
182
|
+
SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
|
183
|
+
|
184
|
+
5. LIMITATION OF LIABILITY
|
185
|
+
|
186
|
+
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
|
187
|
+
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE INITIAL
|
188
|
+
DEVELOPER, ANY CONTRIBUTOR, OR ANY DISTRIBUTOR OF LICENSED SOFTWARE,
|
189
|
+
OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO YOU OR ANY OTHER
|
190
|
+
PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
191
|
+
OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF
|
192
|
+
GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND
|
193
|
+
ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE
|
194
|
+
BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
|
195
|
+
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
|
196
|
+
RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
|
197
|
+
PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
|
198
|
+
EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
|
199
|
+
THAT EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
|
200
|
+
|
201
|
+
6. RESPONSIBILITY FOR CLAIMS.
|
202
|
+
|
203
|
+
You are responsible for damages arising, directly or indirectly, out
|
204
|
+
of Your exercise of rights under this License, based on the number of
|
205
|
+
copies of Licensed Software you made available, the revenues you
|
206
|
+
received from utilizing such rights, and other relevant factors. You
|
207
|
+
agree to work with affected parties to distribute responsibility on an
|
208
|
+
equitable basis.
|
209
|
+
|
210
|
+
7. U.S. GOVERNMENT END USERS.
|
211
|
+
|
212
|
+
The Licensed Software is a "commercial item," as that term is defined
|
213
|
+
in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
|
214
|
+
software" and "commercial computer software documentation," as such
|
215
|
+
terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
|
216
|
+
C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
|
217
|
+
all U.S. Government End Users acquire Licensed Software with only
|
218
|
+
those rights set forth herein.
|
219
|
+
|
220
|
+
8. MISCELLANEOUS.
|
221
|
+
|
222
|
+
This License represents the complete agreement concerning the subject
|
223
|
+
matter hereof. If any provision of this License is held to be
|
224
|
+
unenforceable, such provision shall be reformed only to the extent
|
225
|
+
necessary to make it enforceable. This License shall be governed by
|
226
|
+
Oregon law provisions (except to the extent applicable law, if any,
|
227
|
+
provides otherwise), excluding its conflict-of-law provisions. With
|
228
|
+
respect to disputes in which at least one party is a citizen of, or an
|
229
|
+
entity chartered or registered to do business in, the United States of
|
230
|
+
America any litigation relating to this Agreement shall be subject to
|
231
|
+
personal jurisdiction and venue in the Federal Courts of the District
|
232
|
+
of Oregon, and in the Oregon state courts of Portland, OR, with the
|
233
|
+
losing party responsible for costs, including without limitation,
|
234
|
+
court costs and reasonable attorneys fees and expenses. The
|
235
|
+
application of the United Nations Convention on Contracts for the
|
236
|
+
International Sale of Goods is expressly excluded. Any law or
|
237
|
+
regulation which provides that the language of a contract shall be
|
238
|
+
construed against the drafter shall not apply to this License.
|
239
|
+
|
240
|
+
EXHIBIT A
|
241
|
+
|
242
|
+
Tozny dual licenses this product. For commercial use, please contact
|
243
|
+
info@tozny.com. For non-commercial use, the contents of this file are
|
244
|
+
subject to the TOZNY NON-COMMERCIAL LICENSE (the "License") which
|
245
|
+
permits use of the software only by government agencies, schools,
|
246
|
+
universities, non-profit organizations or individuals on projects that
|
247
|
+
do not receive external funding other than government research grants
|
248
|
+
and contracts. Any other use requires a commercial license. You may
|
249
|
+
not use this file except in compliance with the License. You may obtain
|
250
|
+
a copy of the License at https://tozny.com/legal/non-commercial-license.
|
251
|
+
Software distributed under the License is distributed on an "AS IS"
|
252
|
+
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
253
|
+
License for the specific language governing rights and limitations under
|
254
|
+
the License. Portions of the software are Copyright (c) TOZNY LLC, 2017.
|
255
|
+
All rights reserved.
|
data/README.md
CHANGED
@@ -37,21 +37,40 @@ $ apt-get install libsodium-dev (Ubuntu)
|
|
37
37
|
For more information including libsodium installation instructions
|
38
38
|
for Windows, see the [libsodium web site](https://download.libsodium.org/doc/installation/).
|
39
39
|
|
40
|
-
_Windows Users:_ Make sure to download a recent "MSVC" build. Once
|
40
|
+
_Windows Users:_ Make sure to download a recent "MSVC" build. Once
|
41
|
+
downloaded, find the most recent `libsodium.dll` inside the ZIP file,
|
42
|
+
rename it to `sodium.dll` and copy it to C:\usr\local\lib. You can
|
43
|
+
also copy it to your \Windows\System32 directory.
|
41
44
|
|
42
45
|
## Registering a client
|
43
46
|
|
44
|
-
|
45
|
-
[GitHub releases page](https://github.com/tozny/e3db-go/releases).
|
47
|
+
Register an account with [InnoVault](https://innovault.io) to get started. From the Admin Console you can create clients directly (and grab their credentials from the console) or create registration tokens to dynamically create clients with `E3DB::Client.register()`. Clients registered from within the console will automatically back their credentials up to your account. Clients created dynamically via the SDK can _optionally_ back their credentials up to your account.
|
46
48
|
|
47
|
-
|
49
|
+
For a more complete walkthrough, see [`/examples/registration.rb`](https://github.com/tozny/e3db-ruby/blob/master/examples/registration.rb).
|
48
50
|
|
49
|
-
|
50
|
-
$ e3db register me@mycompany.com
|
51
|
-
```
|
51
|
+
### Without Credential Backup
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
```ruby
|
54
|
+
token = '...'
|
55
|
+
client_name = '...'
|
56
|
+
|
57
|
+
public_key, private_key = E3DB::Client.generate_keypair
|
58
|
+
client_info = E3DB::Client.register(token, client_name, public_key)
|
59
|
+
```
|
60
|
+
|
61
|
+
The object returned from the server contains the client's UUID, API key, and API secret (as well as echos back the public key passed during registration). It's your responsibility to store this information locally as it _will not be recoverable_ without credential backup.
|
62
|
+
|
63
|
+
### With Credential Backup
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
token = '...'
|
67
|
+
client_name = '...'
|
68
|
+
|
69
|
+
public_key, private_key = E3DB::Client.generate_keypair
|
70
|
+
client_info = E3DB::Client.register(token, client_name, public_key, private_key, true)
|
71
|
+
```
|
72
|
+
|
73
|
+
The private key must be passed to the registration handler when backing up credentials as it is used to cryptographically sign the encrypted backup file stored on the server. The private key never leaves the system, and the stored credentials will only be accessible to the newly-registered client itself or the account with which it is registered.
|
55
74
|
|
56
75
|
## Loading configuration and creating a client
|
57
76
|
|
@@ -139,22 +158,24 @@ See the [simple example code](examples/simple.rb) for runnable detailed examples
|
|
139
158
|
|
140
159
|
## Development
|
141
160
|
|
142
|
-
Before running tests, register an
|
143
|
-
|
161
|
+
Before running tests, register an account with
|
162
|
+
[InnoVault](https://innovault.io), and generate a client token.
|
144
163
|
|
145
|
-
|
146
|
-
|
147
|
-
|
164
|
+
After checking out the repo, run `bin/setup` to install dependencies. Next,
|
165
|
+
set two environment variables:
|
166
|
+
|
167
|
+
* API_URL - E3DB host to run tests against.
|
168
|
+
* REGISTRATION_TOKEN - A token obtained from InnoVault that can be used
|
169
|
+
to register E3DB clients.
|
148
170
|
|
149
|
-
|
150
|
-
|
151
|
-
interactive prompt that will allow you to experiment.
|
171
|
+
Run `rake spec` to run the tests. You can also run `bin/console` for
|
172
|
+
an interactive prompt that will allow you to experiment.
|
152
173
|
|
153
|
-
To install this gem onto your local machine, run `bundle exec rake
|
154
|
-
To release a new version, update the version number in
|
155
|
-
then run `bundle exec rake release`, which will
|
156
|
-
version, push git commits and tags, and push
|
157
|
-
[rubygems.org](https://rubygems.org).
|
174
|
+
To install this gem onto your local machine, run `bundle exec rake
|
175
|
+
install`. To release a new version, update the version number in
|
176
|
+
`version.rb`, and then run `bundle exec rake release`, which will
|
177
|
+
create a git tag for the version, push git commits and tags, and push
|
178
|
+
the `.gem` file to [rubygems.org](https://rubygems.org).
|
158
179
|
|
159
180
|
## Documentation
|
160
181
|
|
@@ -168,7 +189,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/tozny/
|
|
168
189
|
|
169
190
|
## License
|
170
191
|
|
171
|
-
|
192
|
+
Tozny dual licenses this product. For commercial use, please contact [info@tozny.com](mailto:info@tozny.com). For non-commercial use, the contents of this file are subject to the TOZNY NON-COMMERCIAL LICENSE (the "License") which permits use of the software only by government agencies, schools, universities, non-profit organizations or individuals on projects that do not receive external funding other than government research grants and contracts. Any other use requires a commercial license. You may not use this file except in compliance with the License. You may obtain a copy of the License at https://tozny.com/legal/non-commercial-license. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Portions of the software are Copyright (c) TOZNY LLC, 2017. All rights reserved.
|
172
193
|
|
173
194
|
[gem-image]: https://badge.fury.io/rb/e3db.svg
|
174
195
|
[gem-url]: https://rubygems.org/gems/e3db
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# This program provides a simple example illustrating how to programmatically
|
2
|
+
# register a client with InnoVault and e3db. In some situations, it's preferable
|
3
|
+
# to register a client from the server or system that will be using its
|
4
|
+
# credentials (to ensure that all data is truly encrypted from end-to-end
|
5
|
+
# with no possibilities of a credential leak). For more detailed information,
|
6
|
+
# please see the documentation home page: https://tozny.com/documentation/e3db
|
7
|
+
#
|
8
|
+
# Author:: Eric Mann (eric@tozny.com)
|
9
|
+
# Copyright:: Copyright (c) 2017 Tozny, LLC
|
10
|
+
# License:: Public Domain
|
11
|
+
|
12
|
+
# ---------------------------------------------------------
|
13
|
+
# Initialization
|
14
|
+
# ---------------------------------------------------------
|
15
|
+
|
16
|
+
require 'e3db'
|
17
|
+
|
18
|
+
# A registration token is required to set up a client. In this situation,
|
19
|
+
# we assume an environment variable called REGISTRATION_TOKEN is set
|
20
|
+
token = ENV["REGISTRATION_TOKEN"]
|
21
|
+
|
22
|
+
# Clients can either create new cryptographic keypairs, or load in a pre-defined
|
23
|
+
# pair of Curve25519 keys. In this situation, we will generate a new keypair.
|
24
|
+
public_key, private_key = E3DB::Client.generate_keypair
|
25
|
+
|
26
|
+
puts("Public Key: " + public_key)
|
27
|
+
puts("Private Key: " + private_key)
|
28
|
+
|
29
|
+
# Clients must be registered with a name unique to your account to help
|
30
|
+
# differentiate between different sets of credentials in the Admin Console.
|
31
|
+
# In this example, the name is set at random
|
32
|
+
client_name = sprintf("client_%s", SecureRandom.hex)
|
33
|
+
|
34
|
+
puts("Client Name: " + client_name)
|
35
|
+
|
36
|
+
# Passing all of the data above into the registration routine will create
|
37
|
+
# a new client with the system. Remember to keep your private key private!
|
38
|
+
client_info = E3DB::Client.register(token, client_name, public_key)
|
39
|
+
|
40
|
+
# Optionally, you can automatically back up the credentials of the newly-created
|
41
|
+
# client to your InnoVault account (accessible via https://console.tozny.com) by
|
42
|
+
# passing your private key and a backup flag when registering. The private key is
|
43
|
+
# not sent anywhere, but is used by the newly-created client to sign an encrypted
|
44
|
+
# copy of its credentials that is itself stored in e3db for later use.
|
45
|
+
#
|
46
|
+
# Client credentials are not backed up by default.
|
47
|
+
|
48
|
+
# client_info = E3DB::Client.register(token, client_name, wrapped_key, private_key, true)
|
49
|
+
|
50
|
+
puts("Client ID: " + client_info.client_id)
|
51
|
+
puts("API Key ID: " + client_info.api_key_id)
|
52
|
+
puts("API Secret: " + client_info.api_secret)
|
53
|
+
|
54
|
+
# ---------------------------------------------------------
|
55
|
+
# Usage
|
56
|
+
# ---------------------------------------------------------
|
57
|
+
|
58
|
+
# Once the client is registered, you can use it immediately to create the
|
59
|
+
# configuration used to instantiate a Client that can communicate with
|
60
|
+
# e3db directly.
|
61
|
+
|
62
|
+
config = E3DB::Config.new(
|
63
|
+
:version => 1,
|
64
|
+
:client_id => client_info.client_id,
|
65
|
+
:api_key_id => client_info.api_key_id,
|
66
|
+
:api_secret => client_info.api_secret,
|
67
|
+
:client_email => '',
|
68
|
+
:public_key => public_key,
|
69
|
+
:private_key => private_key,
|
70
|
+
:api_url => 'https://api.e3db.com',
|
71
|
+
:logging => false
|
72
|
+
)
|
73
|
+
|
74
|
+
# Now create a client using that configuration.
|
75
|
+
client = E3DB::Client.new(config)
|
76
|
+
|
77
|
+
# From this point on, the new client can be used as any other client to read
|
78
|
+
# write, delete, and query for records. See the `simple.rb` documentation
|
79
|
+
# for more complete examples ...
|