edgecast_token 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92c2357949b33ad597c82a7e99b4570710e0f5aa
4
+ data.tar.gz: ed30e3cac30d3ccf1ac338933f92fd2b3d113733
5
+ SHA512:
6
+ metadata.gz: 168e67b41110bda9ccb8cb266d599b7250da3c08ecfd3f960f6e23830776beb2744e273f4e8d0299c1b2cac1e31b5269f979068747c8bcd049a7891dbceb90ec
7
+ data.tar.gz: f0a2b8de6204c4fb669c5c8d99ea6db89d9275dcfd8ecb11dc025d1a3b8fa8ada6655821ded3a64bc5ca9709dd4e0c562cdfc5792c77198078cca6b7021af216
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - rbx-18mode
7
+ - rbx-19mode
8
+ - 1.8.7
9
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ edgecast_token (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.1.0)
10
+ rake-compiler (0.9.1)
11
+ rake
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.3)
18
+ edgecast_token!
19
+ rake
20
+ rake-compiler
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Rick Harris
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,24 @@
1
+ # edgecast_token
2
+ ### EdgeCast token generator for Ruby [![Build Status](https://travis-ci.org/rickharris/edgecast_token.png?branch=master)](https://travis-ci.org/rickharris/edgecast_token)
3
+
4
+ This library generates tokens to be used for EdgeCast's token auth feature.
5
+
6
+ ### Usage
7
+
8
+ ```ruby
9
+ EdgecastToken.generate("my super secret key", "ec_expire=#{Time.now + 2.days}")
10
+ ```
11
+
12
+ ### Installation
13
+
14
+ In your Gemfile
15
+
16
+ ```ruby
17
+ gem 'edgecast_token'
18
+ ```
19
+
20
+ or on the command line
21
+
22
+ ```sh
23
+ gem install edgecast_token
24
+ ```
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ require 'rake/extensiontask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.test_files = FileList['test/*_test.rb']
7
+ end
8
+
9
+ Rake::ExtensionTask.new('edgecast_token') do |ext|
10
+ ext.lib_dir = File.join('lib', 'edgecast_token')
11
+ end
12
+ Rake::Task[:test].prerequisites << :compile
13
+
14
+ desc "Run tests"
15
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'edgecast_token/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "edgecast_token"
8
+ spec.version = EdgecastToken::VERSION
9
+ spec.authors = ["Rick Harris"]
10
+ spec.email = ["rick.c.harris@gmail.com"]
11
+ spec.description = %q{Generate EdgeCast access tokens in Ruby using EdgeCast's encryption algorithm in C.}
12
+ spec.summary = %q{Generate EdgeCast access tokens in Ruby}
13
+ spec.homepage = "https://github.com/rickharris/edgecast_token"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.extensions << 'ext/edgecast_token/extconf.rb'
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rake-compiler"
25
+ end
@@ -0,0 +1,91 @@
1
+ /*********** -*- mode: c; c-file-style: "linux"; -*- **********
2
+ *
3
+ * Copyright (c) 2006-2010 EdgeCast Networks, Inc.
4
+ * All Rights Reserved
5
+ *
6
+ * $Id$
7
+ * $HeadURL$
8
+ *
9
+ * Modified by Rick Harris for edgecast_token.
10
+ *
11
+ ****************************************************************/
12
+ #include <openssl/blowfish.h>
13
+ #include <string.h>
14
+ #include <ruby.h>
15
+
16
+ #define kMAX_TOKEN_LENGTH 512
17
+
18
+ #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
19
+ l|=((unsigned long)(*((c)++)))<<16L, \
20
+ l|=((unsigned long)(*((c)++)))<< 8L, \
21
+ l|=((unsigned long)(*((c)++))))
22
+
23
+ #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
24
+ *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
25
+ *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
26
+ *((c)++)=(unsigned char)(((l) )&0xff))
27
+
28
+ void cfb64_encrypt(const unsigned char* in, unsigned char* out, long length,
29
+ BF_KEY* schedule,
30
+ unsigned char* ivec,
31
+ int *num,
32
+ int encrypt)
33
+ {
34
+ register BF_LONG v0,v1,t;
35
+ register int n= *num;
36
+ register long l=length;
37
+ BF_LONG ti[2];
38
+ unsigned char *iv,c,cc;
39
+
40
+ iv=(unsigned char *)ivec;
41
+ while (l--)
42
+ {
43
+ if (n == 0)
44
+ {
45
+ n2l(iv,v0); ti[0]=v0;
46
+ n2l(iv,v1); ti[1]=v1;
47
+ BF_encrypt((BF_LONG*)ti,schedule);
48
+ iv=(unsigned char *)ivec;
49
+ t=ti[0]; l2n(t,iv);
50
+ t=ti[1]; l2n(t,iv);
51
+ iv=(unsigned char *)ivec;
52
+ }
53
+ c= *(in++)^iv[n];
54
+ *(out++)=c;
55
+ iv[n]=c;
56
+ n=(n+1)&0x07;
57
+ }
58
+ v0=v1=ti[0]=ti[1]=t=c=cc=0;
59
+ *num=n;
60
+ }
61
+
62
+ static VALUE encrypt(VALUE self, VALUE k, VALUE s)
63
+ {
64
+ char *key = StringValueCStr(k);
65
+ char *string = StringValueCStr(s);
66
+ char encrypted[kMAX_TOKEN_LENGTH*4];
67
+ BF_KEY bf_key;
68
+ BF_set_key(&bf_key, strlen(key), key);
69
+ unsigned char ivec[32];
70
+ memset(ivec, '\0', 32);
71
+ int num=0;
72
+
73
+ cfb64_encrypt(string, encrypted, strlen(string), &bf_key, ivec, &num, BF_ENCRYPT);
74
+
75
+ // convert to hex string
76
+ char result[strlen(string) * 2];
77
+ char hex[3];
78
+ strcpy(result, "");
79
+ unsigned int i = 0;
80
+ for(i; i<strlen(string); i++)
81
+ {
82
+ sprintf(hex, "%02x", encrypted[i]&0xff);
83
+ strcat(result, hex);
84
+ }
85
+ return rb_str_new2(result);
86
+ }
87
+
88
+ void Init_edgecast_token(void) {
89
+ VALUE klass = rb_define_module("EdgecastToken");
90
+ rb_define_singleton_method(klass, "encrypt", encrypt, 2);
91
+ }
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+ pkg_config 'openssl'
3
+ create_makefile('edgecast_token/edgecast_token')
@@ -0,0 +1,3 @@
1
+ module EdgecastToken
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "edgecast_token/version"
2
+ require "edgecast_token/edgecast_token"
3
+
4
+ module EdgecastToken
5
+ def self.generate(key, input)
6
+ input = "ec_secure=%03d&%s" % [input.length + 14, input]
7
+ encrypt(key, input)
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require 'edgecast_token'
3
+
4
+ class EdgecastTokenTest < Test::Unit::TestCase
5
+ def test_correct_token_no_args
6
+ key = "supercoolencryptionkey"
7
+ input = ""
8
+ assert_equal "562035ba986e43f8033b58eecad3",
9
+ EdgecastToken.generate(key, input)
10
+ end
11
+
12
+ def test_correct_token_with_args
13
+ key = "supercoolencryptionkey"
14
+ input = "ec_expire=123456789"
15
+ assert_equal "562035ba986e43f8033b58eccdd3b66415caed4be140ef54bc465d36e744064b5c",
16
+ EdgecastToken.generate(key, input)
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edgecast_token
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rick Harris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-13 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Generate EdgeCast access tokens in Ruby using EdgeCast's encryption algorithm
56
+ in C.
57
+ email:
58
+ - rick.c.harris@gmail.com
59
+ executables: []
60
+ extensions:
61
+ - ext/edgecast_token/extconf.rb
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - .travis.yml
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - edgecast_token.gemspec
72
+ - ext/edgecast_token/edgecast_token.c
73
+ - ext/edgecast_token/extconf.rb
74
+ - lib/edgecast_token.rb
75
+ - lib/edgecast_token/version.rb
76
+ - test/edgecast_token_test.rb
77
+ homepage: https://github.com/rickharris/edgecast_token
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Generate EdgeCast access tokens in Ruby
101
+ test_files:
102
+ - test/edgecast_token_test.rb
103
+ has_rdoc: