standard_id-void_which_binds 0.1.0
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 +7 -0
- data/CHANGELOG.md +79 -0
- data/LICENSE +22 -0
- data/README.md +128 -0
- data/Rakefile +12 -0
- data/app/models/standard_id/void_which_binds/login.rb +14 -0
- data/app/models/standard_id/void_which_binds/received_event.rb +26 -0
- data/app/models/standard_id/void_which_binds/subject.rb +48 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20261005000000_create_standard_id_void_which_binds_tables.rb +64 -0
- data/lib/generators/standard_id/void_which_binds/install/install_generator.rb +81 -0
- data/lib/generators/standard_id/void_which_binds/install/templates/initializer.rb.erb +28 -0
- data/lib/standard_id/void_which_binds/configuration.rb +275 -0
- data/lib/standard_id/void_which_binds/current.rb +18 -0
- data/lib/standard_id/void_which_binds/engine.rb +44 -0
- data/lib/standard_id/void_which_binds/errors.rb +48 -0
- data/lib/standard_id/void_which_binds/events_endpoint.rb +92 -0
- data/lib/standard_id/void_which_binds/id_token.rb +178 -0
- data/lib/standard_id/void_which_binds/jose.rb +258 -0
- data/lib/standard_id/void_which_binds/logins.rb +54 -0
- data/lib/standard_id/void_which_binds/providers/void_which_binds.rb +243 -0
- data/lib/standard_id/void_which_binds/receiver.rb +192 -0
- data/lib/standard_id/void_which_binds/security_event.rb +270 -0
- data/lib/standard_id/void_which_binds/staff_policy.rb +72 -0
- data/lib/standard_id/void_which_binds/testing.rb +65 -0
- data/lib/standard_id/void_which_binds/validators.rb +128 -0
- data/lib/standard_id/void_which_binds/version.rb +7 -0
- data/lib/standard_id/void_which_binds.rb +25 -0
- metadata +131 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "digest"
|
|
4
|
+
require "openssl"
|
|
5
|
+
|
|
6
|
+
module StandardId
|
|
7
|
+
module VoidWhichBinds
|
|
8
|
+
# The shapes ADR-0023 fixes for issuers, client ids and person ids, as
|
|
9
|
+
# void-which-binds-go's oidc package checks them.
|
|
10
|
+
module Validators
|
|
11
|
+
# "ed25519:<64 lowercase hex>", in its one canonical spelling.
|
|
12
|
+
ED25519_ID = /\Aed25519:[0-9a-f]{64}\z/
|
|
13
|
+
# "mp:<32 lowercase hex>" (a managed person, roster.NewManagedID).
|
|
14
|
+
MANAGED_ID = /\Amp:[0-9a-f]{32}\z/
|
|
15
|
+
# [a-z0-9][a-z0-9-]{0,63}: a client_id fits a scope path.
|
|
16
|
+
CLIENT_ID = /\A[a-z0-9][a-z0-9-]{0,63}\z/
|
|
17
|
+
# An https origin: lowercase host (a DNS name or an IPv6 literal) and an
|
|
18
|
+
# optional port; no userinfo, path, trailing slash, query or fragment.
|
|
19
|
+
ISSUER = %r{\Ahttps://(?:[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?|\[[0-9a-f:.]+\])(?::[0-9]{1,5})?\z}
|
|
20
|
+
|
|
21
|
+
module_function
|
|
22
|
+
|
|
23
|
+
def ed25519_id?(value)
|
|
24
|
+
value.is_a?(String) && ED25519_ID.match?(value)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# A person id as `sub` carries it: sovereign ("ed25519:") or managed
|
|
28
|
+
# ("mp:"). Never a device, passkey or enrol key.
|
|
29
|
+
def person_id?(value)
|
|
30
|
+
value.is_a?(String) && (MANAGED_ID.match?(value) || ED25519_ID.match?(value))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# nil when `value` is an https origin with no path, no trailing slash, no
|
|
34
|
+
# query, fragment or userinfo, in canonical lowercase form; otherwise why
|
|
35
|
+
# not. (Stricter than Go's url.Parse on exotic hosts, never looser.)
|
|
36
|
+
def issuer_error(value)
|
|
37
|
+
return "is not a string" unless value.is_a?(String)
|
|
38
|
+
return nil if ISSUER.match?(value)
|
|
39
|
+
|
|
40
|
+
"#{value.inspect} is not a canonical https origin"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def client_id_error(value)
|
|
44
|
+
return nil if value.is_a?(String) && CLIENT_ID.match?(value)
|
|
45
|
+
|
|
46
|
+
"client_id #{value.inspect} is not [a-z0-9][a-z0-9-]{0,63}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# PKCE S256 (RFC 7636), the one code_challenge_method ADR-0023 allows.
|
|
51
|
+
module Pkce
|
|
52
|
+
METHOD = "S256"
|
|
53
|
+
VERIFIER = /\A[A-Za-z0-9\-._~]{43,128}\z/
|
|
54
|
+
|
|
55
|
+
module_function
|
|
56
|
+
|
|
57
|
+
# base64url(SHA-256(verifier)).
|
|
58
|
+
def s256(verifier)
|
|
59
|
+
Jose.encode(Digest::SHA256.digest(verifier))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# The authorize endpoint's check: method S256 and a challenge that is 43
|
|
63
|
+
# characters of base64url (a SHA-256). Raises Refusal "pkce".
|
|
64
|
+
def check_challenge!(method, challenge)
|
|
65
|
+
raise Refusal.new("pkce", "code_challenge_method #{method.inspect}, only S256") unless method == METHOD
|
|
66
|
+
raise Refusal.new("pkce", "code_challenge is not a base64url SHA-256") unless Jose.decode(challenge.to_s)&.bytesize == 32
|
|
67
|
+
|
|
68
|
+
true
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# The token endpoint's check: a verifier of 43-128 unreserved characters
|
|
72
|
+
# whose S256 equals the challenge (constant time). Raises Refusal "pkce".
|
|
73
|
+
def verify_verifier!(challenge, verifier)
|
|
74
|
+
raise Refusal.new("pkce", "code_verifier is not 43 to 128 unreserved characters") unless verifier.is_a?(String) && VERIFIER.match?(verifier)
|
|
75
|
+
|
|
76
|
+
computed = s256(verifier)
|
|
77
|
+
unless challenge.is_a?(String) && challenge.bytesize == computed.bytesize &&
|
|
78
|
+
OpenSSL.fixed_length_secure_compare(computed, challenge)
|
|
79
|
+
raise Refusal.new("pkce", "code_verifier does not match code_challenge")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
true
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# The discovery document (/.well-known/openid-configuration) ADR-0023
|
|
87
|
+
# fixes. The RP's own configuration stays authoritative: a discovered
|
|
88
|
+
# issuer that differs from it is a hard error.
|
|
89
|
+
module Discovery
|
|
90
|
+
JWKS_PATH = "/.well-known/jwks.json"
|
|
91
|
+
PATH = "/.well-known/openid-configuration"
|
|
92
|
+
CLAIMS_SUPPORTED = %w[iss sub aud iat exp auth_time nonce org role amr email email_verified].freeze
|
|
93
|
+
|
|
94
|
+
module_function
|
|
95
|
+
|
|
96
|
+
# Renders the exact document for `issuer` (the golden vector's bytes).
|
|
97
|
+
def render(issuer, authorization_endpoint, token_endpoint)
|
|
98
|
+
error = Validators.issuer_error(issuer)
|
|
99
|
+
raise ConfigurationError, "issuer #{error}" if error
|
|
100
|
+
|
|
101
|
+
[authorization_endpoint, token_endpoint].each do |endpoint|
|
|
102
|
+
raise ConfigurationError, "endpoint #{endpoint.inspect} is not on #{issuer}" unless endpoint_on_issuer?(endpoint, issuer)
|
|
103
|
+
end
|
|
104
|
+
Jose.marshal({
|
|
105
|
+
"issuer" => issuer,
|
|
106
|
+
"authorization_endpoint" => authorization_endpoint,
|
|
107
|
+
"token_endpoint" => token_endpoint,
|
|
108
|
+
"jwks_uri" => issuer + JWKS_PATH,
|
|
109
|
+
"response_types_supported" => ["code"],
|
|
110
|
+
"response_modes_supported" => ["query"],
|
|
111
|
+
"grant_types_supported" => ["authorization_code"],
|
|
112
|
+
"subject_types_supported" => ["public"],
|
|
113
|
+
"id_token_signing_alg_values_supported" => ["EdDSA"],
|
|
114
|
+
"token_endpoint_auth_methods_supported" => ["client_secret_basic"],
|
|
115
|
+
"code_challenge_methods_supported" => ["S256"],
|
|
116
|
+
"scopes_supported" => %w[openid email],
|
|
117
|
+
"claims_supported" => CLAIMS_SUPPORTED,
|
|
118
|
+
"authorization_response_iss_parameter_supported" => true
|
|
119
|
+
})
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# An https URL on the issuer's own origin, with no query or fragment.
|
|
123
|
+
def endpoint_on_issuer?(endpoint, issuer)
|
|
124
|
+
endpoint.is_a?(String) && endpoint.start_with?("#{issuer}/") && !endpoint.match?(/[?#\s]/)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "active_support/core_ext/object/blank"
|
|
5
|
+
require "active_support/core_ext/hash/indifferent_access"
|
|
6
|
+
require "standard_id"
|
|
7
|
+
require "standard_id/void_which_binds/version"
|
|
8
|
+
require "standard_id/void_which_binds/errors"
|
|
9
|
+
require "standard_id/void_which_binds/jose"
|
|
10
|
+
require "standard_id/void_which_binds/validators"
|
|
11
|
+
require "standard_id/void_which_binds/id_token"
|
|
12
|
+
require "standard_id/void_which_binds/security_event"
|
|
13
|
+
require "standard_id/void_which_binds/configuration"
|
|
14
|
+
require "standard_id/void_which_binds/current"
|
|
15
|
+
require "standard_id/void_which_binds/providers/void_which_binds"
|
|
16
|
+
require "standard_id/void_which_binds/logins"
|
|
17
|
+
require "standard_id/void_which_binds/receiver"
|
|
18
|
+
require "standard_id/void_which_binds/staff_policy"
|
|
19
|
+
require "standard_id/void_which_binds/events_endpoint"
|
|
20
|
+
require "standard_id/void_which_binds/engine" if defined?(::Rails::Engine)
|
|
21
|
+
|
|
22
|
+
# Registers the provider from a Railtie's after_initialize (a no-op outside
|
|
23
|
+
# Rails). Its config fields are declared earlier, before config/initializers,
|
|
24
|
+
# by standard_id's own engine initializer.
|
|
25
|
+
StandardId::Providers.plugin_railtie(:void_which_binds, "StandardId::Providers::VoidWhichBinds")
|
metadata
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: standard_id-void_which_binds
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rarebit One
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: activesupport
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '8.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '8.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rails
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '8.1'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '8.1'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: json
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '2.13'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '2.13'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: standard_id
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0.46'
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0.46'
|
|
68
|
+
description: 'StandardId provider plugin for an organisation''s Void-Which-Binds broker
|
|
69
|
+
(moneta), per ADR-0023: OIDC authorization code + PKCE with Ed25519 ID tokens verified
|
|
70
|
+
against pinned keys, a staff login-method policy, and an RFC 8935 Security Event
|
|
71
|
+
Token receiver that revokes sessions by watermark.'
|
|
72
|
+
email:
|
|
73
|
+
- code@jaryl.dev
|
|
74
|
+
executables: []
|
|
75
|
+
extensions: []
|
|
76
|
+
extra_rdoc_files: []
|
|
77
|
+
files:
|
|
78
|
+
- CHANGELOG.md
|
|
79
|
+
- LICENSE
|
|
80
|
+
- README.md
|
|
81
|
+
- Rakefile
|
|
82
|
+
- app/models/standard_id/void_which_binds/login.rb
|
|
83
|
+
- app/models/standard_id/void_which_binds/received_event.rb
|
|
84
|
+
- app/models/standard_id/void_which_binds/subject.rb
|
|
85
|
+
- config/routes.rb
|
|
86
|
+
- db/migrate/20261005000000_create_standard_id_void_which_binds_tables.rb
|
|
87
|
+
- lib/generators/standard_id/void_which_binds/install/install_generator.rb
|
|
88
|
+
- lib/generators/standard_id/void_which_binds/install/templates/initializer.rb.erb
|
|
89
|
+
- lib/standard_id/void_which_binds.rb
|
|
90
|
+
- lib/standard_id/void_which_binds/configuration.rb
|
|
91
|
+
- lib/standard_id/void_which_binds/current.rb
|
|
92
|
+
- lib/standard_id/void_which_binds/engine.rb
|
|
93
|
+
- lib/standard_id/void_which_binds/errors.rb
|
|
94
|
+
- lib/standard_id/void_which_binds/events_endpoint.rb
|
|
95
|
+
- lib/standard_id/void_which_binds/id_token.rb
|
|
96
|
+
- lib/standard_id/void_which_binds/jose.rb
|
|
97
|
+
- lib/standard_id/void_which_binds/logins.rb
|
|
98
|
+
- lib/standard_id/void_which_binds/providers/void_which_binds.rb
|
|
99
|
+
- lib/standard_id/void_which_binds/receiver.rb
|
|
100
|
+
- lib/standard_id/void_which_binds/security_event.rb
|
|
101
|
+
- lib/standard_id/void_which_binds/staff_policy.rb
|
|
102
|
+
- lib/standard_id/void_which_binds/testing.rb
|
|
103
|
+
- lib/standard_id/void_which_binds/validators.rb
|
|
104
|
+
- lib/standard_id/void_which_binds/version.rb
|
|
105
|
+
homepage: https://github.com/rarebit-one/standard_id-void_which_binds
|
|
106
|
+
licenses:
|
|
107
|
+
- MIT
|
|
108
|
+
metadata:
|
|
109
|
+
homepage_uri: https://github.com/rarebit-one/standard_id-void_which_binds
|
|
110
|
+
source_code_uri: https://github.com/rarebit-one/standard_id-void_which_binds
|
|
111
|
+
changelog_uri: https://github.com/rarebit-one/standard_id-void_which_binds/blob/main/CHANGELOG.md
|
|
112
|
+
bug_tracker_uri: https://github.com/rarebit-one/standard_id-void_which_binds/issues
|
|
113
|
+
rdoc_options: []
|
|
114
|
+
require_paths:
|
|
115
|
+
- lib
|
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
|
+
requirements:
|
|
118
|
+
- - ">="
|
|
119
|
+
- !ruby/object:Gem::Version
|
|
120
|
+
version: '4.0'
|
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
126
|
+
requirements: []
|
|
127
|
+
rubygems_version: 4.0.20
|
|
128
|
+
specification_version: 4
|
|
129
|
+
summary: Void-Which-Binds (moneta) sign-in and SET deprovisioning for the StandardId
|
|
130
|
+
engine.
|
|
131
|
+
test_files: []
|