Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag Handler Service #36

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Flag Handler Service #36

wants to merge 1 commit into from

Conversation

MayankMittal1
Copy link

@MayankMittal1 MayankMittal1 commented Dec 3, 2021

#32 Flag Submission Service

@MayankMittal1 MayankMittal1 force-pushed the flaghandlerservice branch 2 times, most recently from c2902c4 to e148114 Compare December 7, 2021 10:43
@h3llix
Copy link
Contributor

h3llix commented Dec 23, 2021

@MayankMittal1 Fix lint issues after you are done.

config.sample.toml Outdated Show resolved Hide resolved
configs/types.go Outdated
@@ -52,6 +52,12 @@ type MongoCfg struct {
URL string `toml:"url"`
}

type FlagCfg struct {
FlagLength uint `toml:"flaglength"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe length could be fixed.

types/mongo.go Outdated

type Challenge struct {
ID int `json:"id" bson:"id" binding:"required"`
TeamID int `json:"teamid" bson:"teamid" binding:"required"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a TeamID inside challenge struct? To me it seems it is the last team who solved the challenge.
If that is the case please change this variable to something else.

type Flag struct {
Value string `json:"value" bson:"value" binding:"required"`
ChallengeID int `json:"challengeid" bson:"challengeid" binding:"required"`
TeamID int `json:"teamid" bson:"teamid" binding:"required"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

types/mongo.go Outdated
}

type Submission struct {
Submitter int `json:"submitter" bson:"submitter" binding:"required"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is submitter here ?

  • Team which submits the flag ?

submission := &types.Submission{}
submission.ChallengeID = flag.ChallengeID
submission.Flag = flag.Value
submission.Submitter = team.Index //time of submission could also be stored
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. We might need to store the submission time. And create a watcher service to prevent bruteforcing. Please make a note of this on the channel also.

Comment on lines 30 to 36
if res, err := mongo.FetchChallenge(flag.ChallengeID); err != nil {
log.Println(err)
return false, 0
} else {
team.Score += res.Points
points = res.Points
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic looks wrong. You are increasing points if you can't find the challenge.

}

func flagUpdater(challenge bson.M) {
flagValue := String(int(configs.FlagConfig.FlagLength))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
flagValue := String(int(configs.FlagConfig.FlagLength))
flagLength := String(int(configs.FlagConfig.FlagLength))

Use uint. Dont cast it first to int then to string. If you already want it as a string change the type in FlagCfg struct.

Comment on lines 32 to 33
challengeBytes, _ := bson.Marshal(challenge)
bson.Unmarshal(challengeBytes, challengeStruct)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for errors.

flag.TeamID = challengeStruct.TeamID
flag.ChallengeID = challengeStruct.ID
flag.CreatedAt = time.Now()
if _, err := mongo.InsertOne(context.Background(), mongo.FlagsCollection, flag); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this will be an issue. Use upsert here. Will do a discussion on this.

@h3llix h3llix changed the title wip - flagsubmit service [WIP] Flag Submission Service Dec 23, 2021
@MayankMittal1 MayankMittal1 changed the title [WIP] Flag Submission Service Flag Handler Service Jan 2, 2022
author mayankmittal-iitr <[email protected]> 1638563217 +0530
committer Mayank Mittal <[email protected]> 1642515212 +0530

Add flag submission service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants