Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use base64 #51

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/websocket/handshake/handler/client04.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def handshake_keys
# Sec-WebSocket-Key value
# @return [String] key
def key
@key ||= Base64.encode64((1..16).map { rand(255).chr } * '').strip
@key ||= [(1..16).map { rand(255).chr } * ''].pack('m').strip
end

# Value of Sec-WebSocket-Accept that should be delivered back by server
# @return [Sering] accept
def accept
@accept ||= Base64.encode64(Digest::SHA1.digest(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')).strip
@accept ||= [Digest::SHA1.digest(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')].pack('m').strip
end

# Verify if received header Sec-WebSocket-Accept matches generated one.
Expand Down
2 changes: 1 addition & 1 deletion lib/websocket/handshake/handler/server04.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def handshake_keys
def signature
return unless key
string_to_sign = "#{key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
Base64.encode64(Digest::SHA1.digest(string_to_sign)).chomp
[Digest::SHA1.digest(string_to_sign)].pack('m').chomp
end

def verify_key
Expand Down
Loading