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

Initial implementation for the ExampleBroker bus and the dbus communication with the daemon #3

Merged
merged 5 commits into from
Aug 1, 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
8 changes: 8 additions & 0 deletions cmd/authd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"syscall"

"github.com/ubuntu/authd/cmd/authd/daemon"
"github.com/ubuntu/authd/internal/brokers/examplebroker"
"github.com/ubuntu/authd/internal/log"
)

Expand All @@ -18,6 +19,13 @@ import (

func main() {
//i18n.InitI18nDomain(common.TEXTDOMAIN)
go func() {
err := examplebroker.StartBus()
if err != nil {
log.Error(context.Background(), err)
os.Exit(1)
}
}()
a := daemon.New()
os.Exit(run(a))
}
Expand Down
2 changes: 0 additions & 2 deletions internal/brokers/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ func NewBroker(ctx context.Context, name, configFile string, bus *dbus.Conn) (b
if err != nil {
return Broker{}, err
}
} else if name != localBrokerName {
broker, fullName, brandIcon = newExampleBroker(name)
}

return Broker{
Expand Down
73 changes: 68 additions & 5 deletions internal/brokers/dbusbroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,84 @@ func newDbusBroker(ctx context.Context, bus *dbus.Conn, configFile string) (b db
}, fullNameVal.String(), brandIconVal.String(), nil
}

// To be implemented.
// NewSession calls the corresponding method on the broker bus and returns the session ID and encryption key.
func (b dbusBroker) NewSession(ctx context.Context, username, lang string) (sessionID, encryptionKey string, err error) {
return "", "", nil
dbusMethod := b.interfaceName + ".NewSession"

call := b.dbusObject.CallWithContext(ctx, dbusMethod, 0, username, lang)
if err = call.Err; err != nil {
return "", "", err
}
if err = call.Store(&sessionID, &encryptionKey); err != nil {
return "", "", err
}

return sessionID, encryptionKey, nil
}

// GetAuthenticationModes calls the corresponding method on the broker bus and returns the authentication modes supported by it.
func (b dbusBroker) GetAuthenticationModes(ctx context.Context, sessionID string, supportedUILayouts []map[string]string) (authenticationModes []map[string]string, err error) {
return nil, nil
dbusMethod := b.interfaceName + ".GetAuthenticationModes"

call := b.dbusObject.CallWithContext(ctx, dbusMethod, 0, sessionID, supportedUILayouts)
if err = call.Err; err != nil {
return nil, err
}
if err = call.Store(&authenticationModes); err != nil {
return nil, err
}

return authenticationModes, nil
}

// SelectAuthenticationMode calls the corresponding method on the broker bus and returns the UI layout for the selected mode.
func (b dbusBroker) SelectAuthenticationMode(ctx context.Context, sessionID, authenticationModeName string) (uiLayoutInfo map[string]string, err error) {
return nil, nil
dbusMethod := b.interfaceName + ".SelectAuthenticationMode"

call := b.dbusObject.CallWithContext(ctx, dbusMethod, 0, sessionID, authenticationModeName)
if err = call.Err; err != nil {
return nil, err
}
if err = call.Store(&uiLayoutInfo); err != nil {
return nil, err
}

return uiLayoutInfo, nil
}

// IsAuthorized calls the corresponding method on the broker bus and returns the user information and access.
func (b dbusBroker) IsAuthorized(ctx context.Context, sessionID, authenticationData string) (access, infoUser string, err error) {
return "", "", nil
dbusMethod := b.interfaceName + ".IsAuthorized"

call := b.dbusObject.CallWithContext(ctx, dbusMethod, 0, sessionID, authenticationData)
if err = call.Err; err != nil {
return "", "", err
}
if err = call.Store(&access, &infoUser); err != nil {
return "", "", err
}

return access, infoUser, nil
}

// EndSession calls the corresponding method on the broker bus.
func (b dbusBroker) EndSession(ctx context.Context, sessionID string) (err error) {
dbusMethod := b.interfaceName + ".EndSession"

call := b.dbusObject.CallWithContext(ctx, dbusMethod, 0, sessionID)
if err = call.Err; err != nil {
return err
}

return nil
}

// CancelIsAuthorized calls the corresponding method on the broker bus.
func (b dbusBroker) CancelIsAuthorized(ctx context.Context, sessionID string) {
dbusMethod := b.interfaceName + ".CancelIsAuthorized"

call := b.dbusObject.CallWithContext(ctx, dbusMethod, 0, sessionID)
if call.Err != nil {
log.Errorf(ctx, "could not cancel IsAuthorized call for session %q: %v", sessionID, call.Err)
}
}
8 changes: 8 additions & 0 deletions internal/brokers/examplebroker/ExampleBroker
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Add this to /etc/authd/broker.d to configure the ExampleBroker
name = ExampleBroker
brand_icon = /usr/share/backgrounds/warty-final-ubuntu.png

[dbus]
name = com.ubuntu.auth.ExampleBroker
didrocks marked this conversation as resolved.
Show resolved Hide resolved
object = /com/ubuntu/auth/ExampleBroker
interface = com.ubuntu.auth.ExampleBroker
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->

<!-- This file should be added to /usr/share/dbus-1/system.d/ to allow connection to the bus service. -->

<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">

<busconfig>
<!-- Only root can own the service -->
<policy user="root">
<allow own="com.ubuntu.auth.ExampleBroker"/>
</policy>

<!-- Allow anyone to invoke methods -->
<policy context="default">
<allow send_destination="com.ubuntu.auth.ExampleBroker"
send_interface="com.ubuntu.auth.ExampleBroker"/>
<allow send_destination="com.ubuntu.auth.ExampleBroker"
send_interface="org.freedesktop.DBus.Introspectable"/>
</policy>
</busconfig>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- This file should be added in /usr/share/dbus-1/interfaces/ to configure the ExampleBroker -->

<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">

<node>
<interface name="com.ubuntu.auth.ExampleBroker">
<method name="NewSession">
<arg type="s" direction="in" name="username"/>
<arg type="s" direction="in" name="lang"/>
<arg type="s" direction="out" name="sessionID"/>
<arg type="s" direction="out" name="encryptionKey"/>
</method>
<method name="GetAuthenticationModes">
<arg type="s" direction="in" name="sessionID"/>
<arg type="a{s}s" direction="in" name="supportedUILayouts"/>
<arg type="a{s}s" direction="out" name="authenticationModes"/>
</method>
<method name="SelectAuthenticationMode">
<arg type="s" direction="in" name="sessionID"/>
<arg type="s" direction="in" name="authenticationModeName"/>
<arg type="a{s}s" direction="out" name="uiLayoutInfo"/>
</method>
<method name="IsAuthorized">
<arg type="s" direction="in" name="sessionID"/>
<arg type="s" direction="in" name="authenticationData"/>
<arg type="s" direction="out" name="access"/>
<arg type="s" direction="out" name="infoUser"/>
</method>
<method name="EndSession">
<arg type="s" direction="in" name="sessionID"/>
</method>
<method name="CancelIsAuthorized">
<arg type="s" direction="in" name="sessionID"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="out" direction="out" type="s"/>
</method>
</interface>
</node>
13 changes: 13 additions & 0 deletions internal/brokers/examplebroker/configurebroker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# This script needs sudo privileges

set -eu

# Copy the configuration file to /etc/authd/broker.d/ExampleBroker
cp ./ExampleBroker /etc/authd/broker.d/ExampleBroker

# Copy the interface definition to /usr/share/dbus-1/interfaces
cp ./com.ubuntu.auth.ExampleBroker.xml /usr/share/dbus-1/interfaces/com.ubuntu.auth.ExampleBroker.xml

# Copy the dbus configuration file to /usr/share/dbus-1/system.d/
cp ./com.ubuntu.auth.ExampleBroker.conf /usr/share/dbus-1/system.d/com.ubuntu.auth.ExampleBroker.conf
Loading
Loading