Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ecsec Public
reqesidta-prototype
eid-server
Commits
c98c2534
Commit
c98c2534
authored
Oct 08, 2019
by
Tobias Assmann
Browse files
session starting done, add session timing params to config, start working on tctoken function now
parent
88352731
Changes
9
Show whitespace changes
Inline
Side-by-side
ssa-server/server/src/main/java/reqesidta/ssa/api/Init
Process
Request.java
→
ssa-server/server/src/main/java/reqesidta/ssa/api/InitRequest.java
View file @
c98c2534
...
...
@@ -15,7 +15,7 @@ import javax.json.bind.annotation.JsonbProperty;
*
* @author Neil Crossley
*/
public
class
Init
Process
Request
{
public
class
InitRequest
{
@JsonbProperty
(
"sig-alg"
)
public
String
signatureAlgorithm
;
...
...
ssa-server/server/src/main/java/reqesidta/ssa/api/Init
Process
Response.java
→
ssa-server/server/src/main/java/reqesidta/ssa/api/InitResponse.java
View file @
c98c2534
...
...
@@ -15,7 +15,7 @@ import javax.json.bind.annotation.JsonbProperty;
*
* @author Neil Crossley
*/
public
class
Init
Process
Response
{
public
class
InitResponse
{
@JsonbProperty
(
"tc-token-url"
)
public
String
tcTokenUrl
;
...
...
ssa-server/server/src/main/java/reqesidta/ssa/api/SsaService.java
View file @
c98c2534
...
...
@@ -9,35 +9,41 @@
***************************************************************************/
package
reqesidta.ssa.api
;
import
java.util.Optional
;
import
javax.inject.Inject
;
import
javax.json.bind.Jsonb
;
import
javax.json.bind.JsonbBuilder
;
import
javax.json.bind.JsonbConfig
;
import
javax.json.bind.config.BinaryDataStrategy
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.NotFoundException
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.Response
;
import
reqesidta.ssa.sa.CertificateAuthorityClient
;
import
reqesidta.ssa.server.config.SSAConfig
;
import
reqesidta.ssa.session.SessionStore
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
reqesidta.ssa.session.Session
;
/**
*
* @author Neil Crossley
* @author Neil Crossley
, Tobias Assmann
*/
@Path
(
"/"
)
public
class
SsaService
{
Jsonb
jsonb
;
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
SsaService
.
class
)
;
@Inject
SSAConfig
config
;
@Inject
CertificateAuthorityClient
caClient
;
@Inject
SessionStore
sessionStore
;
private
Jsonb
jsonb
;
@Inject
private
SSAConfig
config
;
@Inject
private
CertificateAuthorityClient
caClient
;
@Inject
private
SessionStore
sessionStore
;
public
SsaService
()
{
JsonbConfig
config
=
new
JsonbConfig
()
...
...
@@ -47,27 +53,48 @@ public class SsaService {
}
@POST
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Path
(
"/init"
)
public
Response
init
(
String
json
)
{
var
req
=
jsonb
.
fromJson
(
json
,
InitProcessRequest
.
class
);
public
Response
init
(
String
reqAsJson
)
{
log
.
info
(
"got request:"
+
reqAsJson
);
var
req
=
jsonb
.
fromJson
(
reqAsJson
,
InitRequest
.
class
);
var
session
=
sessionStore
.
getNewSession
();
session
.
set
(
Session
.
KEY_SIGNATURE_ALGORITHM
,
req
.
signatureAlgorithm
);
session
.
set
(
Session
.
KEY_DOCUMENT_HASH
,
req
.
documentHash
);
InitResponse
response
=
new
InitResponse
();
response
.
tcTokenUrl
=
"/tctoken/"
+
session
.
getId
();
String
respAsJson
=
jsonb
.
toJson
(
response
);
log
.
info
(
"send response:"
+
respAsJson
);
return
Response
.
ok
(
respAsJson
).
build
();
}
InitProcessResponse
response
=
new
InitProcessResponse
();
response
.
tcTokenUrl
=
"123456"
+
req
.
signatureAlgorithm
;
@GET
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Path
(
"/tctoken/{sessionId}"
)
public
Response
tcToken
(
@PathParam
(
"sessionId"
)
String
sessionId
)
{
log
.
info
(
"got sessionId:"
+
sessionId
);
String
jsonString
=
jsonb
.
toJson
(
response
);
Optional
<
Session
>
session
=
sessionStore
.
getSession
(
sessionId
);
if
(
session
.
isEmpty
())
{
throw
new
NotFoundException
();
}
//InitResponse response = new InitResponse();
//response.tcTokenUrl = "/createtoken/" + session.getId();
//String respAsJson = jsonb.toJson(response);
return
Response
.
ok
(
jsonString
).
build
();
return
Response
.
ok
(
"{foo:bar}"
).
build
();
}
@POST
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Path
(
"/cert"
)
public
Response
certs
(
CertificateRequest
req
)
{
Init
Process
Response
response
=
new
Init
Process
Response
();
InitResponse
response
=
new
InitResponse
();
response
.
tcTokenUrl
=
"123456"
;
String
jsonString
=
jsonb
.
toJson
(
response
);
...
...
@@ -79,9 +106,9 @@ public class SsaService {
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Path
(
"/sign"
)
public
Response
sign
(
Init
Process
Request
req
)
{
public
Response
sign
(
InitRequest
req
)
{
Init
Process
Response
response
=
new
Init
Process
Response
();
InitResponse
response
=
new
InitResponse
();
response
.
tcTokenUrl
=
"123456"
;
String
jsonString
=
jsonb
.
toJson
(
response
);
...
...
ssa-server/server/src/main/java/reqesidta/ssa/server/config/ConfigLoader.java
View file @
c98c2534
...
...
@@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
@ApplicationScoped
public
class
ConfigLoader
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ConfigLoader
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ConfigLoader
.
class
);
private
final
SSAConfig
configBean
;
...
...
@@ -38,7 +38,7 @@ public class ConfigLoader {
File
path
=
new
File
(
homeDir
,
"ssa-server.conf"
);
// set property to load external file
if
(
path
.
exists
())
{
LOG
.
debug
(
"Loading config {}"
,
path
.
getAbsolutePath
());
log
.
debug
(
"Loading config {}"
,
path
.
getAbsolutePath
());
System
.
setProperty
(
"config.url"
,
path
.
toURI
().
toString
());
}
ConfigFactory
.
invalidateCaches
();
...
...
ssa-server/server/src/main/java/reqesidta/ssa/server/config/SSAConfig.java
View file @
c98c2534
...
...
@@ -15,17 +15,35 @@ package reqesidta.ssa.server.config;
*/
public
class
SSAConfig
{
private
int
testInt
;
private
int
sessionMaxAge
;
private
int
sessionCheckAgeInterval
;
// private String eidBaseUrl;
private
CertificateAuthorityConfig
caConfig
;
public
int
get
T
es
tInt
()
{
return
t
es
tInt
;
public
int
get
S
es
sionMaxAge
()
{
return
s
es
sionMaxAge
;
}
public
void
set
T
es
tInt
(
int
t
es
tInt
)
{
this
.
t
es
tInt
=
t
es
tInt
;
public
void
set
S
es
sionMaxAge
(
int
s
es
sionMaxAge
)
{
this
.
s
es
sionMaxAge
=
s
es
sionMaxAge
;
}
public
int
getSessionCheckAgeInterval
()
{
return
sessionCheckAgeInterval
;
}
public
void
setSessionCheckAgeInterval
(
int
sessionCheckAgeInterval
)
{
this
.
sessionCheckAgeInterval
=
sessionCheckAgeInterval
;
}
// public String getEidBaseUrl() {
// return this.eidBaseUrl;
// }
//
// public void setEidBaseUrl(String eidBaseUrl) {
// this.eidBaseUrl = eidBaseUrl;
// }
public
CertificateAuthorityConfig
getCaConfig
()
{
return
caConfig
;
}
...
...
ssa-server/server/src/main/java/reqesidta/ssa/session/Session.java
0 → 100644
View file @
c98c2534
package
reqesidta.ssa.session
;
import
java.time.Instant
;
import
java.util.HashMap
;
import
java.util.Optional
;
/**
* @author Tobias Assmann <tobias.assmann@ecsec.de>
*/
public
class
Session
{
private
final
String
ID
;
private
Instant
lastAccess
=
Instant
.
now
();
private
final
HashMap
<
String
,
Object
>
map
;
public
final
static
String
KEY_SIGNATURE_ALGORITHM
=
"sig-alg"
;
public
final
static
String
KEY_DOCUMENT_HASH
=
"doc-hash"
;
Session
(
String
ID
)
{
this
.
ID
=
ID
;
this
.
map
=
new
HashMap
<>();
}
Instant
getLastAccess
()
{
return
lastAccess
;
}
public
String
getId
()
{
lastAccess
=
Instant
.
now
();
return
this
.
ID
;
}
public
void
set
(
String
key
,
Object
value
)
{
lastAccess
=
Instant
.
now
();
this
.
map
.
put
(
key
,
value
);
}
public
Optional
<
Object
>
get
(
String
key
)
{
lastAccess
=
Instant
.
now
();
return
Optional
.
ofNullable
(
this
.
map
.
get
(
key
));
}
// public <T> Optional<T> get(String key, Class<T> type) {
// lastAccess = Instant.now();
// Object get = this.map.get(key);
//
// if (get != null && get.getClass().isAssignableFrom(type)) {
// return Optional.of(type.cast(get));
// }
//
// return Optional.empty();
// }
}
ssa-server/server/src/main/java/reqesidta/ssa/session/SessionStore.java
View file @
c98c2534
...
...
@@ -10,28 +10,28 @@ import java.util.UUID;
import
java.util.concurrent.ConcurrentNavigableMap
;
import
java.util.concurrent.ConcurrentSkipListMap
;
import
javax.annotation.PreDestroy
;
import
org.jboss.logging.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Taken from remote_eac branch of Renè
* @author Tobias Assmann <tobias.assmann@ecsec.de>
*/
public
class
SessionStore
{
private
final
static
Logger
LOG
=
Logger
.
getLogger
(
SessionStore
.
class
);
private
static
final
Logger
log
=
Logger
Factory
.
getLogger
(
SessionStore
.
class
);
private
final
Duration
maxAge
;
private
final
Duration
checkAgeInterval
l
;
private
final
Duration
checkAgeInterval
;
private
final
Timer
sessionLifeTime
=
new
Timer
(
"SessionExpireChecker"
,
true
);
private
final
ConcurrentNavigableMap
<
String
,
Session
>
storage
;
public
SessionStore
(
Duration
timeout
)
{
public
SessionStore
(
Duration
timeout
,
Duration
checkAgeInterval
)
{
this
.
storage
=
new
ConcurrentSkipListMap
<>();
this
.
maxAge
=
timeout
;
this
.
checkAgeInterval
l
=
Duration
.
ofMinutes
(
30
)
;
this
.
checkAgeInterval
=
checkAgeInterval
;
LOG
.
debug
(
"Setting up SessionStore ... starting Timer 'SessionExpireChecker'"
);
log
.
debug
(
"Setting up SessionStore ... starting Timer 'SessionExpireChecker'"
);
this
.
startTimer
();
}
...
...
@@ -64,7 +64,7 @@ public class SessionStore {
public
void
run
()
{
removeExpired
();
}
},
0
,
checkAgeInterval
l
.
toMillis
());
},
0
,
checkAgeInterval
.
toMillis
());
}
private
void
stopTimer
()
{
...
...
ssa-server/server/src/main/java/reqesidta/ssa/session/SessionStoreProvider.java
View file @
c98c2534
...
...
@@ -3,19 +3,24 @@ package reqesidta.ssa.session;
import
java.time.Duration
;
import
javax.enterprise.context.ApplicationScoped
;
import
javax.enterprise.inject.Produces
;
import
javax.inject.Inject
;
import
reqesidta.ssa.server.config.SSAConfig
;
/**
*
* Taken from remote_eac branch of Renè
* @author tobias assmann
*/
@ApplicationScoped
public
class
SessionStoreProvider
{
private
final
SessionStore
store
;
private
SessionStore
store
;
public
SessionStoreProvider
()
{
this
.
store
=
new
SessionStore
(
Duration
.
ofHours
(
1
));
@Inject
public
SessionStoreProvider
(
SSAConfig
config
)
{
this
.
store
=
new
SessionStore
(
Duration
.
ofMinutes
((
long
)
config
.
getSessionMaxAge
()),
Duration
.
ofMinutes
((
long
)
config
.
getSessionCheckAgeInterval
())
);
}
@Produces
...
...
ssa-server/server/src/main/resources/reference.conf
View file @
c98c2534
ssa
-
config
{
test
-
int
:
1
,
sessionMaxAge
:
60
,
sessionCheckAgeInterval
:
30
,
ca
-
config
: {
caName
:
'dummy-caName'
,
cmpAlias
:
'dummy-cmp-alias'
,
...
...
Write
Preview
Supports
Markdown
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