Pages

Showing posts with label future. Show all posts
Showing posts with label future. Show all posts

Monday, May 9, 2016

New in Android Samples Authenticating to remote servers using the Fingerprint API

Posted by Takeshi Hagikura, Yuichi Araki, Developer Programs Engineer

Originally posted on Google Android Developer blog

As we announced in the previous blog post, Android 6.0 Marshmallow is now publicly available to users. Along the way, we’ve been updating our samples collection to highlight exciting new features available to developers.

This week, we’re releasing AsymmetricFingerprintDialog, a new sample demonstrating how to securely integrate with compatible fingerprint readers (like Nexus Imprint) in a client/server environment.

Let’s take a closer look at how this sample works, and talk about how it complements the FingerprintDialog sample we released earlier during the public preview.

Symmetric vs Asymmetric Keys

The Android Fingerprint API protects user privacy by keeping users’ fingerprint features carefully contained within secure hardware on the device. This guards against malicious actors, ensuring that users can safely use their fingerprint, even in untrusted applications.

Android also provides protection for application developers, providing assurances that a user’s fingerprint has been positively identified before providing access to secure data or resources. This protects against tampered applications, providing cryptographic-level security for both offline data and online interactions.

When a user activates their fingerprint reader, they’re unlocking a hardware-backed cryptographic vault. As a developer, you can choose what type of key material is stored in that vault, depending on the needs of your application:

  • Symmetric keys: Similar to a password, symmetric keys allow encrypting local data. This is a good choice securing access to databases or offline files.
  • Asymmetric keys: Provides a key pair, comprised of a public key and a private key. The public key can be safely sent across the internet and stored on a remote server. The private key can later be used to sign data, such that the signature can be verified using the public key. Signed data cannot be tampered with, and positively identifies the original author of that data. In this way, asymmetric keys can be used for network login and authenticating online transactions. Similarly, the public key can be used to encrypt data, such that the data can only be decrypted with the private key.

This sample demonstrates how to use an asymmetric key, in the context of authenticating an online purchase. If you’re curious about using symmetric keys instead, take a look at the FingerprintDialog sample that was published earlier.

Here is a visual explanation of how the Android app, the user, and the backend fit together using the asymmetric key flow:

1. Setting Up: Creating an asymmetric keypair

First you need to create an asymmetric key pair as follows:

KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore");
keyPairGenerator.initialize(
new KeyGenParameterSpec.Builder(KEY_NAME,
KeyProperties.PURPOSE_SIGN)
.setDigests(KeyProperties.DIGEST_SHA256)
.setAlgorithmParameterSpec(new ECGenParameterSpec("secp256r1"))
.setUserAuthenticationRequired(true)
.build());
keyPairGenerator.generateKeyPair();

Note that .setUserAuthenticationRequired(true) requires that the user authenticate with a registered fingerprint to authorize every use of the private key.

Then you can retrieve the created private and public keys with as follows:


KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
PublicKey publicKey =
keyStore.getCertificate(MainActivity.KEY_NAME).getPublicKey();

KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
PrivateKey key = (PrivateKey) keyStore.getKey(KEY_NAME, null);

2. Registering: Enrolling the public key with your server

Second, you need to transmit the public key to your backend so that in the future the backend can verify that transactions were authorized by the user (i.e. signed by the private key corresponding to this public key). This sample uses the fake backend implementation for reference, so it mimics the transmission of the public key, but in real life you need to transmit the public key over the network.

boolean enroll(String userId, String password, PublicKey publicKey);

3. Let’s Go: Signing transactions with a fingerprint

To allow the user to authenticate the transaction, e.g. to purchase an item, prompt the user to touch the fingerprint sensor.

Then start listening for a fingerprint as follows:

Signature.getInstance("SHA256withECDSA");
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
PrivateKey key = (PrivateKey) keyStore.getKey(KEY_NAME, null);
signature.initSign(key);
CryptoObject cryptObject = new FingerprintManager.CryptoObject(signature);

CancellationSignal cancellationSignal = new CancellationSignal();
FingerprintManager fingerprintManager =
context.getSystemService(FingerprintManager.class);
fingerprintManager.authenticate(cryptoObject, cancellationSignal, 0, this, null);

4. Finishing Up: Sending the data to your backend and verifying

After successful authentication, send the signed piece of data (in this sample, the contents of a purchase transaction) to the backend, like so:

Signature signature = cryptoObject.getSignature();
// Include a client nonce in the transaction so that the nonce is also signed
// by the private key and the backend can verify that the same nonce cant be used
// to prevent replay attacks.
Transaction transaction = new Transaction("user", 1, new SecureRandom().nextLong());
try {
signature.update(transaction.toByteArray());
byte[] sigBytes = signature.sign();
// Send the transaction and signedTransaction to the dummy backend
if (mStoreBackend.verify(transaction, sigBytes)) {
mActivity.onPurchased(sigBytes);
dismiss();
} else {
mActivity.onPurchaseFailed();
dismiss();
}
} catch (SignatureException e) {
throw new RuntimeException(e);
}

Last, verify the signed data in the backend using the public key enrolled in step 2:

@Override
public boolean verify(Transaction transaction, byte[] transactionSignature) {
try {
if (mReceivedTransactions.contains(transaction)) {
// It verifies the equality of the transaction including the client nonce
// So attackers cant do replay attacks.
return false;
}
mReceivedTransactions.add(transaction);
PublicKey publicKey = mPublicKeys.get(transaction.getUserId());
Signature verificationFunction = Signature.getInstance("SHA256withECDSA");
verificationFunction.initVerify(publicKey);
verificationFunction.update(transaction.toByteArray());
if (verificationFunction.verify(transactionSignature)) {
// Transaction is verified with the public key associated with the user
// Do some post purchase processing in the server
return true;
}
} catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException e) {
// In a real world, better to send some error message to the user
}
return false;
}

At this point, you can assume that the user is correctly authenticated with their fingerprints because as noted in step 1, user authentication is required before every use of the private key. Let’s do the post processing in the backend and tell the user that the transaction is successful!

Other updated samples

We also have a couple of Marshmallow-related updates to the Android For Work APIs this month for you to peruse:

  • AppRestrictionEnforcer and AppRestrictionSchemaThese samples were originally released when the App Restriction feature was introduced as a part of Android for Work API in Android 5.0 Lollipop. AppRestrictionEnforcer demonstrates how to set restriction to other apps as a profile owner. AppRestrictionSchema defines some restrictions that can be controlled by AppRestrictionEnforcer. This update shows how to use 2 additional restriction types introduced in Android 6.0.
  • We hope you enjoy the updated samples. If you have any questions regarding the samples, please visit us on our GitHub page and file issues or send us pull requests.

    Read More..

    Friday, March 4, 2016

    The 20Time Project how freedom can help prepare students for the future



    (Cross-posted on the Google for Education Blog.)

    Editors note: Leading up to Education on Air, we asked you what topics you’d like to discuss at the conference. The clear winner was “innovation in schools,” so we asked Kevin Brookhouser, a Google Certified Teacher and director of technology at York School, to share his innovative practice of giving students freedom in what and how they learn. Kevin is the author of the new book The 20Time Project and will share his methods during an Education on Air session on May 9. Register here for the free online conference today.

    The 20Time Project stemmed from the collision of several fortunate events: I met a number of inspirational teachers through the Google Teacher Academy, spent time at the Google campus, and read a book by Daniel Pink called Drive: The Surprising Truth About What Motivates Us about how to encourage innovative thinking. Inspired by Pink and Google’s “20 percent time”— a practice that allows employees to take time out of their “day job” to work on a side passion project— I created my own version and applied it to the classroom.
    Guest blogger Kevin Brookhouser speaks around the world about empowering students with time and choice. Hell lead a conference session at Education on Air on May 9th


    20Time is a simple concept that anyone can execute, as long as you give students the choice to design their own learning experience and support them throughout. Give students one day a week to work on a project of their choosing — one that serves a real audience and solves a real-world problem. Help students discover great ideas, write a thoughtful proposal, blog about their progress, craft an elevator pitch, and demonstrate their work through a final presentation.

    20Time affords students the opportunity to follow the three critical ingredients essential to innovation as described in Drive:
    1. Autonomy: freedom in what they learn and how they learn it 
    2. Mastery: the ability to track their learning growth 
    3. Purpose: meeting the needs of an audience outside the walls of the classroom
    When given the freedom to control their own learning, it turns out that students can come up with incredible ideas. The experiences they created are bigger than any I could’ve imagined — like Maria’s YouTube channel, which inspires young people to love books, or Maddie’s Recycling Closets project, which spreads awareness about sustainable consumerism.

    I’m fortunate to work at a future-oriented school that supported the experimental project from day one. But wherever they teach, I recommend that teachers who want to try 20Time give it a go — dive in and present the reasoning behind it. Transparent communication to parents, students and administrators can go a long way toward getting buy-in. For example, I send this letter to students and parents at the beginning of the year, and welcome other teachers to modify it to fit their needs.

    I’ll be sharing more about what I’ve learned about innovating in schools during my session at Education on Air on May 9. Register here to get updates about the conference. You can find 20Time resources, including five steps to get started, at 20Time.org. The 20Time Project is now available on Amazon, and if you’re looking to purchase multiple copies for your school or would like me to speak about 20Time or Google for Education, I welcome you to contact me directly. See you on May 9!
    Read More..

    Saturday, February 27, 2016

    AirDroid Aplikasi Sebagai Penghubung HP Android Ke PC

    Read More..

    Saturday, February 20, 2016

    The future of Android Revolution HD


    Its been quite a long time since I updated some of custom ROMs for HTC One series devices. This weekend I was able to release 2 major update for the HTC One M8 and HTC One M9.

    Android Revolution HD 14.0 | High Quality & Performance | 2.10.401.1 | ARMv8 64
    Re-build from the beginning using latest 2.10.401.1 base
    De-odexed using latest tools with better arm64 support
    SuperSU updated to latest 2.52
    Updated Google apps
    Updated custom apps
    Updated HTC apps
    Sense Toolbox updated to latest 2.2.1
    Total ROM size reduced by almost 200MB
    Other minor changes and fixes
    Android Revolution HD 45.0 | ART | High Quality & Performance | Sense 7.0
    Based on the latest 4.16.401.13 update
    SuperSU updated to latest 2.52
    Updated Google apps
    Updated custom appsUpdated HTC apps
    Sense Toolbox updated to latest 2.2.1
    Total ROM size reduced by almost 200MB
    Other minor changes and fixes
    Now, the short story. If youre wondering whats the reason behind my little activity on the custom ROMs development field, its because last 4 months brought a lot of changes in my life. In June 2015 I became a proud father of the most beautiful girl in the world. As you can imagine, priorities changed :)


    Also, I got married with my fiancée few weeks ago. We planned this marriage since 2013, but as always, last few weeks of preparations were extremely busy. Plus the baby was already here :)

    Its worth to mention, that during last few years Android Revolution HD was the most popular custom ROM for high-end HTC devices. With a total number of 6.430.689 downloads (6,5 millions !!!) Android Revolution custom ROMs series became the biggest and most desirable custom ROM for the HTC high-end devices.

    Android Revolution HD will still be supported, and all projects will be still continued. I just cant spend as much time on it as I used to spend in the past. Plus the the real life business I own expanded and developed significantly, so I need to focus now on my family and work. Both needs me :)

    PS. Im thinking about getting a Nexus 6P as my next daily device, as soon as its available in my country. Are you considering Nexus 6P as your next device too? Would you like to run Android Revolution HD on it? Let me know, as Im trying to find out if its worth to start N6P custom ROM development.

    Do you have any questions or comments? Feel free to share! Also, if you like this article, please use media sharing buttons (Twitter, G+, Facebook) below this post!


    For latest news follow Android Revolution HD on popular social platforms:

    Read More..