Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 6649dd3

Browse files
author
Google
committed
Import BlackBerry source code and project files.
0 parents  commit 6649dd3

45 files changed

Lines changed: 6241 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.hgignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
mobile/blackberry/bin
2+
mobile/blackberry/build
3+
mobile/blackberry/release
4+
mobile/blackberry/local.properties
5+
mobile/blackberry/LogFile.txt
6+
mobile/blackberry/.settings
7+
mobile/blackberry/.project
8+
mobile/blackberry/.classpath
9+
mobile/blackberry/.tmp
10+
mobile/blackberry/com_google_authenticator.cod
11+
mobile/blackberry/com_google_authenticator.csl
12+
mobile/blackberry/com_google_authenticator.cso
13+
mobile/blackberry/com_google_authenticator.debug
14+
mobile/blackberry/com_google_authenticator.jad
15+
mobile/blackberry/com_google_authenticator.jar
16+
mobile/blackberry/com_google_authenticator.rapc
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## RIM Java Development Environment
2+
# RIM Project file
3+
#
4+
# This file is generated and managed by BlackBerry developer tools.
5+
# It SHOULD NOT BE modified manually.
6+
#
7+
AddOn=0
8+
AlwaysBuild=0
9+
[AlxImports
10+
]
11+
AutoRestart=0
12+
[ClassProtection
13+
]
14+
[CustomBuildFiles
15+
]
16+
[CustomBuildRules
17+
]
18+
[DefFiles
19+
]
20+
[DependsOn
21+
]
22+
ExcludeFromBuildAll=0
23+
[Files
24+
src\com\google\authenticator\blackberry\AccountDb.java
25+
src\com\google\authenticator\blackberry\AuthenticatorApplication.java
26+
src\com\google\authenticator\blackberry\AuthenticatorScreen.java
27+
src\com\google\authenticator\blackberry\Base32Legacy.java
28+
src\com\google\authenticator\blackberry\Base32String.java
29+
src\com\google\authenticator\blackberry\BufferedReader.java
30+
src\com\google\authenticator\blackberry\Build.java
31+
src\com\google\authenticator\blackberry\CheckCodeScreen.java
32+
src\com\google\authenticator\blackberry\EnterKeyScreen.java
33+
src\com\google\authenticator\blackberry\FieldUtils.java
34+
src\com\google\authenticator\blackberry\Html.java
35+
src\com\google\authenticator\blackberry\img\ic_lock_lock.png
36+
src\com\google\authenticator\blackberry\img\icon.png
37+
src\com\google\authenticator\blackberry\PasscodeGenerator.java
38+
src\com\google\authenticator\blackberry\PinListField.java
39+
src\com\google\authenticator\blackberry\PinListFieldCallback.java
40+
src\com\google\authenticator\blackberry\resource\Authenticator.rrc
41+
src\com\google\authenticator\blackberry\resource\Authenticator.rrh
42+
src\com\google\authenticator\blackberry\UpdateCallback.java
43+
src\com\google\authenticator\blackberry\UpdateTask.java
44+
src\com\google\authenticator\blackberry\Uri.java
45+
src\com\google\authenticator\blackberry\UriActiveFieldCookie.java
46+
src\com\google\authenticator\blackberry\UriActiveFieldCookieFactory.java
47+
src\com\google\authenticator\blackberry\UriMenuItem.java
48+
src\com\google\authenticator\blackberry\UriStringPattern.java
49+
src\com\google\authenticator\blackberry\URLEncoder.java
50+
src\org\bouncycastle\crypto\CipherParameters.java
51+
src\org\bouncycastle\crypto\DataLengthException.java
52+
src\org\bouncycastle\crypto\Digest.java
53+
src\org\bouncycastle\crypto\digests\GeneralDigest.java
54+
src\org\bouncycastle\crypto\digests\SHA1Digest.java
55+
src\org\bouncycastle\crypto\ExtendedDigest.java
56+
src\org\bouncycastle\crypto\Mac.java
57+
src\org\bouncycastle\crypto\macs\HMac.java
58+
src\org\bouncycastle\crypto\params\KeyParameter.java
59+
src\org\bouncycastle\crypto\RuntimeCryptoException.java
60+
src\org\bouncycastle\crypto\util\Pack.java
61+
]
62+
HaveAlxImports=0
63+
HaveDefs=0
64+
HaveImports=0
65+
[Icons
66+
]
67+
[ImplicitRules
68+
]
69+
[Imports
70+
]
71+
Listing=0
72+
Options=-quiet
73+
OutputFileName=GoogleAuthenticator
74+
[PackageProtection
75+
]
76+
RibbonPosition=0
77+
[RolloverIcons
78+
]
79+
RunOnStartup=0
80+
StartupTier=7
81+
SystemModule=0
82+
Type=0
83+
UserData=|src
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# For <application>
2+
id=com.google.authenticator
3+
name=Google Authenticator
4+
copyright=Copyright (C) 2010 Google Inc.
5+
6+
# For <jdp>
7+
title=Google Authenticator
8+
nameresourcebundle=com.google.authenticator.blackberry.resource.AuthenticatorResource
9+
nameresourceid=0
10+
type=cldc
11+
icon=icon.png
12+
13+
# For both
14+
description=
15+
vendor=Google, Inc.
16+
version=1.0.0

mobile/blackberry/entry/main.properties

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
systemmodule=true
2+
runonstartup=true
3+
arguments=startup
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
systemmodule=true
2+
arguments=uri
4.31 KB
Loading
1.4 KB
Loading
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
/*-
2+
* Copyright 2010 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.google.authenticator.blackberry;
18+
19+
import java.util.Hashtable;
20+
import java.util.Vector;
21+
22+
import com.google.authenticator.blackberry.resource.AuthenticatorResource;
23+
24+
import net.rim.device.api.i18n.ResourceBundle;
25+
import net.rim.device.api.system.CodeSigningKey;
26+
import net.rim.device.api.system.ControlledAccess;
27+
import net.rim.device.api.system.PersistentObject;
28+
import net.rim.device.api.system.PersistentStore;
29+
30+
/**
31+
* BlackBerry port of {@code AccountDb}.
32+
*/
33+
public class AccountDb {
34+
private static final String TABLE_NAME = "accounts";
35+
static final String ID_COLUMN = "_id";
36+
static final String EMAIL_COLUMN = "email";
37+
static final String SECRET_COLUMN = "secret";
38+
static final String COUNTER_COLUMN = "counter";
39+
static final String TYPE_COLUMN = "type";
40+
static final Integer TYPE_LEGACY_TOTP = new Integer(-1); // TODO: remove April 2010
41+
42+
private static final long PERSISTENT_STORE_KEY = 0x9f1343901e600bf7L;
43+
44+
static Hashtable sPreferences;
45+
46+
static PersistentObject sPersistentObject;
47+
48+
/**
49+
* Types of secret keys.
50+
*/
51+
public static class OtpType {
52+
private static ResourceBundle sResources = ResourceBundle.getBundle(
53+
AuthenticatorResource.BUNDLE_ID, AuthenticatorResource.BUNDLE_NAME);
54+
55+
public static final OtpType TOTP = new OtpType(0); // time based
56+
public static final OtpType HOTP = new OtpType(1); // counter based
57+
58+
private static final OtpType[] values = { TOTP, HOTP };
59+
60+
public final Integer value; // value as stored in database
61+
62+
OtpType(int value) {
63+
this.value = new Integer(value);
64+
}
65+
66+
public static OtpType getEnum(Integer i) {
67+
for (int index = 0; index < values.length; index++) {
68+
OtpType type = values[index];
69+
if (type.value.intValue() == i.intValue()) {
70+
return type;
71+
}
72+
}
73+
return null;
74+
}
75+
76+
public static OtpType[] values() {
77+
return values;
78+
}
79+
80+
/**
81+
* {@inheritDoc}
82+
*/
83+
public String toString() {
84+
if (this == TOTP) {
85+
return sResources.getString(AuthenticatorResource.TOTP);
86+
} else if (this == HOTP) {
87+
return sResources.getString(AuthenticatorResource.HOTP);
88+
} else {
89+
return super.toString();
90+
}
91+
}
92+
}
93+
94+
private AccountDb() {
95+
// Don't new me
96+
}
97+
98+
static {
99+
sPersistentObject = PersistentStore
100+
.getPersistentObject(PERSISTENT_STORE_KEY);
101+
if (sPersistentObject.getContents() == null) {
102+
sPreferences = new Hashtable(10);
103+
// Use an instance of a class owned by this application
104+
// to easily get the appropriate CodeSigningKey:
105+
Object appObject = new FieldUtils();
106+
CodeSigningKey codeSigningKey = CodeSigningKey.get(appObject);
107+
Object contents = new ControlledAccess(sPreferences, codeSigningKey);
108+
sPersistentObject.setContents(contents);
109+
sPersistentObject.commit();
110+
}
111+
sPreferences = (Hashtable) sPersistentObject.getContents();
112+
}
113+
114+
private static Vector getAccounts() {
115+
Vector accounts = (Vector) sPreferences.get(TABLE_NAME);
116+
if (accounts == null) {
117+
accounts = new Vector(10);
118+
sPreferences.put(TABLE_NAME, accounts);
119+
sPersistentObject.commit();
120+
}
121+
return accounts;
122+
}
123+
124+
private static Hashtable getAccount(String email) {
125+
if (email == null) {
126+
throw new NullPointerException();
127+
}
128+
Vector accounts = getAccounts();
129+
for (int i = 0, n = accounts.size(); i < n; i++) {
130+
Hashtable account = (Hashtable) accounts.elementAt(i);
131+
if (email.equals(account.get(EMAIL_COLUMN))) {
132+
return account;
133+
}
134+
}
135+
return null;
136+
}
137+
138+
static String[] getNames() {
139+
Vector accounts = getAccounts();
140+
int size = accounts.size();
141+
String[] names = new String[size];
142+
for (int i = 0; i < size; i++) {
143+
Hashtable account = (Hashtable) accounts.elementAt(i);
144+
names[i] = (String) account.get(EMAIL_COLUMN);
145+
}
146+
return names;
147+
}
148+
149+
static boolean nameExists(String email) {
150+
Hashtable account = getAccount(email);
151+
return account != null;
152+
}
153+
154+
static String getSecret(String email) {
155+
Hashtable account = getAccount(email);
156+
return account != null ? (String) account.get(SECRET_COLUMN) : null;
157+
}
158+
159+
static Integer getCounter(String email) {
160+
Hashtable account = getAccount(email);
161+
return account != null ? (Integer) account.get(COUNTER_COLUMN) : null;
162+
}
163+
164+
static void incrementCounter(String email) {
165+
Hashtable account = getAccount(email);
166+
if (account != null) {
167+
Integer counter = (Integer) account.get(COUNTER_COLUMN);
168+
counter = new Integer(counter.intValue() + 1);
169+
account.put(COUNTER_COLUMN, counter);
170+
sPersistentObject.commit();
171+
}
172+
}
173+
174+
static OtpType getType(String user) {
175+
Hashtable account = getAccount(user);
176+
if (account != null) {
177+
Integer value = (Integer) account.get(TYPE_COLUMN);
178+
return OtpType.getEnum(value);
179+
} else {
180+
return null;
181+
}
182+
}
183+
184+
static void delete(String email) {
185+
Vector accounts = getAccounts();
186+
boolean modified = false;
187+
for (int index = 0; index < accounts.size();) {
188+
Hashtable account = (Hashtable) accounts.elementAt(index);
189+
if (email.equals(account.get(EMAIL_COLUMN))) {
190+
accounts.removeElementAt(index);
191+
modified = true;
192+
} else {
193+
index++;
194+
}
195+
}
196+
if (modified) {
197+
sPersistentObject.commit();
198+
}
199+
}
200+
201+
/**
202+
* Save key to database, creating a new user entry if necessary.
203+
* @param email the user email address. When editing, the new user email.
204+
* @param secret the secret key.
205+
* @param oldEmail If editing, the original user email, otherwise null.
206+
*/
207+
static void update(String email, String secret, String oldEmail,
208+
AccountDb.OtpType type) {
209+
Hashtable account = oldEmail != null ? getAccount(oldEmail) : null;
210+
if (account == null) {
211+
account = new Hashtable(10);
212+
Vector accounts = getAccounts();
213+
accounts.addElement(account);
214+
}
215+
account.put(EMAIL_COLUMN, email);
216+
account.put(SECRET_COLUMN, secret);
217+
account.put(TYPE_COLUMN, type.value);
218+
if (!account.containsKey(COUNTER_COLUMN)) {
219+
account.put(COUNTER_COLUMN, new Integer(0));
220+
}
221+
sPersistentObject.commit();
222+
}
223+
}

0 commit comments

Comments
 (0)