use of dev.hawala.xns.level4.common.Time2.Time in project dodo by devhawala.
the class AttributeUtils method courier2file_ordering.
private static void courier2file_ordering(Attribute a, FileEntry fe) {
Ordering ord;
try {
ord = a.decodeData(Ordering::make);
} catch (Exception e) {
// ignored, use defaults
ord = Ordering.make();
}
final int interpretation;
switch(ord.interpretation.get()) {
case bool:
interpretation = FsConstants.intrBoolean;
break;
case cardinal:
interpretation = FsConstants.intrCardinal;
break;
case longCardinal:
interpretation = FsConstants.intrLongCardinal;
break;
case time:
interpretation = FsConstants.intrTime;
break;
case integer:
interpretation = FsConstants.intrInteger;
break;
case longInteger:
interpretation = FsConstants.intrLongInteger;
break;
case string:
interpretation = FsConstants.intrString;
break;
default:
interpretation = FsConstants.intrNone;
break;
}
fe.setOrderingKey(ord.key.get());
fe.setOrderingAscending(ord.ascending.get());
fe.setOrderingInterpretation(interpretation);
}
use of dev.hawala.xns.level4.common.Time2.Time in project dodo by devhawala.
the class AuthChsCommon method checkStrongCredentials.
/**
* Check that the strong credentials and the strong verifier are
* both valid for the recipient on the given machine.
*
* @param chsDatabase the clearinghouse database to check against
* @param credentials the credentials to verify
* @param verifier the verifier going with the credentials
* @param recipient the recipient for which the the strong credentials are encoded
* @param recipientMachineId the target machine for which the verifier is encoded
* @param decodedConversationKey target where to store the conversation encryption key for
* the session (the key will only be stored there if not {@code null} and at least
* 4 entries long).
* @return {@code null} if the credentials is not of strong type or the
* initiator encoded in the credentials is invalid or if the expiration time
* of the credentials are expired or the verifier timestamp is invalid;
* else the Clearinghouse name of the user if the credentials passed the tests.
* @throws EndOfMessageException if decoding the credentials or verifier after
* decryption fails
* @throws IllegalArgumentException if the recipient is invalid or has no
* strong password for decryption
* @throws Exception if any decryption fails
*/
public static ThreePartName checkStrongCredentials(ChsDatabase chsDatabase, Credentials credentials, Verifier verifier, ThreePartName recipient, long recipientMachineId, int[] decodedConversationKey, StrongVerifier decodedVerifier) throws Exception {
// get the recipient decryption password
if (credentials.type.get() != CredentialsType.strong) {
return null;
}
byte[] recipientStrongPw = chsDatabase.getStrongPassword(recipient);
if (recipientStrongPw == null) {
throw new IllegalArgumentException("Invalid recipient (strong password not found)");
}
int[] recipientDecryptPw = StrongAuthUtils.toWords(recipientStrongPw);
// decode the credentials with the recipient's strong password
StrongCredentials creds = StrongCredentials.make();
decryptFrom(recipientDecryptPw, credentials.value, creds);
// decrypt the verifier
if (decodedConversationKey == null || decodedConversationKey.length < 4) {
decodedConversationKey = new int[4];
}
decodedConversationKey[0] = creds.conversationKey.get(0).get();
decodedConversationKey[1] = creds.conversationKey.get(1).get();
decodedConversationKey[2] = creds.conversationKey.get(2).get();
decodedConversationKey[3] = creds.conversationKey.get(3).get();
StrongVerifier verfr = StrongVerifier.make();
decryptFrom(decodedConversationKey, verifier, verfr);
// left justified machine-id => upper 32 bits
long rcptTimestampMachineId32Bits = (recipientMachineId >> 16) & 0xFFFFFFFFL;
// left justified machine-id => lower 32 bits
long rcptTicksMachineId32Bits = (recipientMachineId & 0x0000FFFFL) << 16;
long verifierTicks = verfr.ticks.get() ^ rcptTicksMachineId32Bits;
long verifierTimestamp = verfr.timeStamp.get() ^ rcptTimestampMachineId32Bits;
if (decodedVerifier != null) {
decodedVerifier.ticks.set(verifierTicks);
decodedVerifier.timeStamp.set(verifierTimestamp);
}
// (temp) log the relevant data
Time now = Time.make().now();
System.out.printf("creds.initiator: %s:%s:%s\n", creds.initiator.object.get(), creds.initiator.domain.get(), creds.initiator.organization.get());
System.out.printf("creds.expiration: %d (now: %d)\n", creds.expirationTime.get(), now.get());
System.out.printf("verifier.timeStamp: 0x%08X = %d -> xor-ed(machineId): 0x%08X = %s (now: 0x%08X = %d)\n", verfr.timeStamp.get(), verfr.timeStamp.get(), verifierTimestamp, verifierTimestamp, now.get(), now.get());
System.out.printf("verifier.ticks: 0x%08X = %d -> xor-ed(machineId): 0x%08X = %d\n", verfr.ticks.get(), verfr.ticks.get(), verifierTicks, verifierTicks);
// check the credentials / verifier
if (!chsDatabase.isValidName(creds.initiator)) {
System.out.println("** checkStrongCredentials() => ERR: creds.initiator is not a valid name");
return null;
}
boolean skipTimestampChecks = MachineIds.getCfgBoolean(credentials.remoteHostId.get(), MachineIds.CFG_AUTH_SKIP_TIMESTAMP_CHECKS, false);
if (!skipTimestampChecks) {
if (now.get() > creds.expirationTime.get()) {
System.out.println("** checkStrongCredentials() => ERR: now > creds.expirationTime");
return null;
}
if (now.get() < verifierTimestamp) {
System.out.println("** checkStrongCredentials() => ERR: now < verifierTimestamp");
return null;
}
if (now.get() > (verifierTimestamp + 60)) {
System.out.println("** checkStrongCredentials() => ERR: now > verifierTimestamp+60secs");
return null;
}
} else {
System.out.println("** checkStrongCredentials() => timestamp checks skipped (creds.expirationTime, verifier.timestamp)");
}
System.out.println("** checkStrongCredentials() => strong credentials OK");
return new ThreePartName().from(creds.initiator);
}
use of dev.hawala.xns.level4.common.Time2.Time in project dodo by devhawala.
the class DodoServer method main.
public static void main(String[] args) throws XnsException {
String machinesFile = null;
String baseCfgFile = null;
String cfgFile = null;
boolean dumpChs = false;
// get commandline args
for (String arg : args) {
if (arg.toLowerCase().startsWith("-machinecfg:")) {
String[] parts = arg.split(":");
machinesFile = parts[1];
} else if (arg.toLowerCase().startsWith("-basecfg:")) {
String[] parts = arg.split(":");
baseCfgFile = parts[1];
} else if ("-dumpchs".equalsIgnoreCase(arg)) {
dumpChs = true;
} else if (cfgFile == null) {
cfgFile = arg;
} else {
System.out.printf("Warning: ignoring unknown argument: %s\n", arg);
}
}
// load machines configuration
if (!MachineIds.loadDefinitions(machinesFile)) {
System.out.println("!! failed to load machines configuration");
}
// load configuration(s)
if (baseCfgFile == null) {
File f = new File(DEFAULT_BASECONFIG_FILE);
if (f.exists() && f.canRead()) {
baseCfgFile = DEFAULT_BASECONFIG_FILE;
System.out.printf("Found and using default commons configuration: %s\n", baseCfgFile);
}
}
if (cfgFile == null && (new File(DEFAULT_CONFIG_FILE)).canRead()) {
cfgFile = DEFAULT_CONFIG_FILE;
}
if (baseCfgFile != null) {
initializeConfiguration(baseCfgFile);
}
if (cfgFile != null && !initializeConfiguration(cfgFile)) {
return;
}
// put parts of the configuration data as defaults for client machines
MachineIds.setDefault(MachineIds.CFG_AUTH_SKIP_TIMESTAMP_CHECKS, authSkipTimestampChecks);
MachineIds.setDefault(MachineIds.CFG_BOOTSVC_SIMPLEDATA_SEND_INTERVAL, bootServiceSimpleDataSendInterval);
MachineIds.setDefault(MachineIds.CFG_BOOTSVC_SPPDATA_SEND_INTERVAL, bootServiceSppDataSendInterval);
MachineIds.setDefault(MachineIds.CFG_SPP_HANDSHAKE_SENDACK_COUNTDOWN, sppHandshakeSendackCountdown);
MachineIds.setDefault(MachineIds.CFG_SPP_RESEND_DELAY, sppResendDelay);
MachineIds.setDefault(MachineIds.CFG_SPP_HANDSHAKE_RESEND_COUNTDOWN, sppHandshakeResendCountdown);
MachineIds.setDefault(MachineIds.CFG_SPP_HANDSHAKE_MAX_RESENDS, sppHandshakeMaxResends);
MachineIds.setDefault(MachineIds.CFG_SPP_RESEND_PACKET_COUNT, sppResendPacketCount);
MachineIds.setDefault(MachineIds.CFG_SPP_SENDING_TIME_GAP, sppSendingTimeGap);
// this parameter is global to all SPP connections (cannot be specified at client machine level)
SppConnection.setHandshakeCheckInterval(sppHandshakeCheckInterval);
// open CHS database if there are services requiring it
ChsDatabase chsDatabase = null;
if (startChsAndAuth || !fileServiceSpecs.isEmpty()) {
// create the clearinghouse database
chsDatabase = new ChsDatabase(networkNo, organizationName, domainName, chsDatabaseRoot, allowBlanksInObjectNames);
if (dumpChs) {
System.out.println("\n==\n== machine-id pre-definitions:\n==\n");
MachineIds.dump();
System.out.println("\n==\n== clearinghouse database dump: \n==\n");
chsDatabase.dump();
System.out.println("\n==\n== end of machine-id and clearinghouse database dumps\n==\n");
}
}
// check if we have undefined machine names, aborting startup if any
List<String> undefinedMachineNames = MachineIds.getUndefinedMachineNames();
if (!undefinedMachineNames.isEmpty()) {
System.out.println("The following machine names or IDs are undefined or invalid:");
for (String name : undefinedMachineNames) {
System.out.printf(" -> name: %s\n", name);
}
System.out.printf("Aborting Dodo startup ...\n... please correct the configuration or define the above names in the machine ids file (%s)\n", machinesFile);
System.exit(2);
}
// configure and start the network engine
LocalSite.configureHub(netHubHost, netHubPort);
LocalSite.configureLocal(networkNo, machineId, "DodoServer", doChecksums, doDarkstarWorkaround);
localSite = LocalSite.getInstance();
// set time base for all time dependent items
Time2.setTimeWarp(daysBackInTime);
// boot service
if (startBootService) {
BootResponder bootService = new BootResponder(bootServiceBasedir, bootServiceVerbose);
localSite.clientBindToSocket(IDP.KnownSocket.BOOT.getSocket(), bootService);
}
// echo service
if (startEchoService) {
localSite.clientBindToSocket(IDP.KnownSocket.ECHO.getSocket(), new EchoResponder());
}
// time service
if (startTimeService) {
localSite.pexListen(IDP.KnownSocket.TIME.getSocket(), new TimeServiceResponder(localTimeOffsetMinutes, timeServiceSendingTimeGap));
}
// routing protocol responder
RipResponder ripResponder = null;
if (startRipService) {
ripResponder = new RipResponder();
localSite.clientBindToSocket(IDP.KnownSocket.ROUTING.getSocket(), ripResponder);
}
// clearinghouse and authentication services
if (startChsAndAuth) {
// broadcast for clearinghouse service
// one common implementation for versions 2 and 3, as both versions have the same RetrieveAddresses method
Clearinghouse3Impl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase);
localSite.pexListen(IDP.KnownSocket.CLEARINGHOUSE.getSocket(), new BfsClearinghouseResponder(ripResponder), null);
// broadcast for authentication service
// one common implementation for versions 1, 2 and 3, as all versions are assumed to have
// the same (undocumented) RetrieveAddresses method
Authentication2Impl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase);
localSite.pexListen(IDP.KnownSocket.AUTH.getSocket(), new BfsAuthenticationResponder());
// register clearinghouse and authentication courier programs in registry
Clearinghouse3Impl.register();
Authentication2Impl.register();
// start the mailService always co-located with the clearinghouse
if (mailServiceVolumePath != null) {
MailingOldImpl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase, mailServiceVolumePath);
MailingOldImpl.register();
MailingNewImpl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase, MailingOldImpl.getMailService());
MailingNewImpl.register();
localSite.pexListen(0x001A, new MailingExpeditedCourierResponder());
}
}
// print service
if (printServiceName != null && printServiceOutputDirectory != null) {
try {
Printing3Impl.init(printServiceName, printServiceOutputDirectory, printServiceDisassembleIp, printServicePaperSizes, printServiceIp2PsProcFilename, printServicePsPostprocessor);
Printing3Impl.register();
} catch (Exception e) {
System.out.printf("Error starting printservice '%s': %s\n", printServiceName, e.getMessage());
}
}
// file service(s)
if (fileServiceSpecs.size() > 0) {
// initialize
FilingImpl.init(localSite.getNetworkId(), localSite.getMachineId(), chsDatabase);
// open volume(s)
int openVolumes = 0;
for (Entry<String, String> spec : fileServiceSpecs.entrySet()) {
ThreePartName serviceName = ThreePartName.make().from(spec.getKey());
String volumeBasedirName = spec.getValue();
if (FilingImpl.addVolume(serviceName, volumeBasedirName)) {
openVolumes++;
}
}
// register Courier implementation if volume(s) were successfully opened
if (openVolumes > 0) {
FilingImpl.register();
} else {
System.out.printf("No volumes opened successfully, not registering Filing to Courier");
}
}
// run courier server with dispatcher
CourierServer courierServer = new CourierServer(localSite);
// silence logging a bit
Log.L0.doLog(false);
Log.L1.doLog(false);
Log.L2.doLog(false);
Log.L3.doLog(false);
Log.L4.doLog(false);
/*
* let the server machine run...
*/
}
use of dev.hawala.xns.level4.common.Time2.Time in project android_packages_apps_Etar by LineageOS.
the class DayView method getSelectedTimeInMillis.
/**
* Returns the start of the selected time in milliseconds since the epoch.
*
* @return selected time in UTC milliseconds since the epoch.
*/
long getSelectedTimeInMillis() {
Time time = new Time();
time.set(mBaseDate);
time.setJulianDay(mSelectionDay);
time.setHour(mSelectionHour);
return time.normalize();
}
use of dev.hawala.xns.level4.common.Time2.Time in project android_packages_apps_Etar by LineageOS.
the class DayView method updateTitle.
public void updateTitle() {
Time start = new Time();
start.set(mBaseDate);
start.normalize();
Time end = new Time();
end.set(start);
end.setDay(end.getDay() + mNumDays - 1);
// Move it forward one minute so the formatter doesn't lose a day
end.setMinute(end.getMinute() + 1);
end.normalize();
long formatFlags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
if (mNumDays != 1) {
// Don't show day of the month if for multi-day view
formatFlags |= DateUtils.FORMAT_NO_MONTH_DAY;
// Abbreviate the month if showing multiple months
if (start.getMonth() != end.getMonth()) {
formatFlags |= DateUtils.FORMAT_ABBREV_MONTH;
}
}
mController.sendEvent(this, EventType.UPDATE_TITLE, start, end, null, -1, ViewType.CURRENT, formatFlags, null, null);
}
Aggregations