noteshred 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +39 -0
- data/LICENSE.txt +22 -0
- data/README.md +114 -0
- data/Rakefile +1 -0
- data/build.sh +1 -0
- data/lib/noteshred.rb +33 -0
- data/lib/noteshred/api.rb +28 -0
- data/lib/noteshred/crypto.rb +44 -0
- data/lib/noteshred/note.rb +106 -0
- data/lib/noteshred/request.rb +24 -0
- data/lib/noteshred/tools.rb +18 -0
- data/lib/noteshred/version.rb +3 -0
- data/noteshred.gemspec +27 -0
- data/spec/crypto_spec.rb +22 -0
- data/spec/note_spec.rb +59 -0
- data/spec/request_spec.rb +25 -0
- data/spec/spec_helper.rb +12 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ccde0fd634a9f2be578b6c9b5a903918f386e25f
|
4
|
+
data.tar.gz: 5cca82b3c185dc7baeaab252be29fa5760fd7cc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 320b81ee5a5792451cf5546007071f59aa11e8315b688dee7174544b03a9f879bf2710eeb96caa64505284dd1fde8b3440e4c77c6d286bfc416a3f60cef71416
|
7
|
+
data.tar.gz: d8e6600fb103e32f9c3e05172b001420d62eb7b329be0f8c229dc406e84bada6381ae5eafa867820224096941683e4309e57b41042b68b63b984e5fb0b9a181b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
noteshred (0.0.1)
|
5
|
+
bcrypt (~> 3.1, >= 3.1.7)
|
6
|
+
rest-client (~> 1.7, >= 1.7.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
bcrypt (3.1.7)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
mime-types (1.25.1)
|
14
|
+
netrc (0.7.7)
|
15
|
+
rake (10.3.2)
|
16
|
+
rest-client (1.7.2)
|
17
|
+
mime-types (>= 1.16, < 3.0)
|
18
|
+
netrc (~> 0.7)
|
19
|
+
rspec (3.1.0)
|
20
|
+
rspec-core (~> 3.1.0)
|
21
|
+
rspec-expectations (~> 3.1.0)
|
22
|
+
rspec-mocks (~> 3.1.0)
|
23
|
+
rspec-core (3.1.7)
|
24
|
+
rspec-support (~> 3.1.0)
|
25
|
+
rspec-expectations (3.1.2)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.1.0)
|
28
|
+
rspec-mocks (3.1.3)
|
29
|
+
rspec-support (~> 3.1.0)
|
30
|
+
rspec-support (3.1.2)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.5)
|
37
|
+
noteshred!
|
38
|
+
rake (~> 10.0, >= 10.0.0)
|
39
|
+
rspec (~> 3.0, >= 3.0.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Cheyne Wallace
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Noteshred
|
2
|
+
|
3
|
+
Official gem for interacting with the noteshred.com API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'noteshred'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install noteshred
|
18
|
+
|
19
|
+
## Setup
|
20
|
+
|
21
|
+
If you're not using Rails, you'll need to require noteshred first:
|
22
|
+
```ruby
|
23
|
+
require 'noteshred'
|
24
|
+
```
|
25
|
+
Set your API key:
|
26
|
+
```ruby
|
27
|
+
Noteshred.api_key = '6935629729ae6869c98799936591'
|
28
|
+
```
|
29
|
+
## Creating Notes
|
30
|
+
|
31
|
+
Notes require a few basic properties as a minimum.
|
32
|
+
We will create a note with the bare minimum options.
|
33
|
+
```ruby
|
34
|
+
note = Noteshred::Note.new
|
35
|
+
note.title = 'Super Secret Note'
|
36
|
+
note.content = 'Hey there, here is the info'
|
37
|
+
note.password = 'password098'
|
38
|
+
note.create
|
39
|
+
|
40
|
+
#=> "{"token":"af3222afb4","title":"Super Secret Note","email":"freddy@fingers.com","email_hash":"1590fee271427e2e4fefe4faf12c835","content":"Hey there, here is the info","shred_by":"2014-12-01T21:33:50-08:00","is_shredded":false,"shred_method":1,"has_attachment":false,"created_at":"2014-11-24T21:33:50-08:00","created_by":"Freddy Fingers","hint":null,"activities":[]}"
|
41
|
+
```
|
42
|
+
|
43
|
+
### Options
|
44
|
+
Title, content and password are the minimum options required for a note. This will create a new that will shred after being read once.
|
45
|
+
|
46
|
+
There are other options which can be set to enable various features.
|
47
|
+
|
48
|
+
|
49
|
+
|Option |Type |Description|
|
50
|
+
|-------|-----|-----------|
|
51
|
+
|hint |string|Setting a hint will add a message to any notification you sent to users regarding the note which can be used to include information about how to guess the password. The hint is set as a string. [Read More Here](https://www.noteshred.com/blog/password-hints)|
|
52
|
+
|recipients|array|The recipients option takes an array of email addresses of which each email address will be emailed with details of how to access the note and the included hint message if set.|
|
53
|
+
|
54
|
+
## Pushing Encrypted Notes
|
55
|
+
Pushing a note is much like creating a note except that the encryption is performed locally from the gem and the encrypted contents are simply pushed to the server to be stored.
|
56
|
+
This is an additional measure of security for those that are concerned about wire tapping or man in the middle attacks.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
note = Noteshred::Note.new
|
60
|
+
note.title = 'Super Secret Note'
|
61
|
+
note.content = 'Hey there, here is the info'
|
62
|
+
note.password = 'password098'
|
63
|
+
note.encrypt
|
64
|
+
|
65
|
+
#=> <Noteshred::Note:0x007fe6a5878c30 @title="Super Secret Note", @content=nil, @password=nil, @encrypted_content="2SM3tjApUErFIqo96pKnliOEGEu16y9NAAovADZeALs=\n", @encrypted_content_iv="UiK2yPbKQ4Lo5M3zagvxHA==\n", @encrypted_content_salt="7388b02e588ef54aa34486d9c79234e8", @version=4, @password_hash="$2a$10$Fvb9Q/5YTyDe6hGH/JQtceC9RB1J9BVqqc0y4K1EDo0Cwqsq1Nd6a">
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
calling **.encrypt** on the note will clear any sensitive content and populate the encrypted content fields with IV and salt.
|
70
|
+
To push the note to the server, simply call push on the note.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
note.push
|
74
|
+
```
|
75
|
+
|
76
|
+
###Please note
|
77
|
+
We occasionally adjust the encryption algorithms and handling on the server for security reasons and as newer techniques become known. By using the push functionality you will not automatically use the latest encryption as we release it, but instead will be locked into using the most recent version available within this gem.
|
78
|
+
|
79
|
+
For example, we are currently at encryption version 4. This is available both on the server and within the gem. If we release a version 5, anyone using the standard "note.create" method will automatically use version 5 as we will default everyone to this when creating new notes on the server, where as if you are using the "note.push" method you will still be encrypting notes using version 4 until we release an updated gem.
|
80
|
+
|
81
|
+
## Sharing Notes
|
82
|
+
Sharing a note with someone will email them with details on how to access the note.
|
83
|
+
|
84
|
+
If they have a NoteShred account it will also create a "shared note" which will appear within their user dashboard under the "Shared With Me" section.
|
85
|
+
|
86
|
+
To share a note, you need to know the note id (also known as the token) and the persons email address.
|
87
|
+
Comments are optional
|
88
|
+
|
89
|
+
Multiple recipients can be shared with by using a comma separated string of email addresses.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
Noteshred::Note.share('7561ab7fbd','someguy@gmail.com','Here is the information you requested')
|
93
|
+
#=> {"message"=>"Notification sent", "status"=>"accepted"}
|
94
|
+
```
|
95
|
+
|
96
|
+
## Requesting Information
|
97
|
+
Requests let you receive information from someone without the need for them to have a NoteShred account. Think of it like creating a blank note and asking someone else to fill it in for you.
|
98
|
+
This person will be able to open a password protected link and enter some information to be encrypted which is then sent back to you in the form of a regular note, after which you will see it appear in your note list and can access using the password you originally defined. [Read More About Requests Here](https://www.noteshred.com/blog/information-request)
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
request = Noteshred::Request.new
|
102
|
+
request.recipient_email = 'john@company.com'
|
103
|
+
request.password = 'xyzabc123#%'
|
104
|
+
request.message = 'Please send me the credentials for server-x'
|
105
|
+
request.create
|
106
|
+
```
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
1. Fork it ( http://github.com<my-github-username>/noteshred/fork )
|
111
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
112
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
113
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
114
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/build.sh
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem build noteshred.gemspec && gem install noteshred-1.0.1.gem
|
data/lib/noteshred.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'noteshred/version'
|
2
|
+
require 'noteshred/api'
|
3
|
+
require 'noteshred/crypto'
|
4
|
+
require 'noteshred/tools'
|
5
|
+
require 'noteshred/note'
|
6
|
+
require 'noteshred/request'
|
7
|
+
|
8
|
+
module Noteshred
|
9
|
+
@api_key = nil
|
10
|
+
@hostname = 'api.noteshred.com'
|
11
|
+
@api_ver = 'v1'
|
12
|
+
@protocol = 'https'
|
13
|
+
|
14
|
+
def self.api_key=(api_key)
|
15
|
+
@api_key = api_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.api_key
|
19
|
+
@api_key
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.endpoint
|
23
|
+
"#{@protocol}://#{@hostname}/#{@api_ver}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.url(rel)
|
27
|
+
Noteshred.endpoint + rel
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.bundle
|
31
|
+
Noteshred::API.get('/bundle')
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Noteshred
|
5
|
+
module API
|
6
|
+
RestClient.add_before_execution_proc do |req, params|
|
7
|
+
raise ArgumentError.new('Missing NoteShred API Key') if Noteshred.api_key.nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get(rel,params = nil)
|
11
|
+
response = RestClient.get(Noteshred.url(rel), {:params => params, :authorization => "Token token=#{Noteshred.api_key}"}){|response, request, result| response }
|
12
|
+
Noteshred::API.render(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.post(rel,params = nil)
|
16
|
+
response = RestClient.post(Noteshred.url(rel), params, {:authorization => "Token token=#{Noteshred.api_key}", :content_type => :json, :accept => :json}){|response, request, result| response }
|
17
|
+
Noteshred::API.render(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.render(response)
|
21
|
+
JSON.parse(response)
|
22
|
+
rescue JSON::ParserError => err
|
23
|
+
{:error => err.message}
|
24
|
+
rescue StandardError
|
25
|
+
{:error => 'Error parsing response'}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'digest'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
module Noteshred
|
6
|
+
module Crypto
|
7
|
+
module V4
|
8
|
+
ITERATIONS = 20000
|
9
|
+
|
10
|
+
# Outputs UTF-8 encoded object for storing in database
|
11
|
+
def self.encrypt(content,pass)
|
12
|
+
raise ArgumentError, 'Content and password required' if content.empty? || pass.empty?
|
13
|
+
cipher = OpenSSL::Cipher.new('AES-256-CBC')
|
14
|
+
cipher.encrypt
|
15
|
+
iv = cipher.random_iv
|
16
|
+
salt = SecureRandom.hex(16)
|
17
|
+
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(pass, salt, ITERATIONS, cipher.key_len)
|
18
|
+
result = cipher.update(content)
|
19
|
+
result << cipher.final
|
20
|
+
return {
|
21
|
+
:content => Noteshred::Tools.encode_utf8(result),
|
22
|
+
:iv => Noteshred::Tools.encode_utf8(iv),
|
23
|
+
:salt => salt,
|
24
|
+
:version => 4
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Expects UTF-8 encoded strings from the encrypt method
|
29
|
+
def self.decrypt(content,pass,salt,iv)
|
30
|
+
content = Noteshred::Tools.decode_utf8(content)
|
31
|
+
cipher = OpenSSL::Cipher.new('AES-256-CBC')
|
32
|
+
cipher.decrypt
|
33
|
+
cipher.iv = Noteshred::Tools.decode_utf8(iv)
|
34
|
+
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(pass, salt, ITERATIONS, cipher.key_len)
|
35
|
+
result = cipher.update(content)
|
36
|
+
result << cipher.final
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.hash(pass,salt)
|
40
|
+
return OpenSSL::PKCS5::pbkdf2_hmac_sha1(pass, salt, ITERATIONS, 32)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'bcrypt'
|
2
|
+
module Noteshred
|
3
|
+
class Note
|
4
|
+
attr_accessor :content,
|
5
|
+
:title,
|
6
|
+
:password,
|
7
|
+
:password_hash,
|
8
|
+
:recipients,
|
9
|
+
:encrypted_content,
|
10
|
+
:encrypted_content_salt,
|
11
|
+
:encrypted_content_iv,
|
12
|
+
:shred_method,
|
13
|
+
:shred_by,
|
14
|
+
:hint,
|
15
|
+
:version
|
16
|
+
|
17
|
+
# Shred Methods
|
18
|
+
SHRED_AFTER_READING = 1
|
19
|
+
SHRED_LATER = 2
|
20
|
+
|
21
|
+
def create
|
22
|
+
# For creating notes that are encrypted on the server
|
23
|
+
validate_content
|
24
|
+
validate_options
|
25
|
+
Noteshred::API.post('/notes', Noteshred::Tools.hashify(self))
|
26
|
+
end
|
27
|
+
|
28
|
+
def push
|
29
|
+
# For creating notes that are encrypted by the gem first then pushed to the server
|
30
|
+
validate_options
|
31
|
+
if self.encrypted_content_salt.nil? || encrypted_content_iv.nil?
|
32
|
+
raise ArgumentError.new('No encrypted content found. Must call .encrypt before pushing')
|
33
|
+
end
|
34
|
+
|
35
|
+
Noteshred::API.post('/notes/push', Noteshred::Tools.hashify(self))
|
36
|
+
end
|
37
|
+
|
38
|
+
def pull(token,pass)
|
39
|
+
# For pulling raw encrypted notes from the server
|
40
|
+
# TODO: Implement server side portion
|
41
|
+
if token.nil? || password.nil?
|
42
|
+
raise ArgumentError.new('token and password params are required')
|
43
|
+
end
|
44
|
+
Noteshred::API.get('/notes/pull', {:password => pass, :token => token})
|
45
|
+
end
|
46
|
+
|
47
|
+
def encrypt
|
48
|
+
validate_content
|
49
|
+
crypt = Noteshred::Crypto::V4.encrypt(self.content, self.password)
|
50
|
+
self.encrypted_content = crypt[:content]
|
51
|
+
self.encrypted_content_iv = crypt[:iv]
|
52
|
+
self.encrypted_content_salt = crypt[:salt]
|
53
|
+
self.version = crypt[:version]
|
54
|
+
self.password_hash = BCrypt::Password.create(self.password)
|
55
|
+
self.content = nil
|
56
|
+
self.password = nil
|
57
|
+
return self
|
58
|
+
end
|
59
|
+
|
60
|
+
def decrypt
|
61
|
+
validate_encrypted_content
|
62
|
+
self.content = Noteshred::Crypto::V4.decrypt(self.encrypted_content, self.password, self.encrypted_content_salt, self.encrypted_content_iv)
|
63
|
+
self.encrypted_content_iv = nil
|
64
|
+
self.encrypted_content_salt = nil
|
65
|
+
self.encrypted_content = nil
|
66
|
+
self.password_hash = nil
|
67
|
+
return self
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.share(token,recipients,comments)
|
71
|
+
# Receive comma seperated list of recipients
|
72
|
+
if recipients.nil?
|
73
|
+
raise ArgumentError.new('Recipients are required')
|
74
|
+
end
|
75
|
+
if token.nil?
|
76
|
+
raise ArgumentError.new('Token is required')
|
77
|
+
end
|
78
|
+
Noteshred::API.post("/notes/#{token}/share", {:dest_email => recipients, :comments => comments})
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def validate_content
|
84
|
+
raise ArgumentError.new('Missing Password') if password.nil?
|
85
|
+
raise ArgumentError.new('Password Must Be Minimum 8 Characters') if password.size < 8
|
86
|
+
raise ArgumentError.new('Missing Content') if content.nil?
|
87
|
+
end
|
88
|
+
|
89
|
+
def validate_encrypted_content
|
90
|
+
raise ArgumentError.new('Missing Password') if password.nil?
|
91
|
+
raise ArgumentError.new('Missing Content') if encrypted_content.nil?
|
92
|
+
raise ArgumentError.new('Missing Salt') if encrypted_content_salt.nil?
|
93
|
+
end
|
94
|
+
|
95
|
+
def validate_options
|
96
|
+
raise ArgumentError.new('shred_by date not set') if shred_method == SHRED_LATER && shred_by.nil?
|
97
|
+
if !recipients.nil?
|
98
|
+
raise ArgumentError.new('recipients must be an array.') unless recipients.kind_of?(Array)
|
99
|
+
end
|
100
|
+
|
101
|
+
if self.shred_method.nil?
|
102
|
+
self.shred_method = SHRED_AFTER_READING
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Noteshred
|
2
|
+
class Request
|
3
|
+
attr_accessor :message,
|
4
|
+
:recipient_email,
|
5
|
+
:password,
|
6
|
+
:confirm_password
|
7
|
+
|
8
|
+
def create
|
9
|
+
validate_attributes
|
10
|
+
self.confirm_password = self.password
|
11
|
+
Noteshred::API.post('/note_requests', Noteshred::Tools.hashify(self))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def validate_attributes
|
17
|
+
raise ArgumentError.new('Missing Password') if password.nil?
|
18
|
+
raise ArgumentError.new('Password Must Be Minimum 8 Characters') if password.size < 8
|
19
|
+
raise ArgumentError.new('Missing Message') if message.nil?
|
20
|
+
raise ArgumentError.new('Missing Recipient Email') if recipient_email.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'base64'
|
2
|
+
module Noteshred
|
3
|
+
module Tools
|
4
|
+
def self.encode_utf8(string)
|
5
|
+
Base64.encode64(string).encode('utf-8')
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.decode_utf8(string)
|
9
|
+
Base64.decode64(string.encode('ascii-8bit')).force_encoding('utf-8')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.hashify(obj)
|
13
|
+
obj.instance_variables.each_with_object({}) { |var, hsh|
|
14
|
+
hsh[var.to_s.delete("@")] = obj.instance_variable_get(var)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/noteshred.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'noteshred/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'noteshred'
|
8
|
+
spec.version = Noteshred::VERSION
|
9
|
+
spec.authors = ['Cheyne Wallace']
|
10
|
+
spec.email = ['cheyne.wallace@gmail.com']
|
11
|
+
spec.summary = %q{Gem for interacting with the NoteShred API}
|
12
|
+
spec.description = %q{Gem for interacting with the NoteShred API via HTTPS returning JSON payloads}
|
13
|
+
spec.homepage = 'https://github.com/cheynewallace/noteshred-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0', '>= 10.0.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0', '>= 3.0.0'
|
24
|
+
|
25
|
+
spec.add_dependency 'rest-client', '~> 1.7', '>= 1.7.2'
|
26
|
+
spec.add_dependency 'bcrypt', '~> 3.1', '>= 3.1.7'
|
27
|
+
end
|
data/spec/crypto_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Noteshred::Crypto do
|
3
|
+
context 'V4' do
|
4
|
+
before(:each) do
|
5
|
+
@password = 'password1865#'
|
6
|
+
@content = 'This is secret information'
|
7
|
+
@encrypted = Noteshred::Crypto::V4.encrypt(@content, @password)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should have a salt and iv' do
|
11
|
+
expect(@encrypted[:iv]).not_to be_empty
|
12
|
+
expect(@encrypted[:salt]).not_to be_empty
|
13
|
+
expect(@encrypted[:content]).not_to be_empty
|
14
|
+
expect(@encrypted[:content]).not_to eq(@content)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should decrypt successfully' do
|
18
|
+
decrypted = Noteshred::Crypto::V4.decrypt(@encrypted[:content], @password, @encrypted[:salt], @encrypted[:iv])
|
19
|
+
expect(decrypted).to eq(@content)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/note_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Noteshred::Note do
|
3
|
+
before(:each) do
|
4
|
+
set_key
|
5
|
+
@password = 'password1865#'
|
6
|
+
@content = 'This is secret information'
|
7
|
+
@title = 'This is a title'
|
8
|
+
@encrypted = Noteshred::Crypto::V4.encrypt(@content, @password)
|
9
|
+
@note = Noteshred::Note.new
|
10
|
+
@note.title = @title
|
11
|
+
@note.content = @content
|
12
|
+
@note.password = @password
|
13
|
+
@note.recipients = ['cheyne@somewhere.com']
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'create' do
|
17
|
+
it 'should create a new note' do
|
18
|
+
expect(@note.create['token']).to_not be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'encrypt' do
|
23
|
+
it 'should encrypt a note' do
|
24
|
+
@note.encrypt
|
25
|
+
expect(@note.content).to be_nil
|
26
|
+
expect(@note.encrypted_content).to_not be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'decrypt' do
|
31
|
+
it 'should decrypt a note' do
|
32
|
+
@note.encrypt
|
33
|
+
expect(@note.content).to be_nil
|
34
|
+
expect(@note.encrypted_content).to_not be_nil
|
35
|
+
|
36
|
+
@note.password = @password
|
37
|
+
@note.decrypt
|
38
|
+
expect(@note.content).to eq(@content)
|
39
|
+
expect(@note.encrypted_content).to be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
context 'push' do
|
45
|
+
it 'should push a pre-encrypted note' do
|
46
|
+
@note.encrypt
|
47
|
+
expect(@note.content).to be_nil
|
48
|
+
expect(@note.encrypted_content).to_not be_nil
|
49
|
+
expect(@note.push['token']).to_not be_nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'share' do
|
54
|
+
it 'should share a note' do
|
55
|
+
result = Noteshred::Note.share('7561ab7fbd','someguy@somewhere.com','Here is the info')
|
56
|
+
expect(JSON.parse(result)['status']).to eq('accepted')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Noteshred::Request do
|
3
|
+
before(:each) do
|
4
|
+
set_key
|
5
|
+
@request = Noteshred::Request.new
|
6
|
+
@request.message = 'Send me something private'
|
7
|
+
@request.recipient_email = 'user@someguy.com'
|
8
|
+
@request.password = 'password1234'
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'create' do
|
12
|
+
it 'should create a new request' do
|
13
|
+
result = @request.create
|
14
|
+
expect(result['note']['token']).to_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should error when missing email address' do
|
18
|
+
@request.recipient_email= 'wrong'
|
19
|
+
result = @request.create
|
20
|
+
expect(result['status']).to eq('validation_error')
|
21
|
+
expect(result['message']).to eq('Validation failed: Recipient email must be a valid email address')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: noteshred
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cheyne Wallace
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 10.0.0
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '10.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 10.0.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.0.0
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.0'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.0.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rest-client
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '1.7'
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.7.2
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.7'
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.7.2
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: bcrypt
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '3.1'
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.1.7
|
97
|
+
type: :runtime
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.1'
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 3.1.7
|
107
|
+
description: Gem for interacting with the NoteShred API via HTTPS returning JSON payloads
|
108
|
+
email:
|
109
|
+
- cheyne.wallace@gmail.com
|
110
|
+
executables: []
|
111
|
+
extensions: []
|
112
|
+
extra_rdoc_files: []
|
113
|
+
files:
|
114
|
+
- ".gitignore"
|
115
|
+
- Gemfile
|
116
|
+
- Gemfile.lock
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.md
|
119
|
+
- Rakefile
|
120
|
+
- build.sh
|
121
|
+
- lib/noteshred.rb
|
122
|
+
- lib/noteshred/api.rb
|
123
|
+
- lib/noteshred/crypto.rb
|
124
|
+
- lib/noteshred/note.rb
|
125
|
+
- lib/noteshred/request.rb
|
126
|
+
- lib/noteshred/tools.rb
|
127
|
+
- lib/noteshred/version.rb
|
128
|
+
- noteshred.gemspec
|
129
|
+
- spec/crypto_spec.rb
|
130
|
+
- spec/note_spec.rb
|
131
|
+
- spec/request_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: https://github.com/cheynewallace/noteshred-ruby
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.4.2
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Gem for interacting with the NoteShred API
|
157
|
+
test_files:
|
158
|
+
- spec/crypto_spec.rb
|
159
|
+
- spec/note_spec.rb
|
160
|
+
- spec/request_spec.rb
|
161
|
+
- spec/spec_helper.rb
|