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
b1f18eb9
Commit
b1f18eb9
authored
Mar 19, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
huge tasks refactoring
parent
d6b0bd3e
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
186 additions
and
261 deletions
+186
-261
RegisterTasksCommand.java
...honers/krakyournet/ctf/commands/RegisterTasksCommand.java
+6
-35
ApplicationConfiguration.java
...honers/krakyournet/ctf/core/ApplicationConfiguration.java
+25
-24
TextTaskConfig.java
...m/telephoners/krakyournet/ctf/helpers/TextTaskConfig.java
+0
-44
WebTaskConfig.java
...om/telephoners/krakyournet/ctf/helpers/WebTaskConfig.java
+0
-45
Flag.java
...in/java/com/telephoners/krakyournet/ctf/objects/Flag.java
+13
-17
Solution.java
...ava/com/telephoners/krakyournet/ctf/objects/Solution.java
+13
-1
Task.java
...a/com/telephoners/krakyournet/ctf/objects/tasks/Task.java
+8
-32
TaskContent.java
...elephoners/krakyournet/ctf/objects/tasks/TaskContent.java
+0
-7
TaskCryptoContent.java
...ners/krakyournet/ctf/objects/tasks/TaskCryptoContent.java
+0
-23
TaskWebContent.java
...phoners/krakyournet/ctf/objects/tasks/TaskWebContent.java
+0
-23
TextTask.java
...m/telephoners/krakyournet/ctf/objects/tasks/TextTask.java
+34
-0
WebTask.java
...om/telephoners/krakyournet/ctf/objects/tasks/WebTask.java
+34
-0
TasksRepository.java
...phoners/krakyournet/ctf/repositories/TasksRepository.java
+49
-5
SolutionsResource.java
...ephoners/krakyournet/ctf/resources/SolutionsResource.java
+1
-1
TaskResource.java
...m/telephoners/krakyournet/ctf/resources/TaskResource.java
+3
-4
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/commands/RegisterTasksCommand.java
View file @
b1f18eb9
...
@@ -3,21 +3,15 @@ package com.telephoners.krakyournet.ctf.commands;
...
@@ -3,21 +3,15 @@ package com.telephoners.krakyournet.ctf.commands;
import
com.google.inject.Guice
;
import
com.google.inject.Guice
;
import
com.google.inject.Injector
;
import
com.google.inject.Injector
;
import
com.telephoners.krakyournet.ctf.core.ApplicationConfiguration
;
import
com.telephoners.krakyournet.ctf.core.ApplicationConfiguration
;
import
com.telephoners.krakyournet.ctf.core.TaskType
;
import
com.telephoners.krakyournet.ctf.helpers.TextTaskConfig
;
import
com.telephoners.krakyournet.ctf.helpers.WebTaskConfig
;
import
com.telephoners.krakyournet.ctf.modules.ApplicationModule
;
import
com.telephoners.krakyournet.ctf.modules.ApplicationModule
;
import
com.telephoners.krakyournet.ctf.objects.Flag
;
import
com.telephoners.krakyournet.ctf.objects.tasks.TextTask
;
import
com.telephoners.krakyournet.ctf.objects.tasks.Task
;
import
com.telephoners.krakyournet.ctf.objects.tasks.WebTask
;
import
com.telephoners.krakyournet.ctf.objects.tasks.TaskCryptoContent
;
import
com.telephoners.krakyournet.ctf.objects.tasks.TaskWebContent
;
import
com.telephoners.krakyournet.ctf.repositories.TasksRepository
;
import
com.telephoners.krakyournet.ctf.repositories.TasksRepository
;
import
io.dropwizard.cli.ConfiguredCommand
;
import
io.dropwizard.cli.ConfiguredCommand
;
import
io.dropwizard.setup.Bootstrap
;
import
io.dropwizard.setup.Bootstrap
;
import
net.sourceforge.argparse4j.inf.Namespace
;
import
net.sourceforge.argparse4j.inf.Namespace
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
public
class
RegisterTasksCommand
extends
ConfiguredCommand
<
ApplicationConfiguration
>
public
class
RegisterTasksCommand
extends
ConfiguredCommand
<
ApplicationConfiguration
>
{
{
...
@@ -33,36 +27,13 @@ public class RegisterTasksCommand extends ConfiguredCommand<ApplicationConfigura
...
@@ -33,36 +27,13 @@ public class RegisterTasksCommand extends ConfiguredCommand<ApplicationConfigura
{
{
TasksRepository
tasksRepository
=
injector
.
getInstance
(
TasksRepository
.
class
);
TasksRepository
tasksRepository
=
injector
.
getInstance
(
TasksRepository
.
class
);
List
<
TextTask
Config
>
cryptoTasks
=
applicationConfiguration
.
getTextTasks
();
List
<
TextTask
>
cryptoTasks
=
applicationConfiguration
.
getTextTasks
();
List
<
WebTask
Config
>
webTasks
=
applicationConfiguration
.
getWebTasks
();
List
<
WebTask
>
webTasks
=
applicationConfiguration
.
getWebTasks
();
tasksRepository
.
clean
();
tasksRepository
.
clean
();
cryptoTasks
.
forEach
(
cryptoTaskConfig
->
{
cryptoTaskConfig
.
getFlags
().
stream
()
cryptoTasks
.
forEach
(
tasksRepository:
:
add
);
.
map
(
Flag:
:
new
)
webTasks
.
forEach
(
tasksRepository:
:
add
);
.
collect
(
Collectors
.
toList
());
tasksRepository
.
add
(
new
Task
(
cryptoTaskConfig
.
getName
(),
cryptoTaskConfig
.
getLevel
(),
TaskType
.
TEXT
,
cryptoTaskConfig
.
getFlags
().
stream
()
.
map
(
Flag:
:
new
)
.
collect
(
Collectors
.
toList
()),
new
TaskCryptoContent
(
cryptoTaskConfig
.
getText
())
));
});
webTasks
.
forEach
(
webTaskConfig
->
tasksRepository
.
add
(
new
Task
(
webTaskConfig
.
getName
(),
webTaskConfig
.
getLevel
(),
TaskType
.
WEB
,
webTaskConfig
.
getFlags
().
stream
()
.
map
(
Flag:
:
new
)
.
collect
(
Collectors
.
toList
()),
new
TaskWebContent
(
webTaskConfig
.
getUrl
())
)));
}
}
@Override
@Override
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/core/ApplicationConfiguration.java
View file @
b1f18eb9
package
com
.
telephoners
.
krakyournet
.
ctf
.
core
;
package
com
.
telephoners
.
krakyournet
.
ctf
.
core
;
import
com.telephoners.krakyournet.ctf.helpers.TextTaskConfig
;
import
com.telephoners.krakyournet.ctf.helpers.WebTaskConfig
;
import
com.telephoners.krakyournet.ctf.objects.Team
;
import
com.telephoners.krakyournet.ctf.objects.Team
;
import
com.telephoners.krakyournet.ctf.objects.User
;
import
com.telephoners.krakyournet.ctf.objects.User
;
import
com.telephoners.krakyournet.ctf.objects.tasks.Task
;
import
com.telephoners.krakyournet.ctf.objects.tasks.TextTask
;
import
com.telephoners.krakyournet.ctf.objects.tasks.WebTask
;
import
io.dropwizard.Configuration
;
import
io.dropwizard.Configuration
;
import
java.util.List
;
import
java.util.List
;
...
@@ -15,8 +16,8 @@ public class ApplicationConfiguration extends Configuration
...
@@ -15,8 +16,8 @@ public class ApplicationConfiguration extends Configuration
private
String
dbName
;
private
String
dbName
;
private
String
flagHashMethod
;
private
String
flagHashMethod
;
private
List
<
Team
>
teams
;
private
List
<
Team
>
teams
;
private
List
<
TextTask
Config
>
textTasks
;
private
List
<
TextTask
>
textTasks
;
private
List
<
WebTask
Config
>
webTasks
;
private
List
<
WebTask
>
webTasks
;
private
List
<
User
>
admins
;
private
List
<
User
>
admins
;
public
List
<
User
>
getAdmins
()
public
List
<
User
>
getAdmins
()
...
@@ -29,26 +30,6 @@ public class ApplicationConfiguration extends Configuration
...
@@ -29,26 +30,6 @@ public class ApplicationConfiguration extends Configuration
this
.
admins
=
admins
;
this
.
admins
=
admins
;
}
}
public
List
<
TextTaskConfig
>
getTextTasks
()
{
return
textTasks
;
}
public
void
setTextTasks
(
List
<
TextTaskConfig
>
textTasks
)
{
this
.
textTasks
=
textTasks
;
}
public
List
<
WebTaskConfig
>
getWebTasks
()
{
return
webTasks
;
}
public
void
setWebTasks
(
List
<
WebTaskConfig
>
webTasks
)
{
this
.
webTasks
=
webTasks
;
}
public
String
getFlagHashMethod
()
public
String
getFlagHashMethod
()
{
{
return
flagHashMethod
;
return
flagHashMethod
;
...
@@ -98,4 +79,24 @@ public class ApplicationConfiguration extends Configuration
...
@@ -98,4 +79,24 @@ public class ApplicationConfiguration extends Configuration
{
{
this
.
dbName
=
dbName
;
this
.
dbName
=
dbName
;
}
}
public
List
<
TextTask
>
getTextTasks
()
{
return
textTasks
;
}
public
void
setTextTasks
(
List
<
TextTask
>
textTasks
)
{
this
.
textTasks
=
textTasks
;
}
public
List
<
WebTask
>
getWebTasks
()
{
return
webTasks
;
}
public
void
setWebTasks
(
List
<
WebTask
>
webTasks
)
{
this
.
webTasks
=
webTasks
;
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/helpers/TextTaskConfig.java
deleted
100644 → 0
View file @
d6b0bd3e
package
com
.
telephoners
.
krakyournet
.
ctf
.
helpers
;
import
java.util.List
;
public
class
TextTaskConfig
{
private
String
name
;
private
int
level
;
private
String
text
;
private
List
<
String
>
flags
;
//todo: refactor, map directly to Flag class?
public
String
getName
()
{
return
name
;
}
public
int
getLevel
()
{
return
level
;
}
public
void
setLevel
(
int
level
)
{
this
.
level
=
level
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getText
()
{
return
text
;
}
public
void
setText
(
String
text
)
{
this
.
text
=
text
;
}
public
List
<
String
>
getFlags
()
{
return
flags
;
}
public
void
setFlags
(
List
<
String
>
flags
)
{
this
.
flags
=
flags
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/helpers/WebTaskConfig.java
deleted
100644 → 0
View file @
d6b0bd3e
package
com
.
telephoners
.
krakyournet
.
ctf
.
helpers
;
import
java.util.List
;
/**
* Created by gpietrus on 23.02.2016.
*/
public
class
WebTaskConfig
{
private
String
name
;
private
String
url
;
private
int
level
;
private
List
<
String
>
flags
;
public
String
getName
()
{
return
name
;
}
public
int
getLevel
()
{
return
level
;
}
public
void
setLevel
(
int
level
)
{
this
.
level
=
level
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
List
<
String
>
getFlags
()
{
return
flags
;
}
public
void
setFlags
(
List
<
String
>
flags
)
{
this
.
flags
=
flags
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/objects/Flag.java
View file @
b1f18eb9
package
com
.
telephoners
.
krakyournet
.
ctf
.
objects
;
package
com
.
telephoners
.
krakyournet
.
ctf
.
objects
;
import
java.util.Random
;
/**
* Created by gpietrus on 20.02.2016.
*/
public
class
Flag
{
public
class
Flag
{
private
String
value
;
private
String
value
;
private
static
int
flagLength
=
32
;
private
String
description
;
public
Flag
()
{
public
Flag
()
{
}
}
public
Flag
(
String
value
)
{
public
Flag
(
String
value
,
String
description
)
{
this
.
value
=
value
;
this
.
value
=
value
;
}
this
.
description
=
description
;
public
static
Flag
newRandomFlag
()
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
stringBuilder
.
append
(
"AGH_CTF_"
);
for
(
int
i
=
0
;
i
<
flagLength
;
i
++)
{
char
c
=
(
char
)
(
new
Random
().
nextInt
(
128
-
32
)
+
32
);
stringBuilder
.
append
(
c
);
}
return
new
Flag
(
stringBuilder
.
toString
());
}
}
public
String
getValue
()
{
public
String
getValue
()
{
...
@@ -33,4 +19,14 @@ public class Flag {
...
@@ -33,4 +19,14 @@ public class Flag {
public
void
setValue
(
String
value
)
{
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
this
.
value
=
value
;
}
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/objects/Solution.java
View file @
b1f18eb9
...
@@ -12,11 +12,13 @@ public class Solution
...
@@ -12,11 +12,13 @@ public class Solution
private
ObjectId
id
;
private
ObjectId
id
;
private
Task
task
;
private
Task
task
;
private
Team
team
;
private
Team
team
;
private
Flag
flag
;
public
Solution
(
Team
team
,
Task
task
)
public
Solution
(
Team
team
,
Task
task
,
Flag
flag
)
{
{
this
.
team
=
team
;
this
.
team
=
team
;
this
.
task
=
task
;
this
.
task
=
task
;
this
.
flag
=
flag
;
}
}
public
Solution
()
public
Solution
()
...
@@ -42,4 +44,14 @@ public class Solution
...
@@ -42,4 +44,14 @@ public class Solution
{
{
return
team
;
return
team
;
}
}
public
Flag
getFlag
()
{
return
flag
;
}
public
void
setFlag
(
Flag
flag
)
{
this
.
flag
=
flag
;
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/objects/tasks/Task.java
View file @
b1f18eb9
...
@@ -12,25 +12,21 @@ import java.util.List;
...
@@ -12,25 +12,21 @@ import java.util.List;
@Entity
(
"tasks"
)
@Entity
(
"tasks"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
Task
public
abstract
class
Task
{
{
@Id
@Id
pr
ivate
ObjectId
id
;
pr
otected
ObjectId
id
;
@PublicProperty
@PublicProperty
pr
ivate
String
name
;
pr
otected
String
name
;
@PublicProperty
@PublicProperty
private
int
level
;
protected
int
level
;
private
TaskType
taskType
;
protected
List
<
Flag
>
flags
;
private
List
<
Flag
>
flags
;
private
TaskContent
taskContent
;
public
Task
(
String
name
,
int
level
,
TaskType
type
,
List
<
Flag
>
flags
,
TaskContent
taskContent
)
public
Task
(
String
name
,
int
level
,
List
<
Flag
>
flags
)
{
{
this
.
flags
=
flags
;
this
.
taskType
=
type
;
this
.
level
=
level
;
this
.
name
=
name
;
this
.
name
=
name
;
this
.
taskContent
=
taskContent
;
this
.
level
=
level
;
this
.
flags
=
flags
;
}
}
public
Task
()
public
Task
()
...
@@ -57,16 +53,6 @@ public class Task
...
@@ -57,16 +53,6 @@ public class Task
this
.
level
=
level
;
this
.
level
=
level
;
}
}
public
TaskType
getTaskType
()
{
return
taskType
;
}
public
void
setTaskType
(
TaskType
taskType
)
{
this
.
taskType
=
taskType
;
}
public
List
<
Flag
>
getFlags
()
public
List
<
Flag
>
getFlags
()
{
{
return
flags
;
return
flags
;
...
@@ -76,14 +62,4 @@ public class Task
...
@@ -76,14 +62,4 @@ public class Task
{
{
this
.
flags
=
flags
;
this
.
flags
=
flags
;
}
}
public
TaskContent
getTaskContent
()
{
return
taskContent
;
}
public
void
setTaskContent
(
TaskContent
taskContent
)
{
this
.
taskContent
=
taskContent
;
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/objects/tasks/TaskContent.java
deleted
100644 → 0
View file @
d6b0bd3e
package
com
.
telephoners
.
krakyournet
.
ctf
.
objects
.
tasks
;
/**
* Created by gpietrus on 23.02.2016.
*/
public
abstract
class
TaskContent
{
}
service/src/main/java/com/telephoners/krakyournet/ctf/objects/tasks/TaskCryptoContent.java
deleted
100644 → 0
View file @
d6b0bd3e
package
com
.
telephoners
.
krakyournet
.
ctf
.
objects
.
tasks
;
/**
* Created by gpietrus on 23.02.2016.
*/
public
class
TaskCryptoContent
extends
TaskContent
{
private
String
text
;
public
TaskCryptoContent
(
String
text
)
{
this
.
text
=
text
;
}
public
TaskCryptoContent
()
{}
public
String
getText
()
{
return
text
;
}
public
void
setText
(
String
text
)
{
this
.
text
=
text
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/objects/tasks/TaskWebContent.java
deleted
100644 → 0
View file @
d6b0bd3e
package
com
.
telephoners
.
krakyournet
.
ctf
.
objects
.
tasks
;
/**
* Created by gpietrus on 23.02.2016.
*/
public
class
TaskWebContent
extends
TaskContent
{
private
String
url
;
public
TaskWebContent
(
String
url
)
{
this
.
url
=
url
;
}
public
TaskWebContent
()
{}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/objects/tasks/TextTask.java
0 → 100644
View file @
b1f18eb9
package
com
.
telephoners
.
krakyournet
.
ctf
.
objects
.
tasks
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.telephoners.krakyournet.ctf.objects.Flag
;
import
org.mongodb.morphia.annotations.Entity
;
import
java.util.List
;
@Entity
(
"tasks"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
TextTask
extends
Task
{
private
String
text
;
public
TextTask
(
String
name
,
int
level
,
List
<
Flag
>
flags
,
String
text
)
{
super
(
name
,
level
,
flags
);
this
.
text
=
text
;
}
public
TextTask
()
{
}
public
String
getText
()
{
return
text
;
}
public
void
setText
(
String
text
)
{
this
.
text
=
text
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/objects/tasks/WebTask.java
0 → 100644
View file @
b1f18eb9
package
com
.
telephoners
.
krakyournet
.
ctf
.
objects
.
tasks
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.telephoners.krakyournet.ctf.objects.Flag
;
import
org.mongodb.morphia.annotations.Entity
;
import
java.util.List
;
@Entity
(
"tasks"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
WebTask
extends
Task
{
private
String
url
;
public
WebTask
(
String
name
,
int
level
,
List
<
Flag
>
flags
,
String
url
)
{
super
(
name
,
level
,
flags
);
this
.
url
=
url
;
}
public
WebTask
()
{
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/TasksRepository.java
View file @
b1f18eb9
...
@@ -2,8 +2,10 @@ package com.telephoners.krakyournet.ctf.repositories;
...
@@ -2,8 +2,10 @@ package com.telephoners.krakyournet.ctf.repositories;
import
com.telephoners.krakyournet.ctf.core.ApplicationConfiguration
;
import
com.telephoners.krakyournet.ctf.core.ApplicationConfiguration
;
import
com.telephoners.krakyournet.ctf.helpers.DBObjectUtils
;
import
com.telephoners.krakyournet.ctf.helpers.DBObjectUtils
;
import
com.telephoners.krakyournet.ctf.objects.Flag
;
import
com.telephoners.krakyournet.ctf.objects.Solution
;
import
com.telephoners.krakyournet.ctf.objects.Solution
;
import
com.telephoners.krakyournet.ctf.objects.Team
;
import
com.telephoners.krakyournet.ctf.objects.Team
;
import
com.telephoners.krakyournet.ctf.objects.User
;
import
com.telephoners.krakyournet.ctf.objects.tasks.Task
;
import
com.telephoners.krakyournet.ctf.objects.tasks.Task
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.commons.codec.binary.Hex
;
import
org.mongodb.morphia.Datastore
;
import
org.mongodb.morphia.Datastore
;
...
@@ -15,6 +17,8 @@ import java.security.NoSuchAlgorithmException;
...
@@ -15,6 +17,8 @@ import java.security.NoSuchAlgorithmException;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.function.Function
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Singleton
@Singleton
...
@@ -25,7 +29,7 @@ public class TasksRepository implements Repository
...
@@ -25,7 +29,7 @@ public class TasksRepository implements Repository
private
Datastore
datastore
;
private
Datastore
datastore
;
private
TeamsRepository
teamsRepository
;
private
TeamsRepository
teamsRepository
;
private
SolutionsRepository
solutionsRepository
;
private
SolutionsRepository
solutionsRepository
;
private
String
salt
=
"SECURE_SALT"
;
//todo
private
String
salt
=
"SECURE_SALT"
;
//todo
: move to configuration!
@Inject
@Inject
public
TasksRepository
(
ApplicationConfiguration
applicationConfiguration
,
Datastore
datastore
,
public
TasksRepository
(
ApplicationConfiguration
applicationConfiguration
,
Datastore
datastore
,
...
@@ -83,6 +87,44 @@ public class TasksRepository implements Repository
...
@@ -83,6 +87,44 @@ public class TasksRepository implements Repository
));
));
}
}
private
Optional
<
Task
>
getTaskFlagByHashValue
(
User
user
,
String
userHash
)
{
String
username
=
user
.
getName
();
//todo: inline
//todo: collapse lambdas
List
<
Task
>
tasks
=
this
.
getAll
();
Optional
<
Task
>
task
=
tasks
.
stream
()
.
filter
(
new
Predicate
<
Task
>()
{
@Override
public
boolean
test
(
Task
task
)
{
return
task
.
getFlags
()
.
stream
()
.
map
(
new
Function
<
Flag
,
String
>()
{
@Override
public
String
apply
(
Flag
flag
)
{
return
calculateHashValue
(
username
,
flag
.
getValue
());
}
})
.
filter
(
new
Predicate
<
String
>()
{
@Override
public
boolean
test
(
String
flagValue
)
{
return
flagValue
.
equals
(
userHash
);
}
})
.
findFirst
()
.
isPresent
();
}
})
.
findFirst
();
return
task
;
}
public
String
calculateHashValue
(
String
username
,
String
flagValue
)
public
String
calculateHashValue
(
String
username
,
String
flagValue
)
{
//todo
{
//todo
String
combinedStrings
=
salt
+
username
+
flagValue
;
//todo
String
combinedStrings
=
salt
+
username
+
flagValue
;
//todo
...
@@ -96,12 +138,14 @@ public class TasksRepository implements Repository
...
@@ -96,12 +138,14 @@ public class TasksRepository implements Repository
return
encodedHash
;
return
encodedHash
;
}
}
public
boolean
checkFlag
(
String
username
,
String
flag
Value
)
public
boolean
checkFlag
(
User
user
,
String
hash
Value
)
{
{
Optional
<
Task
>
task
=
getByUserFlag
(
username
,
flagValue
);
Optional
<
Team
>
team
=
teamsRepository
.
getTeamByUserName
(
username
);
Optional
<
Task
>
task
=
getTaskFlagByHashValue
(
user
,
hashValue
);
// Optional<Task> task = getByUserFlag(username, hashValue);
Optional
<
Team
>
team
=
teamsRepository
.
getTeamByUser
(
user
);
if
(
task
.
isPresent
()
&&
team
.
isPresent
())
{
if
(
task
.
isPresent
()
&&
team
.
isPresent
())
{
solutionsRepository
.
add
(
new
Solution
(
team
.
get
(),
task
.
get
()
));
solutionsRepository
.
add
(
new
Solution
(
team
.
get
(),
task
.
get
()
,
null
));
//todo
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/resources/SolutionsResource.java
View file @
b1f18eb9
...
@@ -37,7 +37,7 @@ public class SolutionsResource {
...
@@ -37,7 +37,7 @@ public class SolutionsResource {
public
Response
submitSolution
(
@Auth
User
user
,
public
Response
submitSolution
(
@Auth
User
user
,
String
flag
)
throws
Exception
String
flag
)
throws
Exception
{
{
if
(
tasksRepository
.
checkFlag
(
user
.
getName
()
,
flag
))
{
if
(
tasksRepository
.
checkFlag
(
user
,
flag
))
{
return
Response
.
ok
().
build
();
return
Response
.
ok
().
build
();
}
}
return
Response
.
status
(
Response
.
Status
.
NOT_ACCEPTABLE
).
build
();
return
Response
.
status
(
Response
.
Status
.
NOT_ACCEPTABLE
).
build
();
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/resources/TaskResource.java
View file @
b1f18eb9
...
@@ -2,8 +2,6 @@ package com.telephoners.krakyournet.ctf.resources;
...
@@ -2,8 +2,6 @@ package com.telephoners.krakyournet.ctf.resources;
import
com.telephoners.krakyournet.ctf.objects.User
;
import
com.telephoners.krakyournet.ctf.objects.User
;
import
com.telephoners.krakyournet.ctf.objects.tasks.Task
;
import
com.telephoners.krakyournet.ctf.objects.tasks.Task
;
import
com.telephoners.krakyournet.ctf.objects.tasks.TaskCryptoContent
;
import
com.telephoners.krakyournet.ctf.objects.tasks.TaskWebContent
;
import
com.telephoners.krakyournet.ctf.repositories.TasksRepository
;
import
com.telephoners.krakyournet.ctf.repositories.TasksRepository
;
import
io.dropwizard.auth.Auth
;
import
io.dropwizard.auth.Auth
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpEntity
;
...
@@ -49,14 +47,15 @@ public class TaskResource
...
@@ -49,14 +47,15 @@ public class TaskResource
String
taskText
=
null
;
String
taskText
=
null
;
switch
(
task
.
getTaskType
())
{
/*
switch (task.getTaskType()) {
case TEXT:
case TEXT:
taskText = ((TaskCryptoContent) task.getTaskContent()).getText();
taskText = ((TaskCryptoContent) task.getTaskContent()).getText();
break;
break;
case WEB:
case WEB:
taskText = readStream(proxyRequest(((TaskWebContent) task.getTaskContent()).getUrl(), user));
taskText = readStream(proxyRequest(((TaskWebContent) task.getTaskContent()).getUrl(), user));
break;
break;
}
}*/
//todo!!!!!
return
Response
.
ok
().
entity
(
taskText
).
build
();
return
Response
.
ok
().
entity
(
taskText
).
build
();
}
}
...
...
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