summaryrefslogtreecommitdiff
path: root/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/ui/model/IKeyStore.java
blob: 53dcc5e20e1be9b1fcce94aa7bdc594e0da3cb50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.motorolamobility.studio.android.certmanager.ui.model;

import java.io.File;
import java.security.KeyStore;
import java.util.Date;
import java.util.List;

import com.motorolamobility.studio.android.certmanager.core.PasswordProvider;
import com.motorolamobility.studio.android.certmanager.exception.InvalidPasswordException;
import com.motorolamobility.studio.android.certmanager.exception.KeyStoreManagerException;

public interface IKeyStore
{

    public int KEYSTORE_PASSWORD_MIN_SIZE = 6;

    public int WRONG_KEYSTORE_TYPE_ERROR_CODE = 1;

    PasswordProvider getPasswordProvider();

    List<String> getAliases(String password) throws KeyStoreManagerException,
            InvalidPasswordException;

    /**
     * Returns the {@link KeyStore}
     * @throws KeyStoreManagerException
     */
    KeyStore getKeyStore() throws KeyStoreManagerException;

    /**
     * Load if needed and returns all entries for this KeyStore
     * @param password
     * @return
     * @throws KeyStoreManagerException 
     * @throws InvalidPasswordException 
     */
    List<IKeyStoreEntry> getEntries(String password) throws KeyStoreManagerException,
            InvalidPasswordException;

    /**
     * Load if needed and returns the entry with the given alias.
     * @param alias The alias of the desired entry. 
     * @param keystorePassword the password of the keystore
     * @return The desired entry.
     * @throws KeyStoreManagerException 
     * @throws InvalidPasswordException 
     */
    IKeyStoreEntry getEntry(String alias, String keystorePassword) throws KeyStoreManagerException,
            InvalidPasswordException;

    /**
     * @param password from keystore
     * Forces keystore reload
     * @throws KeyStoreManagerException
     * @throws InvalidPasswordException
     */
    void forceReload(char[] charArray, boolean updateUi) throws KeyStoreManagerException,
            InvalidPasswordException;

    /**
     * Returns this key store file
     * @return
     */
    File getFile();

    /**
     * @return this keystore type
     */
    String getType();

    /**
     * Set this keystore type. This is intended to be used only during creation. 
     * This method won't change the keystore type or convert it to another type.
     * @param type
     * @throws KeyStoreManagerException 
     */
    void setType(String type) throws KeyStoreManagerException;

    /**
     * Set the backup date for this keystore
     * @param lastBackupDate
     */
    void setLastBackupDate(Date lastBackupDate);

    /**
     * Gets the last backup date for this keystore
     * @return null if not backed up yet, a date otherwise
     */
    Date getLastBackupDate();

    /**
     * Deletes a key entry with the given alias
     * @param alias The alias representing the key to be removed.
     * @throws KeyStoreManagerException
     */
    void removeKey(String alias) throws KeyStoreManagerException;

    /**
     * Deletes a list of key entries from the keystore.
     * @param aliases The list of aliases representing the keys to be removed.
     * @throws KeyStoreManagerException
     */
    void removeKeys(List<String> aliases) throws KeyStoreManagerException;

    /**
     * @param password
     */
    public boolean isPasswordValid(String password) throws KeyStoreManagerException,
            InvalidPasswordException;

    /**
     * Return the password of the keystore.
     * If the password is not saved and {@code promptPassword} is set to {@code true}, then a dialog will be opened so the user can enter the password. 
     * @return Return the password of the keystore.
     */
    String getKeyStorePassword(boolean promptPassword);
}