Commit 5037f200 authored by Mudassar Khan's avatar Mudassar Khan
Browse files

add autorization to IPE for security purpose

parent aa2f813d
Loading
Loading
Loading
Loading
+6 −1
Changes for go-apps/meep-ipe/config.env: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -74,7 +74,12 @@ MEEP_CSE_PORT=CSE-PORT
MEEP_CSE_ID=

# CSE name. Default if empty: "laboai-cse-in"
MEEP_CSE_NAME=
MEEP_CSE_NAME=laboai-cse-in

# HTTP Basic auth credentials for the CSE. Leave both empty if the CSE has
# no authorization enabled (no Authorization header is sent).
MEEP_CSE_USER=
MEEP_CSE_PASSWORD=


# ==============================================================================
+3 −0
Changes for go-apps/meep-ipe/config.yaml.in: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -29,5 +29,8 @@ CSE-PORT: '${CSE_PORT}'
CSE-ID: '${CSE_ID}'
#CSE NAME
CSE-NAME: '${CSE_NAME}'
# CSE HTTP Basic auth credentials (empty = no auth)
CSE-USER: '${CSE_USER}'
CSE-PASSWORD: '${CSE_PASSWORD}'
#AE ID
AE-ID: '${AE_ID}'
 No newline at end of file
+7 −0
Changes for go-apps/meep-ipe/entrypoint.sh: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -87,6 +87,10 @@ else
    CSE_NAME="${MEEP_CSE_NAME}"
fi

# CSE HTTP Basic auth credentials — leave empty if the CSE has no auth
CSE_USER="${MEEP_CSE_USER}"
CSE_PASSWORD="${MEEP_CSE_PASSWORD}"

AE_ID='CMecIPE'

echo "Environment variables set:"
@@ -105,6 +109,7 @@ echo "CSE-URL: ${CSE_URL}"
echo "CSE-PORT: ${CSE_PORT}"
echo "CSE-ID: ${CSE_ID}"
echo "CSE-NAME: ${CSE_NAME}"
echo "CSE-USER: ${CSE_USER}"
echo "AE-ID: ${AE_ID}"

export SERVER_IP
@@ -122,6 +127,8 @@ export CSE_URL
export CSE_PORT
export CSE_ID
export CSE_NAME
export CSE_USER
export CSE_PASSWORD
export AE_ID

workdir="/"
+0 −76
Changes for go-apps/meep-ipe/oneM2M/createSubscription.go: 0 added lines, 76 removed lines.
Original line number Diff line number Diff line
package onem2m

import (
	"bytes"
	"crypto/tls"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

// CreateSubscription creates a Subscription resource on the specified container
//
// This function creates a Subscription resource that enables the oneM2M platform
// to send notifications to a specified endpoint when events occur on the container
// (e.g., when new ContentInstances are created).
//
// Reference: oneM2M TS-0001 - Functional Architecture
//
// @param platformURL The base URL of the oneM2M CSE platform
// @param cseName The name of the Common Services Entity (CSE)
// @param appName The resource name for the application
// @param containerName The name of the container to subscribe to
// @return error Returns nil on success, or an error if subscription creation fails
func CreateSubscription(platformURL, cseName, appName, containerName string) error {
	subscriptionURL := fmt.Sprintf("%s/%s/%s/%s", platformURL, cseName, appName, containerName)

	target := subscriptionURL
	// Subscription resource body
	body := map[string]interface{}{
		"m2m:sub": map[string]interface{}{
			"rn":  "DataSyncSub",
			"nu":  []string{"https://192.168.20.163:9999/notifications"},
			"nct": 1,
			"enc": map[string]interface{}{
				"net": []int{3},
			},
		},
	}
	jsonBody, err := json.Marshal(body)
	if err != nil {
		return fmt.Errorf("failed to marshal subscription body: %v", err)
	}

	adminUser := "CAdmin"
	adminSecret := "ikram123"
	authString := fmt.Sprintf("%s:%s", adminUser, adminSecret)
	authHeader := "Basic " + base64.StdEncoding.EncodeToString([]byte(authString))

	req, err := http.NewRequest("POST", target, bytes.NewBuffer(jsonBody))
	if err != nil {
		return fmt.Errorf("failed to create subscription request: %v", err)
	}
	req.Header.Set("X-M2M-Origin", adminUser)
	req.Header.Set("X-M2M-RI", "req-admin")
	req.Header.Set("Authorization", authHeader)
	req.Header.Set("X-M2M-RVI", "5")
	req.Header.Set("Content-Type", "application/json;ty=23")

	// Skip TLS verification for development/testing
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	client := &http.Client{Transport: tr}
	resp, err := client.Do(req)
	if err != nil {
		return fmt.Errorf("failed to send subscription request: %v", err)
	}
	defer resp.Body.Close()
	respBody, _ := io.ReadAll(resp.Body)
	if resp.StatusCode != 201 && resp.StatusCode != 409 { // 409: Already exists
		return fmt.Errorf("subscription creation failed: %s", string(respBody))
	}
	return nil
}
+8 −0
Changes for go-apps/meep-ipe/oneM2M/oneM2m_init.go: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,14 +3,22 @@ package onem2m
import (
	"fmt"
	"log"

	"meep-ipe/utils"
)

var config = make(map[string]interface{})

func Init(configmap map[string]interface{}) {
	config = configmap

	user, _ := config["CSE-USER"].(string)
	password, _ := config["CSE-PASSWORD"].(string)
	utils.SetCSECredentials(user, password)

	log.Println("oneM2M configuration initialized:", config)
}

// NodeName returns the rn of this IPE's node on the CSE. It is suffixed with the
// sandbox name so multiple sandboxes can share the same CSE without conflicts.
func NodeName() string {
Loading