Class: UDAPSecurityTestKit::UDAPJWTBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/udap_security_test_kit/udap_jwt_builder.rb

Class Method Summary collapse

Class Method Details

.encode_jwt_no_x5c_header(payload, private_key, alg) ⇒ Object



15
16
17
# File 'lib/udap_security_test_kit/udap_jwt_builder.rb', line 15

def self.encode_jwt_no_x5c_header(payload, private_key, alg)
  JWT.encode payload, private_key, alg
end

.encode_jwt_with_x5c_header(payload, private_key_pem_string, alg, x5c_certs_pem_string) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/udap_security_test_kit/udap_jwt_builder.rb', line 19

def self.encode_jwt_with_x5c_header(payload, private_key_pem_string, alg, x5c_certs_pem_string)
  private_key = OpenSSL::PKey.read(private_key_pem_string)

  x5c_certs_encoded = x5c_certs_pem_string.map do |cert|
    cert_pem = OpenSSL::X509::Certificate.new(cert)
    Base64.strict_encode64(cert_pem.to_der)
  end

  JWT.encode payload, private_key, alg, { x5c: x5c_certs_encoded }
end

.generate_private_key(pkey_string) ⇒ Object



6
7
8
# File 'lib/udap_security_test_kit/udap_jwt_builder.rb', line 6

def self.generate_private_key(pkey_string)
  OpenSSL::PKey.read(pkey_string)
end

.split_user_input_cert_string(user_input_string) ⇒ Object



10
11
12
13
# File 'lib/udap_security_test_kit/udap_jwt_builder.rb', line 10

def self.split_user_input_cert_string(user_input_string)
  regex = /-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----/m
  user_input_string.scan(regex)
end