Static Public Member Functions | Static Private Attributes

crypto.CipherEngine Class Reference

Common ciphering engine (for the whole application) providing: More...

Collaboration diagram for crypto.CipherEngine:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static String getPrivateKeyDirectory ()
 Returns path to the directory holding our private key.
static String getSignedPublicKey ()
 Returns serialized signed public key (used for encryption of datagrams) as Base64 string.
static String getNamedPublicKey ()
 Returns serialized named public key encoded as Base64 string.
static SymmetricCipher getCipher ()
 Returns local symmetric ciphering engine.
static SignedObject getSignedSecretKey ()
 Returns secret key signed with our private key.
static SymmetricCipher deserializeEncryptedSecretKey (String encryptedSecret)
 Reconstructs secret key from Base64 respresentation of encrypted (using our public key) serialized secret key and verifies signature of the remote peer.
static void initialize ()
 Loads authorized public keys and initializes asymmetric and symmetric ciphering engines, where:
static void reloadAuthorizedPublicKeys ()
 Reloads only authorized public keys.
static boolean generateNewSecret (String algorithm, int keySize, boolean verbose)
 Generates new symmetric secret key.

Static Private Attributes

static AsymmetricCipher privateCipher = null
 Asymmetric cipher used to encrypt secret keys.
static final String myCipherAlgorithm = "Blowfish"
 The default cipher algorithm for data (PDUs and secret chat messages)
static final int myCipherKeySize = 32
 The default key size for cipher algorithm.
static final String defaultPrivateKeyDirectory = ".mykf"
 Subdirectory of the user.home where private key is stored.
static String myPrivateKeyPath = ""
 Full path of the directory holding our private key.
static SymmetricCipher myPduCipher = null
 Symmetric cipher used to encrypt data (PDUs and secret chat messages)

Detailed Description

Common ciphering engine (for the whole application) providing:

Definition at line 22 of file CipherEngine.java.


Member Function Documentation

static SymmetricCipher crypto.CipherEngine.deserializeEncryptedSecretKey ( String  encryptedSecret ) [static]

Reconstructs secret key from Base64 respresentation of encrypted (using our public key) serialized secret key and verifies signature of the remote peer.

Definition at line 112 of file CipherEngine.java.

References crypto.AsymmetricCipher.deserializeEncryptedSecretKey(), and crypto.CipherEngine.privateCipher.

Referenced by CryptoPhoneApp.deferredOnAccept().

    {
        if ( privateCipher == null ) {
            return null;
        }
        
        return privateCipher.deserializeEncryptedSecretKey( encryptedSecret );
    }
static boolean crypto.CipherEngine.generateNewSecret ( String  algorithm,
int  keySize,
boolean  verbose 
) [static]

Generates new symmetric secret key.

Returns:
true if generated cipher may be used (i.e. false in case of error)

Definition at line 219 of file CipherEngine.java.

References crypto.SymmetricCipher.isActive(), crypto.CipherEngine.myCipherAlgorithm, crypto.CipherEngine.myCipherKeySize, and crypto.CipherEngine.myPduCipher.

Referenced by CryptoPhoneApp.executeCommand().

    {
        if ( algorithm == null || algorithm.isEmpty () ) {
            algorithm = myCipherAlgorithm;
        }

        if ( keySize <= 0 ) {
            keySize = myCipherKeySize;
        }

        myPduCipher = new SymmetricCipher( algorithm, keySize, verbose );
        
        return myPduCipher.isActive ();
    }
static SymmetricCipher crypto.CipherEngine.getCipher (  ) [static]

Returns local symmetric ciphering engine.

Definition at line 90 of file CipherEngine.java.

References crypto.CipherEngine.myPduCipher.

Referenced by CryptoPhoneApp.acceptIncomingCall().

    {
        return myPduCipher;
    }
static String crypto.CipherEngine.getNamedPublicKey (  ) [static]

Returns serialized named public key encoded as Base64 string.

Definition at line 78 of file CipherEngine.java.

References crypto.AsymmetricCipher.getNamedPublicKey(), and crypto.CipherEngine.privateCipher.

Referenced by CryptoPhoneApp.executeCommand().

    {
        if ( privateCipher == null ) {
            return null;
        }
        
        return privateCipher.getNamedPublicKey ();
    }
static String crypto.CipherEngine.getPrivateKeyDirectory (  ) [static]
static String crypto.CipherEngine.getSignedPublicKey (  ) [static]

Returns serialized signed public key (used for encryption of datagrams) as Base64 string.

Definition at line 66 of file CipherEngine.java.

References crypto.AsymmetricCipher.getSerializedAndSignedPublicKey(), and crypto.CipherEngine.privateCipher.

Referenced by CryptoPhoneApp.deferredOnInvite(), and CryptoPhoneApp.executeCommand().

    {
        if ( privateCipher == null ) {
            return null;
        }
        
        return privateCipher.getSerializedAndSignedPublicKey ();
    }
static SignedObject crypto.CipherEngine.getSignedSecretKey (  ) [static]

Returns secret key signed with our private key.

Definition at line 98 of file CipherEngine.java.

References crypto.SymmetricCipher.getSecretKey(), crypto.CipherEngine.myPduCipher, crypto.CipherEngine.privateCipher, and crypto.AsymmetricCipher.signObject().

Referenced by CryptoPhoneApp.acceptIncomingCall().

    {
        if ( privateCipher == null ) {
            return null;
        }
        
        return privateCipher.signObject( myPduCipher.getSecretKey () );
    }
static void crypto.CipherEngine.initialize (  ) [static]

Loads authorized public keys and initializes asymmetric and symmetric ciphering engines, where:

  • Asymmetric ciphering is used for verification and encryption/decryption of secret key used in symmetric ciphering.
  • Symmetric ciphering is used for encryption/decryption of PDUs and secret chat text messages.

Initialization is non-blocking and performed in separate worker thread.

Definition at line 132 of file CipherEngine.java.

References crypto.CipherEngine.defaultPrivateKeyDirectory, crypto.PublicEncryptor.loadAuthorizedPublicKeys(), crypto.CipherEngine.myCipherAlgorithm, crypto.CipherEngine.myCipherKeySize, crypto.CipherEngine.myPduCipher, crypto.CipherEngine.myPrivateKeyPath, and crypto.CipherEngine.privateCipher.

Referenced by CryptoPhoneApp.CryptoPhoneApp().

    {
        /* Create directory that will hold private key. Also change permissions using 
         * native OS 'chmod' command (ignoring Windows), so that no one but the 
         * owner might read its contents.
         */
        try
        {
            myPrivateKeyPath = "";
            
            String dirPath = System.getProperty( "user.home" )
                           + System.getProperty( "file.separator" )
                           + defaultPrivateKeyDirectory;

            File directory = new File( dirPath );

            if (  ! directory.exists () ) {
                directory.mkdir ();
            }

            if (  directory.exists () )
            {
                myPrivateKeyPath = dirPath + System.getProperty( "file.separator" );
                
                String osName = System.getProperty( "os.name" ).toLowerCase();
                if ( ! osName.matches( "^.*windows.*$" ) ) 
                {
                    try 
                    {
                        Runtime.getRuntime().exec( new String[] { "chmod", "go=", dirPath } );
                    }
                    catch( IOException e ) 
                    {
                        Log.trace( "Failed to do chmod; OS = " + osName );
                        Log.exception( Log.TRACE, e );
                    }
                }
            }
        }
        catch( Exception e )
        {
            Log.exception( Log.ERROR, e );
        }
            
        Log.trace( "Private Key directory: " + myPrivateKeyPath );

        /* Initialize (load or generate) private/public keys and
         * generate secret key in worker thread, then load authorized public keys. 
         */
        Runnable nonBlockingInitThread = new Runnable () 
        {
            @Override
            public void run() 
            {
                /* Instantiate our ciphers first...
                 */
                if ( myPduCipher == null ) {
                    myPduCipher = new SymmetricCipher( 
                            myCipherAlgorithm, myCipherKeySize, /*report*/ false );
                }

                if ( privateCipher == null ) {
                    privateCipher = new AsymmetricCipher ();
                }
                
                /* ...then load authorized public keys
                 */
                PublicEncryptor.loadAuthorizedPublicKeys ();
            }
        };

        ( new Thread( nonBlockingInitThread, "CipherEngine" ) ).start ();
    }
static void crypto.CipherEngine.reloadAuthorizedPublicKeys (  ) [static]

Reloads only authorized public keys.

Definition at line 209 of file CipherEngine.java.

References crypto.PublicEncryptor.loadAuthorizedPublicKeys().

Referenced by CryptoPhoneApp.executeCommand().

    {
        PublicEncryptor.loadAuthorizedPublicKeys ();
    }

Member Data Documentation

final String crypto.CipherEngine.defaultPrivateKeyDirectory = ".mykf" [static, private]

Subdirectory of the user.home where private key is stored.

Definition at line 42 of file CipherEngine.java.

Referenced by crypto.CipherEngine.initialize().

final String crypto.CipherEngine.myCipherAlgorithm = "Blowfish" [static, private]

The default cipher algorithm for data (PDUs and secret chat messages)

Definition at line 32 of file CipherEngine.java.

Referenced by crypto.CipherEngine.generateNewSecret(), and crypto.CipherEngine.initialize().

final int crypto.CipherEngine.myCipherKeySize = 32 [static, private]

The default key size for cipher algorithm.

Definition at line 37 of file CipherEngine.java.

Referenced by crypto.CipherEngine.generateNewSecret(), and crypto.CipherEngine.initialize().

Symmetric cipher used to encrypt data (PDUs and secret chat messages)

Definition at line 52 of file CipherEngine.java.

Referenced by crypto.CipherEngine.generateNewSecret(), crypto.CipherEngine.getCipher(), crypto.CipherEngine.getSignedSecretKey(), and crypto.CipherEngine.initialize().

String crypto.CipherEngine.myPrivateKeyPath = "" [static, private]

Full path of the directory holding our private key.

Definition at line 47 of file CipherEngine.java.

Referenced by crypto.CipherEngine.getPrivateKeyDirectory(), and crypto.CipherEngine.initialize().


The documentation for this class was generated from the following file: