Skip to content

NetSepio/erebrus-go-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Erebrus Go SDK

Note: You must already have an API key. This SDK does not create organizations or API keys. Obtain your API key from your Erebrus dashboard or admin before using this SDK.

A Go SDK for interacting with the Erebrus DVPN (Decentralized VPN) service. This SDK provides a complete interface for authenticating, creating clients, and establishing VPN connections using WireGuard.

Features

  • Authentication: Secure API authentication with your API key
  • Node Discovery: Get all available VPN nodes
  • Client Creation: Create WireGuard clients for specific nodes
  • VPN Connection: Establish and manage WireGuard VPN connections
  • Configuration Management: Generate and manage WireGuard configuration files

Installation

go get github.com/NetSepio/erebrus-go-sdk

Prerequisites

  • Go 1.21 or higher
  • WireGuard installed on your system
  • Sudo privileges (for VPN connection management)
  • An API key (get this from your Erebrus dashboard or admin)

Installing WireGuard

Ubuntu/Debian:

sudo apt update
sudo apt install wireguard

CentOS/RHEL/Fedora:

sudo yum install wireguard-tools
# or for newer versions
sudo dnf install wireguard-tools

macOS:

brew install wireguard-tools

Quick Start

package main

import (
    "fmt"
    "log"
    "github.com/NetSepio/erebrus-go-sdk/erebrus"
)

func main() {
    apiKey := "YOUR_API_KEY_HERE" // <-- Set your API key here

    // 1. Authenticate with the API key
    token, err := erebrus.Authenticate(apiKey)
    if err != nil {
        log.Fatalf("Failed to authenticate: %v", err)
    }
    fmt.Printf("Authentication successful! Token: %s\n", token)

    // 2. Get available nodes
    nodes, err := erebrus.GetAllNodes(token)
    if err != nil {
        log.Fatalf("Failed to get nodes: %v", err)
    }
    fmt.Printf("Found %d active nodes\n", len(nodes))

    if len(nodes) > 0 {
        // TODO: Replace with the node ID of the node you want to connect to
		nodeID := "YOUR_SELECTED_NODE_ID"

        // 3. Create a client for the first node
        client, err := erebrus.CreateClient(token, nodeID, "my-client")
        if err != nil {
            log.Fatalf("Failed to create client: %v", err)
        }

        // 4. Create WireGuard configuration
        configPath, err := erebrus.CreateWireGuardConfig(client)
        if err != nil {
            log.Fatalf("Failed to create config: %v", err)
        }
        fmt.Printf("WireGuard configuration created at: %s\n", configPath)

        // 5. Connect to VPN (optional, requires sudo)
        success, err := erebrus.ConnectDvpn(token, nodeID)
        if err != nil {
            log.Fatalf("Failed to connect: %v", err)
        }
        fmt.Printf("Connected successfully: %v\n", success)

        6. Disconnect when done (optional)
        err = erebrus.DisconnectVPN("")
        if err != nil {
            log.Printf("Warning: Failed to disconnect: %v", err)
        }
    }
}

API Reference

Authentication

Authenticate(apiKey string) (string, error)

Authenticates with the API using your API key and returns an authentication token.

Parameters:

  • apiKey: Your API key

Returns:

  • string: Authentication token
  • error: Error if authentication fails

Example:

token, err := erebrus.Authenticate(apiKey)
if err != nil {
    log.Fatal(err)
}

Node Management

GetAllNodes(token string) ([]Node, error)

Gets all available nodes in the network.

Parameters:

  • token: Authentication token

Returns:

  • []Node: Array of available nodes
  • error: Error if request fails

Example:

nodes, err := erebrus.GetAllNodes(token)
if err != nil {
    log.Fatal(err)
}
for _, node := range nodes {
    fmt.Printf("Node: %s (%s)\n", node.Name, node.Status)
}

Client Management

CreateClient(token, nodeID, clientName string) (*ClientResponse, error)

Creates a client for a specific node.

Parameters:

  • token: Authentication token
  • nodeID: ID of the target node
  • clientName: Name for the client (optional, defaults to "client")

Returns:

  • *ClientResponse: Client configuration data
  • error: Error if creation fails

Example:

client, err := erebrus.CreateClient(token, nodeID, "my-vpn-client")
if err != nil {
    log.Fatal(err)
}

WireGuard Configuration

CreateWireGuardConfig(clientData *ClientResponse) (string, error)

Creates a WireGuard configuration file from client data.

Parameters:

  • clientData: Client response data from CreateClient

Returns:

  • string: Path to the created configuration file
  • error: Error if creation fails

Example:

configPath, err := erebrus.CreateWireGuardConfig(client)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Config created at: %s\n", configPath)

VPN Connection

ConnectDvpn(token, nodeID string) (bool, error)

Establishes a VPN connection to the specified node.

Parameters:

  • token: Authentication token
  • nodeID: ID of the target node

Returns:

  • bool: True if connection successful
  • error: Error if connection fails

Example:

success, err := erebrus.ConnectDvpn(token, nodeID)
if err != nil {
    log.Fatal(err)
}
if success {
    fmt.Println("VPN connected successfully!")
}

DisconnectVPN(configPath string) error

Disconnects from the VPN connection.

Parameters:

  • configPath: Path to WireGuard config file (optional, defaults to "erebrus-dvpn.conf")

Returns:

  • error: Error if disconnection fails

Example:

err := erebrus.DisconnectVPN("")
if err != nil {
    log.Printf("Warning: %v", err)
}

Data Structures

Node

type Node struct {
    ID     string `json:"id"`
    Status string `json:"status"`
    Name   string `json:"name"`
}

ClientResponse

type ClientResponse struct {
    Status  int    `json:"status"`
    Message string `json:"message"`
    Payload struct {
        Client         Client `json:"client"`
        Endpoint       string `json:"endpoint"`
        ServerPublicKey string `json:"serverPublicKey"`
    } `json:"payload"`
    PrivateKey   string `json:"privateKey,omitempty"`
    PresharedKey string `json:"presharedKey,omitempty"`
}

Error Handling

The SDK uses Go's standard error handling pattern. All functions return an error as the last return value, which should be checked after each function call:

token, err := erebrus.Authenticate(apiKey)
if err != nil {
    log.Fatalf("Failed to authenticate: %v", err)
}

Security Considerations

  • API keys and tokens should be stored securely
  • WireGuard configuration files are created with restricted permissions (600)
  • The SDK requires sudo privileges for VPN operations
  • All network communications use HTTPS

Troubleshooting

Common Issues

  1. WireGuard not installed: Install WireGuard tools for your platform
  2. Permission denied: Ensure you have sudo privileges for VPN operations
  3. Network connectivity: Check your internet connection and firewall settings
  4. API errors: Verify your API key and token are valid

Debugging

The SDK provides detailed logging for all operations. Check the console output for error messages and status updates.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For support and questions, please open an issue on the GitHub repository.

About

A Go SDK for interacting with the Erebrus DVPN (Decentralized VPN) service.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages