ronin-web-session_cookie 0.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4a7441de5e3e4323abf9dec2d8297fa8c82d9a0bf21963422bd0f0da0dde439b
4
+ data.tar.gz: fb8e7eee30b8d70ee587a6a12116d5297eb12ed99e799ae9a9a69ebd62f0f160
5
+ SHA512:
6
+ metadata.gz: 44ebb5338c90ba587ad39f3c34c295f8697cebbbacc4fafc74725d23788ddb707c8d5e2e57f41f52987de67b823556c44b00ad99f320614177d9092cb1a40ec8
7
+ data.tar.gz: 66953042ebe54ea5c9ea736b5dca86c29ee7e22ecab52f09dc85ef0b2fb59c4b285e3f2024806a8970db3644b1346e7e34a8f3f4f8dc14807e11a0bbd14af9d7
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ -
3
+ ChangeLog.md
4
+ COPYING.txt
@@ -0,0 +1,43 @@
1
+ name: CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ tests:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby:
12
+ - '3.0'
13
+ - '3.1'
14
+ - '3.2'
15
+ - '3.3'
16
+ - jruby
17
+ - truffleruby
18
+ name: Ruby ${{ matrix.ruby }}
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Install dependencies
27
+ run: bundle install --jobs 4 --retry 3
28
+ - name: Run tests
29
+ run: bundle exec rake test
30
+
31
+ # rubocop linting
32
+ rubocop:
33
+ runs-on: ubuntu-latest
34
+ steps:
35
+ - uses: actions/checkout@v4
36
+ - name: Set up Ruby
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: 3.0
40
+ - name: Install dependencies
41
+ run: bundle install --jobs 4 --retry 3
42
+ - name: Run rubocop
43
+ run: bundle exec rubocop --parallel
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /coverage
2
+ /doc
3
+ /pkg
4
+ /man/*.[1-9]
5
+ /vendor/bundle
6
+ /Gemfile.lock
7
+ /.bundle
8
+ /.yardoc
9
+ .DS_Store
10
+ *.db
11
+ *.log
12
+ *.swp
13
+ *~
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ TargetRubyVersion: 3.1
5
+
6
+ inherit_gem:
7
+ rubocop-ronin: rubocop.yml
8
+
9
+ Naming/PredicateName:
10
+ Exclude:
11
+ - 'lib/ronin/web/session_cookie/cookie.rb'
12
+
13
+ Security/MarshalLoad:
14
+ Exclude:
15
+ - 'lib/ronin/web/session_cookie/rack.rb'
16
+
17
+ Style/NumericLiterals:
18
+ Exclude:
19
+ - 'spec/jwt_spec.rb'
20
+ - 'spec/django_spec.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.1
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title 'Ronin::Web::SessionCookie Documentation' --protected
data/COPYING.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/ChangeLog.md ADDED
@@ -0,0 +1,13 @@
1
+ ### 0.1.0 / 2024-XX-XX
2
+
3
+ * Initial release:
4
+ * Supports the following session cookie formats:
5
+ * [Rack][rack-session]
6
+ * [Django]
7
+ * [JSON Web Token (JWT)][JWT]
8
+ * Has 98% test coverage.
9
+ * Has 97% documentation coverage.
10
+
11
+ [rack-session]: https://github.com/rack/rack-session
12
+ [Django]: https://docs.djangoproject.com/en/4.1/topics/http/sessions/#using-cookie-based-sessions
13
+ [JWT]: https://jwt.io
data/Gemfile ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'jruby-openssl', '~> 0.7', platform: :jruby
8
+
9
+ # gem 'python-pickle', '~> 0.1', github: 'postmodern/python-pickle.rb',
10
+ # branch: 'main'
11
+
12
+ # Ronin dependencies
13
+ # gem 'ronin-support', '~> 1.1', github: "ronin-rb/ronin-support",
14
+ # branch: 'main'
15
+
16
+ group :development do
17
+ gem 'rake'
18
+ gem 'rubygems-tasks', '~> 0.2'
19
+
20
+ gem 'rspec', '~> 3.0'
21
+ gem 'simplecov', '~> 0.20'
22
+
23
+ gem 'kramdown', '~> 2.0'
24
+ gem 'kramdown-man', '~> 0.1'
25
+
26
+ gem 'redcarpet', platform: :mri
27
+ gem 'yard', '~> 0.9'
28
+ gem 'yard-spellcheck', require: false
29
+
30
+ gem 'dead_end', require: false
31
+ gem 'sord', require: false, platform: :mri
32
+ gem 'stackprof', require: false, platform: :mri
33
+ gem 'rubocop', require: false, platform: :mri
34
+ gem 'rubocop-ronin', require: false, platform: :mri
35
+ end
data/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # ronin-web-session_cookie
2
+
3
+ [![CI](https://github.com/ronin-rb/ronin-web-session_cookie/actions/workflows/ruby.yml/badge.svg)](https://github.com/ronin-rb/ronin-web-session_cookie/actions/workflows/ruby.yml)
4
+ [![Code Climate](https://codeclimate.com/github/ronin-rb/ronin-web-session_cookie.svg)](https://codeclimate.com/github/ronin-rb/ronin-web-session_cookie)
5
+
6
+ * [Website](https://ronin-rb.dev/)
7
+ * [Source](https://github.com/ronin-rb/ronin-web-session_cookie)
8
+ * [Issues](https://github.com/ronin-rb/ronin-web-session_cookie/issues)
9
+ * [Documentation](https://ronin-rb.dev/docs/ronin-web-session_cookie/frames)
10
+ * [Discord](https://discord.gg/6WAb3PsVX9) |
11
+ [Mastodon](https://infosec.exchange/@ronin_rb)
12
+
13
+ ## Description
14
+
15
+ ronin-web-session_cookie is a library for parsing and deserializing various
16
+ session cookie formats. It supports Rack, Django (JSON and Pickled), and JWT.
17
+
18
+ ## Features
19
+
20
+ * Supports the following session cookie formats:
21
+ * [Rack][rack-session]
22
+ * [Django]
23
+ * [JSON Web Token (JWT)][JWT]
24
+ * Has 98% test coverage.
25
+ * Has 97% documentation coverage.
26
+
27
+ ## Examples
28
+
29
+ Parse a [Rack][rack-session] session cookie:
30
+
31
+ ```ruby
32
+ require 'ronin/web/session_cookie'
33
+
34
+ Ronin::Web::SessionCookie.parse('rack.session=BAh7CEkiD3Nlc3Npb25faWQGOgZFVG86HVJhY2s6OlNlc3Npb246OlNlc3Npb25JZAY6D0BwdWJsaWNfaWRJIkUyYWJkZTdkM2I0YTMxNDE5OThiYmMyYTE0YjFmMTZlNTNlMWMzYWJlYzhiYzc4ZjVhMGFlMGUwODJmMjJlZGIxBjsARkkiCWNzcmYGOwBGSSIxNHY1TmRCMGRVaklXdjhzR3J1b2ZhM2xwNHQyVGp5ZHptckQycjJRWXpIZz0GOwBGSSINdHJhY2tpbmcGOwBGewZJIhRIVFRQX1VTRVJfQUdFTlQGOwBUSSItOTkxNzUyMWYzN2M4ODJkNDIyMzhmYmI5Yzg4MzFmMWVmNTAwNGQyYwY7AEY%3D--02184e43850f38a46c8f22ffb49f7f22be58e272')
35
+ # =>
36
+ # #<Ronin::Web::SessionCookie::Rack:0x00007ff67455ee30
37
+ # @params=
38
+ # {"session_id"=>"2abde7d3b4a3141998bbc2a14b1f16e53e1c3abec8bc78f5a0ae0e082f22edb1",
39
+ # "csrf"=>"4v5NdB0dUjIWv8sGruofa3lp4t2TjydzmrD2r2QYzHg=",
40
+ # "tracking"=>{"HTTP_USER_AGENT"=>"9917521f37c882d42238fbb9c8831f1ef5004d2c"}}>
41
+ ```
42
+
43
+ Parse a Django JSON session cookie:
44
+
45
+ ```ruby
46
+ Ronin::Web::SessionCookie.parse('sessionid=eyJmb28iOiJiYXIifQ:1pQcTx:UufiSnuPIjNs7zOAJS0UpqnyvRt7KET7BVes0I8LYbA')
47
+ # =>
48
+ # #<Ronin::Web::SessionCookie::Django:0x00007f29bb9c6b70
49
+ # @hmac=
50
+ # "R\xE7\xE2J{\x8F\"3l\xEF3\x80%-\x14\xA6\xA9\xF2\xBD\e{(D\xFB\x05W\xAC\xD0\x8F\va\xB0",
51
+ # @params={"foo"=>"bar"},
52
+ # @salt=1676070425>
53
+ ```
54
+
55
+ Parse a Django Pickled session cookie:
56
+
57
+ ```ruby
58
+ Ronin::Web::SessionCookie.parse('sessionid=gAWVEAAAAAAAAAB9lIwDZm9vlIwDYmFylHMu:1pQcay:RjaK8DKN4xXQ_APIXXWEyFS08Q-PGo6UlRBFpedFk9M')
59
+ # =>
60
+ # #<Ronin::Web::SessionCookie::Django:0x00007f29b7aa6dc8
61
+ # @hmac=
62
+ # "F6\x8A\xF02\x8D\xE3\x15\xD0\xFC\x03\xC8]u\x84\xC8T\xB4\xF1\x0F\x8F\x1A\x8E\x94\x95\x10E\xA5\xE7E\x93\xD3",
63
+ # @params={"foo"=>"bar"},
64
+ # @salt=1676070860>
65
+ ```
66
+
67
+ Parse a [JSON Web Token (JWT)][JWT] session cookie:
68
+
69
+ ```ruby
70
+ Ronin::Web::SessionCookie.parse('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c')
71
+ # =>
72
+ # #<Ronin::Web::SessionCookie::JWT:0x00007f4e8ef0ff08
73
+ # @header={"alg"=>"HS256", "typ"=>"JWT"},
74
+ # @hmac=
75
+ # "I\xF9J\xC7\x04IH\xC7\x8A(]\x90O\x87\xF0\xA4\xC7\x89\x7F~\x8F:N\xB2%V\x9DB\xCB0\xE5",
76
+ # @params={"sub"=>"1234567890", "name"=>"John Doe", "iat"=>1516239022}>
77
+ ```
78
+
79
+ ## Requirements
80
+
81
+ * [Ruby] >= 3.0.0
82
+ * [ronin-support] ~> 1.0
83
+ * [rack-session] ~> 1.0
84
+ * [python-pickle] ~> 0.1
85
+
86
+ ## Install
87
+
88
+ ```shell
89
+ $ gem install ronin-web-session_cookie
90
+ ```
91
+
92
+ ### Gemfile
93
+
94
+ ```ruby
95
+ gem 'ronin-web-session_cookie', '~> 0.1'
96
+ ```
97
+
98
+ ### gemspec
99
+
100
+ ```ruby
101
+ gem.add_dependency 'ronin-web-session_cookie', '~> 0.1'
102
+ ```
103
+
104
+ ## Development
105
+
106
+ 1. [Fork It!](https://github.com/ronin-rb/ronin-web-session_cookie/fork)
107
+ 2. Clone It!
108
+ 3. `cd ronin-web-session_cookie/`
109
+ 4. `bundle install`
110
+ 5. `git checkout -b my_feature`
111
+ 6. Code It!
112
+ 7. `bundle exec rake spec`
113
+ 8. `git push origin my_feature`
114
+
115
+ ## License
116
+
117
+ Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
118
+
119
+ ronin-web-session_cookie is free software: you can redistribute it and/or modify
120
+ it under the terms of the GNU Lesser General Public License as published
121
+ by the Free Software Foundation, either version 3 of the License, or
122
+ (at your option) any later version.
123
+
124
+ ronin-web-session_cookie is distributed in the hope that it will be useful,
125
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
126
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
127
+ GNU Lesser General Public License for more details.
128
+
129
+ You should have received a copy of the GNU Lesser General Public License
130
+ along with ronin-web-session_cookie. If not, see <https://www.gnu.org/licenses/>.
131
+
132
+ [Ruby]: https://www.ruby-lang.org
133
+ [ronin-support]: https://github.com/ronin-rb/ronin-support#readme
134
+ [rack-session]: https://github.com/rack/rack-session
135
+ [python-pickle]: https://github.com/postmodern/python-pickle#readme
136
+ [Django]: https://docs.djangoproject.com/en/4.1/topics/http/sessions/#using-cookie-based-sessions
137
+ [JWT]: https://jwt.io
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler'
7
+ rescue LoadError => e
8
+ warn e.message
9
+ warn "Run `gem install bundler` to install Bundler"
10
+ exit(-1)
11
+ end
12
+
13
+ begin
14
+ Bundler.setup(:development)
15
+ rescue Bundler::BundlerError => e
16
+ warn e.message
17
+ warn "Run `bundle install` to install missing gems"
18
+ exit e.status_code
19
+ end
20
+
21
+ require 'rake'
22
+
23
+ require 'rubygems/tasks'
24
+ Gem::Tasks.new(sign: {checksum: true, pgp: true})
25
+
26
+ require 'rspec/core/rake_task'
27
+ RSpec::Core::RakeTask.new
28
+ task :test => :spec
29
+ task :default => :spec
30
+
31
+ require 'yard'
32
+ YARD::Rake::YardocTask.new
33
+ task :docs => :yard
34
+
35
+ require 'kramdown/man/task'
36
+ Kramdown::Man::Task.new
data/gemspec.yml ADDED
@@ -0,0 +1,29 @@
1
+ name: ronin-web-session_cookie
2
+ summary: A library for parsing and deserializing various session cookies.
3
+ description: |
4
+ ronin-web-session_cookie is a library for parsing and deserializing various
5
+ session cookie formats. It supports Rack, Django, and JWT.
6
+
7
+ license: LGPL-3.0
8
+ authors: Postmodern
9
+ email: postmodern.mod3@gmail.com
10
+ homepage: https://ronin-rb.dev/
11
+ has_yard: true
12
+
13
+ metadata:
14
+ documentation_uri: https://ronin-rb.dev/docs/ronin-web-session_cookie
15
+ source_code_uri: https://github.com/ronin-rb/ronin-web-session_cookie
16
+ bug_tracker_uri: https://github.com/ronin-rb/ronin-web-session_cookie/issues
17
+ changelog_uri: https://github.com/ronin-rb/ronin-web-session_cookie/blob/main/ChangeLog.md
18
+ rubygems_mfa_required: 'true'
19
+
20
+ required_ruby_version: ">= 3.0.0"
21
+
22
+ dependencies:
23
+ # Ronin dependencies:
24
+ ronin-support: ~> 1.1.0.rc1
25
+ rack-session: ~> 1.0
26
+ python-pickle: ~> 0.1
27
+
28
+ development_dependencies:
29
+ bundler: ~> 2.0
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
4
+ #
5
+ # ronin-web-session_cookie is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published
7
+ # by the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-web-session_cookie is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with ronin-web-session_cookie. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Web
21
+ module SessionCookie
22
+ #
23
+ # Base class for all session cookie classes.
24
+ #
25
+ class Cookie
26
+
27
+ include Enumerable
28
+
29
+ # Regular expression for a URI decoded Base64 blob.
30
+ STRICT_BASE64_REGEXP = %r{(?:[A-Za-z0-9+/]{4})+(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?|[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=}
31
+
32
+ # Regular expression for a URI escaped Base64 blob.
33
+ URI_ENCODED_BASE64_REGEXP = %r{(?:[A-Za-z0-9+/]{4})+(?:[A-Za-z0-9+/]{2}%3D%3D|[A-Za-z0-9+/]{3}%3D)?|[A-Za-z0-9+/]{2}%3D|[A-Za-z0-9+/]{3}%3D}
34
+
35
+ # Regular expression for a URL-safe encoded Base64 blob.
36
+ URL_SAFE_BASE64_REGEXP = /[A-Za-z0-9_-]{2,}/
37
+
38
+ # The cookie params.
39
+ #
40
+ # @return [Hash]
41
+ attr_reader :params
42
+
43
+ #
44
+ # Initializes the session cookie.
45
+ #
46
+ # @param [Hash] params
47
+ # The parsed contents of the session cookie.
48
+ #
49
+ # @api private
50
+ #
51
+ def initialize(params)
52
+ @params = params
53
+ end
54
+
55
+ #
56
+ # Determines if the given string is a valid session cookie.
57
+ #
58
+ # @param [String] string
59
+ #
60
+ # @return [Boolean]
61
+ #
62
+ # @api public
63
+ #
64
+ # @abstract
65
+ #
66
+ def self.identify?(string)
67
+ raise(NotImplementedError,"#{self}.identify? was not implemented")
68
+ end
69
+
70
+ #
71
+ # Parses a session cookie value.
72
+ #
73
+ # @param [String] string
74
+ #
75
+ # @return [Cookie]
76
+ #
77
+ # @abstract
78
+ #
79
+ # @api public
80
+ #
81
+ def self.parse(string)
82
+ raise(NotImplementedError,"#{self}.parse was not implemented")
83
+ end
84
+
85
+ #
86
+ # Extracts and parses the session cookie from an HTTP response.
87
+ #
88
+ # @param [Net::HTTPResponse] response
89
+ # The HTTP response object.
90
+ #
91
+ # @return [Cookie, nil]
92
+ # The parsed session cookie or `nil` if no session cookie could be
93
+ # detected.
94
+ #
95
+ # @abstract
96
+ #
97
+ # @api public
98
+ #
99
+ def self.extract(response)
100
+ raise(NotImplementedError,"#{self}.extract was not implemented")
101
+ end
102
+
103
+ #
104
+ # Determines if the session cookie contains the given param.
105
+ #
106
+ # @param [String] params
107
+ #
108
+ # @return [Boolean]
109
+ #
110
+ # @api public
111
+ #
112
+ def has_key?(params)
113
+ @params.has_key?(params)
114
+ end
115
+
116
+ #
117
+ # Returns the value for the given session cookie param.
118
+ #
119
+ # @param [String] key
120
+ #
121
+ # @return [Object, nil]
122
+ #
123
+ # @api public
124
+ #
125
+ def [](key)
126
+ @params[key]
127
+ end
128
+
129
+ #
130
+ # Enumerates over the params within the session cookie.
131
+ #
132
+ # @yield [key, value]
133
+ #
134
+ # @yieldparam [String] key
135
+ #
136
+ # @yieldparam [Object] value
137
+ #
138
+ # @return [Enumerator]
139
+ #
140
+ # @api public
141
+ #
142
+ def each(&block)
143
+ @params.each(&block)
144
+ end
145
+
146
+ #
147
+ # Converts the session cookie into a Hash.
148
+ #
149
+ # @return [Hash]
150
+ #
151
+ # @api public
152
+ #
153
+ def to_h
154
+ @params
155
+ end
156
+
157
+ end
158
+ end
159
+ end
160
+ end