Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fd3dd9d
Adding the sync APIs for FirebaseAuth
hiranya911 Feb 22, 2018
ac3453b
Added more tests; Added sync APIs for FirebaseMessaging
hiranya911 Feb 22, 2018
ded167e
Removing Task references from database, iid and fcm APIs
hiranya911 Feb 22, 2018
765f209
Fixing a typo
hiranya911 Feb 26, 2018
01ce79e
Minor code clean up
hiranya911 Mar 1, 2018
3913688
Merged with master (auth unit test improvements)
hiranya911 Mar 2, 2018
d5ec1c3
Updated javadocs; Renamed internal helpers of FirebaseMessaging for c…
hiranya911 Mar 8, 2018
f8f33b4
Removed the deprecated FirebaseCredential API (#149)
hiranya911 Mar 9, 2018
27eddb6
Removing the Task API (#152)
hiranya911 Mar 12, 2018
edd825e
Dropping Support for App Engine Java 7 Runtime (#153)
hiranya911 Mar 20, 2018
559ce44
Removing Deprecated LogWrapper API (#154)
hiranya911 Mar 23, 2018
3979c02
Merged with master
hiranya911 Mar 29, 2018
ef036bb
merged with master
hiranya911 Apr 14, 2018
0523bf3
Initial code for the importUsers() API
hiranya911 Apr 18, 2018
0db88c5
Added documentation and more tests
hiranya911 Apr 19, 2018
fe3cc03
Added integration tests; Scrypt hash; more documentation
hiranya911 Apr 19, 2018
46e51ab
Added more tests
hiranya911 Apr 19, 2018
5ede505
Merge branch 'master' into v6
hiranya911 Apr 19, 2018
efc9016
updated test
hiranya911 Apr 24, 2018
dbc1492
Merged with master
hiranya911 May 3, 2018
0633d37
Merged with v6
hiranya911 May 4, 2018
2514703
Adding other hash types
hiranya911 May 4, 2018
ebe905c
Added the remaining hash algorithms
hiranya911 May 4, 2018
1182576
Renamed to ImportUserRecord
hiranya911 May 4, 2018
421a86c
Updated documentation
hiranya911 May 5, 2018
7b085df
Merged with master
hiranya911 May 8, 2018
501faf8
Some minor cleanup
hiranya911 May 8, 2018
dccc454
Updated documentation
hiranya911 May 11, 2018
a4cf116
Updated documentation; Made hash required in UserImportOptions; Other…
hiranya911 May 17, 2018
9130ab2
Renamed BasicHash to RepeatableHash; Made rounds range test configurable
hiranya911 May 22, 2018
3f30183
Added javadoc comment
hiranya911 May 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/google/firebase/auth/hash/Md5.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
* Represents the MD5 password hashing algorithm. Can be used as an instance of
* {@link com.google.firebase.auth.UserImportHash} when importing users.
*/
public class Md5 extends BasicHash {
public class Md5 extends RepeatableHash {

private Md5(Builder builder) {
super("MD5", builder);
super("MD5", 0, 120000, builder);
}

public static Builder builder() {
return new Builder();
}

public static class Builder extends BasicHash.Builder<Builder, Md5> {
public static class Builder extends RepeatableHash.Builder<Builder, Md5> {

private Builder() {}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/google/firebase/auth/hash/Pbkdf2Sha256.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
* Represents the PBKDF2 SHA256 password hashing algorithm. Can be used as an instance of
* {@link com.google.firebase.auth.UserImportHash} when importing users.
*/
public class Pbkdf2Sha256 extends BasicHash {
public class Pbkdf2Sha256 extends RepeatableHash {

private Pbkdf2Sha256(Builder builder) {
super("PBKDF2_SHA256", builder);
super("PBKDF2_SHA256", 0, 120000, builder);
}

public static Builder builder() {
return new Builder();
}

public static class Builder extends BasicHash.Builder<Builder, Pbkdf2Sha256> {
public static class Builder extends RepeatableHash.Builder<Builder, Pbkdf2Sha256> {

private Builder() {}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/google/firebase/auth/hash/PbkdfSha1.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
* Represents the PBKDF SHA1 password hashing algorithm. Can be used as an instance of
* {@link com.google.firebase.auth.UserImportHash} when importing users.
*/
public class PbkdfSha1 extends BasicHash {
public class PbkdfSha1 extends RepeatableHash {

private PbkdfSha1(Builder builder) {
super("PBKDF_SHA1", builder);
super("PBKDF_SHA1", 0, 120000, builder);
}

public static Builder builder() {
return new Builder();
}

public static class Builder extends BasicHash.Builder<Builder, PbkdfSha1> {
public static class Builder extends RepeatableHash.Builder<Builder, PbkdfSha1> {

private Builder() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
import com.google.firebase.auth.UserImportHash;
import java.util.Map;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a short class comment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

abstract class BasicHash extends UserImportHash {
abstract class RepeatableHash extends UserImportHash {

private final int rounds;

BasicHash(String name, Builder builder) {
RepeatableHash(String name, int min, int max, Builder builder) {
super(name);
checkArgument(builder.rounds >= 0 && builder.rounds <= 120000,
"Rounds value must be between 0 and 120000 (inclusive).");
checkArgument(builder.rounds >= min && builder.rounds <= max,
"Rounds value must be between %s and %s (inclusive).", min, max);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this "%d".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.rounds = builder.rounds;
}

@Override
protected final Map<String, Object> getOptions() {
protected Map<String, Object> getOptions() {
return ImmutableMap.<String, Object>of("rounds", rounds);
}

Expand Down
39 changes: 14 additions & 25 deletions src/main/java/com/google/firebase/auth/hash/Scrypt.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.io.BaseEncoding;
import com.google.firebase.auth.UserImportHash;
import java.util.Map;

/**
Expand All @@ -29,18 +28,16 @@
* Firebase Auth. See {@link StandardScrypt} for the standard Scrypt algorithm. Can be used as an
* instance of {@link com.google.firebase.auth.UserImportHash} when importing users.
*/
public final class Scrypt extends UserImportHash {
public final class Scrypt extends RepeatableHash {

private final String key;
private final String saltSeparator;
private final int rounds;
private final int memoryCost;

private Scrypt(Builder builder) {
super("SCRYPT");
super("SCRYPT",0, 8, builder);
checkArgument(builder.key != null && builder.key.length > 0,
"A non-empty key is required for Scrypt");
checkArgument(builder.rounds > 0 && builder.rounds <= 8, "rounds must be between 1 and 8");
checkArgument(builder.memoryCost > 0 && builder.memoryCost <= 14,
"memoryCost must be between 1 and 14");
this.key = BaseEncoding.base64Url().encode(builder.key);
Expand All @@ -49,29 +46,27 @@ private Scrypt(Builder builder) {
} else {
this.saltSeparator = BaseEncoding.base64Url().encode(new byte[0]);
}
this.rounds = builder.rounds;
this.memoryCost = builder.memoryCost;
}

@Override
protected Map<String, Object> getOptions() {
return ImmutableMap.<String, Object>of(
"signerKey", key,
"rounds", rounds,
"memoryCost", memoryCost,
"saltSeparator", saltSeparator
);
return ImmutableMap.<String, Object>builder()
.putAll(super.getOptions())
.put("signerKey", key)
.put("memoryCost", memoryCost)
.put("saltSeparator", saltSeparator)
.build();
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
public static class Builder extends RepeatableHash.Builder<Builder, Scrypt> {

private byte[] key;
private byte[] saltSeparator;
private int rounds;
private int memoryCost;

private Builder() {}
Expand All @@ -98,17 +93,6 @@ public Builder setSaltSeparator(byte[] saltSeparator) {
return this;
}

/**
* Sets the number of rounds. Required field.
*
* @param rounds an integer between 1 and 8 (inclusive).
* @return this builder.
*/
public Builder setRounds(int rounds) {
this.rounds = rounds;
return this;
}

/**
* Sets the memory cost. Required field.
*
Expand All @@ -120,6 +104,11 @@ public Builder setMemoryCost(int memoryCost) {
return this;
}

@Override
protected Builder getInstance() {
return this;
}

public Scrypt build() {
return new Scrypt(this);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/google/firebase/auth/hash/Sha1.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
* Represents the SHA1 password hashing algorithm. Can be used as an instance of
* {@link com.google.firebase.auth.UserImportHash} when importing users.
*/
public class Sha1 extends BasicHash {
public class Sha1 extends RepeatableHash {

private Sha1(Builder builder) {
super("SHA1", builder);
super("SHA1", 0, 120000, builder);
}

public static Builder builder() {
return new Builder();
}

public static class Builder extends BasicHash.Builder<Builder, Sha1> {
public static class Builder extends RepeatableHash.Builder<Builder, Sha1> {

private Builder() {}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/google/firebase/auth/hash/Sha256.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
* Represents the SHA256 password hashing algorithm. Can be used as an instance of
* {@link com.google.firebase.auth.UserImportHash} when importing users.
*/
public class Sha256 extends BasicHash {
public class Sha256 extends RepeatableHash {

private Sha256(Builder builder) {
super("SHA256", builder);
super("SHA256", 0, 120000, builder);
}

public static Builder builder() {
return new Builder();
}

public static class Builder extends BasicHash.Builder<Builder, Sha256> {
public static class Builder extends RepeatableHash.Builder<Builder, Sha256> {

private Builder() {}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/google/firebase/auth/hash/Sha512.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
* Represents the SHA512 password hashing algorithm. Can be used as an instance of
* {@link com.google.firebase.auth.UserImportHash} when importing users.
*/
public class Sha512 extends BasicHash {
public class Sha512 extends RepeatableHash {

private Sha512(Builder builder) {
super("SHA512", builder);
super("SHA512", 0, 120000, builder);
}

public static Builder builder() {
return new Builder();
}

public static class Builder extends BasicHash.Builder<Builder, Sha512> {
public static class Builder extends RepeatableHash.Builder<Builder, Sha512> {

private Builder() {}

Expand Down
11 changes: 8 additions & 3 deletions src/test/java/com/google/firebase/auth/hash/InvalidHashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void testInvalidHmac() {
}

@Test
public void testInvalidBasic() {
List<BasicHash.Builder> builders = ImmutableList.<BasicHash.Builder>builder()
public void testInvalidRepeatableHash() {
List<RepeatableHash.Builder> builders = ImmutableList.<RepeatableHash.Builder>builder()
.add(Sha512.builder().setRounds(-1))
.add(Sha256.builder().setRounds(-1))
.add(Sha1.builder().setRounds(-1))
Expand All @@ -62,7 +62,7 @@ public void testInvalidBasic() {
.add(Pbkdf2Sha256.builder().setRounds(120001))
.add(PbkdfSha1.builder().setRounds(120001))
.build();
for (BasicHash.Builder builder : builders) {
for (RepeatableHash.Builder builder : builders) {
try {
builder.build();
fail("No error thrown for invalid rounds");
Expand All @@ -84,6 +84,11 @@ public void testInvalidScrypt() {
.setSaltSeparator(SALT_SEPARATOR)
.setRounds(9)
.setMemoryCost(14),
Scrypt.builder() // invalid rounds (< 0)
.setKey(SIGNER_KEY)
.setSaltSeparator(SALT_SEPARATOR)
.setRounds(-1)
.setMemoryCost(14),
Scrypt.builder() // invalid memory cost (> 15)
.setKey(SIGNER_KEY)
.setSaltSeparator(SALT_SEPARATOR)
Expand Down