mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-09-30 07:43:14 +00:00
Add headerless-body and DER-wrap strategies to ASC key normalizer
The .p8 file from Apple has no PEM headers, just the raw base64 body. Add strategies for: headerless body wrapped with PEM headers, base64-decoded DER re-wrapped as PEM, and double-decoded DER. Also show hex bytes in diagnostics for better binary data analysis. Secret has been re-set with properly PEM-wrapped + base64-encoded content matching the reusable workflow's expected format.
This commit is contained in:
parent
279cd6c94a
commit
a1f2e22562
1 changed files with 13 additions and 1 deletions
|
|
@ -27,6 +27,12 @@ def normalize_p8_key(raw)
|
|||
candidates << ["rewrapped PEM", rewrapped]
|
||||
end
|
||||
|
||||
unless with_newlines.include?("BEGIN")
|
||||
body = cleaned.strip.gsub(/\s+/, '')
|
||||
pem = "-----BEGIN PRIVATE KEY-----\n#{body.scan(/.{1,64}/).join("\n")}\n-----END PRIVATE KEY-----\n"
|
||||
candidates << ["headerless body → PEM", pem]
|
||||
end
|
||||
|
||||
begin
|
||||
decoded = Base64.decode64(cleaned.strip)
|
||||
if decoded.include?("BEGIN")
|
||||
|
|
@ -37,6 +43,8 @@ def normalize_p8_key(raw)
|
|||
candidates << ["base64→PEM rewrapped", rewrapped]
|
||||
elsif decoded.length.between?(32, 256)
|
||||
candidates << ["base64→DER", decoded]
|
||||
der_pem = "-----BEGIN PRIVATE KEY-----\n#{Base64.strict_encode64(decoded).scan(/.{1,64}/).join("\n")}\n-----END PRIVATE KEY-----\n"
|
||||
candidates << ["base64→DER→PEM", der_pem]
|
||||
end
|
||||
rescue StandardError
|
||||
# not valid base64
|
||||
|
|
@ -46,6 +54,9 @@ def normalize_p8_key(raw)
|
|||
double = Base64.decode64(Base64.decode64(cleaned.strip).strip)
|
||||
if double.include?("BEGIN")
|
||||
candidates << ["double-base64→PEM", double.gsub("\r", "")]
|
||||
elsif double.length.between?(32, 256)
|
||||
der_pem = "-----BEGIN PRIVATE KEY-----\n#{Base64.strict_encode64(double).scan(/.{1,64}/).join("\n")}\n-----END PRIVATE KEY-----\n"
|
||||
candidates << ["double-base64→DER→PEM", der_pem]
|
||||
end
|
||||
rescue StandardError
|
||||
# not double-encoded
|
||||
|
|
@ -72,7 +83,8 @@ def normalize_p8_key(raw)
|
|||
UI.error("Header (first 27 chars): #{raw[0..26]}")
|
||||
begin
|
||||
d = Base64.decode64(raw.strip)
|
||||
UI.error("After base64 decode — length: #{d.bytesize}, header: #{d[0..26]}")
|
||||
hex = d.bytes[0..15].map { |b| format('%02x', b) }.join(' ')
|
||||
UI.error("After base64 decode — length: #{d.bytesize}, first 16 bytes hex: #{hex}")
|
||||
rescue StandardError
|
||||
UI.error("base64 decode raised an exception")
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue