forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
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 ManageIQ#16490 from skateman/websocket-webmks
Allow proxying WebMKS consoles using the WebsocketWorker (cherry picked from commit 6421e3d) https://bugzilla.redhat.com/show_bug.cgi?id=1523404
- Loading branch information
1 parent
06fb156
commit 276946b
Showing
6 changed files
with
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class WebsocketRight | ||
def initialize(socket, model) | ||
@sock = socket | ||
@model = model | ||
end | ||
|
||
def fetch(*) | ||
raise NotImplementedError, 'This should be defined in a subclass' | ||
end | ||
|
||
def issue(*) | ||
raise NotImplementedError, 'This should be defined in a subclass' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class WebsocketSocket < WebsocketRight | ||
def fetch(length) | ||
yield(@sock.recv_nonblock(length)) | ||
end | ||
|
||
def issue(data) | ||
@sock.write(data) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class WebsocketSSLSocket < WebsocketRight | ||
def initialize(socket, model) | ||
super(socket, model) | ||
|
||
context = OpenSSL::SSL::SSLContext.new | ||
context.cert = OpenSSL::X509::Certificate.new(File.open('certs/server.cer')) | ||
context.key = OpenSSL::PKey::RSA.new(File.open('certs/server.cer.key')) | ||
context.ssl_version = :SSLv23 | ||
context.verify_depth = OpenSSL::SSL::VERIFY_NONE | ||
@ssl = OpenSSL::SSL::SSLSocket.new(@sock, context) | ||
@ssl.sync_close = true | ||
@ssl.connect | ||
end | ||
|
||
def fetch(length) | ||
yield(@ssl.sysread(length)) | ||
end | ||
|
||
def issue(data) | ||
@ssl.syswrite(data) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class WebsocketWebmks < WebsocketSSLSocket | ||
attr_accessor :url | ||
|
||
def initialize(socket, model) | ||
super(socket, model) | ||
@url = URI::Generic.build(:scheme => 'wss', | ||
:host => @model.host_name, | ||
:port => @model.port, | ||
:path => "/ticket/#{@model.secret}").to_s | ||
@driver = WebSocket::Driver.client(self, :protocols => ['binary']) | ||
@driver.on(:close) { socket.close unless socket.closed? } | ||
@driver.start | ||
end | ||
|
||
def fetch(length) | ||
# WebSocket::Driver requires an event handler that should be registered only once | ||
@driver.on(:message) { |msg| yield(msg.data) } if @driver.listeners(:message).length.zero? | ||
|
||
data = @ssl.sysread(length) | ||
@driver.parse(data) | ||
end | ||
|
||
def issue(data) | ||
@driver.binary(data) | ||
end | ||
|
||
def write(data) | ||
@ssl.syswrite(data) | ||
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