assu

Quickly reminder

As part of my Google Summer of Code (GSoC) project, I embarked on the journey of implementing XEP-0389 in ejabberd. This blog post details the process of setting up ejabberd, the challenges I encountered, and how I overcame them. I aim to provide a comprehensive guide for developers, especially those new to ejabberd and XMPP.

Setting Up ejabberd

1. Installation:

  • First, I installed ejabberd from the official website. For developers it is strongly recommended to download the source code and follow the instructions : https://docs.ejabberd.im/admin/install/source/ For this project, the configuration file is located at /usr/local/etc/ejabberd/ejabberd.yml.

2. Configuration: (Optional)

  • I configured ejabberd to use SQL for user management instead of the default Mnesia database: yaml auth_method: sql sql_type: pgsql sql_server: "localhost" sql_database: "ejabberd" sql_username: "ejabberd" sql_password: "password"

3. Port Configuration:

  • I made sure ejabberd listens on the correct ports by updating ejabberd.yml: `yaml listen:
    • port: 5222 ip: “::” module: ejabberdc2s starttls: false starttlsrequired: false `

Overcoming Challenges

1. Module Loading Issues:

  • Initially, I encountered issues with modules not loading. The command ejabberdctl modules_installed returned empty. After verifying that the module files were in place and correctly referenced in the configuration, I realized that I was wrong. I reached out to ejabberd developpers (badlop and prefiks helped oud on this) and got some usefull feedbacks from them. ` if you want to check if an ejabberd module is loaded (this includes internal, external/contrib...)

$ ejabberdctl debug

genmod:loadedmodules(<<“localhost”>>). [modadhoc,modping,modmam,modannounce,mod_offline, ...

genmod:isloaded(<<“localhost”>>, mod_ping). true you can also check any erlang beam file, not only ejabberd modules:

code:isloaded(modping). {file,“/home/badlop/git/ejabberd/build/dev/lib/ejabberd/ebin/modping.beam”}

code:isloaded(ejabberdsm). {file,“/home/badlop/git/ejabberd/build/dev/lib/ejabberd/ebin/ejabberdsm.beam”}

code:is_loaded(mnesia). {file,“/home/badlop/.asdf/installs/erlang/27.0/lib/mnesia-4.23.2/ebin/mnesia.beam”}`

Also I ensured the ejabberd service user had the necessary permissions: sh sudo chown -R assu_2000:ejabberd /usr/local/var/lib/ejabberd sudo chmod -R 750 /usr/local/var/lib/ejabberd

2. Database Configuration:

  • I needed to switch from the default Mnesia database to SQL for user management.

  • Solution:

    • Install PostgreSQL and configure the database.
    • Update ejabberd.yml with the appropriate database settings as shown above.

3. TLS and Connection Issues:

  • During testing with xmppconsole, I faced TLS connection issues and errors indicating that the server was refusing to authenticate over an unencrypted connection. I didn't want to encrypt the connection as I was working and testing locally.

  • Solution: I set starttls_required: false in the ejabberd.yml configuration: `yaml listen:

    • port: 5222 ip: “::” module: ejabberdc2s starttls: false starttlsrequired: false `
  • Also I ensured that the main.go file (more on this later) was set up to allow un-encrypted connection. ` package main

import ( “fmt” “log” “os”

“github.com/xmppo/go-xmpp” )

func main() { jid := os.Getenv(“JID”) password := os.Getenv(“PASSWORD”) host := os.Getenv(“HOST”)

if jid == “” || password == “” || host == “” { log.Fatal(“Usage: JID, PASSWORD and HOST must be set as environment variables”) }

options := xmpp.Options{ Host: host, User: jid, Password: password, NoTLS: true, StartTLS: false, Debug: true, InsecureAllowUnencryptedAuth: true, Session: true, Status: “available”, StatusMessage: “Welcome on our new codebot overlords.”, Resource: “xmppconsole”, }

talk, err := options.NewClient() if err != nil { log.Fatalf(“Failed to create XMPP client: %v”, err) }

fmt.Println(“Connected to XMPP server.”) for { chat, err := talk.Recv() if err != nil { log.Fatal(err) } switch v := chat.(type) { case xmpp.Chat: fmt.Printf(“Received message from %s: %s\n”, v.Remote, v.Text) case xmpp.Presence: fmt.Printf(“Received presence from %s\n”, v.From) } } }

`

4. Hostname and Hosts File Configuration:

  • I faced issues with hostname resolution and had to ensure that my /etc/hosts file was correctly configured: plaintext 127.0.0.1 localhost mbula

Using ejabberdctl

Instead of using systemctl, I decided to use ejabberdctl to manage the ejabberd server. Here are some useful commands:

  • Start ejabberd: sh ejabberdctl start

  • Stop ejabberd: sh ejabberdctl stop

  • Check registered users: sh ejabberdctl registered_users localhost

  • Register new user : sh ejabberdctl register newuser localhost newpassword

Setting Up xmppconsole

xmppconsole has the unique purpose of testing. To execute it , you need it installed alongside Python3 or Go. I chose to go with Go :) By the way, xmppconsole has only 1 required dependency: libstrophe version 0.10.0 or higher This is where the main.go file plays a key role .

1. Installation and Configuration:

  • Clone the xmppconsole repository: sh git clone https://github.com/xmppo/xmppconsole cd xmppconsole go mod init xmppconsole go mod tidy go build

2. Configuring main.go:

  • Ensure the main.go file is set up to use environment variables for JID, password, and host: `go package main

    import ( “fmt” “os” “github.com/mattn/go-xmpp” )

    func main() { options := xmpp.Options{ Host: os.Getenv(“HOST”), User: os.Getenv(“JID”), Password: os.Getenv(“PASSWORD”), NoTLS: true, Debug: true, }

    client, err := options.NewClient() if err != nil { fmt.Printf(“Failed to create XMPP client: %v\n”, err) return }

    fmt.Println(“Connected to XMPP server.”) } `

  • Set the environment variables before running xmppconsole: sh export JID=assu@localhost export PASSWORD=yourpassword export HOST=localhost

3. Running xmppconsole:

  • I executed the following command to connect to ejabberd: sh ./xmppconsole -jid=assu@localhost -password=yourpassword -host=localhost -port=5222 Expected output : ` ./xmppconsole -jid=assu@localhost -password=yourpassword -host=localhost -port=5222 <?xml version='1.0'?> <?xml version='1.0'?> stream:featuresDIGEST-MD5PLAINSCRAM-SHA-1X-OAUTH2/stream:features biwsbj1hc3N1LHI9MDVmMDA0OGFiMWI4NThhMA== cj0wNWYwMDQ4YWIxYjg1OGEwQXpsUnd3b1p4Uk05ZzZTendCOEsyQT09LHM9bFBQdjJJc0hHemdaK1d5eTFsQlcvdz09LGk9NDA5Ng== Yz1iaXdzLHI9MDVmMDA0OGFiMWI4NThhMEF6bFJ3d29aeFJNOWc2U3p3QjhLMkE9PSxwPVFleTE1SWE2T1hydThRaE5yWElJZ1pycHFxTT0= dj1TYzloRFU3a2w0MEp5WXA5UUNQRk15M1Q2Nzg9 <?xml version='1.0'?> <?xml version='1.0'?> stream:features/stream:features xmppconsole assu@localhost/xmppconsole availableWelcome on our new codebot overlords. Connected to XMPP server. availableI for one welcome our new codebot overlords.Bad value of cdata in tag <show/> qualified by namespace 'jabber:client' Received presence from

`

Using xmppconsole

Once connected, I could send messages and manage presence using xmppconsole. Here are a few examples:

*Send a Message: sh message recipient@localhost "Hello, this is a test message"

*Set Presence: sh presence

Conclusion

Setting up ejabberd for XEP-0389 implementation involved configuring the server, addressing module loading issues, managing database settings, and overcoming connection problems with xmppconsole. This detailed journey highlights the common challenges and solutions, providing a guide for developers embarking on similar projects.

For more detailed information and troubleshooting, refer to the ejabberd and XMPP documentation and the ejabberd xmpp community group as well. Happy coding!


P.S : This blog post provides a comprehensive overview of my experience setting up ejabberd and troubleshooting various issues. By following this guide, other developers should be able to set up their environments more smoothly and focus on implementing new features other to XEP-0389.

I'd love to hear from you! If you're struggling with XMPP implementation or have any questions, feel free to reach out. I'm always happy to help a fellow coder out.

Github Profile : Link

Thanks for reading !

GSoC and Open Source: My First Steps into XMPP

Image

Introduction

Hello readers!

My name is MBULA Assurance, a GSoC 2024 contributor, and I am excited to share my experience with you today. Many of us say that GSoC is a life-changing experience, and that’s simply true in every sense of the word. Over the past few weeks, my values, skills, and almost everything about me have evolved tremendously. It is a unique journey, and I want to share a bit of the wonder that GSoC contributors experience.

It all started some months ago on March 5th when I embarked on this journey by expressing my interest to my mentor. All I knew about the program was that I was here to study organization rules, contribute to projects, and earn my certificate and stipend. I was on cloud nine, and I'm pretty sure every contributor felt the same. Like many computer science students, I was confident that with my good grades on the national exam, GSoC would be an easy journey without challenges. After all, it’s just some lines of code—it couldn't be as complicated as the physics problems I tackled in high school.

I was confident in my programming abilities, but when we started writing a simple technical document, I realized how inexperienced I was. I had never written a technical document before, even though I had worked on several production projects. So, I relied on A.I. to help, and I was caught a couple of times by my mentors. During those moments, it was easy to lose confidence, but these experiences and challenges opened my eyes.

From day one, everyone I met was constantly saying, “I am here for you, how can I help ? ” ,“We've done development and mentoring before ChatGPT too. Things have gone pretty fine with all kind of non-English speakers” ,“How can I help ? ” ,“Talk to me” , “Communicate” . With such amazing mentors, community, and support, I wonder how could you not succeed?

I was very overwhelmed when I first started the program—new protocols, a new world, new terminologies. I was mesmerized by the sheer number of things I did not know. But I am in an environment where people are telling me “ it’s going to be fine, we have all been there”.

This is what the GSoC and my organization's (XMPP) environment is like. An environment where I feel growing every single day.

Someone can say, we are bound to succeed .

What is GSoC ?

Image

The Google Summer of Code (GSoC) is an annual program that encourages participation in open-source software development worldwide. Launched by Google in 2005, GSoC aims to provide real-world software development experience by contributing to open-source projects over the summer. This year, GSoC is celebrating 20 years of existence and has expanded its scope to include not only students but everyone interested in contributing to open-source projects. Participants work under the guidance of experienced mentors from various open-source organizations, helping them improve their coding skills and make meaningful contributions to projects that benefit the global community.

GSoC presents numerous benefits to all graduates, adding valuable experience and skills to their CVs. It provides a unique opportunity to work on real-world projects, network with professionals in the field, and gain exposure to the open-source community, thereby enhancing their career prospects globally.

What is XMPP ?

Image

The Extensible Messaging and Presence Protocol (XMPP) is an open-standard communication protocol primarily used for instant messaging, presence information, and contact list maintenance. XMPP is designed to enable real-time communication and is widely used in applications such as messaging apps, online gaming, voice-over-IP (VoIP) services, and Internet of Things (IoT) devices. Its significance lies in its decentralized nature, allowing for secure and extensible communication across diverse platforms, making it a powerful tool for creating robust, real-time communication systems.

XMPP is trusted and utilized by many big companies, including Facebook, WhatsApp, and Google Talk, for their messaging services. This widespread adoption highlights its reliability and efficiency in handling real-time communication needs. The protocol’s flexibility and extensibility make it ideal for various innovative applications, ensuring secure and seamless interactions across different devices and networks.

Discovering the potential of XMPP can open doors to understanding how major tech companies handle communication and build robust infrastructures. Stay tuned to learn more about this powerful protocol and how it can transform communication systems!

Project Overview

Prav Server is a component built on top of the XMPP server Ejabberd. To create a user account, Prav.app makes an HTTP call to the Prav Server API. This API handles user authentication through the generation and verification of OTPs. After successfully verifying the user's OTP, Prav Server initiates a persistent TCP connection with the Ejabberd server, running on the same machine. This request is no longer HTTP but XMPP, aimed at creating the user account within Ejabberd.

For reasons of protocol standardization on the XMPP network, XEP 0389 was developed to address this issue, allowing any XMPP client implementing this protocol to benefit from these functionalities on an XMPP server. Therefore, the primary communication flow of Prav Server, based on HTTP, will need to be carried out using XMPP elements.

Ideally, these implementations should be done directly within the main Ejabberd server, allowing the entire community to benefit. However, the goal of this work is to study the feasibility and implementation of this protocol directly in Prav Server, i.e., examining the possibility of routing this from Ejabberd to the Java code of Prav Server. If this is not possible, Ejabberd itself will have to handle it.

The implementation will be carried out in eJabberd and Erlang as the module interface cannot forward XMPP stanzas to the Prav server component in Java.

Why this project ?

Choosing the right project for GSoC was not an easy task. The GSoC site featured many organizations, but finding one that genuinely piqued my interest was a challenge. After browsing through several options, only a few stood out to me, with Prav being one of them. My initial interactions with the mentors via email were smooth and encouraging, which further solidified my interest in the project.

Additionally, I have been part of the AsyncAPI community for a long time and was very well positioned for a GSoC project focused on maintainership. My place within AsyncAPI was nearly guaranteed, with a high probability of 70% to 90%. However, I always reminded myself that I joined GSoC not for the money but to learn and enhance my coding skills. I sought a project that would truly challenge me.

When it came time to make a decision, I knew immediately that Prav was the way to go. By the grace of God, here we are, trying :)

Technical insights

I am super proud of the progress I've made so far. Initially, I thought this experience would primarily enhance my Java skills. However, I have learned so much more. I now have a deeper understanding of XMPP and have discovered various open-source tools that I wasn’t previously aware of. This newfound knowledge is incredibly exciting because it opens up opportunities for new career paths in my life.

Moreover, I am now part of an amazing community that has been incredibly supportive and welcoming. Technically, I am also gaining skills in Erlang/OTP, which I had not anticipated. This journey has not only broadened my technical expertise but also connected me with passionate and knowledgeable individuals who inspire me every day.

Conclusion

Reflecting on my journey so far, I am incredibly grateful for the opportunity to participate in GSoC and work with the XMPP organization. This experience has been transformative, and I am excited to continue growing and learning. I encourage everyone to follow my progress and consider getting involved with the XMPP community or GSoC.

Stay tuned, as I will be publishing a blog every week about my project until the end of GSoC. I invite you to leave comments, ask questions, or share your own experiences. Your feedback and interaction mean a lot to me!


For more details, you can check out these links :

Prav App : Link

XMPP : Link

Ejabberd : Link

Github Profile : Link

LinkedIn Profile : Link

Thank you for reading, and I look forward to sharing more with you soon!