use of ca.nrc.cadc.caom2.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 ca.nrc.cadc.caom2.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 ca.nrc.cadc.caom2.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);
}
use of ca.nrc.cadc.caom2.Time in project android_packages_apps_Etar by LineageOS.
the class DayView method switchViews.
private View switchViews(boolean forward, float xOffSet, float width, float velocity) {
mAnimationDistance = width - xOffSet;
if (DEBUG) {
Log.d(TAG, "switchViews(" + forward + ") O:" + xOffSet + " Dist:" + mAnimationDistance);
}
float progress = Math.abs(xOffSet) / width;
if (progress > 1.0f) {
progress = 1.0f;
}
float inFromXValue, inToXValue;
float outFromXValue, outToXValue;
if (forward) {
inFromXValue = 1.0f - progress;
inToXValue = 0.0f;
outFromXValue = -progress;
outToXValue = -1.0f;
} else {
inFromXValue = progress - 1.0f;
inToXValue = 0.0f;
outFromXValue = progress;
outToXValue = 1.0f;
}
final Time start = new Time(mBaseDate.getTimezone());
start.set(mController.getTime());
if (forward) {
start.setDay(start.getDay() + mNumDays);
} else {
start.setDay(start.getDay() - mNumDays);
}
mController.setTime(start.normalize());
Time newSelected = start;
if (mNumDays == 7) {
newSelected = new Time();
newSelected.set(start);
adjustToBeginningOfWeek(start);
}
final Time end = new Time();
end.set(start);
end.setDay(end.getDay() + mNumDays - 1);
// We have to allocate these animation objects each time we switch views
// because that is the only way to set the animation parameters.
TranslateAnimation inAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, inFromXValue, Animation.RELATIVE_TO_SELF, inToXValue, Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f);
TranslateAnimation outAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, outFromXValue, Animation.RELATIVE_TO_SELF, outToXValue, Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f);
long duration = calculateDuration(width - Math.abs(xOffSet), width, velocity);
inAnimation.setDuration(duration);
inAnimation.setInterpolator(mHScrollInterpolator);
outAnimation.setInterpolator(mHScrollInterpolator);
outAnimation.setDuration(duration);
outAnimation.setAnimationListener(new GotoBroadcaster(start, end));
mViewSwitcher.setInAnimation(inAnimation);
mViewSwitcher.setOutAnimation(outAnimation);
DayView view = (DayView) mViewSwitcher.getCurrentView();
view.cleanup();
mViewSwitcher.showNext();
view = (DayView) mViewSwitcher.getCurrentView();
view.setSelected(newSelected, true, false);
view.requestFocus();
view.reloadEvents();
view.updateTitle();
view.restartCurrentTimeUpdates();
return view;
}
use of ca.nrc.cadc.caom2.Time in project android_packages_apps_Etar by LineageOS.
the class DayView method init.
private void init(Context context) {
setFocusable(true);
// Allow focus in touch mode so that we can do keyboard shortcuts
// even after we've entered touch mode.
setFocusableInTouchMode(true);
setClickable(true);
setOnCreateContextMenuListener(this);
mFirstDayOfWeek = Utils.getFirstDayOfWeek(context);
mCurrentTime = new Time(Utils.getTimeZone(context, mTZUpdater));
long currentTime = System.currentTimeMillis();
mCurrentTime.set(currentTime);
mTodayJulianDay = Time.getJulianDay(currentTime, mCurrentTime.getGmtOffset());
mWeek_todayColor = DynamicTheme.getColor(mContext, "week_today");
mWeek_saturdayColor = DynamicTheme.getColor(mContext, "week_saturday");
mWeek_sundayColor = DynamicTheme.getColor(mContext, "week_sunday");
mCalendarDateBannerTextColor = DynamicTheme.getColor(mContext, "calendar_date_banner_text_color");
mFutureBgColorRes = DynamicTheme.getColor(mContext, "calendar_future_bg_color");
mBgColor = DynamicTheme.getColor(mContext, "calendar_hour_background");
mCalendarHourLabelColor = DynamicTheme.getColor(mContext, "calendar_hour_label");
mCalendarGridAreaSelected = DynamicTheme.getColor(mContext, "calendar_grid_area_selected");
mCalendarGridLineInnerHorizontalColor = DynamicTheme.getColor(mContext, "calendar_grid_line_inner_horizontal_color");
mCalendarGridLineInnerVerticalColor = DynamicTheme.getColor(mContext, "calendar_grid_line_inner_vertical_color");
mPressedColor = DynamicTheme.getColor(mContext, "pressed");
mClickedColor = DynamicTheme.getColor(mContext, "day_event_clicked_background_color");
mEventTextColor = DynamicTheme.getColor(mContext, "calendar_event_text_color");
mMoreEventsTextColor = DynamicTheme.getColor(mContext, "month_event_other_color");
int gridLineColor = mResources.getColor(R.color.calendar_grid_line_highlight_color);
Paint p = mSelectionPaint;
p.setColor(gridLineColor);
p.setStyle(Style.FILL);
p.setAntiAlias(false);
p = mPaint;
p.setAntiAlias(true);
// Allocate space for 2 weeks worth of weekday names so that we can
// easily start the week display at any week day.
mDayStrs = new String[14];
// Also create an array of 2-letter abbreviations.
mDayStrs2Letter = new String[14];
for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
int index = i - Calendar.SUNDAY;
// e.g. Tue for Tuesday
mDayStrs[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_MEDIUM);
mDayStrs[index + 7] = mDayStrs[index];
// e.g. Tu for Tuesday
mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORT);
// If we don't have 2-letter day strings, fall back to 1-letter.
if (mDayStrs2Letter[index].equals(mDayStrs[index])) {
mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORTEST);
}
mDayStrs2Letter[index + 7] = mDayStrs2Letter[index];
}
// Figure out how much space we need for the 3-letter abbrev names
// in the worst case.
p.setTextSize(DATE_HEADER_FONT_SIZE);
p.setTypeface(mBold);
String[] dateStrs = { " 28", " 30" };
mDateStrWidth = computeMaxStringWidth(0, dateStrs, p);
p.setTextSize(DAY_HEADER_FONT_SIZE);
mDateStrWidth += computeMaxStringWidth(0, mDayStrs, p);
p.setTextSize(HOURS_TEXT_SIZE);
p.setTypeface(null);
handleOnResume();
String[] timeStrs = { "12 AM", "12 PM", "22:00" };
p.setTextSize(HOURS_TEXT_SIZE);
mHoursWidth = HOURS_MARGIN + computeMaxStringWidth(mHoursWidth, timeStrs, p);
GRID_LINE_LEFT_MARGIN = mHoursWidth;
LayoutInflater inflater;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mPopupView = inflater.inflate(R.layout.bubble_event, null);
mPopupView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mPopup = new PopupWindow(context);
mPopup.setContentView(mPopupView);
Resources.Theme dialogTheme = getResources().newTheme();
dialogTheme.applyStyle(android.R.style.Theme_Dialog, true);
TypedArray ta = dialogTheme.obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
mPopup.setBackgroundDrawable(ta.getDrawable(0));
ta.recycle();
// Enable touching the popup window
mPopupView.setOnClickListener(this);
// Catch long clicks for creating a new event
setOnLongClickListener(this);
mBaseDate = new Time(Utils.getTimeZone(context, mTZUpdater));
long millis = System.currentTimeMillis();
mBaseDate.set(millis);
mEarliestStartHour = new int[mNumDays];
mHasAllDayEvent = new boolean[mNumDays];
// mLines is the array of points used with Canvas.drawLines() in
// drawGridBackground() and drawAllDayEvents(). Its size depends
// on the max number of lines that can ever be drawn by any single
// drawLines() call in either of those methods.
final int maxGridLines = // max horizontal lines we might draw
(24 + 1) + // max vertical lines we might draw
(mNumDays + 1);
mLines = new float[maxGridLines * 4];
}
Aggregations