public class SecurityService
extends java.lang.Object
implements jadex.bridge.service.types.security.ISecurityService
Modifier and Type | Field and Description |
---|---|
protected boolean |
argstrustedlan
Determines if trusted lan was specified during creation.
|
protected boolean |
argsusepass
Determines if password was specified during creation.
|
protected jadex.bridge.IInternalAccess |
component
The component.
|
protected jadex.bridge.service.types.context.IContextService |
contextser
The ContextService.
|
protected java.util.Map<java.lang.String,jadex.commons.Tuple2<java.lang.Long,byte[]>> |
digests
The currently valid digests.
|
protected java.lang.String |
keypass
The key password.
|
protected java.security.KeyStore |
keystore
The keystore.
|
protected java.util.List<AAcquisitionMechanism> |
mechanisms
The list of key aquire mechanisms.
|
protected java.util.List<java.net.InetAddress> |
networkips
The network ips, cached for speed.
|
protected java.util.Map<java.lang.String,java.lang.String> |
networkpasses
The stored passwords.
|
protected java.lang.String |
password
The local password (if any).
|
protected java.util.Map<java.lang.String,java.lang.String> |
platformpasses
The stored passwords.
|
protected boolean |
printpass
Print password on startup or change.
|
static java.lang.String |
PROEPRTIES_ID
Properties id for the settings service.
|
protected int |
selmech
The currently selected mechanism.
|
protected jadex.bridge.service.IServiceIdentifier |
sid
The service id.
|
protected java.lang.String |
storepass
The keystore password.
|
protected java.lang.String |
storepath
The path to the keystore.
|
protected java.util.Set<jadex.commons.future.SubscriptionIntermediateFuture<jadex.commons.ChangeEvent<java.lang.Object>>> |
subscribers
The futures of active subscribers.
|
protected boolean |
trustedlan
The trusted lan mode.
|
protected boolean |
usepass
Flag to enable / disable password protection.
|
protected long |
valdur
The default message validity duration.
|
protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
virtualsmap
The mappings of virtual names to platform names.
|
CERTIFICATE, KEYPAIR, PROPERTY_KEYSTOREENTRIES, PROPERTY_KEYSTORESETTINGS, PROPERTY_LOCALPASS, PROPERTY_MECHANISMPARAMETER, PROPERTY_NETWORKPASS, PROPERTY_PLATFORMPASS, PROPERTY_SELECTEDMECHANISM, PROPERTY_TRUSTEDLAN, PROPERTY_USEPASS, PROPERTY_VALIDITYDURATION, PROPERTY_VIRTUALS, TRUSTED_CERTIFICATE
Constructor and Description |
---|
SecurityService()
Create a security service.
|
SecurityService(java.lang.Boolean usepass,
boolean printpass,
java.lang.Boolean trustedlan,
java.lang.String[] networknames,
java.lang.String[] networkpasses)
Create a security service.
|
SecurityService(java.lang.Boolean usepass,
boolean printpass,
java.lang.Boolean trustedlan,
java.lang.String[] networknames,
java.lang.String[] networkpasses,
AAcquisitionMechanism[] mechanisms,
java.util.Map<java.lang.String,java.util.Set<java.lang.String>> namemap,
java.lang.Long valdur)
Create a security service.
|
Modifier and Type | Method and Description |
---|---|
protected jadex.commons.future.IFuture<java.security.cert.Certificate> |
acquireCertificate(java.lang.String name)
Delegates an acquire certificate call to the selected
(or no) mechanism.
|
jadex.commons.future.IFuture<java.lang.Void> |
addPlatformCertificate(jadex.bridge.IComponentIdentifier cid,
java.security.cert.Certificate cert)
Add a trusted certificate of a platform.
|
jadex.commons.future.IFuture<java.lang.Void> |
addVirtual(java.lang.String virtual,
java.lang.String name)
Add a name to the mappings of a virtual name.
|
static byte[] |
buildDigest(byte[] input)
Build the digest given the timestamp and password.
|
static byte[] |
buildDigest(long timestamp,
java.lang.String secret)
Build the digest given the timestamp and password.
|
static boolean |
checkDigest(byte[] test,
java.util.List<byte[]> digests)
Check if the test digest in contained in the digest list.
|
java.lang.String |
checkDigests(jadex.bridge.service.types.security.IAuthorizable request,
java.lang.String password,
java.util.Map<java.lang.String,java.lang.String> networkpasses)
Check if there is a shared secret.
|
jadex.commons.future.IFuture<java.lang.Void> |
checkVirtual(java.lang.String[] virtuals,
java.lang.String name)
Check if the name belongs to the mappings of one
of the virtual names.
|
jadex.commons.future.IFuture<java.lang.Void> |
createKeyPair(jadex.bridge.IComponentIdentifier cid,
java.lang.String algorithm,
int keysize,
java.lang.String pass,
int validity)
Create a key pair entry (with associated certificate).
|
jadex.commons.future.IFuture<java.util.List<jadex.bridge.service.types.security.MechanismInfo>> |
getAcquisitionMechanisms()
Get the supported certificate acquire mechanism infos.
|
protected jadex.commons.future.IFuture<java.security.cert.Certificate> |
getCertificate(java.lang.String name)
Get a certificate with an alias name.
|
jadex.bridge.IInternalAccess |
getComponent()
Get the component.
|
byte[] |
getDigest(long timestamp,
java.lang.String secret)
Get the digest.
|
protected java.security.KeyStore |
getKeyStore()
Get the keystore.
|
jadex.commons.future.IFuture<java.util.Map<java.lang.String,jadex.bridge.service.types.security.KeyStoreEntry>> |
getKeystoreDetails()
Get info about the current keystore that is used.
|
jadex.commons.future.IFuture<java.lang.String[]> |
getKeystoreInfo()
Set the keystore info.
|
jadex.commons.future.IFuture<java.lang.String> |
getLocalPassword()
Get the local password.
|
protected AAcquisitionMechanism |
getMechanism(java.lang.Class<?> type)
Get the mechanism for a type.
|
jadex.commons.future.IFuture<java.lang.String> |
getNetworkPassword(java.lang.String network)
Get the password for a network.
|
jadex.commons.future.IFuture<java.util.Map<java.lang.String,java.lang.String>> |
getNetworkPasswords()
Get all stored network passwords.
|
jadex.commons.future.IFuture<java.security.cert.Certificate> |
getPlatformCertificate(jadex.bridge.IComponentIdentifier cid)
Get the certificate of a platform.
|
jadex.commons.future.IFuture<java.lang.String> |
getPlatformPassword(jadex.bridge.IComponentIdentifier target)
Get the password for a target component.
|
jadex.commons.future.IFuture<java.util.Map<java.lang.String,java.lang.String>> |
getPlatformPasswords()
Get all stored passwords.
|
jadex.commons.future.IFuture<java.lang.Integer> |
getSelectedAcquisitionMechanism()
Get the active acquisition mechanism.
|
jadex.bridge.service.IServiceIdentifier |
getServiceIdentifier()
Get the service identifier.
|
jadex.commons.future.IFuture<jadex.bridge.service.types.settings.ISettingsService> |
getSettingsService()
Get the settings service.
|
jadex.commons.future.IFuture<java.lang.Long> |
getValidityDuration()
Get the validity duration.
|
jadex.commons.future.IFuture<java.util.Map<java.lang.String,java.util.Set<java.lang.String>>> |
getVirtuals()
Get the virtual names and their contents.
|
jadex.commons.future.IFuture<java.lang.Boolean> |
isTrustedLanMode()
Get the trusted lan mode.
|
jadex.commons.future.IFuture<java.lang.Boolean> |
isUsePassword()
Check if password protection is enabled.
|
static void |
main(java.lang.String[] args)
Main for testing.
|
jadex.commons.future.IFuture<java.lang.Void> |
preprocessRequest(jadex.bridge.service.types.security.IAuthorizable request,
jadex.bridge.IComponentIdentifier target)
Preprocess a request.
|
protected void |
publishCurrentState()
Publish the current state.
|
protected void |
publishEvent(jadex.commons.ChangeEvent<java.lang.Object> event)
Publish events to all subscribers.
|
jadex.commons.future.IFuture<java.lang.Void> |
removeKeyStoreEntry(java.lang.String alias)
Remove a key store entry.
|
jadex.commons.future.IFuture<java.lang.Void> |
removeVirtual(java.lang.String virtual,
java.lang.String name)
Remove a name from the mappings of a virtual name.
|
protected void |
saveKeyStore()
Save the keystore.
|
jadex.commons.future.IFuture<java.lang.Void> |
setAcquisitionMechanism(java.lang.Class<?> type)
Set the acquire mechanism.
|
jadex.commons.future.IFuture<java.lang.Void> |
setAcquisitionMechanismParameterValue(java.lang.Class<?> type,
java.lang.String name,
java.lang.Object value)
Set a mechanism parameter.
|
jadex.commons.future.IFuture<java.lang.Void> |
setKeystoreInfo(java.lang.String storepath,
java.lang.String storepass,
java.lang.String keypass)
Set the keystore info.
|
jadex.commons.future.IFuture<java.lang.Void> |
setLocalPassword(java.lang.String password)
Set the local password.
|
jadex.commons.future.IFuture<java.lang.Void> |
setNetworkPassword(java.lang.String network,
java.lang.String password)
Set the password for a network.
|
jadex.commons.future.IFuture<java.lang.Void> |
setPlatformPassword(jadex.bridge.IComponentIdentifier target,
java.lang.String password)
Set the password for a target component.
|
jadex.commons.future.IFuture<java.lang.Void> |
setTrustedLanMode(boolean allowed)
Set the trusted lan mode.
|
jadex.commons.future.IFuture<java.lang.Void> |
setUsePassword(boolean enable)
Enable / disable password protection.
|
jadex.commons.future.IFuture<java.lang.Void> |
setValidityDuration(long validityduration)
Set the validity duration.
|
jadex.commons.future.IFuture<java.lang.Void> |
shutdown()
Shutdown the service.
|
jadex.commons.future.IFuture<byte[]> |
signCall(byte[] content)
Sign a byte[] with the platform key that is stored in the
keystore under the platform prefix name.
|
jadex.commons.future.IFuture<java.lang.Void> |
start()
Start the service.
|
jadex.commons.future.ISubscriptionIntermediateFuture<jadex.commons.ChangeEvent<java.lang.Object>> |
subscribeToEvents()
Subscribe to changes.
|
jadex.commons.future.IFuture<java.lang.Void> |
validateRequest(jadex.bridge.service.types.security.IAuthorizable request)
Validate a request.
|
boolean |
verifyCall(byte[] content,
byte[] signed,
java.security.cert.Certificate cert)
Internal verify method that just checks if f-pubkey(content)=signed.
|
jadex.commons.future.IFuture<java.lang.Void> |
verifyCall(byte[] content,
byte[] signed,
java.lang.String name)
Verify an authenticated service call.
|
public static final java.lang.String PROEPRTIES_ID
protected jadex.bridge.IInternalAccess component
protected jadex.bridge.service.IServiceIdentifier sid
protected boolean usepass
protected boolean argsusepass
protected boolean printpass
protected java.lang.String password
protected java.util.Map<java.lang.String,java.lang.String> platformpasses
protected java.util.Map<java.lang.String,java.lang.String> networkpasses
protected boolean trustedlan
protected boolean argstrustedlan
protected long valdur
protected java.lang.String storepath
protected java.lang.String storepass
protected java.lang.String keypass
protected jadex.bridge.service.types.context.IContextService contextser
protected java.util.Map<java.lang.String,jadex.commons.Tuple2<java.lang.Long,byte[]>> digests
protected java.security.KeyStore keystore
protected java.util.List<AAcquisitionMechanism> mechanisms
protected int selmech
protected java.util.Set<jadex.commons.future.SubscriptionIntermediateFuture<jadex.commons.ChangeEvent<java.lang.Object>>> subscribers
protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> virtualsmap
protected java.util.List<java.net.InetAddress> networkips
public SecurityService()
public SecurityService(java.lang.Boolean usepass, boolean printpass, java.lang.Boolean trustedlan, java.lang.String[] networknames, java.lang.String[] networkpasses)
public SecurityService(java.lang.Boolean usepass, boolean printpass, java.lang.Boolean trustedlan, java.lang.String[] networknames, java.lang.String[] networkpasses, AAcquisitionMechanism[] mechanisms, java.util.Map<java.lang.String,java.util.Set<java.lang.String>> namemap, java.lang.Long valdur)
public jadex.commons.future.IFuture<java.lang.Void> start()
public jadex.commons.future.IFuture<jadex.bridge.service.types.settings.ISettingsService> getSettingsService()
public jadex.commons.future.IFuture<java.lang.Void> shutdown()
protected java.security.KeyStore getKeyStore()
public jadex.commons.future.IFuture<java.lang.Boolean> isUsePassword()
isUsePassword
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Void> setUsePassword(boolean enable)
setUsePassword
in interface jadex.bridge.service.types.security.ISecurityService
enable
- If true, password protection is enabled, otherwise disabled.Exception,
- when enable is true and no password is set.public jadex.commons.future.IFuture<java.lang.String> getLocalPassword()
getLocalPassword
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Void> setLocalPassword(java.lang.String password)
setLocalPassword
in interface jadex.bridge.service.types.security.ISecurityService
password
- The password of the local platform.Exception,
- when a null password is provided and use password is true.public jadex.commons.future.IFuture<java.lang.Long> getValidityDuration()
getValidityDuration
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Void> setValidityDuration(long validityduration)
setValidityDuration
in interface jadex.bridge.service.types.security.ISecurityService
validityduration
- The validityduration to set.public jadex.commons.future.IFuture<java.lang.String> getPlatformPassword(jadex.bridge.IComponentIdentifier target)
getPlatformPassword
in interface jadex.bridge.service.types.security.ISecurityService
target
- The id of the target component.public jadex.commons.future.IFuture<java.lang.Void> setPlatformPassword(jadex.bridge.IComponentIdentifier target, java.lang.String password)
setPlatformPassword
in interface jadex.bridge.service.types.security.ISecurityService
target
- The id of the target component.password
- The password or null if no password should be used.public jadex.commons.future.IFuture<java.lang.String> getNetworkPassword(java.lang.String network)
getNetworkPassword
in interface jadex.bridge.service.types.security.ISecurityService
targetName
- The id of the target component.public jadex.commons.future.IFuture<java.lang.Void> setNetworkPassword(java.lang.String network, java.lang.String password)
setNetworkPassword
in interface jadex.bridge.service.types.security.ISecurityService
network
- The id of the network.password
- The password or null if no password should be used.public jadex.commons.future.IFuture<java.util.Map<java.lang.String,java.lang.String>> getPlatformPasswords()
getPlatformPasswords
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.util.Map<java.lang.String,java.lang.String>> getNetworkPasswords()
getNetworkPasswords
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Void> setTrustedLanMode(boolean allowed)
setTrustedLanMode
in interface jadex.bridge.service.types.security.ISecurityService
allowed
- The flag if it is allowed.public jadex.commons.future.IFuture<java.lang.Boolean> isTrustedLanMode()
isTrustedLanMode
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.String[]> getKeystoreInfo()
getKeystoreInfo
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Void> setKeystoreInfo(java.lang.String storepath, java.lang.String storepass, java.lang.String keypass)
setKeystoreInfo
in interface jadex.bridge.service.types.security.ISecurityService
storepath
- The path to the keystore.storepass
- The password of the store.keypass
- The password of the key.public jadex.commons.future.IFuture<java.lang.Void> validateRequest(jadex.bridge.service.types.security.IAuthorizable request)
validateRequest
in interface jadex.bridge.service.types.security.ISecurityService
request
- The request to be validated.SecurityException,
- when request is not valid.public byte[] getDigest(long timestamp, java.lang.String secret)
public static boolean checkDigest(byte[] test, java.util.List<byte[]> digests)
public java.lang.String checkDigests(jadex.bridge.service.types.security.IAuthorizable request, java.lang.String password, java.util.Map<java.lang.String,java.lang.String> networkpasses)
public jadex.commons.future.IFuture<java.lang.Void> preprocessRequest(jadex.bridge.service.types.security.IAuthorizable request, jadex.bridge.IComponentIdentifier target)
preprocessRequest
in interface jadex.bridge.service.types.security.ISecurityService
request
- The request to be preprocessed.target
- The target to which the request should be sent later.public jadex.commons.future.IFuture<byte[]> signCall(byte[] content)
signCall
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Void> checkVirtual(java.lang.String[] virtuals, java.lang.String name)
checkVirtual
in interface jadex.bridge.service.types.security.ISecurityService
virtuals
- The virtual names.name
- The name to check.public jadex.commons.future.IFuture<java.lang.Void> addVirtual(java.lang.String virtual, java.lang.String name)
addVirtual
in interface jadex.bridge.service.types.security.ISecurityService
virtual
- The virtual name.name
- The name to add.public jadex.commons.future.IFuture<java.lang.Void> removeVirtual(java.lang.String virtual, java.lang.String name)
removeVirtual
in interface jadex.bridge.service.types.security.ISecurityService
virtual
- The virtual name.name
- The name to remove.public jadex.commons.future.IFuture<java.util.Map<java.lang.String,java.util.Set<java.lang.String>>> getVirtuals()
getVirtuals
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Void> verifyCall(byte[] content, byte[] signed, java.lang.String name)
verifyCall
in interface jadex.bridge.service.types.security.ISecurityService
content
- The content that should be checked.signed
- The desired output hash.name
- The callers name (used to find the certificate and public key).public jadex.commons.future.IFuture<java.security.cert.Certificate> getPlatformCertificate(jadex.bridge.IComponentIdentifier cid)
getPlatformCertificate
in interface jadex.bridge.service.types.security.ISecurityService
cid
- The platform component identifier (null for own certificate).public jadex.commons.future.IFuture<java.util.Map<java.lang.String,jadex.bridge.service.types.security.KeyStoreEntry>> getKeystoreDetails()
getKeystoreDetails
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Void> removeKeyStoreEntry(java.lang.String alias)
removeKeyStoreEntry
in interface jadex.bridge.service.types.security.ISecurityService
String
- alias The alias name.public boolean verifyCall(byte[] content, byte[] signed, java.security.cert.Certificate cert)
public jadex.commons.future.IFuture<java.lang.Void> addPlatformCertificate(jadex.bridge.IComponentIdentifier cid, java.security.cert.Certificate cert)
addPlatformCertificate
in interface jadex.bridge.service.types.security.ISecurityService
name
- The entry name.cert
- The certificate.protected jadex.commons.future.IFuture<java.security.cert.Certificate> getCertificate(java.lang.String name)
name
- The alias name.public jadex.commons.future.IFuture<java.lang.Void> createKeyPair(jadex.bridge.IComponentIdentifier cid, java.lang.String algorithm, int keysize, java.lang.String pass, int validity)
createKeyPair
in interface jadex.bridge.service.types.security.ISecurityService
cid
- The entry name.algorithm
- The algorithm.keysize
- The key size (in bits).protected jadex.commons.future.IFuture<java.security.cert.Certificate> acquireCertificate(java.lang.String name)
public jadex.bridge.IInternalAccess getComponent()
public jadex.bridge.service.IServiceIdentifier getServiceIdentifier()
public jadex.commons.future.IFuture<java.lang.Void> setAcquisitionMechanismParameterValue(java.lang.Class<?> type, java.lang.String name, java.lang.Object value)
setAcquisitionMechanismParameterValue
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.util.List<jadex.bridge.service.types.security.MechanismInfo>> getAcquisitionMechanisms()
getAcquisitionMechanisms
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Integer> getSelectedAcquisitionMechanism()
getSelectedAcquisitionMechanism
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.IFuture<java.lang.Void> setAcquisitionMechanism(java.lang.Class<?> type)
setAcquisitionMechanism
in interface jadex.bridge.service.types.security.ISecurityService
public jadex.commons.future.ISubscriptionIntermediateFuture<jadex.commons.ChangeEvent<java.lang.Object>> subscribeToEvents()
subscribeToEvents
in interface jadex.bridge.service.types.security.ISecurityService
protected AAcquisitionMechanism getMechanism(java.lang.Class<?> type)
type
- The type.protected void publishEvent(jadex.commons.ChangeEvent<java.lang.Object> event)
protected void saveKeyStore()
protected void publishCurrentState()
public static byte[] buildDigest(long timestamp, java.lang.String secret)
public static byte[] buildDigest(byte[] input)
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception