Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class SecureKeyboard
ImplementsAnimation, 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 types
enum SecureKeyboard.Layout | The key set, chosen from the field’s constraint by layoutFor(int). |
Methods
public static SecureKeyboard install(TextArea field) | Routes a field’s input through a secure keyboard instead of the system keyboard. |
public static void uninstall(TextArea field) | Removes a keyboard added by install(TextArea) and restores the field’s editability. |
public static SecureKeyboard getInstalled(TextArea field) | The keyboard installed on a field, or null. |
public static SecureKeyboard.Layout layoutFor(int constraint) | Picks the layout a field with this TextArea constraint gets. |
public TextArea getField() | The field this keyboard types into. |
public SecureKeyboard.Layout getLayout() | The current layout. |
public void setLayout(SecureKeyboard.Layout layout) | Overrides the layout chosen from the field’s constraint. |
public boolean isScrambled() | Whether the digit keys are shuffled each time the keyboard opens. |
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. |
public void setDigitOrder(String order) | Puts the digit keys in a fixed order, for documentation screenshots and tests that need the same picture every time. |
public boolean isShowing() | Whether the keyboard is on screen. |
public void show() | Shows the keyboard at the bottom of the field’s form. |
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. |
protected void initComponent() | Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state |
protected void deinitialize() | Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. |
protected Dimension calcPreferredSize() | Calculates the preferred size based on component content. |
public void pointerPressed(int x, int y) | If this Component is focused, the pointer pressed event will call this method |
public void pointerDragged(int x, int y) | If this Component is focused, the pointer dragged event will call this method |
public void pointerReleased(int x, int y) | If this Component is focused, the pointer released event will call this method |
public boolean animate() | Allows the animation to reduce “repaint” calls when it returns false. |
public void paint(Graphics g) | This 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. |
Inherited fields
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
From Component
setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, initLaf, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyPressed, keyReleased, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, getContextMenuCommands, setContextMenuCommands, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setHovered, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip
Method details
install
public static SecureKeyboard install(TextArea field)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
fieldTextArea- the field to protect
Returns
uninstall
public static void uninstall(TextArea field)install(TextArea) and restores the field’s editability.Parameters
fieldTextArea- the protected field
getInstalled
public static SecureKeyboard getInstalled(TextArea field)Parameters
fieldTextArea- the field to look up
Returns
layoutFor
public static SecureKeyboard.Layout layoutFor(int constraint)TextArea constraint gets.Parameters
constraintint- a
TextAreaconstraint, flags included
Returns
getField
public TextArea getField()Returns
getLayout
public SecureKeyboard.Layout getLayout()Returns
setLayout
public void setLayout(SecureKeyboard.Layout layout)Parameters
layoutSecureKeyboard.Layout- the layout to use; null restores the one the constraint picks
isScrambled
public boolean isScrambled()Returns
setScrambled
public void setScrambled(boolean scrambled)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
scrambledboolean- true to shuffle the digits
setDigitOrder
public void setDigitOrder(String order)setScrambled(boolean); it also turns scrambling off, since the next
show() would otherwise replace the order.Parameters
orderString- the ten digits, each exactly once, in the order the keys show them
isShowing
public boolean isShowing()Returns
show
public void show()hide
public void hide()initComponent
protected void initComponent()deinitialize
protected void deinitialize()calcPreferredSize
protected Dimension calcPreferredSize()Returns
pointerPressed
public void pointerPressed(int x, int y)Parameters
xint- the pointer x coordinate
yint- the pointer y coordinate
pointerDragged
public void pointerDragged(int x, int y)Parameters
xint- the pointer x coordinate
yint- the pointer y coordinate
pointerReleased
public void pointerReleased(int x, int y)Parameters
xint- the pointer x coordinate
yint- the pointer y coordinate
animate
public boolean animate()com.codename1.ui.Display class.Returns
paint
public void paint(Graphics g)Parameters
gGraphics- the component graphics