wowza-secure_token 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 804f53ee8a6cd95adeefe35257bd1d6a1373e517
4
+ data.tar.gz: 73c27aa164cc42269750442ecc77d579603ba717
5
+ SHA512:
6
+ metadata.gz: a2c182e127be7708a249313a8f4a0461a66231ec89ed3c149efbc0407447315fd18b1e109fbf00c0cd675fed2ca373c97984aefcee105234ee7a0b3471796ed2
7
+ data.tar.gz: 50839716fffb893020c0912791002e38f4be14953f99eef56a167c309477e77f173ebcb4d14df43a259cd0c5ad2f58a2acc5988e60d344ff5971820f1f743d54
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2018 Trustees of Columbia University
2
+ Additional copyright may be held by others, as reflected in CONTRIBUTORS or the commit history.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ #Wowza::SecureToken
2
+
3
+ Calculating a secure token prefix for Wowza streaming from parameters.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # docs TBD
4
+ module Wowza
5
+ require 'wowza/secure_token'
6
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+ require 'base64'
5
+
6
+ module Wowza
7
+ # docs TBD
8
+ module SecureToken
9
+ require 'wowza/secure_token/version'
10
+ # Wraps a params hash in the sorting and hashing logic necessary
11
+ # to generate a Wowza secure token
12
+ class Params
13
+ # Create the wrapper
14
+ # required symbol keys for:
15
+ # - stream
16
+ # - secret
17
+ # - client_ip
18
+ # - prefix
19
+ # - starttime (Integer)
20
+ # - endtime (Integer)
21
+ # - playstart (Integer)
22
+ # - playduration (Integer)
23
+ # @param opts [Hash] options used to generate a token url
24
+ def initialize(opts)
25
+ @prefix = opts.delete(:prefix)
26
+ @stream = opts.delete(:stream)
27
+ @client_ip = opts.delete(:client_ip)
28
+ @secret = opts.delete(:secret)
29
+ @params = opts
30
+ end
31
+
32
+ # @return the sorted token string for the wrapped params
33
+ def to_token
34
+ query_string = params_to_sorted_query_string(prefix_params(@params).merge(@client_ip => nil, @secret => nil))
35
+ "#{@stream}?#{query_string}"
36
+ end
37
+
38
+ # @param digest_alg the digest algorithm to be used to hash the params
39
+ # @return a URL-safe B64 encoded hash
40
+ def to_token_hash(digest_alg = Digest::SHA256)
41
+ Base64.urlsafe_encode64(digest_alg.digest(to_token))
42
+ end
43
+
44
+ def to_url_with_token_hash(host, port, stream_type)
45
+ query_string = params_to_sorted_query_string(prefix_params(@params))
46
+ case stream_type
47
+ when 'hls', 'hls-ssl'
48
+ (stream_type == 'hls' ? 'http' : 'https') + "://#{host}:#{port}/#{@stream}/playlist.m3u8?#{query_string}&#{@prefix}hash=#{self.to_token_hash}"
49
+ when 'mpeg-dash', 'mpeg-dash-ssl'
50
+ (stream_type == 'mpeg-dash' ? 'http' : 'https') + "://#{host}:#{port}/#{@stream}/manifest.mpd?#{query_string}&#{@prefix}hash=#{self.to_token_hash}"
51
+ when 'rtmp', 'rtmps'
52
+ "#{stream_type}://#{host}:#{port}/#{@stream}?#{query_string}&#{@prefix}hash=#{self.to_token_hash}"
53
+ else
54
+ raise "Unsupported stream_type: #{stream_type}"
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def params_to_sorted_query_string(prms)
61
+ prms.sort.map { |p| p[1].to_s == '' ? p[0] : "#{p[0]}=#{p[1]}" }.join('&')
62
+ end
63
+
64
+ def prefix_params(hsh)
65
+ hsh = hsh.clone
66
+ hsh.map { |p| ["#{@prefix}#{p[0]}", p[1]] }.to_h
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wowza
4
+ module SecureToken
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wowza-secure_token
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Armintor
8
+ - Eric O'Hanlon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '10.1'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '10.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.1'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubocop
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.58.2
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.58.2
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubocop-rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.20.1
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.20.1
70
+ description: Generate secure token prefix for wowza requests and allow configurable
71
+ defaults (e.g., secret).
72
+ email: armintor@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - LICENSE
78
+ - README.md
79
+ - lib/wowza.rb
80
+ - lib/wowza/secure_token.rb
81
+ - lib/wowza/secure_token/version.rb
82
+ homepage: https://github.com/cul/wowza-secure_token
83
+ licenses:
84
+ - APACHE2
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.6.14
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Generate secure token prefix for wowza requests.
106
+ test_files: []