Ignore:
Timestamp:
01/31/19 16:34:06 (5 years ago)
Author:
bln4
Message:

org.expeditee.auth.EncryptedExpReader ->
org.expeditee.auth.EncryptedExpWriter ->
Actions ->
AttributeUtils ->
Frame ->
FrameIO ->
UserSettings ->

Changed how reading and writing encrypted files worked. A Frame attribute is now consulted to determine what to use as key for encryption. The 'profile' attribute setting is used to signal that the users personal aes key is used. Further enhancement will mean that other labels will be able to be used.


Actions ->

MailMode action now consults the database to reaquire the mail.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/auth/EncryptedExpWriter.java

    r1226 r1227  
    1919import org.ngikm.cryptography.CryptographyConstants;
    2020
    21 public class EncryptedProfileExpWriter extends ExpWriter implements CryptographyConstants {
    22         private SecretKey personalKey;
     21public class EncryptedExpWriter extends ExpWriter implements CryptographyConstants {
     22        private SecretKey key;
     23        private String label;
    2324        private static final String nl = "\n";
    2425       
    25         public EncryptedProfileExpWriter() throws IOException {
    26                 // obtain personal key
    27                 final Text text = KeyList.PersonalKey.get();
    28                 final byte[] keyBytes = Base64.getDecoder().decode(text.getData().get(0));
    29                 personalKey = new SecretKeySpec(keyBytes, SymmetricAlgorithm);         
     26        public EncryptedExpWriter(String encryptionLabel) throws IOException {
     27                if (encryptionLabel.compareTo("Profile") == 0) {
     28                        // obtain personal key
     29                        Text text = KeyList.PersonalKey.get();
     30                        byte[] keyBytes = Base64.getDecoder().decode(text.getData().get(0));
     31                        key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
     32                        label = "Profile";
     33                } else {
     34                        byte[] keyBytes = resolveKeyFromLabel(encryptionLabel);
     35                        key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
     36                        label = encryptionLabel;
     37                }
    3038        }
    3139
     
    3341        protected void preOutputFrame() {
    3442                try {
    35                         final String line = EncryptedExpReader.ENCRYPTED_EXP_FLAG + nl;
     43                        String line = EncryptedExpReader.ENCRYPTED_EXP_FLAG + label + nl;
    3644                        _writer.write(line);
    3745                        _stringWriter.append(line);
     
    4755               
    4856                // prepare line to write out
    49                 final byte[] encrypted = EncryptSymmetric(line.getBytes(), personalKey);
    50                 final String toWrite = Base64.getEncoder().encodeToString(encrypted) + nl;
     57                byte[] encrypted = EncryptSymmetric(line.getBytes(), key);
     58                String toWrite = Base64.getEncoder().encodeToString(encrypted) + nl;
    5159               
    5260                // output
     
    5563        }
    5664       
    57         private static byte[] EncryptSymmetric(final byte[] toEncrypt, final SecretKey key) {
     65        private byte[] resolveKeyFromLabel(String label) {
     66                return null;
     67        }
     68       
     69        private static byte[] EncryptSymmetric(byte[] toEncrypt, SecretKey key) {
    5870                try {
    59                         final Cipher cipher = Cipher.getInstance(SymmetricAlgorithm + SymmetricAlgorithmParameters);
     71                        Cipher cipher = Cipher.getInstance(SymmetricAlgorithm + SymmetricAlgorithmParameters);
    6072                        cipher.init(Cipher.ENCRYPT_MODE, key);
    6173                        //could use modulus
    62                         final int length = (int) ((Math.ceil(toEncrypt.length / 16f)) * 16);
    63                         final byte[] toEncryptSizeAdjusted = Arrays.copyOf(toEncrypt, length);
    64                         final byte[] result = cipher.doFinal(toEncryptSizeAdjusted);
     74                        int length = (int) ((Math.ceil(toEncrypt.length / 16f)) * 16);
     75                        byte[] toEncryptSizeAdjusted = Arrays.copyOf(toEncrypt, length);
     76                        byte[] result = cipher.doFinal(toEncryptSizeAdjusted);
    6577                        return result;
    6678                } catch (final NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
Note: See TracChangeset for help on using the changeset viewer.