-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2021 from cyberark/integrate-12.0
Integrate 12.0 Release Branch
- Loading branch information
Showing
12 changed files
with
161 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.11.1 | ||
1.11.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
app/domain/authentication/authn_k8s/web_socket_client.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
## This code is based on github.com/shokai/websocket-client-simple (MIT License) | ||
|
||
require "event_emitter" | ||
require 'websocket' | ||
|
||
# Utility class for processing WebSocket messages. | ||
module Authentication | ||
module AuthnK8s | ||
class WebSocketClient | ||
include EventEmitter | ||
attr_reader :url, :handshake | ||
|
||
def self.connect(url, options = {}) | ||
client = WebSocketClient.new | ||
yield client if block_given? | ||
client.connect url, options | ||
return client | ||
end | ||
|
||
def connect(url, options = {}) | ||
return if @socket | ||
@url = url | ||
uri = URI.parse url | ||
@socket = TCPSocket.new(uri.host, | ||
uri.port || (uri.scheme == 'wss' ? 443 : 80)) | ||
if ['https', 'wss'].include? uri.scheme | ||
ctx = OpenSSL::SSL::SSLContext.new | ||
ctx.ssl_version = options[:ssl_version] || 'SSLv23' | ||
ctx.verify_mode = options[:verify_mode] || OpenSSL::SSL::VERIFY_NONE #use VERIFY_PEER for verification | ||
cert_store = options[:cert_store] | ||
unless cert_store | ||
cert_store = OpenSSL::X509::Store.new | ||
cert_store.set_default_paths | ||
end | ||
ctx.cert_store = cert_store | ||
@socket = ::OpenSSL::SSL::SSLSocket.new(@socket, ctx) | ||
@socket.connect | ||
end | ||
@handshake = ::WebSocket::Handshake::Client.new :url => url, :headers => options[:headers] | ||
@handshaked = false | ||
@pipe_broken = false | ||
frame = ::WebSocket::Frame::Incoming::Client.new | ||
@closed = false | ||
once :__close do |err| | ||
close | ||
emit :close, err | ||
end | ||
|
||
@thread = Thread.new do | ||
while !@closed do | ||
begin | ||
unless recv_data = @socket.getc | ||
sleep 1 | ||
next | ||
end | ||
unless @handshaked | ||
@handshake << recv_data | ||
if @handshake.finished? | ||
@handshaked = true | ||
emit :open | ||
end | ||
else | ||
frame << recv_data | ||
while msg = frame.next | ||
emit :message, msg | ||
end | ||
end | ||
rescue => e | ||
emit :error, e | ||
end | ||
end | ||
end | ||
|
||
@socket.write @handshake.to_s | ||
end | ||
|
||
def send(data, opt = { :type => :text }) | ||
return if !@handshaked or @closed | ||
type = opt[:type] | ||
frame = ::WebSocket::Frame::Outgoing::Client.new(:data => data, :type => type, :version => @handshake.version) | ||
begin | ||
@socket.write frame.to_s | ||
rescue Errno::EPIPE => e | ||
@pipe_broken = true | ||
emit :__close, e | ||
end | ||
end | ||
|
||
def close | ||
return if @closed | ||
if !@pipe_broken | ||
send nil, :type => :close | ||
end | ||
@closed = true | ||
@socket.close if @socket | ||
@socket = nil | ||
emit :__close | ||
Thread.kill @thread if @thread | ||
end | ||
|
||
def open? | ||
@handshake.finished? and !@closed | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters