Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
CTF
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grzegorz
CTF
Commits
240b3c18
Commit
240b3c18
authored
Mar 22, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
6e7e351f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
11 deletions
+14
-11
HashValidator.java
...a/com/telephoners/krakyournet/ctf/core/HashValidator.java
+3
-3
SolutionsRepository.java
...ers/krakyournet/ctf/repositories/SolutionsRepository.java
+1
-3
SolutionsResource.java
...ephoners/krakyournet/ctf/resources/SolutionsResource.java
+10
-5
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/core/HashValidator.java
View file @
240b3c18
...
@@ -39,9 +39,9 @@ public class HashValidator
...
@@ -39,9 +39,9 @@ public class HashValidator
return
Hex
.
encodeHexString
(
messageDigest
.
digest
(
combinedStrings
.
getBytes
()));
return
Hex
.
encodeHexString
(
messageDigest
.
digest
(
combinedStrings
.
getBytes
()));
}
}
public
boolean
checkHash
(
User
user
,
String
hashValue
,
int
taskLevel
)
public
Pair
<
Task
,
Flag
>
checkHash
(
User
user
,
String
hashValue
,
int
taskLevel
)
{
{
Pair
<
Task
,
Flag
>
taskFlagPair
=
tasksRepository
.
getTaskFlagPairByHashValue
(
user
,
hashValue
,
taskLevel
);
return
tasksRepository
.
getTaskFlagPairByHashValue
(
user
,
hashValue
,
taskLevel
);
return
solutionsRepository
.
submitSolution
(
user
,
taskFlagPair
.
getKey
(),
taskFlagPair
.
getValue
(),
hashValue
);
//todo: what if null?
}
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/SolutionsRepository.java
View file @
240b3c18
...
@@ -72,10 +72,8 @@ public class SolutionsRepository extends Repository<Solution>
...
@@ -72,10 +72,8 @@ public class SolutionsRepository extends Repository<Solution>
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
}
}
public
boolean
submitSolution
(
User
user
,
Task
task
,
Flag
flag
,
String
hashValue
)
public
boolean
submitSolution
(
Solution
solution
)
{
{
Team
team
=
teamsRepository
.
getTeamByUser
(
user
);
Solution
solution
=
new
Solution
(
team
,
task
,
flag
,
hashValue
);
if
(!
isAlreadySubmittedSolution
(
solution
))
{
if
(!
isAlreadySubmittedSolution
(
solution
))
{
add
(
solution
);
add
(
solution
);
return
true
;
return
true
;
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/resources/SolutionsResource.java
View file @
240b3c18
package
com
.
telephoners
.
krakyournet
.
ctf
.
resources
;
package
com
.
telephoners
.
krakyournet
.
ctf
.
resources
;
import
com.telephoners.krakyournet.ctf.beans.Flag
;
import
com.telephoners.krakyournet.ctf.beans.Solution
;
import
com.telephoners.krakyournet.ctf.beans.Team
;
import
com.telephoners.krakyournet.ctf.beans.Team
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.beans.tasks.Task
;
import
com.telephoners.krakyournet.ctf.core.HashValidator
;
import
com.telephoners.krakyournet.ctf.core.HashValidator
;
import
com.telephoners.krakyournet.ctf.repositories.SolutionsRepository
;
import
com.telephoners.krakyournet.ctf.repositories.SolutionsRepository
;
import
com.telephoners.krakyournet.ctf.repositories.TasksRepository
;
import
com.telephoners.krakyournet.ctf.repositories.TeamsRepository
;
import
com.telephoners.krakyournet.ctf.repositories.TeamsRepository
;
import
io.dropwizard.auth.Auth
;
import
io.dropwizard.auth.Auth
;
import
javafx.util.Pair
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
javax.inject.Singleton
;
import
javax.inject.Singleton
;
...
@@ -15,7 +18,6 @@ import javax.ws.rs.core.MediaType;
...
@@ -15,7 +18,6 @@ import javax.ws.rs.core.MediaType;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Singleton
@Singleton
...
@@ -42,8 +44,11 @@ public class SolutionsResource
...
@@ -42,8 +44,11 @@ public class SolutionsResource
@PathParam
(
"task_level"
)
int
taskLevel
,
@PathParam
(
"task_level"
)
int
taskLevel
,
String
hash
)
throws
Exception
String
hash
)
throws
Exception
{
{
if
(
hashValidator
.
checkHash
(
user
,
hash
,
taskLevel
))
{
Pair
<
Task
,
Flag
>
taskFlagPair
=
hashValidator
.
checkHash
(
user
,
hash
,
taskLevel
);
return
Response
.
ok
().
build
();
if
(
taskFlagPair
!=
null
)
{
if
(
solutionsRepository
.
submitSolution
(
new
Solution
(
teamsRepository
.
getTeamByUser
(
user
),
taskFlagPair
.
getKey
(),
taskFlagPair
.
getValue
(),
hash
)))
{
return
Response
.
ok
().
build
();
}
}
}
return
Response
.
status
(
Response
.
Status
.
NOT_ACCEPTABLE
).
build
();
return
Response
.
status
(
Response
.
Status
.
NOT_ACCEPTABLE
).
build
();
}
}
...
@@ -64,7 +69,7 @@ public class SolutionsResource
...
@@ -64,7 +69,7 @@ public class SolutionsResource
.
collect
(
Collectors
.
toMap
(
.
collect
(
Collectors
.
toMap
(
Team:
:
getName
,
Team:
:
getName
,
team
->
solutionsRepository
.
getCompletedTasks
(
team
)
team
->
solutionsRepository
.
getCompletedTasks
(
team
)
));
));
}
}
@GET
@GET
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment