Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • jhtsi/didcomm-connector
  • eclipse/xfsc/common-services/didcomm-connector
  • mberstecher/didcomm-connector
  • mikesell/didcomm-connector
  • mxgor/didcomm-connector
5 results
Show changes
Commits on Source (63)
Showing
with 855 additions and 243 deletions
FROM ubuntu:latest as base
RUN apt-get update
RUN apt-get -y install curl wget git
RUN apt-get -y install gcc make
RUN apt-get -y install golang-1.23
RUN apt-get -y install ca-certificates
ENV PATH /usr/lib/go-1.23/bin:$PATH
FROM alpine/git:2.43.0 as gitclone-build
WORKDIR /clone
RUN git clone https://github.com/esatus/didcomm-rust
FROM rust:1.73 as rust-build
COPY --from=gitclone-build /clone/didcomm-rust /src
WORKDIR /src
#RUN build the rust library
RUN cd uniffi && cargo build --release
FROM base
# Copies your source code into the go directory
COPY . /src
# set work directory
WORKDIR /src
# copy lib from rust build
RUN mkdir -p didcomm/lib
COPY --from=rust-build /src/uniffi/target/release/libdidcomm_uniffi.* didcomm/lib/
RUN echo ls
COPY ./cmd/api/database /src/database/
#RUN go build to build the application with the name app
#RUN GOOS=linux GOARCH=amd64 go build -o /src/app ./cmd/api/
#
#EXPOSE 9090
#
#ENV LD_LIBRARY_PATH=/src/didcomm/lib
#CMD ["/src/app"]
\ No newline at end of file
{
"dockerComposeFile": "docker-compose.yml",
"service": "devcontainer",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}"
}
\ No newline at end of file
version : '3.9'
networks:
test:
driver: bridge
name: didcomm-devcontainer
services:
devcontainer:
build:
context: ../.
dockerfile: ./.devcontainer/Dockerfile
volumes:
- ../..:/workspaces:cached
- /var/run/docker.sock:/var/run/docker.sock
command: sleep infinity
networks:
- test
nats:
image: nats:latest
ports:
- "4222:4222"
networks:
- test
uni-resolver:
image: universalresolver/uni-resolver-web:latest
ports:
- "8080:8080"
healthcheck:
test: curl --fail http://uni-resolver:8080/1.0/testIdentifers || exit 1
interval: 10s
timeout: 5s
retries: 5
environment:
uniresolver_web_driver_url_did_jwk: http://did-jwk-driver:8080
uniresolver_web_driver_url_did_peer: http://uni-resolver-driver-did-uport:8081
uniresolver_web_driver_url_did_web: http://did-jwk-driver:8080
networks:
- test
uni-resolver-driver-did-uport:
image: uport/uni-resolver-driver-did-uport:4.3.0
ports:
- "8083:8081"
networks:
- test
did-jwk-driver:
image: transmute/restricted-resolver:latest
ports:
- "8134:8080"
networks:
- test
cassandra:
image: cassandra:4.1
ports:
- 9042:9042
networks:
- test
healthcheck:
test: cqlsh
interval: 30s
timeout: 120s
retries: 5
\ No newline at end of file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/cmd/api",
"env": {
"LD_LIBRARY_PATH": "../didcomm/lib"
},
"args": [
"-test.run",
"TestEnv"
]
},
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/api",
"env": {
"LD_LIBRARY_PATH": "../../didcomm/lib"
},
}
]
}
\ No newline at end of file
{
"go.testEnvVars": {
"LD_LIBRARY_PATH": "../didcomm/lib"
},
"rest-client.environmentVariables": {
"local": {
"baseUrl": "http://localhost:9090",
"didcommPath": "/message/receive",
"userPeerDid": "did:peer:2.Ez6LSmg6eZ5FdMcE8PPSMMBWXDvDPQ2weFhbTWjabmgeo3hQh.Vz6Mknr5Zt1YeLF6XpCchBSCrepSoaXpFV93TR5YyhnU3nu8A.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly9sb2NhbGhvc3Q6OTA5MC9tZXNzYWdlL3JlY2VpdmUiLCJhIjpbImRpZGNvbW0vdjIiXSwiciI6W119fQ",
"mediatorPeerDid": "did:peer:2.Ez6LSmg6eZ5FdMcE8PPSMMBWXDvDPQ2weFhbTWjabmgeo3hQh.Vz6Mknr5Zt1YeLF6XpCchBSCrepSoaXpFV93TR5YyhnU3nu8A.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly9sb2NhbGhvc3Q6OTA5MC9tZXNzYWdlL3JlY2VpdmUiLCJhIjpbImRpZGNvbW0vdjIiXSwiciI6W119fQ",
"recipient_did": "did:peer:alice_did_for_bob",
"bas64Attachement": "ICAgICAgICB7CiAgICAgICAgICAgICAgICAiaWQiOiAiMTIzNDU2Nzg5YWJjZGVmZ2hpIiwKICAgICAgICAgICAgICAgICJ0eXBlIjogImh0dHBzOi8vZGlkY29tbS5vcmcvYmFzaWNtZXNzYWdlLzIuMC9tZXNzYWdlIiwKICAgICAgICAgICAgICAgICJib2R5IjogewogICAgICAgICAgICAgICAgICAgICJjb250ZW50IjogIllvdXIgaG92ZXJjcmFmdCBpcyBmdWxsIG9mIGVlbHMuIgogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICJmcm9tIjoge3tmcm9tfX0sCiAgICAgICAgICAgICAgICAidG8iOiBbCiAgICAgICAgICAgICAgICAgICAge3t0b319CiAgICAgICAgICAgICAgICBdLAogICAgICAgICAgICAgICAgImNyZWF0ZWRfdGltZSI6IDUsCiAgICAgICAgICAgICAgICAiZXhwaXJlc190aW1lIjogNTAsCiAgICAgICAgICAgICAgICAiYXR0YWNobWVudHMiOiBbXQogICAgICAgICAgICB9",
"someDid": "did:peer:2.EzFc6PynFjHZeV4C1kCyWuoLgsgTq3rAqJJ2mVzn4VQtxA.VzHSH2ADF99d69NAS5wA43mbkssyqre4qPwrj7p5ifYvGJ.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly9sb2NhbGhvc3Q6MTIzNC9tZXNzYWdlL3JlY2VpdmUiLCJhIjpbImRpZGNvbW0vdjIiXSwiciI6W119fQ",
"attachmentId": "5"
}
}
}
\ No newline at end of file
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2024 Steffen Schulze
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# DIDComm Connector # DIDComm Connector
# Status
The DIDComm Connector is an mediator like tool which enables DIDComm V2 Protocol between a Cloud Entity, Devices and Other DIDComm Connectors. Please note that this connector should be considered as Mediator in an Standalone Running way for a third party, because it implements currently no encryption/signing in this version. Ensure therefore that all connections between the device/party and this connector is TLS protected to avoid privacy problems. Multiple Router Hops of messages are also not recommended so long as the party is not trusted to process the data within the messages.
## Protocol
1. Create Invitation from Actor to Mediator. Result is a URL with an token
2. Call the mediate request to register your actor by using the token in bearer auth
3. Follow the message flow. The message flow for delivering messages can be found [here](https://didcomm.org/messagepickup/3.0/) Check status route if message are arriving in your inbox. If yes, call delivery request. If received, call message received with the ids of messages which can be removed from mediator.
If a message should be forwarded to anyone use the forwarding message.
## Description ## Description
The DIDCommConnector can be used as a Mediator and Connection Management Service by parties who want to set up trust with another party. The DIDCommConnector uses DIDComm v2 and provides a message layer and a management component for the following two use cases: The DIDCommConnector can be used as a Mediator and Connection Management Service by parties who want to set up trust with another party. The DIDCommConnector uses DIDComm v2 and provides a message layer and a management component for the following two use cases:
...@@ -168,6 +182,13 @@ The application contains a database adapter interface. An implementation of it i ...@@ -168,6 +182,13 @@ The application contains a database adapter interface. An implementation of it i
Migration: Migration:
The database-initialization script, stored in `database/migrations`, will be executed once the application is being run for the first time and the db.inMemory in `config.yaml` is set to `false`. To make changes to the database, add another script(s) and run the application again. The database-initialization script, stored in `database/migrations`, will be executed once the application is being run for the first time and the db.inMemory in `config.yaml` is set to `false`. To make changes to the database, add another script(s) and run the application again.
Retrieve connections:
```bash
cqlsh <cassandra host> <cassandra port> -u <cassandra user> -p <cassandra password> -e "SELECT * FROM dcc.mediatees;"
```
## Test ## Test
To run all unit tests execute `make test`. To run all unit tests execute `make test`.
......
env: DEV # DEV, PROD
logLevel: "info" # info, debug, warning, error
label: My Mediator
port: 8081
url: "http://localhost:8081"
tokenExpiration: 500000
didcomm:
resolverUrl: "http://localhost:8080"
messageEncrypted: false
# database
db:
inMemory: false
host: "localhost"
port: 9042
user: "cassandra"
password: "f0U5AoZtVk"
keyspace: "didcomm_space"
dbName: "cassandra"
# config for cloudEventProdvider
messaging:
protocol: "nats"
nats:
url: "nats://localhost:4222"
topic: "/message/receive"
queueGroup: logger # optional
timeoutInSec: 10 # optional
http:
url: "http://localhost:1111" # URL to send cloud event
port: 1111 # port to send cloud event
path: "xyz" # Path to receive cloud event
\ No newline at end of file
package main package main
import ( import (
"gaiax/didcommconnector/didcomm" "encoding/base64"
"gaiax/didcommconnector/internal/config" "encoding/json"
connectionmanager "gaiax/didcommconnector/mediator/connectionManager" "errors"
"gaiax/didcommconnector/mediator/database" "gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/protocol"
"gaiax/didcommconnector/protocol" "io"
"net/http" "net/http"
"net/url"
"strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/didcomm"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/internal/config"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/mediator"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/mediator/database"
) )
type ConnectionResponse struct {
database.Mediatee
DidDoc *mediator.DidDocumentJSON `json:"didDocument,omitempty"`
}
// @Summary Get connections // @Summary Get connections
// @Schemes // @Schemes
// @Description Returns a list with the existing connections // @Description Returns a list with the existing connections
...@@ -19,17 +30,63 @@ import ( ...@@ -19,17 +30,63 @@ import (
// @Produce json // @Produce json
// @Success 200 {array} database.Mediatee // @Success 200 {array} database.Mediatee
// @Failure 500 "Internal Server Error" // @Failure 500 "Internal Server Error"
// @Router /connections [get] // @Router /admin/connections [get]
func (app *application) GetConnections(context *gin.Context) { func (app *application) GetConnections(context *gin.Context) {
logTag := "/connections [get]" logTag := "/admin/connections [get]"
config.Logger.Info(logTag, "Start", true) config.Logger.Info(logTag, "Start", true)
connections, err := app.mediator.Database.GetMediatees()
var g *string
var s *string
group, ok := context.GetQuery("group")
if ok {
g = &group
}
search, ok := context.GetQuery("search")
if ok {
s = &search
}
connections, err := app.mediator.Database.GetMediatees(g)
if err != nil { if err != nil {
config.Logger.Error(logTag, "Error", err) config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusInternalServerError) context.Status(http.StatusInternalServerError)
} }
var responseObjects = make([]ConnectionResponse, 0)
for _, x := range connections {
// Filter out all Temporary records
if !strings.Contains(x.RemoteDid, "did:") {
continue
}
if s != nil {
b, _ := json.Marshal(x)
if !strings.Contains(string(b), *s) {
continue
}
}
doc, _ := app.mediator.DidResolver.ResolveDidAsJson(x.RemoteDid)
response := ConnectionResponse{
Mediatee: x,
DidDoc: doc,
}
responseObjects = append(responseObjects, response)
}
config.Logger.Info(logTag, "End", true) config.Logger.Info(logTag, "End", true)
context.JSON(http.StatusOK, connections)
context.JSON(http.StatusOK, responseObjects)
} }
// @Summary Get connection // @Summary Get connection
...@@ -42,18 +99,27 @@ func (app *application) GetConnections(context *gin.Context) { ...@@ -42,18 +99,27 @@ func (app *application) GetConnections(context *gin.Context) {
// @Success 200 {object} database.Mediatee // @Success 200 {object} database.Mediatee
// @Failure 204 "No object found" // @Failure 204 "No object found"
// @Failure 500 "Internal Server Error" // @Failure 500 "Internal Server Error"
// @Router /connections/{did} [get] // @Router /admin/connections/:did [get]
func (app *application) GetConnection(context *gin.Context) { func (app *application) GetConnection(context *gin.Context) {
logTag := "/connections/{did} [get]" logTag := "/admin/connections/{did} [get]"
did := context.Param("did") did := context.Param("did")
config.Logger.Info(logTag, "did", did, "Start", true) config.Logger.Info(logTag, "did", did, "Start", true)
connection, err := app.mediator.Database.GetMediatee(did) connection, err := app.mediator.Database.GetMediatee(did)
if err != nil { if err != nil {
config.Logger.Error(logTag, "Error", err) config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusInternalServerError) context.Status(http.StatusInternalServerError)
return
}
doc, _ := app.mediator.DidResolver.ResolveDidAsJson(did)
response := ConnectionResponse{
Mediatee: *connection,
DidDoc: doc,
} }
config.Logger.Info(logTag, "End", true) config.Logger.Info(logTag, "End", true)
context.IndentedJSON(http.StatusOK, connection)
context.IndentedJSON(http.StatusOK, response)
} }
// @Summary Create a new connection // @Summary Create a new connection
...@@ -67,9 +133,9 @@ func (app *application) GetConnection(context *gin.Context) { ...@@ -67,9 +133,9 @@ func (app *application) GetConnection(context *gin.Context) {
// @Failure 400 "Bad Request" // @Failure 400 "Bad Request"
// @Failure 423 "Locked" // @Failure 423 "Locked"
// @Failure 500 "Internal Server Error" // @Failure 500 "Internal Server Error"
// @Router /connections [post] // @Router /admin/connections [post]
func (app *application) CreateConnection(context *gin.Context) { /*func (app *application) CreateConnection(context *gin.Context) {
logTag := "/connections [post]" logTag := "/admin/connections [post]"
config.Logger.Info(logTag, "Start", true) config.Logger.Info(logTag, "Start", true)
context.Header("Content-Type", "application/json") context.Header("Content-Type", "application/json")
...@@ -94,7 +160,7 @@ func (app *application) CreateConnection(context *gin.Context) { ...@@ -94,7 +160,7 @@ func (app *application) CreateConnection(context *gin.Context) {
return return
} }
err = app.mediator.ConnectionManager.CreateConnectionInvitation(mediateeBase.Protocol, mediateeBase.RemoteDid, mediateeBase.Topic, mediateeBase.Properties) err = app.mediator.ConnectionManager.StoreConnection(mediateeBase.Protocol, mediateeBase.RemoteDid, mediateeBase.Topic, mediateeBase.Properties)
if err != nil { if err != nil {
if err == connectionmanager.ERROR_PROTOCOL_NOT_SUPPORTED { if err == connectionmanager.ERROR_PROTOCOL_NOT_SUPPORTED {
_ = app.SendPr(context, protocol.PR_PROTOCOL_NOT_SUPPORTED, err) _ = app.SendPr(context, protocol.PR_PROTOCOL_NOT_SUPPORTED, err)
...@@ -112,8 +178,8 @@ func (app *application) CreateConnection(context *gin.Context) { ...@@ -112,8 +178,8 @@ func (app *application) CreateConnection(context *gin.Context) {
return return
} }
oob := protocol.NewOutOfBand(app.mediator) /*oob := protocol.NewOutOfBand(app.mediator)
invitation, err := oob.Handle() invitation, err := oob.Handle(config.CurrentConfiguration.Label)
if err != nil { if err != nil {
config.Logger.Error(logTag, "Error", err) config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusInternalServerError) context.Status(http.StatusInternalServerError)
...@@ -121,7 +187,7 @@ func (app *application) CreateConnection(context *gin.Context) { ...@@ -121,7 +187,7 @@ func (app *application) CreateConnection(context *gin.Context) {
} }
config.Logger.Info(logTag, "End", true) config.Logger.Info(logTag, "End", true)
context.String(http.StatusCreated, invitation) context.String(http.StatusCreated, invitation)
} }*/
// @Summary Deletes a connection // @Summary Deletes a connection
// @Schemes // @Schemes
...@@ -132,9 +198,9 @@ func (app *application) CreateConnection(context *gin.Context) { ...@@ -132,9 +198,9 @@ func (app *application) CreateConnection(context *gin.Context) {
// @Param did path string true "DID" // @Param did path string true "DID"
// @Success 200 "OK" // @Success 200 "OK"
// @Failure 500 "Internal Server Error" // @Failure 500 "Internal Server Error"
// @Router /connections/{did} [delete] // @Router /admin/connections/{did} [delete]
func (app *application) DeleteConnection(context *gin.Context) { func (app *application) DeleteConnection(context *gin.Context) {
logTag := "/connections/{did} [delete]" logTag := "/admin/connections/{did} [delete]"
did := context.Param("did") did := context.Param("did")
config.Logger.Info(logTag, "did", did, "Start", true) config.Logger.Info(logTag, "did", did, "Start", true)
err := app.mediator.Database.DeleteMediatee(did) err := app.mediator.Database.DeleteMediatee(did)
...@@ -148,6 +214,72 @@ func (app *application) DeleteConnection(context *gin.Context) { ...@@ -148,6 +214,72 @@ func (app *application) DeleteConnection(context *gin.Context) {
} }
// @Summary Updates a connection
// @Schemes
// @Description Updates a connection
// @Tags Connections
// @Accept json
// @Produce json
// @Param did path string true "DID"
// @Success 200 "OK"
// @Failure 500 "Internal Server Error"
// @Router /admin/connections/{did} [delete]
func (app *application) UpdateConnection(context *gin.Context) {
logTag := "/admin/connections/{did} [update]"
did := context.Param("did")
config.Logger.Info(logTag, "did", did, "Start", true)
body, err := io.ReadAll(context.Request.Body)
if err != nil {
config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusBadRequest)
return
}
err = context.Request.Body.Close()
if err != nil {
config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusBadRequest)
return
}
if len(body) == 0 {
config.Logger.Error(logTag, "Error", errors.New("no body"))
context.Status(http.StatusBadRequest)
return
}
var mediatee database.Mediatee
err = json.Unmarshal(body, &mediatee)
if err != nil {
config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusBadRequest)
return
}
if mediatee.RemoteDid != "" && mediatee.RemoteDid != did {
config.Logger.Error(logTag, "Error", errors.New("did mismatch"))
context.Status(http.StatusBadRequest)
return
}
mediatee.RemoteDid = did
err = app.mediator.Database.UpdateMediatee(mediatee)
if err != nil {
config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusInternalServerError)
return
}
config.Logger.Info(logTag, "End", true)
context.Status(http.StatusOK)
}
// @Summary Blocks connection // @Summary Blocks connection
// @Schemes // @Schemes
// @Description Blocks connection // @Description Blocks connection
...@@ -157,9 +289,9 @@ func (app *application) DeleteConnection(context *gin.Context) { ...@@ -157,9 +289,9 @@ func (app *application) DeleteConnection(context *gin.Context) {
// @Param did path string true "Did to be blocked" // @Param did path string true "Did to be blocked"
// @Success 200 "OK" // @Success 200 "OK"
// @Failure 500 "Internal Server Error" // @Failure 500 "Internal Server Error"
// @Router /connections/block/{did} [post] // @Router /admin/connections/block/{did} [post]
func (app *application) BlockConnection(context *gin.Context) { func (app *application) BlockConnection(context *gin.Context) {
logTag := "/connections/block/{did} [post]" logTag := "/admin/connections/block/{did} [post]"
did := context.Param("did") did := context.Param("did")
config.Logger.Info(logTag, "did", did, "Start", true) config.Logger.Info(logTag, "did", did, "Start", true)
...@@ -182,9 +314,9 @@ func (app *application) BlockConnection(context *gin.Context) { ...@@ -182,9 +314,9 @@ func (app *application) BlockConnection(context *gin.Context) {
// @Param did path string true "Did to be unblocked" // @Param did path string true "Did to be unblocked"
// @Success 200 "OK" // @Success 200 "OK"
// @Failure 500 "Internal Server Error" // @Failure 500 "Internal Server Error"
// @Router /connections/unblock/{did} [post] // @Router /admin/connections/unblock/{did} [post]
func (app *application) UnblockConnection(context *gin.Context) { func (app *application) UnblockConnection(context *gin.Context) {
logTag := "/connections/unblock/{did} [post]" logTag := "/admin/connections/unblock/{did} [post]"
did := context.Param("did") did := context.Param("did")
config.Logger.Info(logTag, "did", did, "Start", true) config.Logger.Info(logTag, "did", did, "Start", true)
err := app.mediator.Database.UnblockMediatee(did) err := app.mediator.Database.UnblockMediatee(did)
...@@ -206,9 +338,9 @@ func (app *application) UnblockConnection(context *gin.Context) { ...@@ -206,9 +338,9 @@ func (app *application) UnblockConnection(context *gin.Context) {
// @Param did path string true "Did" // @Param did path string true "Did"
// @Success 200 {object} boolean // @Success 200 {object} boolean
// @Failure 500 "Internal Server Error" // @Failure 500 "Internal Server Error"
// @Router /connections/isblocked/{did} [get] // @Router /admin/connections/isblocked/{did} [get]
func (app *application) IsBlocked(context *gin.Context) { func (app *application) IsBlocked(context *gin.Context) {
logTag := "/connections/isblocked/{did} [get]" logTag := "/admin/connections/isblocked/{did} [get]"
did := context.Param("did") did := context.Param("did")
config.Logger.Info(logTag, "did", did, "Start", true) config.Logger.Info(logTag, "did", did, "Start", true)
...@@ -222,6 +354,124 @@ func (app *application) IsBlocked(context *gin.Context) { ...@@ -222,6 +354,124 @@ func (app *application) IsBlocked(context *gin.Context) {
context.IndentedJSON(http.StatusOK, ib) context.IndentedJSON(http.StatusOK, ib)
} }
// @Summary Accept connection
// @Schemes
// @Description accept connection
// @Tags Connections
// @Accept json
// @Produce json
// @Success 200 "OK"
// @Failure 500 "Internal Server Error"
// @Router /admin/connections/unblock/{did} [post]
func (app *application) AcceptConnection(context *gin.Context) {
logTag := "/admin/connections/accept"
config.Logger.Info(logTag, "Start", true)
type Invitation struct {
Invitation string `json:"invitation"`
database.MediateeBase
}
var inv Invitation
err := context.ShouldBindJSON(&inv)
if inv.Invitation == "" ||
inv.EventType == "" ||
inv.Properties == nil ||
inv.Topic == "" ||
inv.Group == "" {
_ = app.SendPr(context, protocol.PR_INVALID_REQUEST, err)
context.Status(http.StatusBadRequest)
return
}
if err != nil {
_ = app.SendPr(context, protocol.PR_INVALID_REQUEST, err)
context.Status(http.StatusBadRequest)
return
}
uri, err := url.Parse(inv.Invitation)
if err != nil {
config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusBadRequest)
return
}
q, err := url.ParseQuery(uri.RawQuery)
if err != nil {
config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusInternalServerError)
return
}
oob := q.Get("_oob")
b, err := base64.RawURLEncoding.DecodeString(oob)
if err != nil {
config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusBadRequest)
return
}
msg, err := app.mediator.UnpackMessage(string(b))
if err != nil {
config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusBadRequest)
return
}
var bodyJson map[string]interface{}
err = json.Unmarshal([]byte(msg.Body), &bodyJson)
if err != nil {
config.Logger.Error("error unmarshalling", err)
context.Status(http.StatusInternalServerError)
return
}
s, err := mediator.CreateServiceEntry()
if err != nil {
config.Logger.Error("cant create Service", err)
context.Status(http.StatusInternalServerError)
return
}
orgPeerDid, err := mediator.NumAlgo2([]didcomm.Service{s}, app.mediator.SecretsResolver, app.mediator.DidResolver)
if err != nil {
config.Logger.Error("cant generate peer did", err)
context.Status(http.StatusInternalServerError)
return
}
// routing key must be extracted from mediaton request
connectUrl := uri.Scheme + "://" + uri.Host + uri.Path + "/message/receive"
peerdid, err := app.mediator.ConnectionManager.Connect(connectUrl, *msg.From, orgPeerDid, bodyJson["auth"].(string))
if err != nil {
config.Logger.Error("cant connect to the peer", err, "url", connectUrl)
context.Status(http.StatusInternalServerError)
return
}
err = app.mediator.ConnectionManager.StoreConnection(inv.Protocol, *msg.From, inv.Topic, inv.Properties, inv.EventType, []string{peerdid}, inv.Group)
if err != nil {
config.Logger.Error(logTag, "Error", err)
context.Status(http.StatusBadRequest)
return
}
config.Logger.Info(logTag, "End", true)
context.JSON(200, peerdid)
}
func (app *application) SendPr(context *gin.Context, pr didcomm.Message, err error) error { func (app *application) SendPr(context *gin.Context, pr didcomm.Message, err error) error {
context.Header("Content-Type", "application/json") context.Header("Content-Type", "application/json")
if err != nil { if err != nil {
......
...@@ -34,12 +34,12 @@ INSERT INTO secret_types(id, description) VALUES (6,'SecretTypeEd25519Verificati ...@@ -34,12 +34,12 @@ INSERT INTO secret_types(id, description) VALUES (6,'SecretTypeEd25519Verificati
INSERT INTO secret_types(id, description) VALUES (7,'SecretTypeOther'); " INSERT INTO secret_types(id, description) VALUES (7,'SecretTypeOther'); "
CREATE_SECRETS_TABLE="CREATE TABLE IF NOT EXISTS ${CASSANDRA_KEYSPACE}.secrets CREATE_SECRETS_TABLE="CREATE TABLE IF NOT EXISTS ${CASSANDRA_KEYSPACE}.secrets
(id text, type int, key text, PRIMARY KEY (id)); " (id text, type int, key text,added TIMESTAMP , PRIMARY KEY (id)); "
CREATE_MESSAGES_TABLE="CREATE TABLE IF NOT EXISTS ${CASSANDRA_KEYSPACE}.messages CREATE_MESSAGES_TABLE="CREATE TABLE IF NOT EXISTS ${CASSANDRA_KEYSPACE}.messages
(message_id text, recipient_did text, description text, filename text, media_type text, format text, (message_id text, recipient_did text, description text, filename text, media_type text, format text,
lastmod_time bigint, byte_count bigint, attachment_data text, PRIMARY KEY (message_id)); " lastmod_time bigint, byte_count bigint, attachment_data text,added TIMESTAMP PRIMARY KEY (message_id)); "
INDEX_MESSAGES_TABLE="CREATE INDEX IF NOT EXISTS messages_recipient_did_idx ON ${CASSANDRA_KEYSPACE}.messages (recipient_did);" INDEX_MESSAGES_TABLE="CREATE INDEX IF NOT EXISTS messages_recipient_did_idx ON ${CASSANDRA_KEYSPACE}.messages (recipient_did);"
......
package database package database
import ( import (
"gaiax/didcommconnector/internal/config" "gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/internal/config"
"github.com/gocql/gocql" "github.com/gocql/gocql"
migrate "github.com/golang-migrate/migrate/v4" migrate "github.com/golang-migrate/migrate/v4"
......
...@@ -9,14 +9,17 @@ CREATE TABLE IF NOT EXISTS mediator_did ( ...@@ -9,14 +9,17 @@ CREATE TABLE IF NOT EXISTS mediator_did (
CREATE TABLE IF NOT EXISTS mediatees ( CREATE TABLE IF NOT EXISTS mediatees (
remote_did TEXT, remote_did TEXT,
group TEXT,
routing_key TEXT, routing_key TEXT,
protocol TEXT, protocol TEXT,
topic TEXT, topic TEXT,
eventType TEXT,
recipient_dids SET<TEXT>, recipient_dids SET<TEXT>,
properties MAP<TEXT, TEXT>, properties MAP<TEXT, TEXT>,
added TIMESTAMP, added TIMESTAMP,
PRIMARY KEY (remote_did) PRIMARY KEY (remote_did)
); );
CREATE INDEX IF NOT EXISTS ON mediatees (group);
CREATE INDEX IF NOT EXISTS ON mediatees (recipient_dids); CREATE INDEX IF NOT EXISTS ON mediatees (recipient_dids);
CREATE TABLE IF NOT EXISTS blocked_dids ( CREATE TABLE IF NOT EXISTS blocked_dids (
......
...@@ -3,15 +3,16 @@ package main ...@@ -3,15 +3,16 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"gaiax/didcommconnector/database"
"gaiax/didcommconnector/internal/config"
"gaiax/didcommconnector/mediator"
"gaiax/didcommconnector/protocol"
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"time" "time"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/cmd/api/database"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/internal/config"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/mediator"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/protocol"
) )
// @title DIDComm Connector API // @title DIDComm Connector API
...@@ -79,6 +80,7 @@ func main() { ...@@ -79,6 +80,7 @@ func main() {
// subscribe to nats // subscribe to nats
go protocol.ReceiveMessage(app.mediator) go protocol.ReceiveMessage(app.mediator)
} }
router := app.NewRouter() router := app.NewRouter()
srv := &http.Server{ srv := &http.Server{
Addr: ":" + fmt.Sprint(config.CurrentConfiguration.Port), Addr: ":" + fmt.Sprint(config.CurrentConfiguration.Port),
......
...@@ -5,13 +5,20 @@ import ( ...@@ -5,13 +5,20 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"gaiax/didcommconnector/internal/config"
intErr "gaiax/didcommconnector/internal/errors"
"gaiax/didcommconnector/protocol"
"io" "io"
"net/http" "net/http"
"time"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/internal/config"
intErr "gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/internal/errors"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/mediator"
connectionmanager "gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/mediator/connectionManager"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/mediator/database"
"gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/protocol"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt"
"github.com/google/uuid"
) )
// @Summary Receives a DIDComm message // @Summary Receives a DIDComm message
...@@ -26,7 +33,7 @@ import ( ...@@ -26,7 +33,7 @@ import (
// @Failure 500 "Internal Server Error" // @Failure 500 "Internal Server Error"
// @Router /message/receive [post] // @Router /message/receive [post]
func (app *application) ReceiveMessage(context *gin.Context) { func (app *application) ReceiveMessage(context *gin.Context) {
bearer := context.Request.Header.Get("Authorization")
// get body of request // get body of request
bodyBytes, err := io.ReadAll(context.Request.Body) bodyBytes, err := io.ReadAll(context.Request.Body)
if err != nil { if err != nil {
...@@ -36,7 +43,7 @@ func (app *application) ReceiveMessage(context *gin.Context) { ...@@ -36,7 +43,7 @@ func (app *application) ReceiveMessage(context *gin.Context) {
bodyString := string(bodyBytes) bodyString := string(bodyBytes)
// handle message // handle message
packMsg, err := protocol.HandleMessage(bodyString, app.mediator) packMsg, err := protocol.HandleMessage(bodyString, app.mediator, bearer)
if err != nil { if err != nil {
if errors.Is(err, intErr.ErrUnpackingMessage) { if errors.Is(err, intErr.ErrUnpackingMessage) {
context.Status(http.StatusBadRequest) context.Status(http.StatusBadRequest)
...@@ -62,15 +69,78 @@ func (app *application) ReceiveMessage(context *gin.Context) { ...@@ -62,15 +69,78 @@ func (app *application) ReceiveMessage(context *gin.Context) {
} }
} }
// @Summary Create a connection invitation which is used for requesting the mediate
// @Schemes
// @Description Create a connection invitation
// @Tags Administration
// @Accept json
// @Produce json
// @Param message body didcomm.Message true "Message"
// @Success 200 "OK"
// @Failure 400 "Bad Request"
// @Failure 500 "Internal Server Error"
// @Router /admin/invitiation [post]
func (app *application) InvitationMessage(context *gin.Context) { func (app *application) InvitationMessage(context *gin.Context) {
mediator := app.mediator
oob := protocol.NewOutOfBand(mediator)
msg, err := oob.Handle() m := app.mediator
var mediateeBase database.MediateeBase
err := context.ShouldBindJSON(&mediateeBase)
if err != nil {
_ = app.SendPr(context, protocol.PR_INVALID_REQUEST, err)
context.Status(http.StatusBadRequest)
return
}
mediateeBase.RemoteDid = uuid.NewString() //temporary
isBlocked, err := app.mediator.Database.IsBlocked(mediateeBase.RemoteDid)
if err != nil {
_ = app.SendPr(context, protocol.PR_INTERNAL_SERVER_ERROR, err)
context.Status(http.StatusInternalServerError)
return
}
if isBlocked {
_ = app.SendPr(context, protocol.PR_DID_BLOCKED, err)
context.Status(http.StatusLocked)
return
}
err = app.mediator.ConnectionManager.StoreConnection(mediateeBase.Protocol, mediateeBase.RemoteDid, mediateeBase.Topic, mediateeBase.Properties, mediateeBase.EventType, []string{}, mediateeBase.Group)
if err != nil {
if err == connectionmanager.ERROR_PROTOCOL_NOT_SUPPORTED {
_ = app.SendPr(context, protocol.PR_PROTOCOL_NOT_SUPPORTED, err)
context.Status(http.StatusBadRequest)
} else if err == connectionmanager.ERROR_INTERNAL {
_ = app.SendPr(context, protocol.PR_INTERNAL_SERVER_ERROR, err)
context.Status(http.StatusInternalServerError)
} else if err == connectionmanager.ERROR_CONNECTION_ALREADY_EXISTS {
_ = app.SendPr(context, protocol.PR_ALREADY_CONNECTED, err)
context.Status(http.StatusInternalServerError)
} else {
_ = app.SendPr(context, protocol.PR_INTERNAL_SERVER_ERROR, err)
context.Status(http.StatusInternalServerError)
}
return
}
oob := protocol.NewOutOfBand(m)
payload := jwt.MapClaims{
"exp": time.Now().Add(time.Minute * time.Duration(config.CurrentConfiguration.TokenExpiration)).Unix(),
"invitationId": mediateeBase.RemoteDid,
}
token, err := mediator.GenerateSignedToken(m.Did, payload, m.SecretsResolver, m.DidResolver)
msg, err := oob.Handle(config.CurrentConfiguration.Label, token)
if err != nil { if err != nil {
context.String(http.StatusInternalServerError, "Error handling out of band") context.String(http.StatusInternalServerError, "Error handling out of band")
} else { } else {
msg64 := base64.StdEncoding.EncodeToString([]byte(msg))
msg64 := base64.RawURLEncoding.EncodeToString([]byte(msg))
oob := fmt.Sprintf("%s?_oob=%s", config.CurrentConfiguration.Url, msg64) oob := fmt.Sprintf("%s?_oob=%s", config.CurrentConfiguration.Url, msg64)
context.String(http.StatusOK, oob) context.String(http.StatusOK, oob)
} }
......
package main package main
import ( import (
_ "gaiax/didcommconnector/docs" _ "gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/docs"
"gaiax/didcommconnector/internal/config" "gitlab.eclipse.org/eclipse/xfsc/common-services/didcomm-connector/internal/config"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
sloggin "github.com/samber/slog-gin" sloggin "github.com/samber/slog-gin"
...@@ -20,20 +20,23 @@ func (app *application) NewRouter() *gin.Engine { ...@@ -20,20 +20,23 @@ func (app *application) NewRouter() *gin.Engine {
router.Use(sloggin.New(config.Logger)) router.Use(sloggin.New(config.Logger))
// Connections (Mediatees) // Connections (Mediatees)
connectionsGroup := router.Group("connections") adminGroup := router.Group("admin")
connectionsGroup := adminGroup.Group("connections")
connectionsGroup.GET("", app.GetConnections) connectionsGroup.GET("", app.GetConnections)
connectionsGroup.GET(":did", app.GetConnection) connectionsGroup.GET(":did", app.GetConnection)
connectionsGroup.POST("", app.CreateConnection) connectionsGroup.PUT(":did", app.UpdateConnection)
connectionsGroup.DELETE(":did", app.DeleteConnection) connectionsGroup.DELETE(":did", app.DeleteConnection)
// Block Connections (Mediatees) // Block Connections (Mediatees)
connectionsGroup.POST("block/:did", app.BlockConnection) connectionsGroup.POST("block/:did", app.BlockConnection)
connectionsGroup.POST("unblock/:did", app.UnblockConnection) connectionsGroup.POST("unblock/:did", app.UnblockConnection)
connectionsGroup.GET("isblocked/:did", app.IsBlocked) connectionsGroup.GET("isblocked/:did", app.IsBlocked)
connectionsGroup.POST("accept", app.AcceptConnection)
adminGroup.POST("invitation", app.InvitationMessage)
// messages // messages
messagesGroup := router.Group("message") messagesGroup := router.Group("message")
messagesGroup.POST("receive", app.ReceiveMessage) messagesGroup.POST("receive", app.ReceiveMessage)
messagesGroup.GET("invitation", app.InvitationMessage)
// healthcheck // healthcheck
router.GET("health", app.HealthCheck) router.GET("health", app.HealthCheck)
......
-- TODO: dont use this migration in production
-- This migration drops all tables and recreates them for testing purposes
-- change current workflow of creating tables in docker compose
-- Creating Keyspace
CREATE KEYSPACE IF NOT EXISTS dcc WITH REPLICATION = {
'class' : 'SimpleStrategy',
'replication_factor' : 1
};
-- Dropping Tables
DROP TABLE IF EXISTS mediatees;
DROP TABLE IF EXISTS mediator_did;
DROP TABLE IF EXISTS recipient_dids;
DROP TABLE IF EXISTS deny_list;
DROP TABLE IF EXISTS secret_types;
DROP TABLE IF EXISTS secrets;
DROP TABLE IF EXISTS messages;
-- Creating Tables
CREATE TABLE IF NOT EXISTS mediatees (
remote_did text,
routing_key text,
created TIMESTAMP,
protocol text,
topic text,
properties map<text, text>,
PRIMARY KEY (remote_did)
);
CREATE TABLE IF NOT EXISTS mediator_did (
did text,
created TIMESTAMP,
PRIMARY KEY (did)
);
CREATE TABLE IF NOT EXISTS recipient_dids (
recipient_did text,
remote_did text,
PRIMARY KEY (recipient_did)
);
CREATE INDEX IF NOT EXISTS recipient_dids_remote_did_idx ON recipient_dids (remote_did);
CREATE TABLE IF NOT EXISTS deny_list (
did text,
created TIMESTAMP,
PRIMARY KEY (did)
);
CREATE TABLE IF NOT EXISTS secret_types (
id int,
description text,
PRIMARY KEY (id)
);
-- Inserting into Secret Types Table
INSERT INTO secret_types(id, description) VALUES (1,'SecretTypeJsonWebKey2020');
INSERT INTO secret_types(id, description) VALUES (2,'SecretTypeX25519KeyAgreementKey2019');
INSERT INTO secret_types(id, description) VALUES (3,'SecretTypeEd25519VerificationKey2018');
INSERT INTO secret_types(id, description) VALUES (4,'SecretTypeEcdsaSecp256k1VerificationKey2019');
INSERT INTO secret_types(id, description) VALUES (5,'SecretTypeX25519KeyAgreementKey2020');
INSERT INTO secret_types(id, description) VALUES (6,'SecretTypeEd25519VerificationKey2020');
INSERT INTO secret_types(id, description) VALUES (7,'SecretTypeOther');
CREATE TABLE IF NOT EXISTS secrets (
id text,
type int,
key text,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS messages (
message_id text,
recipient_did text,
description text,
filename text,
media_type text,
format text,
lastmod_time bigint,
byte_count bigint,
attachment_data text,
PRIMARY KEY (message_id)
);
CREATE INDEX IF NOT EXISTS messages_recipient_did_idx ON messages (recipient_did);
#!/bin/bash
echo "Starting to execute SH script..."
CREATE_KEYSPACE="CREATE KEYSPACE IF NOT EXISTS ${CASSANDRA_KEYSPACE} WITH REPLICATION = {
'class' : 'SimpleStrategy',
'replication_factor' : 1 }; "
USE_KEYSPACE="USE ${CASSANDRA_KEYSPACE}; "
CREATE_CONNECTIONS_TABLE="CREATE TABLE IF NOT EXISTS connections (
did text, is_mediated boolean, is_denied boolean, added TIMESTAMP, PRIMARY KEY (did)) "
CQL="$CREATE_KEYSPACE$USE_KEYSPACE$CREATE_CONNECTIONS_TABLE"
echo "$CQL"
while ! cqlsh cassandra_db -u "${CASSANDRA_USERNAME}" -p "${CASSANDRA_PASSWORD}" -e 'describe cluster' ; do
echo "Waiting for main instance to be ready..."
sleep 5
done
cqlsh cassandra_db -u "${CASSANDRA_USERNAME}" -p "${CASSANDRA_PASSWORD}" -e "${CQL}"
# for cql_file in ./cql/*.cql;
# do
# cqlsh cassandra_db -u "${CASSANDRA_USERNAME}" -p "${CASSANDRA_PASSWORD}" -f "${cql_file}" ;
# echo "Script ""${cql_file}"" executed"
# done
echo "Execution of SH script is finished"
echo "Stopping temporary database instance"
\ No newline at end of file
...@@ -3,7 +3,7 @@ FROM alpine/git:2.43.0 as gitclone-build ...@@ -3,7 +3,7 @@ FROM alpine/git:2.43.0 as gitclone-build
WORKDIR /clone WORKDIR /clone
RUN git clone https://github.com/esatus/didcomm-rust RUN git clone https://github.com/esatus/didcomm-rust
FROM rust:1.70 as rust-build FROM rust:1.78 as rust-build
COPY --from=gitclone-build /clone/didcomm-rust /src COPY --from=gitclone-build /clone/didcomm-rust /src
WORKDIR /src WORKDIR /src
...@@ -22,32 +22,38 @@ WORKDIR /src ...@@ -22,32 +22,38 @@ WORKDIR /src
# copy lib from rust build # copy lib from rust build
RUN mkdir -p didcomm/lib RUN mkdir -p didcomm/lib
COPY --from=rust-build /src/uniffi/target/release/libdidcomm_uniffi.* didcomm/lib/ COPY --from=rust-build /src/uniffi/target/release/libdidcomm_uniffi.* didcomm/lib/
COPY ./cmd/api/database /src/database/
#RUN go build to build the application with the name app #RUN go build to build the application with the name app
RUN go build -o /src/app ./cmd/api/ RUN GOOS=linux GOARCH=amd64 go build -o /src/app ./cmd/api/
EXPOSE 9090
ENV LD_LIBRARY_PATH=/src/didcomm/lib
CMD ["/src/app"]
FROM scratch # FROM scratch
# copy lib and dependencies (finde dependencies with: ldd <executable>) # # copy lib and dependencies (finde dependencies with: ldd <executable>)
COPY --from=go-build /src/didcomm/lib /bin/lib/ # COPY --from=go-build /src/didcomm/lib /bin/lib/
COPY --from=go-build /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/libgcc_s.so.1 # COPY --from=go-build /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/libgcc_s.so.1
COPY --from=go-build /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0 # COPY --from=go-build /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0
COPY --from=go-build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6 # COPY --from=go-build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
COPY --from=go-build /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so.2 # COPY --from=go-build /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so.2
COPY --from=go-build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 # COPY --from=go-build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=go-build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 # COPY --from=go-build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
# add curl for healthcheck # # add curl for healthcheck
COPY --from=ghcr.io/tarampampam/curl:8.6.0 /bin/curl /bin/curl # COPY --from=ghcr.io/tarampampam/curl:8.6.0 /bin/curl /bin/curl
# copy config file # # copy config file
COPY --from=go-build /src/config.yaml /config.yaml # COPY --from=go-build /src/cmd/api/config.yaml /config.yaml
# copy binary # # copy binary
COPY --from=go-build /src/app /bin/app # COPY --from=go-build /src/app /bin/app
# set enviroment variable for lib # # set enviroment variable for lib
ENV LD_LIBRARY_PATH=/bin/lib # ENV LD_LIBRARY_PATH=/bin/lib
EXPOSE 9090:9090 # EXPOSE 9090:9090
HEALTHCHECK --interval=5s --timeout=2s --retries=2 --start-period=2s CMD ["curl", "--fail", "http://127.0.0.1:9090/health"] # HEALTHCHECK --interval=5s --timeout=2s --retries=2 --start-period=2s CMD ["curl", "--fail", "http://127.0.0.1:9090/health"]
CMD ["/bin/app"] # CMD ["/bin/app"]
env: DEV # DEV, PROD env: DEV # DEV, PROD
logLevel: "info" # info, debug, warning, error logLevel: "info" # info, debug, warning, error
label: My Mediator
port: 9090 port: 9090
url: "http://localhost:9090" url: "http://host.docker.internal:9090"
tokenExpiration: 500000
didcomm: didcomm:
resolverUrl: "http://localhost:8081" resolverUrl: "http://host.docker.internal:8081"
messageEncrypted: false messageEncrypted: false
# database # database
db: db:
inMemory: true inMemory: false
host: "localhost" host: "localhost"
port: 9042 port: 9042
user: "cassandra" user: "cassandra"
...@@ -19,9 +20,9 @@ db: ...@@ -19,9 +20,9 @@ db:
# config for cloudEventProdvider # config for cloudEventProdvider
messaging: messaging:
protocol: "http" protocol: "nats"
nats: nats:
url: "demo.nats.io" url: "nats://host.docker.internal:4222"
topic: "/message/receive" topic: "/message/receive"
queueGroup: logger # optional queueGroup: logger # optional
timeoutInSec: 10 # optional timeoutInSec: 10 # optional
......
version: "3"
networks:
test:
name: test_network
external:
true
services:
didcomconnectorAlpha:
image: node-654e3bca7fbeeed18f81d7c7.ps-xaas.io/common-services/didcomm-connector:refactoring
container_name: dccAlpha
depends_on:
uni-resolverAlpha:
condition: service_healthy
cassandraAlpha:
condition: service_healthy
ports:
- 9092:8080
environment:
- DIDCOMMCONNECTOR_DIDCOMM_RESOLVERURL=http://uni-resolverAlpha:8081
- DIDCOMMCONNECTOR_CLOUDFORWARDING_NATS_URL=nats://natsAlpha:4222
- DIDCOMMCONNECTOR_DATBASE_HOST=cassandraAlpha
- DIDCOMMCONNECTOR_DATBASE_KEYSPACE=tenant_space
- DIDCOMMCONNECTOR_DATBASE_DBNAME=dcc
- DIDCOMMCONNECTOR_DATBASE_PORT=9042
- DIDCOMMCONNECTOR_CLOUDFORWARDING_NATS_TOPIC=connector
- DIDCOMMCONNECTOR_URL=http://localhost:9092
- DIDCOMMCONNECTOR_CLOUDFORWARDING_PROTOCOL=nats
networks:
- test
natsAlpha:
image: nats:latest
container_name: natsAlpha
ports:
- "4223:4222"
networks:
- test
uni-resolverAlpha:
image: universalresolver/uni-resolver-web:latest
container_name: uni-resolverAlpha
ports:
- "8080:8080"
healthcheck:
test: curl --fail http://uni-resolver:8080/1.0/testIdentifers || exit 1
interval: 10s
timeout: 5s
retries: 5
environment:
uniresolver_web_driver_url_did_jwk: http://did-jwk-driver:8080
uniresolver_web_driver_url_did_peer: http://uni-resolver-driver-did-uport:8081
uniresolver_web_driver_url_did_web: http://did-jwk-driver:8080
networks:
- test
cassandraAlpha:
image: cassandra:4.1
container_name: cassandra_dbAlpha
ports:
- 7001:7000
- 9043:9042
networks:
- test
healthcheck:
test: cqlsh
interval: 30s
timeout: 120s
retries: 5
\ No newline at end of file