diff --git a/src/java/JavaFileStorage/src/keepass2android/yubiclip/scancode/KeyboardLayout.java b/src/java/JavaFileStorage/src/keepass2android/yubiclip/scancode/KeyboardLayout.java new file mode 100644 index 00000000..83b46415 --- /dev/null +++ b/src/java/JavaFileStorage/src/keepass2android/yubiclip/scancode/KeyboardLayout.java @@ -0,0 +1,38 @@ +package keepass2android.yubiclip.scancode; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +/** + * Created by dain on 2/17/14. + */ +public abstract class KeyboardLayout { + private static final Map layouts = new HashMap(); + + static { + layouts.put("US", new USKeyboardLayout()); + } + + public static KeyboardLayout forName(String name) { + return layouts.get(name.toUpperCase()); + } + + public static Set availableLayouts() { + return new TreeSet(layouts.keySet()); + } + + protected static final int SHIFT = 0x80; + + protected abstract String fromScanCode(int code); + + public final String fromScanCodes(byte[] bytes) { + StringBuilder buf = new StringBuilder(); + for (byte b : bytes) { + buf.append(fromScanCode(b & 0xff)); + } + + return buf.toString(); + } +} diff --git a/src/java/JavaFileStorage/src/keepass2android/yubiclip/scancode/USKeyboardLayout.java b/src/java/JavaFileStorage/src/keepass2android/yubiclip/scancode/USKeyboardLayout.java new file mode 100644 index 00000000..ca306d0b --- /dev/null +++ b/src/java/JavaFileStorage/src/keepass2android/yubiclip/scancode/USKeyboardLayout.java @@ -0,0 +1,141 @@ +package keepass2android.yubiclip.scancode; + +/** + * Created by dain on 2/17/14. + */ +public class USKeyboardLayout extends KeyboardLayout { + private static final String[] usb2key1 = new String[]{ + "", + "", + "", + "", + "a", + "b", + "c", + "d", + "e", + "f", + "g", /* 0xa */ + "h", + "i", + "j", + "k", + "l", + "m", + "n", + "o", + "p", + "q", /* 0x14 */ + "r", + "s", + "t", + "u", + "v", + "w", + "x", + "y", + "z", + "1", /* 0x1e */ + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "0", + "\n", /* 0x28 */ + "", + "", + "\t", + " ", + "-", + "=", + "[", + "]", + "", + "\\", + ";", + "'", + "`", + ",", + ".", + "/", /* 0x38 */ + }; + private static final String[] usb2key2 = new String[]{ + "", + "", + "", + "", + "A", + "B", + "C", + "D", + "E", + "F", + "G", /* 0x8a */ + "H", + "I", + "J", + "K", + "L", + "M", + "N", + "O", + "P", + "Q", /* 0x94 */ + "R", + "S", + "T", + "U", + "V", + "W", + "X", + "Y", + "Z", + "!", + "@", + "#", + "$", + "%", + "^", + "&", + "*", + "(", + ")", + "", + "", + "", + "", + "", + "_", + "+", + "{", + "}", + "", + "|", + ":", + "\"", + "~", + "<", + ">", + "?", + }; + + @Override + protected String fromScanCode(int code) { + if (code < SHIFT) { + if (code < usb2key1.length) { + return usb2key1[code]; + } + } else { + code = code ^ SHIFT; + if (code < usb2key2.length) { + return usb2key2[code]; + } + } + + return ""; + } +} diff --git a/src/keepass2android/Assets/DejaVuSansMono.ttf b/src/keepass2android/Assets/DejaVuSansMono.ttf deleted file mode 100644 index 8b7bb2a4..00000000 Binary files a/src/keepass2android/Assets/DejaVuSansMono.ttf and /dev/null differ diff --git a/src/keepass2android/Assets/LICENSE_SourceCodePro.txt b/src/keepass2android/Assets/LICENSE_SourceCodePro.txt new file mode 100644 index 00000000..11773304 --- /dev/null +++ b/src/keepass2android/Assets/LICENSE_SourceCodePro.txt @@ -0,0 +1,93 @@ +Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/keepass2android/Assets/LICENSE_dejavu b/src/keepass2android/Assets/LICENSE_dejavu deleted file mode 100644 index 254e2cc4..00000000 --- a/src/keepass2android/Assets/LICENSE_dejavu +++ /dev/null @@ -1,99 +0,0 @@ -Fonts are (c) Bitstream (see below). DejaVu changes are in public domain. -Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below) - -Bitstream Vera Fonts Copyright ------------------------------- - -Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is -a trademark of Bitstream, Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of the fonts accompanying this license ("Fonts") and associated -documentation files (the "Font Software"), to reproduce and distribute the -Font Software, including without limitation the rights to use, copy, merge, -publish, distribute, and/or sell copies of the Font Software, and to permit -persons to whom the Font Software is furnished to do so, subject to the -following conditions: - -The above copyright and trademark notices and this permission notice shall -be included in all copies of one or more of the Font Software typefaces. - -The Font Software may be modified, altered, or added to, and in particular -the designs of glyphs or characters in the Fonts may be modified and -additional glyphs or characters may be added to the Fonts, only if the fonts -are renamed to names not containing either the words "Bitstream" or the word -"Vera". - -This License becomes null and void to the extent applicable to Fonts or Font -Software that has been modified and is distributed under the "Bitstream -Vera" names. - -The Font Software may be sold as part of a larger software package but no -copy of one or more of the Font Software typefaces may be sold by itself. - -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, -TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME -FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING -ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE -FONT SOFTWARE. - -Except as contained in this notice, the names of Gnome, the Gnome -Foundation, and Bitstream Inc., shall not be used in advertising or -otherwise to promote the sale, use or other dealings in this Font Software -without prior written authorization from the Gnome Foundation or Bitstream -Inc., respectively. For further information, contact: fonts at gnome dot -org. - -Arev Fonts Copyright ------------------------------- - -Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of the fonts accompanying this license ("Fonts") and -associated documentation files (the "Font Software"), to reproduce -and distribute the modifications to the Bitstream Vera Font Software, -including without limitation the rights to use, copy, merge, publish, -distribute, and/or sell copies of the Font Software, and to permit -persons to whom the Font Software is furnished to do so, subject to -the following conditions: - -The above copyright and trademark notices and this permission notice -shall be included in all copies of one or more of the Font Software -typefaces. - -The Font Software may be modified, altered, or added to, and in -particular the designs of glyphs or characters in the Fonts may be -modified and additional glyphs or characters may be added to the -Fonts, only if the fonts are renamed to names not containing either -the words "Tavmjong Bah" or the word "Arev". - -This License becomes null and void to the extent applicable to Fonts -or Font Software that has been modified and is distributed under the -"Tavmjong Bah Arev" names. - -The Font Software may be sold as part of a larger software package but -no copy of one or more of the Font Software typefaces may be sold by -itself. - -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL -TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. - -Except as contained in this notice, the name of Tavmjong Bah shall not -be used in advertising or otherwise to promote the sale, use or other -dealings in this Font Software without prior written authorization -from Tavmjong Bah. For further information, contact: tavmjong @ free -. fr. - -$Id: LICENSE 2133 2007-11-28 02:46:28Z lechimp $ diff --git a/src/keepass2android/Assets/SourceCodePro-Regular.ttf b/src/keepass2android/Assets/SourceCodePro-Regular.ttf new file mode 100644 index 00000000..b2cff928 Binary files /dev/null and b/src/keepass2android/Assets/SourceCodePro-Regular.ttf differ diff --git a/src/keepass2android/EntryActivity.cs b/src/keepass2android/EntryActivity.cs index b75fb1f8..0c298155 100644 --- a/src/keepass2android/EntryActivity.cs +++ b/src/keepass2android/EntryActivity.cs @@ -816,7 +816,7 @@ namespace keepass2android { if (_passwordFont == null) { - _passwordFont = Typeface.CreateFromAsset(Assets, "DejaVuSansMono.ttf"); + _passwordFont = Typeface.CreateFromAsset(Assets, "SourceCodePro-Regular.ttf"); } textView.Typeface = _passwordFont; } diff --git a/src/keepass2android/NfcOtpActivity.cs b/src/keepass2android/NfcOtpActivity.cs index 3d716e02..cefefc78 100644 --- a/src/keepass2android/NfcOtpActivity.cs +++ b/src/keepass2android/NfcOtpActivity.cs @@ -2,9 +2,12 @@ using System; using Android.App; using Android.Content; using Android.Content.PM; +using Android.Nfc; using Android.OS; using Android.Widget; +using Java.Util; using Java.Util.Regex; +using Keepass2android.Yubiclip.Scancode; namespace keepass2android { @@ -31,11 +34,24 @@ namespace keepass2android String otp = matcher.Group(1); return otp; } + else + { + IParcelable[] raw = Intent.GetParcelableArrayExtra(NfcAdapter.ExtraNdefMessages); + + byte[] bytes = ((NdefMessage) raw[0]).ToByteArray(); + bytes = Arrays.CopyOfRange(bytes, DATA_OFFSET, bytes.Length); + String layout = "US"; + KeyboardLayout kbd = KeyboardLayout.ForName(layout); + String otp = kbd.FromScanCodes(bytes); + return otp; + } return null; } - private static readonly Java.Util.Regex.Pattern OtpPattern = Java.Util.Regex.Pattern.Compile("^https://my\\.yubico\\.com/neo/(.+)$"); + //private static readonly Java.Util.Regex.Pattern OtpPattern = Java.Util.Regex.Pattern.Compile("^https://my\\.yubico\\.com/neo/(.+)$"); + private static readonly Java.Util.Regex.Pattern OtpPattern = Java.Util.Regex.Pattern.Compile("^https://my\\.yubico\\.com/neo/([a-zA-Z0-9!]+)$"); + private const int DATA_OFFSET = 23; private ActivityDesign _design; diff --git a/src/keepass2android/PasswordActivity.cs b/src/keepass2android/PasswordActivity.cs index 4351e2f5..deaf61c9 100644 --- a/src/keepass2android/PasswordActivity.cs +++ b/src/keepass2android/PasswordActivity.cs @@ -844,7 +844,7 @@ namespace keepass2android return false; } - //user obviously wants to use OTP: + //assume user wants to use OTP (for static password, they need to open KP2A first and select the key provider type, then see OnNewIntent) _keyFileOrProvider = KeyProviderIdOtp; if (savedInstanceState == null) //only when not re-creating @@ -1349,39 +1349,51 @@ namespace keepass2android if ((intent != null) && (intent.HasExtra(Intents.OtpExtraKey))) { string otp = intent.GetStringExtra(Intents.OtpExtraKey); - _keepPasswordInOnResume = true; - if (_otpInfo == null) + + if (this.KeyProviderType == KeyProviders.Otp) { - //Entering OTPs not yet initialized: - _pendingOtps.Add(otp); - UpdateKeyProviderUiState(); + _keepPasswordInOnResume = true; + + if (_otpInfo == null) + { + //Entering OTPs not yet initialized: + _pendingOtps.Add(otp); + UpdateKeyProviderUiState(); + } + else + { + //Entering OTPs is initialized. Write OTP into first empty field: + bool foundEmptyField = false; + foreach (int otpId in _otpTextViewIds) + { + EditText otpEdit = FindViewById(otpId); + if ((otpEdit.Visibility == ViewStates.Visible) && String.IsNullOrEmpty(otpEdit.Text)) + { + otpEdit.Text = otp; + foundEmptyField = true; + break; + } + } + //did we find a field? + if (!foundEmptyField) + { + Toast.MakeText(this, GetString(Resource.String.otp_discarded_no_space), ToastLength.Long).Show(); + } + } + + Spinner passwordModeSpinner = FindViewById(Resource.Id.password_mode_spinner); + if (passwordModeSpinner.SelectedItemPosition != (int)KeyProviders.Otp) + { + passwordModeSpinner.SetSelection((int)KeyProviders.Otp); + } } else { - //Entering OTPs is initialized. Write OTP into first empty field: - bool foundEmptyField = false; - foreach (int otpId in _otpTextViewIds) - { - EditText otpEdit = FindViewById(otpId); - if ((otpEdit.Visibility == ViewStates.Visible) && String.IsNullOrEmpty(otpEdit.Text)) - { - otpEdit.Text = otp; - foundEmptyField = true; - break; - } - } - //did we find a field? - if (!foundEmptyField) - { - Toast.MakeText(this, GetString(Resource.String.otp_discarded_no_space), ToastLength.Long).Show(); - } + //assume the key should be used as static password + FindViewById(Resource.Id.password).Text += otp; } - Spinner passwordModeSpinner = FindViewById(Resource.Id.password_mode_spinner); - if (passwordModeSpinner.SelectedItemPosition != (int) KeyProviders.Otp) - { - passwordModeSpinner.SetSelection((int)KeyProviders.Otp); - } + } } diff --git a/src/keepass2android/keepass2android.csproj b/src/keepass2android/keepass2android.csproj index f5706e81..e1dbffa4 100644 --- a/src/keepass2android/keepass2android.csproj +++ b/src/keepass2android/keepass2android.csproj @@ -222,8 +222,7 @@ - - + @@ -1101,4 +1100,7 @@ + + + \ No newline at end of file