Skip to content

Commit 774bf4f

Browse files
author
James Stapleton
committed
Fixed hmac stacktrace on empty password, Allow multiple accounts to have url parts, not requiring it to be the default. Added a add all favorites.
1 parent f330bf5 commit 774bf4f

File tree

9 files changed

+231
-161
lines changed

9 files changed

+231
-161
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.passwordmaker</groupId>
88
<artifactId>passwordmaker-je-lib</artifactId>
9-
<version>0.9.3</version>
9+
<version>0.9.4</version>
1010

1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/org/daveware/passwordmaker/Account.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public static String createId() {
186186
*/
187187
public static String createId(String str)
188188
throws Exception {
189-
MessageDigest digest = MessageDigest.getInstance("SHA1", "BC");
189+
MessageDigest digest = MessageDigest.getInstance("SHA1", PasswordMaker.getDefaultCryptoProvider());
190190
return "rdf:#$" + byteArrayToHexString(digest.digest(str.getBytes()));
191191
}
192192

src/main/java/org/daveware/passwordmaker/AccountManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import org.daveware.passwordmaker.util.Joiner;
44
import org.daveware.passwordmaker.util.Splitter;
55

6-
import java.util.ArrayList;
7-
import java.util.Arrays;
8-
import java.util.List;
9-
import java.util.UUID;
6+
import java.util.*;
107
import java.util.concurrent.CopyOnWriteArrayList;
118

129
public class AccountManager implements DatabaseListener {
@@ -162,6 +159,10 @@ public void addFavoriteUrl(String url) {
162159
favoriteUrls.add(url);
163160
}
164161

162+
public void addFavoriteUrls(Collection<String> urls) {
163+
favoriteUrls.addAll(urls);
164+
}
165+
165166
public void removeFavoriteUrl(String url) {
166167
favoriteUrls.remove(url);
167168
}

src/main/java/org/daveware/passwordmaker/PasswordMaker.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private static Account createVerificationAccount() {
5454
public static void setDefaultCryptoProvider(String provider) {
5555
CRYPTO_PROVIDER = provider;
5656
}
57+
public static String getDefaultCryptoProvider() { return CRYPTO_PROVIDER; };
5758

5859
/**
5960
* Calculates the strength of a password.
@@ -287,6 +288,12 @@ public final String getModifiedInputText(final String inputText, final Account a
287288
*/
288289
public SecureCharArray makePassword(SecureCharArray masterPassword, Account account, final String inputText)
289290
throws Exception {
291+
292+
// HMAC algorithm requires a key that is >0 length.
293+
if ( account.isHmac() && masterPassword.length() == 0 ) {
294+
return new SecureCharArray();
295+
}
296+
290297
LeetLevel leetLevel = account.getLeetLevel();
291298
//int count = 0;
292299
int length = account.getLength();

src/main/java/org/daveware/passwordmaker/RDFDatabaseReader.java

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -279,28 +279,19 @@ private Account readAccountFromDescriptionNode(Element element)
279279
account.setSuffix(element.getAttribute("NS1:suffix").trim());
280280
account.setAutoPop(element.getAttribute("NS1:autoPopulate").trim().compareTo("true") == 0);
281281

282-
// TODO: should preserve this, but I don't care much to
283-
// I'm fairly sure I don't need this. I think this stores the tab index
284-
// of the last time you edited this account.
285-
//String selectedTabIndex = element.getAttribute("NS1:selectedTabIndex").trim();
286-
287282
// Read the URL extraction specifiers
288-
if (account.isDefault()) {
289-
account.clearUrlComponents();
290-
if (element.getAttribute("NS1:protocolCB").trim().compareToIgnoreCase("true") == 0)
291-
account.addUrlComponent(Account.UrlComponents.Protocol);
292-
if (element.getAttribute("NS1:subdomainCB").trim().compareToIgnoreCase("true") == 0)
293-
account.addUrlComponent(Account.UrlComponents.Subdomain);
294-
if (element.getAttribute("NS1:domainCB").trim().compareToIgnoreCase("true") == 0)
295-
account.addUrlComponent(Account.UrlComponents.Domain);
296-
if (element.getAttribute("NS1:pathCB").trim().compareToIgnoreCase("true") == 0)
297-
account.addUrlComponent(Account.UrlComponents.PortPathAnchorQuery);
298-
} else {
299-
// Otherwise use the URL stored with the node
300-
account.setUrl(element.getAttribute("NS1:urlToUse").trim());
301-
}
302-
303-
// pattern info... I really hope nobody has more than 100000
283+
account.clearUrlComponents();
284+
if (element.getAttribute("NS1:protocolCB").trim().compareToIgnoreCase("true") == 0)
285+
account.addUrlComponent(Account.UrlComponents.Protocol);
286+
if (element.getAttribute("NS1:subdomainCB").trim().compareToIgnoreCase("true") == 0)
287+
account.addUrlComponent(Account.UrlComponents.Subdomain);
288+
if (element.getAttribute("NS1:domainCB").trim().compareToIgnoreCase("true") == 0)
289+
account.addUrlComponent(Account.UrlComponents.Domain);
290+
if (element.getAttribute("NS1:pathCB").trim().compareToIgnoreCase("true") == 0)
291+
account.addUrlComponent(Account.UrlComponents.PortPathAnchorQuery);
292+
account.setUrl(element.getAttribute("NS1:urlToUse").trim());
293+
294+
// pattern info... I really hope nobody has more than 100000(MAX_PATTERNS)
304295
for (int iPattern = 0; iPattern < MAX_PATTERNS; ++iPattern) {
305296
String pattern = element.getAttribute("NS1:pattern" + iPattern).trim();
306297
String patternType = element.getAttribute("NS1:patterntype" + iPattern).trim();
@@ -315,7 +306,7 @@ private Account readAccountFromDescriptionNode(Element element)
315306
data.setDesc(patternDesc);
316307
account.getPatterns().add(data);
317308
} else {
318-
iPattern = 999999;
309+
iPattern = MAX_PATTERNS + 1;
319310
}
320311
}
321312
}

src/main/java/org/daveware/passwordmaker/RDFDatabaseWriter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,17 @@ private void writeDescription(Account account, XmlStreamWriter writer)
156156
writer.writeAttribute("NS1:autoPopulate", "false"); // TODO: make this a setting allowed in accounts
157157

158158
// The default account contains specifiers for extracting pieces of an URL
159-
if (account.isDefault()) {
160-
Set<Account.UrlComponents> urlComponents = account.getUrlComponents();
159+
Set<Account.UrlComponents> urlComponents = account.getUrlComponents();
160+
// only write out any of them, if atleast one is set to true
161+
if ( ! urlComponents.isEmpty() ) {
161162
writer.writeAttribute("NS1:protocolCB", urlComponents.contains(Account.UrlComponents.Protocol) ? "true" : "false");
162163
writer.writeAttribute("NS1:subdomainCB", urlComponents.contains(Account.UrlComponents.Subdomain) ? "true" : "false");
163164
writer.writeAttribute("NS1:domainCB", urlComponents.contains(Account.UrlComponents.Domain) ? "true" : "false");
164165
writer.writeAttribute("NS1:pathCB", urlComponents.contains(Account.UrlComponents.PortPathAnchorQuery) ? "true" : "false");
165-
} else {
166-
// The non-default accounts store the URL
167-
writer.writeAttribute("NS1:urlToUse", account.getUrl());
168166
}
167+
// only write out urlToUse if its set, or if no url components are set.
168+
if ( urlComponents.isEmpty() || ! account.getUrl().isEmpty() )
169+
writer.writeAttribute("NS1:urlToUse", account.getUrl());
169170

170171
int patternCount = 0;
171172
for (AccountPatternData data : account.getPatterns()) {

0 commit comments

Comments
 (0)