Class SecureKeyboard
- All Implemented Interfaces:
Animation, Editable, StyleListener
An on-screen keyboard drawn by the application itself, for fields a keylogging keyboard must never see.
On Android the system keyboard is an app the user chose, and it receives every keystroke typed
into every other app. A malicious one is a keylogger nothing in the app can switch off: password
and TextArea.SENSITIVE fields already ask the keyboard not to learn what is typed, but only a
well-behaved keyboard honours the request. A field with a SecureKeyboard installed is never
handed to the system keyboard at all. It is made uneditable, so the platform editor cannot open
on it, and a tap shows this keyboard instead, which writes into the field directly.
TextField pin = new TextField("", "PIN", 6, TextArea.NUMERIC | TextArea.PASSWORD);
SecureKeyboard kb = SecureKeyboard.install(pin);
kb.setScrambled(true);
A common pattern is to install it only when DeviceIntegrity.isThirdPartyKeyboardActive(String...)
reports a user-installed keyboard, so most users keep the keyboard they know.
What it does against the threats a penetration test checks for:
- Keylogging keyboards: no keystroke goes through the platform input method.
- Screen recording and overlays capturing a pressed key: pressed keys are not enlarged in a
popup as system keyboards do. Combine it with
DeviceIntegrity.setSecureScreen(boolean)to keep the screen out of recordings, andDeviceIntegrity.setTapjackingProtection(TapjackingPolicy). - Tap-coordinate logging: with
setScrambled(boolean)the digit keys move every time the keyboard opens, so recorded touch positions do not map back to digits.
The layout follows the field's constraint: a number pad for TextArea.NUMERIC, TextArea.DECIMAL
and TextArea.PHONENUMBER, letters with @ or / for TextArea.EMAILADDR and TextArea.URL,
and letters otherwise. It draws its own keys in the style of the platform keyboards, light or
dark following the theme's dark mode, under a strip with a lock icon that tells the user this is
not their usual keyboard.
It types ASCII only: no accented letters, no other scripts, no dictation, no autofill. That is the price of keeping input away from the platform, and why it suits credentials and codes rather than free text.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe key set, chosen from the field's constraint bylayoutFor(int). -
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Method Summary
Modifier and TypeMethodDescriptionbooleananimate()Allows the animation to reduce "repaint" calls when it returns false.protected DimensionCalculates the preferred size based on component content.protected voidInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.getField()The field this keyboard types into.static SecureKeyboardgetInstalled(TextArea field) The keyboard installed on a field, or null.The current layout.voidhide()Hides the keyboard and reports the edit as complete, as the platform editor does when it closes: the field's action listeners fire.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component statestatic SecureKeyboardRoutes a field's input through a secure keyboard instead of the system keyboard.booleanWhether the digit keys are shuffled each time the keyboard opens.booleanWhether the keyboard is on screen.static SecureKeyboard.LayoutlayoutFor(int constraint) Picks the layout a field with thisTextAreaconstraint gets.voidThis method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.voidpointerDragged(int x, int y) If this Component is focused, the pointer dragged event will call this methodvoidpointerPressed(int x, int y) If this Component is focused, the pointer pressed event will call this methodvoidpointerReleased(int x, int y) If this Component is focused, the pointer released event will call this methodvoidsetDigitOrder(String order) Puts the digit keys in a fixed order, for documentation screenshots and tests that need the same picture every time.voidsetLayout(SecureKeyboard.Layout layout) Overrides the layout chosen from the field's constraint.voidsetScrambled(boolean scrambled) Shuffles the digit keys every time the keyboard opens, withSecureRandom, so touch coordinates recorded by malware do not reveal which digits were typed.voidshow()Shows the keyboard at the bottom of the field's form.static voidRemoves a keyboard added byinstall(TextArea)and restores the field's editability.Methods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addNativeDragOverListener, addNativeDropListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, canAcceptNativeDrop, cancelRepaints, clearClientProperties, consumesRawTextInput, contains, containsOrOwns, createNativeDragOperation, createStyleAnimation, deinitializeCustomStyle, deregisterFromAnimation, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, fireClicked, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAcceptedDropActions, getAcceptedDropMimeTypes, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBottomGap, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getContextMenuCommands, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getHoverStyle, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeDragOperation, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getSideGap, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getTopLevelContainer, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initLaf, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHovered, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isNativeDragSource, isNativeDropTarget, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSelectableInteraction, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyPressed, keyReleased, keyRepeated, laidOut, longKeyPress, longPointerPress, mouseWheel, nativeDragEnter, nativeDragExit, nativeDragOver, nativeDrop, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, paramString, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, registerForAnimation, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removeNativeDragOverListener, removeNativeDropListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAcceptedDropActions, setAcceptedDropMimeTypes, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setContextMenuCommands, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setHovered, setHoverStyle, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNativeDragOperation, setNativeDragSource, setNativeDropTarget, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stopScrollMomentum, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
-
Method Details
-
install
Routes a field's input through a secure keyboard instead of the system keyboard.
The field is made uneditable, which is what keeps the platform editor from ever opening on it, and a tap on it shows the returned keyboard. Installing twice returns the keyboard already installed.
Parameters
field: the field to protect
Returns
the keyboard now serving the field
-
uninstall
Removes a keyboard added by
install(TextArea)and restores the field's editability.Parameters
field: the protected field
-
getInstalled
The keyboard installed on a field, or null.
Parameters
field: the field to look up
Returns
its keyboard, or null when none is installed
-
layoutFor
-
getField
The field this keyboard types into.
Returns
the protected field
-
getLayout
The current layout.
Returns
the layout in use
-
setLayout
Overrides the layout chosen from the field's constraint.
Parameters
layout: the layout to use; null restores the one the constraint picks
-
isScrambled
public boolean isScrambled()Whether the digit keys are shuffled each time the keyboard opens.
Returns
true when the digits are scrambled
-
setScrambled
public void setScrambled(boolean scrambled) Shuffles the digit keys every time the keyboard opens, with
SecureRandom, so touch coordinates recorded by malware do not reveal which digits were typed. Off by default: it slows typing down, so keep it for PINs and one-time codes.Parameters
scrambled: true to shuffle the digits
-
setDigitOrder
Puts the digit keys in a fixed order, for documentation screenshots and tests that need the same picture every time. A fixed order is exactly what scrambling exists to avoid, so do not use this in place of
setScrambled(boolean); it also turns scrambling off, since the nextshow()would otherwise replace the order.Parameters
order: the ten digits, each exactly once, in the order the keys show them
-
isShowing
public boolean isShowing()Whether the keyboard is on screen.
Returns
true while it is showing
-
show
public void show()Shows the keyboard at the bottom of the field's form. Called by a tap on the field; call it yourself to open the keyboard when a screen appears. -
hide
public void hide()Hides the keyboard and reports the edit as complete, as the platform editor does when it closes: the field's action listeners fire. -
initComponent
protected void initComponent()Description copied from class:ComponentAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classComponent
-
deinitialize
protected void deinitialize()Description copied from class:ComponentInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.- Overrides:
deinitializein classComponent
-
calcPreferredSize
Description copied from class:ComponentCalculates the preferred size based on component content. This method is invoked lazily by getPreferred size.
Returns
the calculated preferred size based on component content
- Overrides:
calcPreferredSizein classComponent
-
pointerPressed
public void pointerPressed(int x, int y) Description copied from class:ComponentIf this Component is focused, the pointer pressed event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerPressedin classComponent
-
-
pointerDragged
public void pointerDragged(int x, int y) Description copied from class:ComponentIf this Component is focused, the pointer dragged event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerDraggedin classComponent
-
-
pointerReleased
public void pointerReleased(int x, int y) Description copied from class:ComponentIf this Component is focused, the pointer released event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerReleasedin classComponent
-
-
animate
public boolean animate()Description copied from class:ComponentAllows the animation to reduce "repaint" calls when it returns false. It is called once for every frame. Frames are defined by the
com.codename1.ui.Displayclass.Returns
true if a repaint is desired or false if no repaint is necessary
-
paint
Description copied from class:ComponentThis method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
Parameters
g: the component graphics
-