Skip to content

Commit

Permalink
F OpenNebula#2497: two factor authentication
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Lobo <jlobo@opennebula.systems>
  • Loading branch information
Jorge Lobo committed Jul 4, 2019
1 parent 28ff5c8 commit 0ae0122
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/sunstone/models/OpenNebula2FA/SunstoneOPTP.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require 'rotp'

# 2F Token
class MyTotp
class SunstoneOPTP

def self.build(secret, issuer)
totp = ROTP::TOTP.new(secret, :issuer => issuer)
Expand Down
2 changes: 1 addition & 1 deletion src/sunstone/models/OpenNebula2FA/SunstoneQRCode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require 'rqrcode'

# Generate Qr Code
class MyQrCode
class SunstoneQRCode

def self.build(code)
qr_code = RQRCode::QRCode.new(code)
Expand Down
4 changes: 2 additions & 2 deletions src/sunstone/models/OpenNebula2FA/Suntone2FAuth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
require 'SunstoneOPTP'

# 2F Auth
module TwoFactorAuth
module Suntone2FAuth

def self.authenticate(secret, token)
totp = MyTotp.build(secret, nil)
totp = SunstoneOPTP.build(secret, nil)
totp.verify(token)
end

Expand Down
2 changes: 1 addition & 1 deletion src/sunstone/models/OpenNebulaJSON/UserJSON.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def update(params=Hash.new)
end

def enable_two_factor_auth(params=Hash.new)
unless TwoFactorAuth.authenticate(params["secret"], params["token"])
unless Suntone2FAuth.authenticate(params["secret"], params["token"])
return OpenNebula::Error.new("Invalid token.")
end

Expand Down
6 changes: 3 additions & 3 deletions src/sunstone/sunstone-server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def build_session
if !two_factor_auth_token || two_factor_auth_token == ""
return [202, { code: "two_factor_auth" }.to_json]
else
unless TwoFactorAuth.authenticate(user[TWO_FACTOR_AUTH_SECRET_XPATH], two_factor_auth_token)
unless Suntone2FAuth.authenticate(user[TWO_FACTOR_AUTH_SECRET_XPATH], two_factor_auth_token)
logger.info { "Unauthorized two factor authentication login attempt" }
return [401, ""]
end
Expand Down Expand Up @@ -570,9 +570,9 @@ def destroy_session
get '/two_factor_auth_hotp_qr_code' do
content_type 'image/svg+xml'
issuer = $conf[:two_factor_auth_issuer].nil?? "sunstone-opennebula" : $conf[:two_factor_auth_issuer]
totp = MyTotp.build(params[:secret], issuer)
totp = SunstoneOPTP.build(params[:secret], issuer)
totp_uri = totp.provisioning_uri(session[:user])
qr_code = MyQrCode.build(totp_uri)
qr_code = SunstoneQRCode.build(totp_uri)
[200, qr_code.as_svg]
end

Expand Down

0 comments on commit 0ae0122

Please sign in to comment.