GithubHelp home page GithubHelp logo

yakivmospan / scytale Goto Github PK

View Code? Open in Web Editor NEW
432.0 14.0 44.0 184 KB

One tool to manage key generation, key storing and encryption on different APIs of Android.

Java 100.00%
android 3rd-party-libraries encryption scytale

scytale's Introduction

scytale's People

Contributors

jmartinesp avatar pavelsynek avatar pavlospt avatar yakivmospan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scytale's Issues

Yakimov.. quick help .. I use a PIN.. number ie test to feed the key

Store store = new Store(getApplicationContext());
if (!store.hasKey("12345")) {
SecretKey key = store.generateSymmetricKey("12345", null);
}

your code above.. I generated and presumeStore was set to the PIN number .. but when I went in it said the Store did not see the 12345 related key in the keystore and thus could not find it..

do I have to put something in the manifest ? as a lower activity creates the store from Store but when I re-enter the App .. how would I reference store from the ApplicationContext ? it seems to not find the key I stored in the last Activity and when I re-enter the App it cannot find the key :-(

missing something obvious ? in a droid setup ? for the manifest ? yes I need to persist stored entries in Store

Uncaught exception thrown by finalizer

Hi. I am getting this exception and can't reallize where it is comming from.

07-06 12:56:28.426 22855-22918/com.tecnocen.beneficiosandroid.ap E/System: Uncaught exception thrown by finalizer 07-06 12:56:28.445 22855-22918/com.tecnocen.beneficiosandroid.ap E/System: java.lang.IllegalStateException: Binder has been finalized! at android.os.BinderProxy.transactNative(Native Method) at android.os.BinderProxy.transact(Binder.java:628) at android.security.IKeystoreService$Stub$Proxy.abort(IKeystoreService.java:1411) at android.security.KeyStore.abort(KeyStore.java:885) at android.security.keystore.AndroidKeyStoreCipherSpiBase.finalize(AndroidKeyStoreCipherSpiBase.java:744) at android.security.keystore.AndroidKeyStoreRSACipherSpi$PKCS1Padding.finalize(AndroidKeyStoreRSACipherSpi.java) at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:222) at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:209) at java.lang.Thread.run(Thread.java:762)

This is my class, and I am providing it as a Singleton with Dagger 2:

public class KeyStoreHelperImpl implements KeyStoreHelper {

    private static final String STORE_NAME = "STORE_NAME";

    private Crypto crypto;
    private KeyPair keyPair;

    @Inject
    public KeyStoreHelperImpl(@ApplicationContext Context context) {


        // Create and save key
        Store store = new Store(context, STORE_NAME, BASE_CYPHER_PASSWORD.toCharArray());
        final int keysize = 512;

        if(!store.hasKey(STORE_NAME)) {
            // Create store with specific name and password
            final String alias = STORE_NAME;

            final Calendar start = Calendar.getInstance();
            final Calendar end = Calendar.getInstance();
            end.add(Calendar.YEAR, 1);

            // Create a key store params, some of them are specific per platform
            // Check KeyProps doc for more info
            KeyProps keyProps = new KeyProps.Builder()
                    .setAlias(alias)
                    .setPassword(BASE_CYPHER_PASSWORD.toCharArray())
                    .setKeySize(keysize)
                    .setKeyType("RSA")
                    .setSerialNumber(BigInteger.ONE)
                    .setSubject(new X500Principal("CN=" + alias + " CA Certificate"))
                    .setStartDate(start.getTime())
                    .setEndDate(end.getTime())
                    .setBlockModes("ECB")
                    .setEncryptionPaddings("PKCS1Padding")
                    .setSignatureAlgorithm("SHA256WithRSAEncryption")
                    .build();

            // Generate KeyPair depending on KeyProps
            keyPair = store.generateAsymmetricKey(keyProps);

        } else {
            keyPair =  store.getAsymmetricKey(STORE_NAME, BASE_CYPHER_PASSWORD.toCharArray());
        }

        // Encrypt/Dencrypt data using buffer with or without Initialisation Vectors
        // This additional level of safety is required on 23 API level for
        // some algorithms. Specify encryption/decryption block size to use buffer for
        // large data when using block based algorithms (such as RSA)

        final int encryptionBlockSize = keysize / 8 - 11; // as specified for RSA/ECB/PKCS1Padding keys
        final int decryptionBlockSize = keysize / 8; // as specified for RSA/ECB/PKCS1Padding keys

        crypto = new Crypto("RSA/ECB/PKCS1Padding", encryptionBlockSize, decryptionBlockSize);
    }

    @Override
    public String encryptString(String string) {
        if(string != null)
        return crypto.encrypt(string, keyPair.getPublic(), false);
        return null;
    }

    @Override
    public String decryptString(String string) {
        if(string != null)
        return crypto.decrypt(string, keyPair.getPrivate(), false);
        return null;
    }
}`
```

getSymmetricKey() is null

Hi there,
After calling generateSymmetricKey() for the first time the user's runs the app, and when reopening the app i'm calling getSymmetricKey() everything seems to be working fine.
But when restarting the device, getSymmetricKey() return null and app stops working of course.
I'm using this library with Realm.

My code:

Store store = new Store(getApplicationContext());
        Crypto crypto = new Crypto(Options.TRANSFORMATION_SYMMETRIC);
        SecretKey key;

        if (!store.hasKey(getALString())) {
            freshStart = true;

            key = store.generateSymmetricKey(getALString(), null);
        } else {
            freshStart = false;

            key = store.getSymmetricKey(getALString(), null);
        }

The above code get called on: public class MyApplication extends MultiDexApplication

Appreciate the help.

getCertificate(alias) returns null

Hello, this is the full error stack. The exception is thrown from android 8.1.0 device.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.security.PublicKey java.security.cert.Certificate.getPublicKey()' on a null object reference
       at com.yakivmospan.scytale.Store.getAsymmetricKeyFromAndroidKeyStore(Store.java:17)
       at com.yakivmospan.scytale.Store.getAsymmetricKey(Store.java:11)
       at br.com.***.library.securemobiletoken.KeystoreUtils.encryptString(KeystoreUtils.java:21)
       at br.com.***.library.securemobiletoken.SecureMobileToken.setBalance(SecureMobileToken.java:29)
       at br.com.***.***.fragments.wallet.prepaid.FragmentWallet.firebaseAction(FragmentWallet.java:397)
       at br.com.***.***.fragments.wallet.prepaid.FragmentWallet.access$300(FragmentWallet.java)
       at br.com.***.***.fragments.wallet.prepaid.FragmentWallet$3.onDataChange(FragmentWallet.java:44)
       at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:13)
       at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:2)
       at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:63)
       at android.os.Handler.handleCallback(Handler.java:790)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6647)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

Is this a bug? Thanks in advance.

Multiparty encryption

Not so much an issue as a feature query, hope this is ok. Would it be possible to perform multiparty encryption/decryption i.e. encrypt a file with AES shared key and encrypt this key with multiple public RSA keys?

Like in openssl, please find example below.

openssl smime -encrypt -aes256 -in secrets.txt -out secrets.txt.enc -outform PEM bob.pub alice.pub frank.pub carol.pub

The recipients could just use their private keys to decrypt like maybe:

openssl smime -decrypt -in secrets.txt.enc -inform PEM -inkey alice.key

Any hints very much appreciated! thanks

not picking up a stored key.. heres the code

 Toast.makeText(getApplicationContext(), pinview.getValue(), Toast.LENGTH_LONG).show();
            String pin = "78454";

            SecretKey key;

            if (pinview.getValue().equals(pin)) {

                // New Install - got geninstall Activity to get new PIN confirm &
                // obtain a new HH account
                //
                // with an option to generate new account and key from platform 0.0.8660 account

                key = store.generateSymmetricKey("78454", null);

                // openActivityinstallacc();

            } else {

                // check to see if pin and keys in store, if so then open wallet
                // and get existing account and key

                if (store.hasKey("78454"))
                {
                    openActivityhbal();
                }

** I create the key 78454 and put it to store ... then on re-opening app.. doesnt find 78454 in the store

getAsymmetricKeyFromAndroidKeyStore NullPointerException

I get this error frequently. Is there any update for that?
Thanks!

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.security.PublicKey java.security.cert.Certificate.getPublicKey()' on a null object reference at com.yakivmospan.scytale.Store.getAsymmetricKeyFromAndroidKeyStore(Store.java:491) at com.yakivmospan.scytale.Store.getAsymmetricKey(Store.java:177)

I get a crash from fabric, but i can't reproduced it.

Caused by android.security.keystore.KeyStoreConnectException: Failed to communicate with keystore service
       at android.security.keystore.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized + 256(AndroidKeyStoreCipherSpiBase.java:256)
       at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineInit + 148(AndroidKeyStoreCipherSpiBase.java:148)
       at javax.crypto.Cipher.tryTransformWithProvider + 2980(Cipher.java:2980)
       at javax.crypto.Cipher.tryCombinations + 2891(Cipher.java:2891)
       at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider + 2796(Cipher.java:2796)
       at javax.crypto.Cipher.chooseProvider + 773(Cipher.java:773)
       at javax.crypto.Cipher.init + 1288(Cipher.java:1288)
       at javax.crypto.Cipher.init + 1223(Cipher.java:1223)

What happens when decryption fails?

It is not very clear what happens whenever a decryption fails. If I provide a wrongly encrypted data to the decrypt method then the decryption must fail, however, does this throws an error or simply returns null?

Document security settings (device-lock) quirks

If I understand correctly a keystore can become inaccessible if the user makes changes to device security settings. It may also be impossible to create a keystore if the devise is missing a proper security lock. It would be very helpful to explain this in the README page and maybe even provide some example code to check for those conditions. Let me know I can update the doc and submit a pull request.

Password is ignored in most cases

when generating key I can provide an additional password which is ignored in most cases. So annoying.... It should not be in the interface if it is not used.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.