akkounts/app/controllers/web_key_directory_controller.rb
Râu Cao ebbd87368c
All checks were successful
continuous-integration/drone/push Build is passing
Handle l param missing for WKD request
2025-05-18 14:37:22 +04:00

37 lines
905 B
Ruby

class WebKeyDirectoryController < WellKnownController
before_action :allow_cross_origin_requests
# /.well-known/openpgpkey/hu/:hashed_username(.txt)?l=username
def show
username = params[:l] || ""
@user = User.find_by(cn: username.downcase)
if @user.nil? ||
@user.pgp_pubkey.blank? ||
!@user.pgp_pubkey_contains_user_address?
http_status :not_found and return
end
if params[:hashed_username] != @user.wkd_hash
http_status :unprocessable_entity and return
end
respond_to do |format|
format.text do
response.headers['Content-Type'] = 'text/plain'
render plain: @user.pgp_pubkey
end
format.any do
key = @user.gnupg_key.export
send_data key, filename: "#{@user.wkd_hash}.pem",
type: "application/octet-stream"
end
end
end
def policy
head :ok
end
end