Skip to content

Commit

Permalink
Merge pull request #674 from 0xPolygonID/feature/check-type-message
Browse files Browse the repository at this point in the history
fix: verify iden3comm message media type
  • Loading branch information
ilya-korotya authored Jun 17, 2024
2 parents c314c16 + 15f1183 commit 631cf8e
Show file tree
Hide file tree
Showing 24 changed files with 369 additions and 127 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ db/migrate: $(BIN)/install-goose $(BIN)/godotenv $(BIN)/platformid-migrate ## In
lint: $(BIN)/golangci-lint
$(BIN)/golangci-lint run

.PHONY: lint-fix
lint-fix: $(BIN)/golangci-lint
$(BIN)/golangci-lint run --fix

# usage: make private_key=xxx add-private-key
.PHONY: add-private-key
add-private-key:
Expand Down
2 changes: 1 addition & 1 deletion cmd/issuer_initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func main() {
rhsFactory := reverse_hash.NewFactory(cfg.CredentialStatus.RHS.GetURL(), ethConn, common.HexToAddress(cfg.CredentialStatus.OnchainTreeStore.SupportedTreeStoreContract), reverse_hash.DefaultRHSTimeOut)
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
cfg.CredentialStatus.SingleIssuer = true
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, nil, claimsRepository, nil, nil, storage, nil, nil, nil, cfg.CredentialStatus, rhsFactory, revocationStatusResolver)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, nil, claimsRepository, nil, nil, storage, nil, nil, nil, cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)

didCreationOptions := &ports.DIDCreationOptions{
Method: core.DIDMethod(cfg.APIUI.IdentityMethod),
Expand Down
4 changes: 2 additions & 2 deletions cmd/notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func newCredentialsService(ctx context.Context, cfg *config.Configuration, stora
mtService := services.NewIdentityMerkleTrees(mtRepository)
qrService := services.NewQrStoreService(cachex)

identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, nil, nil, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, nil, nil, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)

return claimsService, nil
}
4 changes: 2 additions & 2 deletions cmd/pending_publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func main() {
rhsFactory := reverse_hash.NewFactory(cfg.CredentialStatus.RHS.GetURL(), cl, common.HexToAddress(cfg.CredentialStatus.OnchainTreeStore.SupportedTreeStoreContract), reverse_hash.DefaultRHSTimeOut)
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)

identityService := services.NewIdentity(keyStore, identityRepo, mtRepo, identityStateRepo, mtService, qrService, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, qrService, mtService, identityStateRepo, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver)
identityService := services.NewIdentity(keyStore, identityRepo, mtRepo, identityStateRepo, mtService, qrService, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
claimsService := services.NewClaim(claimsRepo, identityService, qrService, mtService, identityStateRepo, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)

circuitsLoaderService := circuitLoaders.NewCircuits(cfg.Circuit.Path)
proofService := initProofService(ctx, cfg, circuitsLoaderService)
Expand Down
4 changes: 2 additions & 2 deletions cmd/platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func main() {

cfg.CredentialStatus.SingleIssuer = false
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, nil, nil, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.ServerUrl, ps, cfg.IPFS.GatewayURL, revocationStatusResolver)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, nil, nil, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.ServerUrl, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
proofService := gateways.NewProver(ctx, cfg, circuitsLoaderService)

transactionService, err := gateways.NewTransaction(ethereumClient, cfg.Ethereum.ConfirmationBlockCount)
Expand Down
4 changes: 2 additions & 2 deletions cmd/platform_ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ func main() {

cfg.CredentialStatus.SingleIssuer = true
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, connectionsRepository, storage, verifier, sessionRepository, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, connectionsRepository, storage, verifier, sessionRepository, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
schemaService := services.NewSchema(schemaRepository, schemaLoader)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
connectionsService := services.NewConnection(connectionsRepository, claimsRepository, storage)
linkService := services.NewLinkService(storage, claimsService, qrService, claimsRepository, linkRepository, schemaRepository, schemaLoader, sessionRepository, ps, cfg.IPFS.GatewayURL)

Expand Down
2 changes: 2 additions & 0 deletions internal/api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/iden3/iden3comm/v2"
"github.com/piprate/json-gold/ld"

"github.com/polygonid/sh-id-platform/internal/common"
"github.com/polygonid/sh-id-platform/internal/config"
"github.com/polygonid/sh-id-platform/internal/core/ports"
"github.com/polygonid/sh-id-platform/internal/db"
Expand Down Expand Up @@ -107,6 +108,7 @@ func TestMain(m *testing.M) {
URL: "http://localhost:3001",
},
}
cfg.AutoPublishingToOnChainRHS = common.ToPointer[bool](true)

m.Run()
}
Expand Down
4 changes: 2 additions & 2 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (s *Server) Agent(ctx context.Context, request AgentRequestObject) (AgentRe
return Agent400JSONResponse{N400JSONResponse{"cannot proceed with an empty request"}}, nil
}

basicMessage, _, err := s.packageManager.Unpack([]byte(*request.Body))
basicMessage, mediatype, err := s.packageManager.Unpack([]byte(*request.Body))
if err != nil {
log.Debug(ctx, "agent bad request", "err", err, "body", *request.Body)
return Agent400JSONResponse{N400JSONResponse{"cannot proceed with the given request"}}, nil
Expand All @@ -420,7 +420,7 @@ func (s *Server) Agent(ctx context.Context, request AgentRequestObject) (AgentRe
return Agent400JSONResponse{N400JSONResponse{err.Error()}}, nil
}

agent, err := s.claimService.Agent(ctx, req)
agent, err := s.claimService.Agent(ctx, req, mediatype)
if err != nil {
log.Error(ctx, "agent error", "err", err)
return Agent400JSONResponse{N400JSONResponse{err.Error()}}, nil
Expand Down
Loading

0 comments on commit 631cf8e

Please sign in to comment.